mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 16:01:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
<p>The distance between two adjacent cells is <code>1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-1-grid.jpg" style="width: 253px; height: 253px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[0,0,0]]
|
||||
<strong>Output:</strong> [[0,0,0],[0,1,0],[0,0,0]]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-2-grid.jpg" style="width: 253px; height: 253px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[1,1,1]]
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<p>Given a binary array <code>bits</code> that ends with <code>0</code>, return <code>true</code> if the last character must be a one-bit character.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> bits = [1,0,0]
|
||||
@@ -17,7 +17,7 @@
|
||||
So the last character is one-bit character.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> bits = [1,1,1,0]
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<p>Given an array of <code>n</code> integers <code>nums</code>, a <strong>132 pattern</strong> is a subsequence of three integers <code>nums[i]</code>, <code>nums[j]</code> and <code>nums[k]</code> such that <code>i < j < k</code> and <code>nums[i] < nums[k] < nums[j]</code>.</p>
|
||||
<p>Given an array of <code>n</code> integers <code>nums</code>, a <strong>132 pattern</strong> is a subsequence of three integers <code>nums[i]</code>, <code>nums[j]</code> and <code>nums[k]</code> such that <code>i < j < k</code> and <code>nums[i] < nums[k] < nums[j]</code>.</p>
|
||||
|
||||
<p>Return <em><code>true</code> if there is a <strong>132 pattern</strong> in <code>nums</code>, otherwise, return <code>false</code>.</em></p>
|
||||
<p>Return <code>true</code><em> if there is a <strong>132 pattern</strong> in </em><code>nums</code><em>, otherwise, return </em><code>false</code><em>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> There is no 132 pattern in the sequence.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,1,4,2]
|
||||
@@ -19,7 +19,7 @@
|
||||
<strong>Explanation:</strong> There is a 132 pattern in the sequence: [1, 4, 2].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,3,2,0]
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<p>Given an integer <code>n</code>, return <em>the minimum number of operations to get the character</em> <code>'A'</code> <em>exactly</em> <code>n</code> <em>times on the screen</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3
|
||||
@@ -19,7 +19,7 @@ In step 2, we use Paste operation to get 'AA'.
|
||||
In step 3, we use Paste operation to get 'AAA'.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<p>Return <code>true</code> if you can get such expression that evaluates to <code>24</code>, and <code>false</code> otherwise.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cards = [4,1,8,7]
|
||||
@@ -32,7 +32,7 @@
|
||||
<strong>Explanation:</strong> (8-4) * (7-1) = 24
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cards = [1,2,1,2]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>You may assume that each input would have exactly one solution.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,2,1,-4], target = 1
|
||||
@@ -13,18 +13,19 @@
|
||||
<strong>Explanation:</strong> The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0], target = 1
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> The sum that is closest to the target is 0. (0 + 0 + 0 = 0).
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 1000</code></li>
|
||||
<li><code>3 <= nums.length <= 500</code></li>
|
||||
<li><code>-1000 <= nums[i] <= 1000</code></li>
|
||||
<li><code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>As the answer can be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,1,2,2,3,3,4,4,5,5], target = 8
|
||||
@@ -16,7 +16,7 @@ Enumerating by the values (arr[i], arr[j], arr[k]):
|
||||
(2, 3, 3) occurs 2 times.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,1,2,2,2,2], target = 5
|
||||
@@ -27,7 +27,7 @@ We choose one 1 from [1,1] in 2 ways,
|
||||
and two 2s from [2,2,2,2] in 6 ways.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [2,1,3], target = 6
|
||||
|
@@ -3,20 +3,39 @@
|
||||
<p>Notice that the solution set must not contain duplicate triplets.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [-1,0,1,2,-1,-4]
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,0,1,2,-1,-4]
|
||||
<strong>Output:</strong> [[-1,-1,2],[-1,0,1]]
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = []
|
||||
<strong>Output:</strong> []
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [0]
|
||||
<strong>Output:</strong> []
|
||||
<strong>Explanation:</strong>
|
||||
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
|
||||
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
|
||||
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
|
||||
The distinct triplets are [-1,0,1] and [-1,-1,2].
|
||||
Notice that the order of the output and the order of the triplets does not matter.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,1,1]
|
||||
<strong>Output:</strong> []
|
||||
<strong>Explanation:</strong> The only possible triplet does not sum up to 0.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0]
|
||||
<strong>Output:</strong> [[0,0,0]]
|
||||
<strong>Explanation:</strong> The only possible triplet sums up to 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= nums.length <= 3000</code></li>
|
||||
<li><code>3 <= nums.length <= 3000</code></li>
|
||||
<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]
|
||||
@@ -17,7 +17,7 @@ The two tuples are:
|
||||
2. (1, 1, 0, 0) -> nums1[1] + nums2[1] + nums3[0] + nums4[0] = 2 + (-1) + (-1) + 0 = 0
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]
|
||||
|
@@ -9,14 +9,14 @@
|
||||
<p>You may return the answer in <strong>any order</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,0,-1,0,-2,2], target = 0
|
||||
<strong>Output:</strong> [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,2,2,2,2], target = 8
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Given an integer <code>num</code>, <strong>reverse</strong> <code>num</code> to get <code>reversed1</code>, <strong>then reverse</strong> <code>reversed1</code> to get <code>reversed2</code>. Return <code>true</code> <em>if</em> <code>reversed2</code> <em>equals</em> <code>num</code>. Otherwise return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 526
|
||||
@@ -15,7 +15,7 @@
|
||||
<strong>Explanation:</strong> Reverse num to get 625, then reverse 625 to get 526, which equals num.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 1800
|
||||
@@ -23,7 +23,7 @@
|
||||
<strong>Explanation:</strong> Reverse num to get 81, then reverse 81 to get 18, which does not equal num.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 0
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<p>Return <em>a string denoting the <strong>abbreviated product</strong> of all integers in the <strong>inclusive</strong> range</em> <code>[left, right]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> left = 1, right = 4
|
||||
@@ -35,7 +35,7 @@ Since the number of digits is 2, which is less than 10, we do not have to abbrev
|
||||
Thus, the final representation is "24e0".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> left = 2, right = 11
|
||||
@@ -46,7 +46,7 @@ The number of digits after removing the trailing zeros is 6, so we do not abbrev
|
||||
Hence, the abbreviated product is "399168e2".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> left = 371, right = 375
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>After merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails <strong>in sorted order</strong>. The accounts themselves can be returned in <strong>any order</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> accounts = [["John","johnsmith@mail.com","john_newyork@mail.com"],["John","johnsmith@mail.com","john00@mail.com"],["Mary","mary@mail.com"],["John","johnnybravo@mail.com"]]
|
||||
@@ -17,7 +17,7 @@ We could return these lists in any order, for example the answer [['Mary'
|
||||
['John', 'john00@mail.com', 'john_newyork@mail.com', 'johnsmith@mail.com']] would still be accepted.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> accounts = [["Gabe","Gabe0@m.co","Gabe3@m.co","Gabe1@m.co"],["Kevin","Kevin3@m.co","Kevin5@m.co","Kevin0@m.co"],["Ethan","Ethan5@m.co","Ethan4@m.co","Ethan0@m.co"],["Hanzo","Hanzo3@m.co","Hanzo1@m.co","Hanzo0@m.co"],["Fern","Fern5@m.co","Fern1@m.co","Fern0@m.co"]]
|
||||
@@ -30,7 +30,7 @@ We could return these lists in any order, for example the answer [['Mary'
|
||||
<ul>
|
||||
<li><code>1 <= accounts.length <= 1000</code></li>
|
||||
<li><code>2 <= accounts[i].length <= 10</code></li>
|
||||
<li><code>1 <= accounts[i][j] <= 30</code></li>
|
||||
<li><code>1 <= accounts[i][j].length <= 30</code></li>
|
||||
<li><code>accounts[i][0]</code> consists of English letters.</li>
|
||||
<li><code>accounts[i][j] (for j > 0)</code> is a valid email.</li>
|
||||
</ul>
|
||||
|
@@ -8,19 +8,19 @@
|
||||
| director_id | int |
|
||||
| timestamp | int |
|
||||
+-------------+---------+
|
||||
timestamp is the primary key column for this table.
|
||||
timestamp is the primary key (column with unique values) for this table.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a SQL query for a report that provides the pairs <code>(actor_id, director_id)</code> where the actor has cooperated with the director at least three times.</p>
|
||||
<p>Write a solution to find all the pairs <code>(actor_id, director_id)</code> where the actor has cooperated with the director at least three times.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>Given two binary strings <code>a</code> and <code>b</code>, return <em>their sum as a binary string</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> a = "11", b = "1"
|
||||
<strong>Output:</strong> "100"
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> a = "1010", b = "1011"
|
||||
<strong>Output:</strong> "10101"
|
||||
</pre>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 38
|
||||
@@ -12,7 +12,7 @@
|
||||
Since 2 has only one digit, return it.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 0
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em>the <strong>minimum</strong> number of rungs that must be added to the ladder in order for you to climb to the last rung.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rungs = [1,3,5,10], dist = 2
|
||||
@@ -16,7 +16,7 @@ Add rungs at heights 7 and 8 to climb this ladder.
|
||||
The ladder will now have rungs at [1,3,5,<u>7</u>,<u>8</u>,10].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rungs = [3,6,8,10], dist = 3
|
||||
@@ -25,7 +25,7 @@ The ladder will now have rungs at [1,3,5,<u>7</u>,<u>8</u>,10].
|
||||
This ladder can be climbed without adding additional rungs.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rungs = [3,4,6,7], dist = 2
|
||||
|
@@ -12,14 +12,14 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/15/addrow-tree.jpg" style="width: 500px; height: 231px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,2,6,3,1,5], val = 1, depth = 2
|
||||
<strong>Output:</strong> [4,1,1,2,null,null,6,3,1,5]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/11/add2-tree.jpg" style="width: 500px; height: 277px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,2,null,3,1], val = 1, depth = 3
|
||||
|
@@ -3,21 +3,21 @@
|
||||
<p>You must solve the problem without using any built-in library for handling large integers (such as <code>BigInteger</code>). You must also not convert the inputs to integers directly.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num1 = "11", num2 = "123"
|
||||
<strong>Output:</strong> "134"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num1 = "456", num2 = "77"
|
||||
<strong>Output:</strong> "533"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num1 = "0", num2 = "0"
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Given <code>num</code>, the <strong>array-form</strong> of an integer, and an integer <code>k</code>, return <em>the <strong>array-form</strong> of the integer</em> <code>num + k</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = [1,2,0,0], k = 34
|
||||
@@ -15,7 +15,7 @@
|
||||
<strong>Explanation:</strong> 1200 + 34 = 1234
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = [2,7,4], k = 181
|
||||
@@ -23,7 +23,7 @@
|
||||
<strong>Explanation:</strong> 274 + 181 = 455
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = [2,1,5], k = 806
|
||||
|
@@ -1,6 +1,6 @@
|
||||
Given two integers <code>num1</code> and <code>num2</code>, return <em>the <strong>sum</strong> of the two integers</em>.
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num1 = 12, num2 = 5
|
||||
@@ -8,7 +8,7 @@ Given two integers <code>num1</code> and <code>num2</code>, return <em>the <stro
|
||||
<strong>Explanation:</strong> num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num1 = -10, num2 = 4
|
||||
|
@@ -3,21 +3,21 @@
|
||||
<p>You may assume the two numbers do not contain any leading zero, except the number 0 itself.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/sumii-linked-list.jpg" style="width: 523px; height: 342px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [7,2,4,3], l2 = [5,6,4]
|
||||
<strong>Output:</strong> [7,8,0,7]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [2,4,3], l2 = [5,6,4]
|
||||
<strong>Output:</strong> [8,0,7]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [0], l2 = [0]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>You may assume the two numbers do not contain any leading zero, except the number 0 itself.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg" style="width: 483px; height: 342px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [2,4,3], l2 = [5,6,4]
|
||||
@@ -11,14 +11,14 @@
|
||||
<strong>Explanation:</strong> 342 + 465 = 807.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [0], l2 = [0]
|
||||
<strong>Output:</strong> [0]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
|
||||
|
@@ -24,5 +24,5 @@ promise2 = new Promise(resolve => setTimeout(() => resolve(-12), 30))
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>promise1 and promise2 are promises that resolve with a number</code></li>
|
||||
<li><code>promise1</code> and <code>promise2</code> are promises that resolve with a number</li>
|
||||
</ul>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Return<strong> </strong><em>the modified string <strong>after</strong> the spaces have been added.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "LeetcodeHelpsMeLearn", spaces = [8,13,15]
|
||||
@@ -17,7 +17,7 @@ The indices 8, 13, and 15 correspond to the underlined characters in "Leetc
|
||||
We then place spaces before those characters.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "icodeinpython", spaces = [1,5,7,9]
|
||||
@@ -27,7 +27,7 @@ The indices 1, 5, 7, and 9 correspond to the underlined characters in "i<u>
|
||||
We then place spaces before those characters.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "spacing", spaces = [0,1,2,3,4,5,6]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return the result of adding <code>arr1</code> and <code>arr2</code> in the same format: as an array of 0s and 1s with no leading zeros.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr1 = [1,1,1,1,1], arr2 = [1,0,1]
|
||||
@@ -13,14 +13,14 @@
|
||||
<strong>Explanation: </strong>arr1 represents 11, arr2 represents 5, the output represents 16.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr1 = [0], arr2 = [0]
|
||||
<strong>Output:</strong> [0]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr1 = [0], arr2 = [1]
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p><strong>Note:</strong> Numbers in the additive sequence <strong>cannot</strong> have leading zeros, so sequence <code>1, 2, 03</code> or <code>1, 02, 3</code> is invalid.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> "112358"
|
||||
@@ -17,7 +17,7 @@ The digits can form an additive sequence: 1, 1, 2, 3, 5, 8.
|
||||
1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> "199100199"
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<p>Return <em>any permutation of </em><code>nums1</code><em> that maximizes its <strong>advantage</strong> with respect to </em><code>nums2</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> nums1 = [2,7,11,15], nums2 = [1,10,4,11]
|
||||
<strong>Output:</strong> [2,11,7,15]
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> nums1 = [12,24,8,32], nums2 = [13,25,32,11]
|
||||
<strong>Output:</strong> [24,32,8,12]
|
||||
</pre>
|
||||
|
@@ -8,14 +8,14 @@
|
||||
<p>Return <em>the probability that the </em><code>n<sup>th</sup></code><em> person gets his own seat</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
<strong>Output:</strong> 1.00000
|
||||
<strong>Explanation: </strong>The first person can only get the first seat.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>Notice that <code>"10:00"</code> - <code>"11:00"</code> is considered to be within a one-hour period, while <code>"22:51"</code> - <code>"23:52"</code> is not considered to be within a one-hour period.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> keyName = ["daniel","daniel","daniel","luis","luis","luis","luis"], keyTime = ["10:00","10:40","11:00","09:00","11:00","13:00","15:00"]
|
||||
@@ -17,7 +17,7 @@
|
||||
<strong>Explanation:</strong> "daniel" used the keycard 3 times in a one-hour period ("10:00","10:40", "11:00").
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> keyName = ["alice","alice","alice","bob","bob","bob","bob"], keyTime = ["12:01","12:00","18:00","21:00","21:20","21:30","23:00"]
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>A node <code>u</code> is an <strong>ancestor</strong> of another node <code>v</code> if <code>u</code> can reach <code>v</code> via a set of edges.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/12/e1.png" style="width: 322px; height: 265px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 8, edgeList = [[0,3],[0,4],[1,3],[2,4],[2,7],[3,5],[3,6],[3,7],[4,6]]
|
||||
@@ -22,7 +22,7 @@ The above diagram represents the input graph.
|
||||
- Node 7 has four ancestors 0, 1, 2, and 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/12/e2.png" style="width: 343px; height: 299px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, edgeList = [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<p>Return <em><strong>all distinct indices</strong> that have the <strong>highest</strong> possible <strong>division score</strong></em>. You may return the answer in <strong>any order</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,1,0]
|
||||
@@ -25,7 +25,7 @@
|
||||
Indices 2 and 4 both have the highest possible division score 3.
|
||||
Note the answer [4,2] would also be accepted.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0]
|
||||
@@ -38,7 +38,7 @@ Note the answer [4,2] would also be accepted.</pre>
|
||||
Only index 3 has the highest possible division score 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1]
|
||||
|
@@ -1,14 +1,14 @@
|
||||
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e1.png" style="width: 457px; height: 207px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root1 = [2,1,4], root2 = [1,0,3]
|
||||
<strong>Output:</strong> [0,1,1,2,3,4]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e5-.png" style="width: 352px; height: 197px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root1 = [1,null,8], root2 = [8,1]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>You can return the answer in <strong>any order</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/06/28/sketch0.png" style="width: 500px; height: 429px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2
|
||||
@@ -11,7 +11,7 @@
|
||||
Explanation: The nodes that are a distance 2 from the target node (with value 5) have values 7, 4, and 1.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1], target = 1, k = 3
|
||||
|
@@ -10,8 +10,10 @@
|
||||
<li><code>getMinKey()</code> Returns one of the keys with the minimum count. If no element exists, return an empty string <code>""</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>Note</strong> that each function must run in <code>O(1)</code> average time complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>The graph is given as follows: <code>graph[i]</code> is a list of all nodes you can visit from node <code>i</code> (i.e., there is a directed edge from node <code>i</code> to node <code>graph[i][j]</code>).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/28/all_1.jpg" style="width: 242px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> graph = [[1,2],[3],[3],[]]
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/28/all_2.jpg" style="width: 423px; height: 301px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> graph = [[4,3,1],[3,2,4],[3],[4],[]]
|
||||
|
@@ -5,14 +5,14 @@
|
||||
<p>A <strong>full binary tree</strong> is a binary tree where each node has exactly <code>0</code> or <code>2</code> children.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/22/fivetrees.png" style="width: 700px; height: 400px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7
|
||||
<strong>Output:</strong> [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>The test cases are generated so that the answer fits in a 32-bit integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_11_1816.png" style="width: 454px; height: 154px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> houses = [1,4,8,10,20], k = 3
|
||||
@@ -14,7 +14,7 @@
|
||||
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_2_1816.png" style="width: 433px; height: 154px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> houses = [2,3,5,12,18], k = 2
|
||||
|
@@ -33,6 +33,7 @@ onceFn(4, 6, 8); // undefined, fn was not called
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>calls</code> is a valid JSON array</li>
|
||||
<li><code>1 <= calls.length <= 10</code></li>
|
||||
<li><code>1 <= calls[i].length <= 100</code></li>
|
||||
<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>
|
||||
|
@@ -19,10 +19,10 @@
|
||||
<li><code>'U'</code> moves our position up one row, if the position exists on the board;</li>
|
||||
|
||||
<li><code>'D'</code> moves our position down one row, if the position exists on the board;</li>
|
||||
|
||||
|
||||
<li><code>'L'</code> moves our position left one column, if the position exists on the board;</li>
|
||||
|
||||
<li><code>'R'</code> moves our position right one column, if the position exists on the board;</li>
|
||||
<li><code>'R'</code> moves our position right one column, if the position exists on the board;</li>
|
||||
|
||||
<li><code>'!'</code> adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code> to the answer.</li>
|
||||
|
||||
|
@@ -11,14 +11,14 @@
|
||||
<p>The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "(123)"
|
||||
<strong>Output:</strong> ["(1, 2.3)","(1, 23)","(1.2, 3)","(12, 3)"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "(0123)"
|
||||
@@ -26,7 +26,7 @@
|
||||
<strong>Explanation:</strong> 0.0, 00, 0001 or 00.01 are not allowed.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "(00011)"
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<p>Return <em>the number of minutes needed for the entire tree to be infected.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231744-1.png" style="width: 400px; height: 306px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1,5,3,null,4,10,6,9,2], start = 3
|
||||
@@ -24,7 +24,7 @@
|
||||
It takes 4 minutes for the whole tree to be infected so we return 4.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231812-2.png" style="width: 75px; height: 66px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1], start = 1
|
||||
|
@@ -3,21 +3,21 @@
|
||||
<p>Answers within <code>10<sup>-5</sup></code> of the actual value will be accepted as correct.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/26/sample_1_1673.png" style="width: 300px; height: 296px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> hour = 12, minutes = 30
|
||||
<strong>Output:</strong> 165
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/26/sample_2_1673.png" style="width: 300px; height: 301px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> hour = 3, minutes = 30
|
||||
<strong>Output:</strong> 75
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/26/sample_3_1673.png" style="width: 300px; height: 301px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> hour = 3, minutes = 15
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Return<em> the sum of the</em> <code>k</code> <em>integers appended to</em> <code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,4,25,10,25], k = 2
|
||||
@@ -12,7 +12,7 @@
|
||||
The resulting sum of nums is 1 + 4 + 25 + 10 + 25 + 2 + 3 = 70, which is the minimum.
|
||||
The sum of the two integers appended is 2 + 3 = 5, so we return 5.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,6], k = 6
|
||||
|
@@ -12,7 +12,7 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
@@ -34,7 +34,7 @@ cashier.getBill([7,3],[10,10]); // return 4000.0. 5<sup>th<
|
||||
cashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // return 7350.0. 6<sup>th</sup> customer, 50% discount.
|
||||
// Original bill = 14700, but with
|
||||
// Actual bill = 14700 * ((100 - 50) / 100) = 7350.
|
||||
cashier.getBill([2,3,5],[5,3,2]); // return 2500.0. 6<sup>th</sup> customer, no discount.
|
||||
cashier.getBill([2,3,5],[5,3,2]); // return 2500.0. 7<sup>th</sup> customer, no discount.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<p>Note that all prices will contain <strong>at most</strong> <code>10</code> digits.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> sentence = "there are $1 $2 and 5$ candies in the shop", discount = 50
|
||||
@@ -22,7 +22,7 @@ The words which represent prices are "$1" and "$2".
|
||||
- A 50% discount on "$2" yields "$1". Since we need to have exactly 2 decimal places after a price, we replace "$2" with "$1.00".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> sentence = "1 2 $3 4 $5 $6 7 8$ $9 $10$", discount = 100
|
||||
@@ -41,7 +41,7 @@ Each of them is replaced by "$0.00".
|
||||
<li><code>sentence</code> consists of lowercase English letters, digits, <code>' '</code>, and <code>'$'</code>.</li>
|
||||
<li><code>sentence</code> does not have leading or trailing spaces.</li>
|
||||
<li>All words in <code>sentence</code> are separated by a single space.</li>
|
||||
<li>All prices will be <strong>positive</strong> integers without leading zeros.</li>
|
||||
<li>All prices will be <strong>positive</strong> numbers without leading zeros.</li>
|
||||
<li>All prices will have <strong>at most</strong> <code>10</code> digits.</li>
|
||||
<li><code>0 <= discount <= 100</code></li>
|
||||
</ul>
|
||||
|
@@ -37,5 +37,5 @@ The function increases each value in the array by one.
|
||||
<ul>
|
||||
<li><code>0 <= arr.length <= 1000</code></li>
|
||||
<li><code><font face="monospace">-10<sup>9</sup> <= arr[i] <= 10<sup>9</sup></font></code></li>
|
||||
<li><font face="monospace"><code>fn returns a number</code></font></li>
|
||||
<li><code>fn</code> returns a number</li>
|
||||
</ul>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
<p>The test cases are generated so that the answer fits in <strong>32-bit</strong> integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,4,6,8,10]
|
||||
@@ -31,7 +31,7 @@
|
||||
[2,6,10]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [7,7,7,7,7]
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>A <strong>subarray</strong> is a contiguous subsequence of the array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
@@ -17,7 +17,7 @@
|
||||
<strong>Explanation:</strong> We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1]
|
||||
|
@@ -17,7 +17,7 @@
|
||||
<p>Return <em>a list of </em><code>boolean</code> <em>elements</em> <code>answer</code><em>, where</em> <code>answer[i]</code> <em>is</em> <code>true</code> <em>if the subarray</em> <code>nums[l[i]], nums[l[i]+1], ... , nums[r[i]]</code><em> can be <strong>rearranged</strong> to form an <strong>arithmetic</strong> sequence, and</em> <code>false</code> <em>otherwise.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = <code>[4,6,5,9,3,7]</code>, l = <code>[0,0,2]</code>, r = <code>[2,3,5]</code>
|
||||
@@ -27,7 +27,7 @@ In the 0<sup>th</sup> query, the subarray is [4,6,5]. This can be rearranged as
|
||||
In the 1<sup>st</sup> query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.
|
||||
In the 2<sup>nd</sup> query, the subarray is <code>[5,9,3,7]. This</code> can be rearranged as <code>[3,5,7,9]</code>, which is an arithmetic sequence.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Given the integer <code>n</code>, return <em>the number of <strong>complete rows</strong> of the staircase you will build</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/arrangecoins1-grid.jpg" style="width: 253px; height: 253px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> Because the 3<sup>rd</sup> row is incomplete, we return 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/arrangecoins2-grid.jpg" style="width: 333px; height: 333px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 8
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<p>Return <em>the longest length of a set</em> <code>s[k]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,4,0,3,1,6,2]
|
||||
@@ -22,7 +22,7 @@ One of the longest sets s[k]:
|
||||
s[0] = {nums[0], nums[5], nums[6], nums[2]} = {5, 6, 2, 0}
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,1,2]
|
||||
|
@@ -1,21 +1,21 @@
|
||||
<p>Given an integer array of even length <code>arr</code>, return <code>true</code><em> if it is possible to reorder </em><code>arr</code><em> such that </em><code>arr[2 * i + 1] = 2 * arr[2 * i]</code><em> for every </em><code>0 <= i < len(arr) / 2</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [3,1,3,6]
|
||||
<strong>Output:</strong> false
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [2,1,2,6]
|
||||
<strong>Output:</strong> false
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [4,-2,2,-4]
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<p>Given an integer array <code>nums</code> of <code>2n</code> integers, group these integers into <code>n</code> pairs <code>(a<sub>1</sub>, b<sub>1</sub>), (a<sub>2</sub>, b<sub>2</sub>), ..., (a<sub>n</sub>, b<sub>n</sub>)</code> such that the sum of <code>min(a<sub>i</sub>, b<sub>i</sub>)</code> for all <code>i</code> is <strong>maximized</strong>. Return<em> the maximized sum</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,4,3,2]
|
||||
@@ -12,7 +12,7 @@
|
||||
3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4
|
||||
So the maximum possible sum is 4.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [6,2,6,5,1,2]
|
||||
|
@@ -1,9 +1,12 @@
|
||||
Write code that enhances all arrays such that you can call the <code>array.last()</code> method on any array and it will return the last element. If there are no elements in the array, it should return <code>-1</code>.
|
||||
<p>Write code that enhances all arrays such that you can call the <code>array.last()</code> method on any array and it will return the last element. If there are no elements in the array, it should return <code>-1</code>.</p>
|
||||
|
||||
<p>You may assume the array is the output of <code>JSON.parse</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3]
|
||||
<strong>Input:</strong> nums = [null, {}, 3]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> Calling nums.last() should return the last element: 3.
|
||||
</pre>
|
||||
@@ -20,6 +23,6 @@ Write code that enhances all arrays such that you can call the <code>array.
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>arr</code> is a valid JSON array</li>
|
||||
<li><code>0 <= arr.length <= 1000</code></li>
|
||||
<li><code>0 <= arr[i] <= 1000</code></li>
|
||||
</ul>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<p>Given an integer array <code>nums</code>, a reducer function <code>fn</code>, and an intial value <code>init</code>, return a <strong>reduced</strong> array.</p>
|
||||
<p>Given an integer array <code>nums</code>, a reducer function <code>fn</code>, and an initial value <code>init</code>, return a <strong>reduced</strong> array.</p>
|
||||
|
||||
<p>A <strong>reduced</strong> array is created by applying the following operation: <code>val = fn(init, nums[0])</code>, <code>val = fn(val, nums[1])</code>, <code>val = fn(val, arr[2])</code>, <code>...</code> until every element in the array has been processed. The final value of <code>val</code> is returned.</p>
|
||||
<p>A <strong>reduced</strong> array is created by applying the following operation: <code>val = fn(init, nums[0])</code>, <code>val = fn(val, nums[1])</code>, <code>val = fn(val, nums[2])</code>, <code>...</code> until every element in the array has been processed. The final value of <code>val</code> is returned.</p>
|
||||
|
||||
<p>If the length of the array is 0, it should return <code>init</code>.</p>
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em><strong>any</strong> rearrangement of </em><code>nums</code><em> that meets the requirements</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||
@@ -16,7 +16,7 @@ When i=2, nums[i] = 4, and the average of its neighbors is (2+5) / 2 = 3.5.
|
||||
When i=3, nums[i] = 5, and the average of its neighbors is (4+3) / 2 = 3.5.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [6,2,0,9,7]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p>Create a class <code>ArrayWrapper</code> that accepts an array of integers in it's constructor. This class should have two features:</p>
|
||||
<p>Create a class <code>ArrayWrapper</code> that accepts an array of integers in its constructor. This class should have two features:</p>
|
||||
|
||||
<ul>
|
||||
<li>When two instances of this class are added together with the <code>+</code> operator, the resulting value is the sum of all the elements in both arrays.</li>
|
||||
|
@@ -9,21 +9,21 @@
|
||||
| viewer_id | int |
|
||||
| view_date | date |
|
||||
+---------------+---------+
|
||||
There is no primary key for this table, it may have duplicate rows.
|
||||
There is no primary key (column with unique values) for this table, the table may have duplicate rows.
|
||||
Each row of this table indicates that some viewer viewed an article (written by some author) on some date.
|
||||
Note that equal author_id and viewer_id indicate the same person.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write an SQL query to find all the authors that viewed at least one of their own articles.</p>
|
||||
<p>Write a solution to find all the authors that viewed at least one of their own articles.</p>
|
||||
|
||||
<p>Return the result table sorted by <code>id</code> in ascending order.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>The distance used in this problem is the Manhattan distance: the distance between two cells <code>(x0, y0)</code> and <code>(x1, y1)</code> is <code>|x0 - x1| + |y0 - y1|</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex1.JPG" style="width: 185px; height: 87px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,0,1],[0,0,0],[1,0,1]]
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> The cell (1, 1) is as far as possible from all the land with distance 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex2.JPG" style="width: 184px; height: 87px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,0,0],[0,0,0],[0,0,0]]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Each child <code>i</code> has a greed factor <code>g[i]</code>, which is the minimum size of a cookie that the child will be content with; and each cookie <code>j</code> has a size <code>s[j]</code>. If <code>s[j] >= g[i]</code>, we can assign the cookie <code>j</code> to the child <code>i</code>, and the child <code>i</code> will be content. Your goal is to maximize the number of your content children and output the maximum number.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> g = [1,2,3], s = [1,1]
|
||||
@@ -13,7 +13,7 @@ And even though you have 2 cookies, since their size is both 1, you could only m
|
||||
You need to output 1.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> g = [1,2], s = [1,2,3]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> asteroids = [5,10,-5]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> asteroids = [8,-8]
|
||||
@@ -21,7 +21,7 @@
|
||||
<strong>Explanation:</strong> The 8 and -8 collide exploding each other.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> asteroids = [10,2,-5]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em>the <strong>number of available captures</strong> for the white rook</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/02/20/1253_example_1_improved.PNG" style="width: 300px; height: 305px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> In this example, the rook is attacking all the pawns.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/02/19/1253_example_2_improved.PNG" style="width: 300px; height: 306px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> board = [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||||
@@ -21,7 +21,7 @@
|
||||
<strong>Explanation:</strong> The bishops are blocking the rook from attacking any of the pawns.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/02/20/1253_example_3_improved.PNG" style="width: 300px; height: 305px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
Given the <code>root</code> of a binary tree, return <em>the average value of the nodes on each level in the form of an array</em>. Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/avg1-tree.jpg" style="width: 277px; height: 302px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
|
||||
@@ -9,7 +9,7 @@ Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and
|
||||
Hence return [3, 14.5, 11].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/avg2-tree.jpg" style="width: 292px; height: 302px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [3,9,20,15,7]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Return <em>the average salary of employees excluding the minimum and maximum salary</em>. Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> salary = [4000,3000,1000,2000]
|
||||
@@ -12,7 +12,7 @@
|
||||
Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> salary = [1000,2000,3000]
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<p>Return <em>the <strong>average</strong> waiting time of all customers</em>. Solutions within <code>10<sup>-5</sup></code> from the actual answer are considered accepted.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> customers = [[1,2],[2,5],[4,3]]
|
||||
@@ -22,7 +22,7 @@
|
||||
So the average waiting time = (2 + 6 + 7) / 3 = 5.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> customers = [[5,2],[5,4],[10,3],[20,1]]
|
||||
|
@@ -20,7 +20,7 @@
|
||||
<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rains = [1,2,3,4]
|
||||
@@ -32,7 +32,7 @@ After the fourth day full lakes are [1,2,3,4]
|
||||
There's no day to dry any lake and there is no flood in any lake.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rains = [1,2,0,0,2,1]
|
||||
@@ -46,7 +46,7 @@ After the sixth day, full lakes are [1,2].
|
||||
It is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> rains = [1,2,0,1,2]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Note that after backspacing an empty text, the text will continue empty.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "ab#c", t = "ad#c"
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> Both s and t become "ac".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "ab##", t = "c#d#"
|
||||
@@ -19,7 +19,7 @@
|
||||
<strong>Explanation:</strong> Both s and t become "".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "a#c", t = "b"
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<p>Return <em>the largest possible <strong>score</strong> you can achieve after playing any number of tokens</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> tokens = [100], power = 50
|
||||
@@ -20,7 +20,7 @@
|
||||
<strong>Explanation</strong><strong>:</strong> Playing the only token in the bag is impossible because you either have too little power or too little score.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> tokens = [100,200], power = 150
|
||||
@@ -29,7 +29,7 @@
|
||||
There is no need to play the 1<sup>st</sup> token since you cannot play it face up to add to your score.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> tokens = [100,200,300,400], power = 200
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every node never differs by more than <code>1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/10/balance1-tree.jpg" style="width: 500px; height: 319px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1,null,2,null,3,null,4,null,null]
|
||||
@@ -11,7 +11,7 @@
|
||||
<b>Explanation:</b> This is not the only correct answer, [3,1,4,null,2] is also correct.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/08/10/balanced2-tree.jpg" style="width: 224px; height: 145px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [2,1,3]
|
||||
|
@@ -1,27 +1,21 @@
|
||||
<p>Given a binary tree, determine if it is height-balanced.</p>
|
||||
|
||||
<p>For this problem, a height-balanced binary tree is defined as:</p>
|
||||
|
||||
<blockquote>
|
||||
<p>a binary tree in which the left and right subtrees of <em>every</em> node differ in height by no more than 1.</p>
|
||||
</blockquote>
|
||||
<p>Given a binary tree, determine if it is <span data-keyword="height-balanced"><strong>height-balanced</strong></span>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg" style="width: 342px; height: 221px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg" style="width: 452px; height: 301px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1,2,2,3,3,null,null,4,4]
|
||||
<strong>Output:</strong> false
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> root = []
|
||||
|
@@ -7,8 +7,9 @@
|
||||
| account | int |
|
||||
| name | varchar |
|
||||
+--------------+---------+
|
||||
account is the primary key for this table.
|
||||
account is the primary key (column with unique values) for this table.
|
||||
Each row of this table contains the account number of each user in the bank.
|
||||
There will be no two users having the same name in the table.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -24,7 +25,7 @@ Each row of this table contains the account number of each user in the bank.
|
||||
| amount | int |
|
||||
| transacted_on | date |
|
||||
+---------------+---------+
|
||||
trans_id is the primary key for this table.
|
||||
trans_id is the primary key (column with unique values) for this table.
|
||||
Each row of this table contains all changes made to all accounts.
|
||||
amount is positive if the user received money and negative if they transferred money.
|
||||
All accounts start with a balance of 0.
|
||||
@@ -32,14 +33,14 @@ All accounts start with a balance of 0.
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write an SQL query to report the name and balance of users with a balance higher than <code>10000</code>. The balance of an account is equal to the sum of the amounts of all transactions involving that account.</p>
|
||||
<p>Write a solution to report the name and balance of users with a balance higher than <code>10000</code>. The balance of an account is equal to the sum of the amounts of all transactions involving that account.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<p>Given an integer <code>num</code>, return <em>a string of its <strong>base 7</strong> representation</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> num = 100
|
||||
<strong>Output:</strong> "202"
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> num = -7
|
||||
<strong>Output:</strong> "-10"
|
||||
</pre>
|
||||
|
@@ -1,18 +1,37 @@
|
||||
<p>You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.</p>
|
||||
<p>You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record.</p>
|
||||
|
||||
<p>At the beginning of the game, you start with an empty record. You are given a list of strings <code>ops</code>, where <code>ops[i]</code> is the <code>i<sup>th</sup></code> operation you must apply to the record and is one of the following:</p>
|
||||
<p>You are given a list of strings <code>operations</code>, where <code>operations[i]</code> is the <code>i<sup>th</sup></code> operation you must apply to the record and is one of the following:</p>
|
||||
|
||||
<ol>
|
||||
<li>An integer <code>x</code> - Record a new score of <code>x</code>.</li>
|
||||
<li><code>"+"</code> - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.</li>
|
||||
<li><code>"D"</code> - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.</li>
|
||||
<li><code>"C"</code> - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li>An integer <code>x</code>.
|
||||
|
||||
<p>Return <em>the sum of all the scores on the record</em>. The test cases are generated so that the answer fits in a 32-bit integer.</p>
|
||||
<ul>
|
||||
<li>Record a new score of <code>x</code>.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><code>'+'</code>.
|
||||
<ul>
|
||||
<li>Record a new score that is the sum of the previous two scores.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><code>'D'</code>.
|
||||
<ul>
|
||||
<li>Record a new score that is the double of the previous score.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><code>'C'</code>.
|
||||
<ul>
|
||||
<li>Invalidate the previous score, removing it from the record.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the sum of all the scores on the record after applying all the operations</em>.</p>
|
||||
|
||||
<p>The test cases are generated such that the answer and all intermediate calculations fit in a <strong>32-bit</strong> integer and that all operations are valid.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ops = ["5","2","C","D","+"]
|
||||
@@ -26,7 +45,7 @@
|
||||
The total sum is 5 + 10 + 15 = 30.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ops = ["5","-2","4","C","D","9","+","+"]
|
||||
@@ -43,19 +62,23 @@ The total sum is 5 + 10 + 15 = 30.
|
||||
The total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ops = ["1"]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Input:</strong> ops = ["1","C"]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
"1" - Add 1 to the record, record is now [1].
|
||||
"C" - Invalidate and remove the previous score, record is now [].
|
||||
Since the record is empty, the total sum is 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= ops.length <= 1000</code></li>
|
||||
<li><code>ops[i]</code> is <code>"C"</code>, <code>"D"</code>, <code>"+"</code>, or a string representing an integer in the range <code>[-3 * 10<sup>4</sup>, 3 * 10<sup>4</sup>]</code>.</li>
|
||||
<li><code>1 <= operations.length <= 1000</code></li>
|
||||
<li><code>operations[i]</code> is <code>"C"</code>, <code>"D"</code>, <code>"+"</code>, or a string representing an integer in the range <code>[-3 * 10<sup>4</sup>, 3 * 10<sup>4</sup>]</code>.</li>
|
||||
<li>For operation <code>"+"</code>, there will always be at least two previous scores on the record.</li>
|
||||
<li>For operations <code>"C"</code> and <code>"D"</code>, there will always be at least one previous score on the record.</li>
|
||||
</ul>
|
||||
|
@@ -7,13 +7,13 @@
|
||||
<p><strong>Note:</strong> You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as <code>eval()</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> s = "3+2*2"
|
||||
<strong>Output:</strong> 7
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> s = " 3/2 "
|
||||
<strong>Output:</strong> 1
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> s = " 3+5 / 2 "
|
||||
<strong>Output:</strong> 5
|
||||
</pre>
|
||||
|
@@ -34,22 +34,24 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>Note:</strong> You may assume that the given expression is always valid. All intermediate results will be in the range of <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "e + 8 - a + 5", evalvars = ["e"], evalints = [1]
|
||||
<strong>Output:</strong> ["-1*a","14"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "e - 8 + temperature - pressure", evalvars = ["e", "temperature"], evalints = [1, 12]
|
||||
<strong>Output:</strong> ["-1*pressure","5"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "(e + 8) * (e - 8)", evalvars = [], evalints = []
|
||||
|
@@ -3,21 +3,21 @@
|
||||
<p><strong>Note:</strong> You are <strong>not</strong> allowed to use any built-in function which evaluates strings as mathematical expressions, such as <code>eval()</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "1 + 1"
|
||||
<strong>Output:</strong> 2
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = " 2-1 + 2 "
|
||||
<strong>Output:</strong> 3
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "(1+(4+5+2)-3)+(6+8)"
|
||||
|
@@ -3,14 +3,14 @@
|
||||
<p><strong>Battleships</strong> can only be placed horizontally or vertically on <code>board</code>. In other words, they can only be made of the shape <code>1 x k</code> (<code>1</code> row, <code>k</code> columns) or <code>k x 1</code> (<code>k</code> rows, <code>1</code> column), where <code>k</code> can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/10/battelship-grid.jpg" style="width: 333px; height: 333px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> board = [["X",".",".","X"],[".",".",".","X"],[".",".",".","X"]]
|
||||
<strong>Output:</strong> 2
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> board = [["."]]
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Return <em>the list</em> <code>answer</code>. If there multiple valid answers, return <strong>any of them</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, k = 1
|
||||
@@ -15,7 +15,7 @@
|
||||
Explanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, k = 2
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<p>Given an integer <code>n</code>, return <em>the <strong>number</strong> of the <strong>beautiful arrangements</strong> that you can construct</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
@@ -22,7 +22,7 @@ The second beautiful arrangement is [2,1]:
|
||||
- i = 2 is divisible by perm[2] = 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
|
@@ -8,10 +8,10 @@
|
||||
<p>Given the integer <code>n</code>, return <em>any <strong>beautiful</strong> array </em><code>nums</code><em> of length </em><code>n</code>. There will be at least one valid answer for the given <code>n</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 4
|
||||
<strong>Output:</strong> [2,1,4,3]
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 5
|
||||
<strong>Output:</strong> [3,1,2,5,4]
|
||||
</pre>
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<p><strong>Note</strong> that the return values are <strong>case-sensitive</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ranks = [13,2,3,1,9], suits = ["a","a","a","a","a"]
|
||||
@@ -22,7 +22,7 @@
|
||||
<strong>Explanation:</strong> The hand with all the cards consists of 5 cards with the same suit, so we have a "Flush".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ranks = [4,4,2,4,4], suits = ["d","a","a","b","c"]
|
||||
@@ -31,7 +31,7 @@
|
||||
Note that we could also make a "Pair" hand but "Three of a Kind" is a better hand.
|
||||
Also note that other cards could be used to make the "Three of a Kind" hand.</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ranks = [10,10,2,12,9], suits = ["a","b","c","a","d"]
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Answers within <code>10<sup>-5</sup></code> of the actual value will be accepted.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/06/25/q4_e1.jpg" style="width: 377px; height: 362px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> positions = [[0,1],[1,0],[1,2],[2,1]]
|
||||
@@ -15,7 +15,7 @@
|
||||
<strong>Explanation:</strong> As shown, you can see that choosing [x<sub>centre</sub>, y<sub>centre</sub>] = [1, 1] will make the distance to each customer = 1, the sum of all distances is 4 which is the minimum possible we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/06/25/q4_e3.jpg" style="width: 419px; height: 419px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> positions = [[1,1],[3,3]]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em>the maximum score of a pair of sightseeing spots</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> values = [8,1,5,2,6]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> values = [1,2]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Given two lists, <code>scores</code> and <code>ages</code>, where each <code>scores[i]</code> and <code>ages[i]</code> represents the score and age of the <code>i<sup>th</sup></code> player, respectively, return <em>the highest overall score of all possible basketball teams</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> scores = [1,3,5,10,15], ages = [1,2,3,4,5]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> You can choose all the players.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> scores = [4,5,6,5], ages = [2,1,2,1]
|
||||
@@ -21,7 +21,7 @@
|
||||
<strong>Explanation:</strong> It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> scores = [1,2,3,5], ages = [8,9,10,1]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Find and return <em>the <strong>maximum</strong> profit you can achieve</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [7,1,5,3,6,4]
|
||||
@@ -15,7 +15,7 @@ Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
|
||||
Total profit is 4 + 3 = 7.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1,2,3,4,5]
|
||||
@@ -24,7 +24,7 @@ Total profit is 4 + 3 = 7.
|
||||
Total profit is 4.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [7,6,4,3,1]
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [3,3,5,0,0,3,1,4]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
|
||||
Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1,2,3,4,5]
|
||||
@@ -22,7 +22,7 @@ Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.</
|
||||
Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [7,6,4,3,1]
|
||||
|
@@ -1,11 +1,11 @@
|
||||
<p>You are given an integer array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day, and an integer <code>k</code>.</p>
|
||||
|
||||
<p>Find the maximum profit you can achieve. You may complete at most <code>k</code> transactions.</p>
|
||||
<p>Find the maximum profit you can achieve. You may complete at most <code>k</code> transactions: i.e. you may buy at most <code>k</code> times and sell at most <code>k</code> times.</p>
|
||||
|
||||
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 2, prices = [2,4,1]
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 2, prices = [3,2,6,5,0,3]
|
||||
@@ -25,7 +25,7 @@
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= k <= 100</code></li>
|
||||
<li><code>0 <= prices.length <= 1000</code></li>
|
||||
<li><code>1 <= k <= 100</code></li>
|
||||
<li><code>1 <= prices.length <= 1000</code></li>
|
||||
<li><code>0 <= prices[i] <= 1000</code></li>
|
||||
</ul>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1,2,3,0,2]
|
||||
@@ -17,7 +17,7 @@
|
||||
<strong>Explanation:</strong> transactions = [buy, sell, cooldown, buy, sell]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1]
|
||||
|
@@ -2,10 +2,15 @@
|
||||
|
||||
<p>Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.</p>
|
||||
|
||||
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>
|
||||
<p><strong>Note:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</li>
|
||||
<li>The transaction fee is only charged once for each stock purchase and sale.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1,3,2,8,4,9], fee = 2
|
||||
@@ -18,7 +23,7 @@
|
||||
The total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [1,3,7,5,10,3], fee = 3
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em>the maximum profit you can achieve from this transaction</em>. If you cannot achieve any profit, return <code>0</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [7,1,5,3,6,4]
|
||||
@@ -14,7 +14,7 @@
|
||||
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> prices = [7,6,4,3,1]
|
||||
|
@@ -8,9 +8,9 @@
|
||||
| continent | varchar |
|
||||
| area | int |
|
||||
| population | int |
|
||||
| gdp | int |
|
||||
| gdp | bigint |
|
||||
+-------------+---------+
|
||||
name is the primary key column for this table.
|
||||
name is the primary key (column with unique values) for this table.
|
||||
Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.
|
||||
</pre>
|
||||
|
||||
@@ -23,14 +23,14 @@ Each row of this table gives information about the name of a country, the contin
|
||||
<li>it has a population of at least twenty-five million (i.e., <code>25000000</code>).</li>
|
||||
</ul>
|
||||
|
||||
<p>Write an SQL query to report the name, population, and area of the <strong>big countries</strong>.</p>
|
||||
<p>Write a solution to find the name, population, and area of the <strong>big countries</strong>.</p>
|
||||
|
||||
<p>Return the result table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Two <code>1</code>'s are <strong>adjacent</strong> if there are only <code>0</code>'s separating them (possibly no <code>0</code>'s). The <b>distance</b> between two <code>1</code>'s is the absolute difference between their bit positions. For example, the two <code>1</code>'s in <code>"1001"</code> have a distance of 3.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 22
|
||||
@@ -15,7 +15,7 @@ The answer is the largest of these two distances, which is 2.
|
||||
Note that "<u>1</u>01<u>1</u>0" is not a valid pair since there is a 1 separating the two 1's underlined.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 8
|
||||
@@ -24,7 +24,7 @@ Note that "<u>1</u>01<u>1</u>0" is not a valid pair since there is a 1
|
||||
There are not any adjacent pairs of 1's in the binary representation of 8, so we return 0.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<p>Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5
|
||||
@@ -9,14 +9,14 @@
|
||||
<strong>Explanation:</strong> The binary representation of 5 is: 101
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The binary representation of 7 is: 111.</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 11
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>Return <em>an array of booleans </em><code>answer</code><em> where </em><code>answer[i]</code><em> is </em><code>true</code><em> if </em><code>x<sub>i</sub></code><em> is divisible by </em><code>5</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,1,1]
|
||||
@@ -18,7 +18,7 @@
|
||||
Only the first number is divisible by 5, so answer[0] is true.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1]
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<p>You may assume that <code>next()</code> calls will always be valid. That is, there will be at least a next number in the in-order traversal when <code>next()</code> is called.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/25/bst-tree.png" style="width: 189px; height: 178px;" />
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
|
@@ -9,14 +9,14 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/05/02/tree.png" style="width: 400px; height: 273px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]
|
||||
<strong>Output:</strong> [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [0,null,1]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>You must write an algorithm with <code>O(log n)</code> runtime complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,0,3,5,9,12], target = 9
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> 9 exists in nums and its index is 4
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,0,3,5,9,12], target = 2
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> s = "0110", n = 3
|
||||
<strong>Output:</strong> true
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> s = "0110", n = 4
|
||||
<strong>Output:</strong> false
|
||||
</pre>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<p> </p>
|
||||
@@ -15,7 +15,7 @@
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,0,1,0,1], goal = 2
|
||||
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user