mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 06:51: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]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>An integer <code>n</code> is a power of two, if there exists an integer <code>x</code> such that <code>n == 2<sup>x</sup></code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation: </strong>2<sup>0</sup> = 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 16
|
||||
@@ -19,7 +19,7 @@
|
||||
<strong>Explanation: </strong>2<sup>4</sup> = 16
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3
|
||||
|
@@ -7,20 +7,20 @@
|
||||
| user_id | int |
|
||||
| time_stamp | datetime |
|
||||
+----------------+----------+
|
||||
(user_id, time_stamp) is the primary key for this table.
|
||||
(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.
|
||||
Each row contains information about the login time for the user with ID user_id.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write an SQL query to report the <strong>latest</strong> login for all users in the year <code>2020</code>. Do <strong>not</strong> include the users who did not login in <code>2020</code>.</p>
|
||||
<p>Write a solution to report the <strong>latest</strong> login for all users in the year <code>2020</code>. Do <strong>not</strong> include the users who did not login in <code>2020</code>.</p>
|
||||
|
||||
<p>Return the result table <strong>in 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>
|
||||
|
@@ -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]
|
||||
|
@@ -3,25 +3,28 @@
|
||||
<p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 27
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> 27 = 3<sup>3</sup>
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 0
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = 0.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 9
|
||||
<strong>Output:</strong> true
|
||||
<strong>Input:</strong> n = -1
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = (-1).
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<p>Given an integer array <code>slices</code> that represent the sizes of the pizza slices in a clockwise direction, return <em>the maximum possible sum of slice sizes that you can pick</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/2020/02/18/sample_3_1723.png" style="width: 500px; height: 266px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> slices = [1,2,3,4,5,6]
|
||||
@@ -18,7 +18,7 @@
|
||||
<strong>Explanation:</strong> Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2020/02/18/sample_4_1723.png" style="width: 500px; height: 299px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> slices = [8,9,8,6,1,1]
|
||||
|
@@ -3,13 +3,13 @@
|
||||
<p>An integer <code>n</code> is a power of four, if there exists an integer <code>x</code> such that <code>n == 4<sup>x</sup></code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 16
|
||||
<strong>Output:</strong> true
|
||||
</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> false
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 1
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</code><em>)</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 9669
|
||||
@@ -16,7 +16,7 @@ Changing the fourth digit results in 9666.
|
||||
The maximum number is 9969.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 9996
|
||||
@@ -24,7 +24,7 @@ The maximum number is 9969.
|
||||
<strong>Explanation:</strong> Changing the last digit 6 to 9 results in the maximum number.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 9999
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<p>Return <em>an array of all the words</em> <code>third</code> <em>for each occurrence of</em> <code>"first second third"</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> text = "alice is a good girl she is a good student", first = "a", second = "good"
|
||||
<strong>Output:</strong> ["girl","student"]
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> text = "we will we will rock you", first = "we", second = "will"
|
||||
<strong>Output:</strong> ["we","rock"]
|
||||
</pre>
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<p>Return <em>the number of <strong>valid permutations</strong> </em><code>perm</code>. Since the answer may be 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> s = "DID"
|
||||
@@ -28,7 +28,7 @@
|
||||
(3, 1, 2, 0)
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "D"
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<p>Suppose every senator is smart enough and will play the best strategy for his own party. Predict which party will finally announce the victory and change the Dota2 game. The output should be <code>"Radiant"</code> or <code>"Dire"</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> senate = "RD"
|
||||
@@ -25,7 +25,7 @@ And the second senator can't exercise any rights anymore since his right has
|
||||
And in round 2, the first senator can just announce the victory since he is the only guy in the senate who can vote.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> senate = "RDD"
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<p>Return <em>the <strong>list of cells</strong></em> <code>(x, y)</code> <em>such that</em> <code>r1 <= x <= r2</code> <em>and</em> <code>c1 <= y <= c2</code>. The cells should be represented as <strong>strings</strong> in the format mentioned above and be sorted in <strong>non-decreasing</strong> order first by columns and then by rows.</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/02/08/ex1drawio.png" style="width: 250px; height: 160px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "K1:L2"
|
||||
@@ -25,7 +25,7 @@ The above diagram shows the cells which should be present in the list.
|
||||
The red arrows denote the order in which the cells should be presented.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/02/09/exam2drawio.png" style="width: 500px; height: 50px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "A1:F1"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p>Given a string <code>columnTitle</code> that represents the column title as appear in an Excel sheet, return <em>its corresponding column number</em>.</p>
|
||||
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p>
|
||||
|
||||
<p>For example:</p>
|
||||
|
||||
@@ -14,21 +14,21 @@ AB -> 28
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnTitle = "A"
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnTitle = "AB"
|
||||
<strong>Output:</strong> 28
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnTitle = "ZY"
|
||||
|
@@ -14,21 +14,21 @@ AB -> 28
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnNumber = 1
|
||||
<strong>Output:</strong> "A"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnNumber = 28
|
||||
<strong>Output:</strong> "AB"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> columnNumber = 701
|
||||
|
@@ -8,13 +8,13 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 3
|
||||
<strong>Output:</strong> ["1","2","Fizz"]
|
||||
</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> ["1","2","Fizz","4","Buzz"]
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 15
|
||||
<strong>Output:</strong> ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
|
||||
</pre>
|
||||
|
@@ -1,13 +1,11 @@
|
||||
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper and <code>citations</code> is sorted in an <strong>ascending order</strong>, return compute the researcher's <code>h</code><strong>-index</strong>.</p>
|
||||
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper and <code>citations</code> is sorted in <strong>ascending order</strong>, return <em>the researcher's h-index</em>.</p>
|
||||
|
||||
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: A scientist has an index <code>h</code> if <code>h</code> of their <code>n</code> papers have at least <code>h</code> citations each, and the other <code>n − h</code> papers have no more than <code>h</code> citations each.</p>
|
||||
|
||||
<p>If there are several possible values for <code>h</code>, the maximum one is taken as the <code>h</code><strong>-index</strong>.</p>
|
||||
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: The h-index is defined as the maximum value of <code>h</code> such that the given researcher has published at least <code>h</code> papers that have each been cited at least <code>h</code> times.</p>
|
||||
|
||||
<p>You must write an algorithm that runs in logarithmic time.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> citations = [0,1,3,5,6]
|
||||
@@ -16,7 +14,7 @@
|
||||
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> citations = [1,2,100]
|
||||
|
@@ -1,11 +1,9 @@
|
||||
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return compute the researcher's <code>h</code><strong>-index</strong>.</p>
|
||||
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return <em>the researcher's h-index</em>.</p>
|
||||
|
||||
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: A scientist has an index <code>h</code> if <code>h</code> of their <code>n</code> papers have at least <code>h</code> citations each, and the other <code>n − h</code> papers have no more than <code>h</code> citations each.</p>
|
||||
|
||||
<p>If there are several possible values for <code>h</code>, the maximum one is taken as the <code>h</code><strong>-index</strong>.</p>
|
||||
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: The h-index is defined as the maximum value of <code>h</code> such that the given researcher has published at least <code>h</code> papers that have each been cited at least <code>h</code> times.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> citations = [3,0,6,1,5]
|
||||
@@ -14,7 +12,7 @@
|
||||
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> citations = [1,3,1]
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<p>Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> water = "HOH"
|
||||
@@ -22,7 +22,7 @@
|
||||
<strong>Explanation:</strong> "HOH" and "OHH" are also valid answers.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> water = "OOHHHH"
|
||||
|
@@ -16,7 +16,7 @@
|
||||
<p>Return <em>the text after replacing the entities by the special characters</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> text = "&amp; is an HTML entity but &ambassador; is not."
|
||||
@@ -24,7 +24,7 @@
|
||||
<strong>Explanation:</strong> The parser will replace the &amp; entity by &
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> text = "and I quote: &quot;...&quot;"
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
|
||||
<p>A <em>defanged IP address</em> replaces every period <code>"."</code> with <code>"[.]"</code>.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>The answer is guaranteed to fit in a 32-bit signed integer.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]
|
||||
@@ -21,7 +21,7 @@ Since you can choose at most 2 projects, you need to finish the project indexed
|
||||
Therefore, output the final maximized capital, which is 0 + 1 + 3 = 4.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]
|
||||
|
@@ -5,14 +5,14 @@
|
||||
<p>You may not alter the values in the list's nodes, only nodes themselves may be changed.</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/03/reverse_ex1.jpg" style="width: 542px; height: 222px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,2,3,4,5], k = 2
|
||||
<strong>Output:</strong> [2,1,4,3,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/10/03/reverse_ex2.jpg" style="width: 542px; height: 222px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,2,3,4,5], k = 3
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an 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,1,2,3], k = 2
|
||||
@@ -17,7 +17,7 @@
|
||||
<strong>Explanation:</strong> Subarrays formed with exactly 2 different integers: [1,2], [2,1], [1,2], [2,3], [1,2,1], [2,1,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 = [1,2,1,3,4], k = 3
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Given two integers n and k, return the number of different arrays consist of numbers from <code>1</code> to <code>n</code> such that there are exactly <code>k</code> <strong>inverse pairs</strong>. Since the answer can be huge, 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> n = 3, k = 0
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> Only the array [1,2,3] which consists of numbers from 1 to 3 has exactly 0 inverse pairs.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, k = 1
|
@@ -5,7 +5,7 @@
|
||||
<p>Return <em>the maximum number of operations you can perform on the array</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], k = 5
|
||||
@@ -15,7 +15,7 @@
|
||||
- Remove numbers 2 and 3, then nums = []
|
||||
There are no more pairs that sum up to 5, hence a total of 2 operations.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,1,3,4,3], k = 6
|
||||
|
@@ -7,21 +7,21 @@
|
||||
<p>As the answer can be very large, return the answer <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,2], k = 3
|
||||
<strong>Output:</strong> 9
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,-2,1], k = 5
|
||||
<strong>Output:</strong> 2
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [-1,-2], k = 7
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>Return <em>the largest possible sum of the array after modifying it in this way</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,2,3], k = 1
|
||||
@@ -17,7 +17,7 @@
|
||||
<strong>Explanation:</strong> Choose index 1 and nums becomes [4,-2,3].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,-1,0,2], k = 3
|
||||
@@ -25,7 +25,7 @@
|
||||
<strong>Explanation:</strong> Choose indices (1, 2, 2) and nums becomes [3,1,0,2].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,-3,-1,5,-4], k = 2
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Return<em> the <strong>maximum</strong> <strong>product</strong> of </em><code>nums</code><em> after <strong>at most</strong> </em><code>k</code><em> operations. </em>Since the answer may be very large, return it <b>modulo</b> <code>10<sup>9</sup> + 7</code>. Note that you should maximize the product before taking the modulo. </p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,4], k = 5
|
||||
@@ -14,7 +14,7 @@ It can be shown that 20 is maximum product possible, so we return 20.
|
||||
Note that there may be other ways to increment nums to have the maximum product.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [6,3,3,2], k = 2
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<p>Return <em>the <strong>maximum value</strong> of the topmost element of the pile possible after <strong>exactly</strong></em> <code>k</code> <em>moves</em>. In case it is not possible to obtain a non-empty pile after <code>k</code> moves, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,2,2,4,0,6], k = 4
|
||||
@@ -26,7 +26,7 @@ One of the ways we can end with 5 at the top of the pile after 4 moves is as fol
|
||||
Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2], k = 1
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<p>Return <code>true</code> if it's possible to convert <code>s</code> into <code>t</code> in no more than <code>k</code> moves, 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> s = "input", t = "ouput", k = 9
|
||||
@@ -22,7 +22,7 @@
|
||||
<b>Explanation: </b>In the 6th move, we shift 'i' 6 times to get 'o'. And in the 7th move we shift 'n' to get 'u'.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abc", t = "bcd", k = 10
|
||||
@@ -30,7 +30,7 @@
|
||||
<strong>Explanation: </strong>We need to shift each character in s one time to convert it into t. We can shift 'a' to 'b' during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "aab", t = "bbb", k = 27
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p><strong>Note:</strong> The array can have <strong>any size</strong> at the start and does<strong> not </strong>count towards the number of resizing operations.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [10,20], k = 0
|
||||
@@ -17,7 +17,7 @@ We can set the initial size to be 20.
|
||||
The total wasted space is (20 - 10) + (20 - 20) = 10.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [10,20,30], k = 1
|
||||
@@ -27,7 +27,7 @@ We can set the initial size to be 20 and resize to 30 at time 2.
|
||||
The total wasted space is (20 - 10) + (20 - 20) + (30 - 30) = 10.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [10,20,15,30,20], k = 2
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>You are also given three integers <code>src</code>, <code>dst</code>, and <code>k</code>, return <em><strong>the cheapest price</strong> from </em><code>src</code><em> to </em><code>dst</code><em> with at most </em><code>k</code><em> stops. </em>If there is no such route, return<em> </em><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/2022/03/18/cheapest-flights-within-k-stops-3drawio.png" style="width: 332px; height: 392px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1
|
||||
@@ -14,7 +14,7 @@ The optimal path with at most 1 stop from city 0 to 3 is marked in red and has c
|
||||
Note that the path through cities [0,1,2,3] is cheaper but is invalid because it uses 2 stops.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/18/cheapest-flights-within-k-stops-1drawio.png" style="width: 332px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 1
|
||||
@@ -24,7 +24,7 @@ The graph is shown above.
|
||||
The optimal path with at most 1 stop from city 0 to 2 is marked in red and has cost 100 + 100 = 200.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/18/cheapest-flights-within-k-stops-2drawio.png" style="width: 332px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, flights = [[0,1,100],[1,2,100],[0,2,500]], src = 0, dst = 2, k = 0
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>After converting, each digit should be interpreted as a base <code>10</code> number, and the sum should be returned in base <code>10</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 34, k = 6
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation: </strong>34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 10, k = 10
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,1,0], k = 1
|
||||
@@ -15,7 +15,7 @@
|
||||
<strong>Explanation:</strong> Flip nums[0], then flip nums[2].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,0], k = 2
|
||||
@@ -23,7 +23,7 @@
|
||||
<strong>Explanation:</strong> No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,0,0,1,0,1,1,0], k = 3
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<p>The functions <code data-stringify-type="code">get</code> and <code data-stringify-type="code">put</code> must each 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>
|
||||
@@ -50,7 +50,7 @@ lfu.get(4); // return 4
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= capacity <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= capacity <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= key <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= value <= 10<sup>9</sup></code></li>
|
||||
<li>At most <code>2 * 10<sup>5</sup></code> calls will be made to <code>get</code> and <code>put</code>.</li>
|
||||
|
@@ -5,13 +5,13 @@
|
||||
<ul>
|
||||
<li><code>LRUCache(int capacity)</code> Initialize the LRU cache with <strong>positive</strong> size <code>capacity</code>.</li>
|
||||
<li><code>int get(int key)</code> Return the value of the <code>key</code> if the key exists, otherwise return <code>-1</code>.</li>
|
||||
<li><code>void put(int key, int value)</code> Update the value of the <code>key</code> if the <code>key</code> exists. Otherwise, add the <code>key-value</code> pair to the cache. If the number of keys exceeds the <code>capacity</code> from this operation, <strong>evict</strong> the least recently used key.</li>
|
||||
<li><code>void put(int key, int value)</code> Update the value of the <code>key</code> if the <code>key</code> exists. Otherwise, add the <code>key-value</code> pair to the cache. If the number of keys exceeds the <code>capacity</code> from this operation, <strong>evict</strong> the least recently used key.</li>
|
||||
</ul>
|
||||
|
||||
<p>The functions <code data-stringify-type="code">get</code> and <code data-stringify-type="code">put</code> must each run in <code>O(1)</code> average time complexity.</p>
|
||||
<p>The functions <code>get</code> and <code>put</code> must each 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>
|
||||
@@ -40,5 +40,5 @@ lRUCache.get(4); // return 4
|
||||
<li><code>1 <= capacity <= 3000</code></li>
|
||||
<li><code>0 <= key <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= value <= 10<sup>5</sup></code></li>
|
||||
<li>At most 2<code> * 10<sup>5</sup></code> calls will be made to <code>get</code> and <code>put</code>.</li>
|
||||
<li>At most <code>2 * 10<sup>5</sup></code> calls will be made to <code>get</code> and <code>put</code>.</li>
|
||||
</ul>
|
||||
|
@@ -13,7 +13,7 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "(let x 2 (mult x (let x 3 y 4 (add x y))))"
|
||||
@@ -23,7 +23,7 @@ we check from the innermost scope to the outermost in the context of the variabl
|
||||
Since x = 3 is found first, the value of x is 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "(let x 3 x 2 x)"
|
||||
@@ -31,7 +31,7 @@ Since x = 3 is found first, the value of x is 3.
|
||||
<strong>Explanation:</strong> Assignment in let statements is processed sequentially.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "(let x 1 y 2 x (add x y) (add x y))"
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png" style="width: 100%; max-width: 300px;" /></p>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<strong>Output:</strong> [1,3,5,6,2,4]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png" style="width: 296px; height: 241px;" /></p>
|
||||
|
||||
|
@@ -3,14 +3,14 @@
|
||||
<p>Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img src="https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png" style="width: 100%; max-width: 300px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1,null,3,2,4,null,5,6]
|
||||
<strong>Output:</strong> [5,6,3,2,4,1]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png" style="width: 296px; height: 241px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png" style="width: 100%; max-width: 300px;" /></p>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<strong>Output:</strong> [[1],[3,2,4],[5,6]]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png" style="width: 296px; height: 241px;" /></p>
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img src="https://assets.leetcode.com/uploads/2018/10/12/narytreeexample.png" style="width: 100%; max-width: 300px;" /></p>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<strong>Output:</strong> 3
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/08/sample_4_964.png" style="width: 296px; height: 241px;" /></p>
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<p>Return the state of the prison after <code>n</code> days (i.e., <code>n</code> such changes described above).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cells = [0,1,0,1,1,0,0,1], n = 7
|
||||
@@ -30,7 +30,7 @@ Day 6: [0, 0, 1, 0, 1, 1, 0, 0]
|
||||
Day 7: [0, 0, 1, 1, 0, 0, 0, 0]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cells = [1,0,0,1,0,0,1,0], n = 1000000000
|
||||
|
@@ -15,14 +15,14 @@ string convert(string s, int numRows);
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "PAYPALISHIRING", numRows = 3
|
||||
<strong>Output:</strong> "PAHNAPLSIIGYIR"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "PAYPALISHIRING", numRows = 4
|
||||
@@ -34,7 +34,7 @@ Y A H R
|
||||
P I
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "A", numRows = 1
|
@@ -13,7 +13,7 @@
|
||||
<p>The function <code>gcd(x, y)</code> is the greatest common divisor of <code>x</code> and <code>y</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2]
|
||||
@@ -22,7 +22,7 @@
|
||||
(1 * gcd(1, 2)) = 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,4,6,8]
|
||||
@@ -31,7 +31,7 @@
|
||||
(1 * gcd(3, 6)) + (2 * gcd(4, 8)) = 3 + 8 = 11
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5,6]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Given an integer <code>n</code>, return <em>the number of distinct solutions to the <strong>n-queens puzzle</strong></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/2020/11/13/queens.jpg" style="width: 600px; height: 268px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> There are two distinct solutions to the 4-queens puzzle as shown.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
@@ -5,7 +5,7 @@
|
||||
<p>Each solution contains a distinct board configuration of the n-queens' placement, where <code>'Q'</code> and <code>'.'</code> both indicate a queen and an empty space, respectively.</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/11/13/queens.jpg" style="width: 600px; height: 268px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> There exist two distinct solutions to the 4-queens puzzle as shown above
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<p>Given <code>n</code>, the number of stones in the heap, return <code>true</code><em> if you can win the game assuming both you and your friend play optimally, otherwise return </em><code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4
|
||||
@@ -22,14 +22,14 @@
|
||||
In all outcomes, your friend wins.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<p><code>RandomizedCollection</code> is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also removing a random element.</p>
|
||||
<p><code>RandomizedCollection</code> is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also reporting a random element.</p>
|
||||
|
||||
<p>Implement the <code>RandomizedCollection</code> class:</p>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<li><code>RandomizedCollection()</code> Initializes the empty <code>RandomizedCollection</code> object.</li>
|
||||
<li><code>bool insert(int val)</code> Inserts an item <code>val</code> into the multiset, even if the item is already present. Returns <code>true</code> if the item is not present, <code>false</code> otherwise.</li>
|
||||
<li><code>bool remove(int val)</code> Removes an item <code>val</code> from the multiset if present. Returns <code>true</code> if the item is present, <code>false</code> otherwise. Note that if <code>val</code> has multiple occurrences in the multiset, we only remove one of them.</li>
|
||||
<li><code>int getRandom()</code> Returns a random element from the current multiset of elements. The probability of each element being returned is <strong>linearly related</strong> to the number of same values the multiset contains.</li>
|
||||
<li><code>int getRandom()</code> Returns a random element from the current multiset of elements. The probability of each element being returned is <strong>linearly related</strong> to the number of the same values the multiset contains.</li>
|
||||
</ul>
|
||||
|
||||
<p>You must implement the functions of the class such that each function works on <strong>average</strong> <code>O(1)</code> time complexity.</p>
|
||||
@@ -14,7 +14,7 @@
|
||||
<p><strong>Note:</strong> The test cases are generated such that <code>getRandom</code> will only be called if there is <strong>at least one</strong> item in the <code>RandomizedCollection</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<p>You must implement the functions of the class such that each function works in <strong>average</strong> <code>O(1)</code> time complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
|
@@ -1,21 +1,21 @@
|
||||
<p>Implement <a href="http://www.cplusplus.com/reference/valarray/pow/" target="_blank">pow(x, n)</a>, which calculates <code>x</code> raised to the power <code>n</code> (i.e., <code>x<sup>n</sup></code>).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> x = 2.00000, n = 10
|
||||
<strong>Output:</strong> 1024.00000
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> x = 2.10000, n = 3
|
||||
<strong>Output:</strong> 9.26100
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> x = 2.00000, n = -2
|
||||
@@ -29,5 +29,7 @@
|
||||
<ul>
|
||||
<li><code>-100.0 < x < 100.0</code></li>
|
||||
<li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup>-1</code></li>
|
||||
<li><code>n</code> is an integer.</li>
|
||||
<li>Either <code>x</code> is not zero or <code>n > 0</code>.</li>
|
||||
<li><code>-10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
||||
|
@@ -14,7 +14,7 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
|
@@ -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>
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p><em>Return the probability that after <code>t</code> seconds the frog is on the vertex <code>target</code>. </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>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/21/frog1.jpg" style="width: 338px; height: 304px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4
|
||||
@@ -13,7 +13,7 @@
|
||||
<strong>Explanation:</strong> The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after <strong>second 1</strong> and then jumping with 1/2 probability to vertex 4 after <strong>second 2</strong>. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<strong><img alt="" src="https://assets.leetcode.com/uploads/2021/12/21/frog2.jpg" style="width: 304px; height: 304px;" /></strong>
|
||||
|
||||
<pre>
|
||||
|
@@ -13,7 +13,7 @@
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> url = "https://leetcode.com/problems/design-tinyurl"
|
||||
@@ -22,7 +22,7 @@
|
||||
<strong>Explanation:</strong>
|
||||
Solution obj = new Solution();
|
||||
string tiny = obj.encode(url); // returns the encoded tiny url.
|
||||
string ans = obj.decode(tiny); // returns the original url after deconding it.
|
||||
string ans = obj.decode(tiny); // returns the original url after decoding it.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<p><strong>Note: </strong>The input is an array of integers. Only the <strong>least significant 8 bits</strong> of each integer is used to store the data. This means each integer represents only 1 byte of data.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> data = [197,130,1]
|
||||
@@ -33,7 +33,7 @@
|
||||
It is a valid utf-8 encoding for a 2-bytes character followed by a 1-byte character.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> data = [235,140,4]
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<p>Given the base <code>k</code> and the number <code>n</code>, return <em>the <strong>sum</strong> of the</em> <code>n</code> <em><strong>smallest</strong> k-mirror numbers</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 2, n = 5
|
||||
@@ -24,7 +24,7 @@
|
||||
Their sum = 1 + 3 + 5 + 7 + 9 = 25.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 3, n = 7
|
||||
@@ -42,7 +42,7 @@ Their sum = 1 + 3 + 5 + 7 + 9 = 25.
|
||||
Their sum = 1 + 2 + 4 + 8 + 121 + 151 + 212 = 499.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> k = 7, n = 17
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Consider a list of all factors of <code>n</code> sorted in <strong>ascending order</strong>, return <em>the </em><code>k<sup>th</sup></code><em> factor</em> in this list or return <code>-1</code> if <code>n</code> has less than <code>k</code> factors.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 12, k = 3
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> Factors list is [1, 2, 3, 4, 6, 12], the 3<sup>rd</sup> factor is 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7, k = 2
|
||||
@@ -19,7 +19,7 @@
|
||||
<strong>Explanation:</strong> Factors list is [1, 7], the 2<sup>nd</sup> factor is 7.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4, k = 4
|
||||
@@ -33,3 +33,8 @@
|
||||
<ul>
|
||||
<li><code>1 <= k <= n <= 1000</code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Follow up:</strong></p>
|
||||
|
||||
<p>Could you solve this problem in less than O(n) complexity?</p>
|
||||
|
@@ -1,23 +1,27 @@
|
||||
<p>Given a non-negative integer <code>x</code>, compute and return <em>the square root of</em> <code>x</code>.</p>
|
||||
<p>Given a non-negative integer <code>x</code>, return <em>the square root of </em><code>x</code><em> rounded down to the nearest integer</em>. The returned integer should be <strong>non-negative</strong> as well.</p>
|
||||
|
||||
<p>Since the return type is an integer, the decimal digits are <strong>truncated</strong>, and only <strong>the integer part</strong> of the result is returned.</p>
|
||||
<p>You <strong>must not use</strong> any built-in exponent function or operator.</p>
|
||||
|
||||
<p><strong>Note: </strong>You are not allowed to use any built-in exponent function or operator, such as <code>pow(x, 0.5)</code> or <code>x ** 0.5</code>.</p>
|
||||
<ul>
|
||||
<li>For example, do not use <code>pow(x, 0.5)</code> in c++ or <code>x ** 0.5</code> in python.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> x = 4
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> The square root of 4 is 2, so we return 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> x = 8
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.</pre>
|
||||
<strong>Explanation:</strong> The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be formed.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/05/1536_ex1_upd.JPG" style="width: 132px; height: 35px;" /></strong></p>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/05/1536_ex2_upd.JPG" style="width: 267px; height: 35px;" /></strong></p>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<strong>Output:</strong> 2
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> text = "leetcode"
|
||||
|
@@ -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
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Return <em>the <strong>minimum</strong> degree of a connected trio in the graph, or</em> <code>-1</code> <em>if the graph has no connected trios.</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/01/26/trios1.png" style="width: 388px; height: 164px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]
|
||||
@@ -15,7 +15,7 @@
|
||||
<strong>Explanation:</strong> There is exactly one trio, which is [1,2,3]. The edges that form its degree are bolded in the figure above.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/26/trios2.png" style="width: 388px; height: 164px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]
|
||||
|
@@ -5,21 +5,21 @@
|
||||
<p>Return the answer as one of the following values <code>{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> day = 31, month = 8, year = 2019
|
||||
<strong>Output:</strong> "Saturday"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> day = 18, month = 7, year = 1999
|
||||
<strong>Output:</strong> "Sunday"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> day = 15, month = 8, year = 1993
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<p>A set <code>x</code> is a <strong>subset</strong> of a set <code>y</code> if all elements of <code>x</code> are also elements of <code>y</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strs = ["10","0001","111001","1","0"], m = 5, n = 3
|
||||
@@ -15,7 +15,7 @@ Other valid but smaller subsets include {"0001", "1"} and {&
|
||||
{"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> strs = ["10","0","1"], m = 1, n = 1
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<p>Given a string <code>date</code> representing a <a href="https://en.wikipedia.org/wiki/Gregorian_calendar" target="_blank">Gregorian calendar</a> date formatted as <code>YYYY-MM-DD</code>, return <em>the day number of the year</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> date = "2019-01-09"
|
||||
@@ -9,7 +9,7 @@
|
||||
<strong>Explanation:</strong> Given date is the 9th day of the year in 2019.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> date = "2019-02-10"
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Given an integer array <code>hand</code> where <code>hand[i]</code> is the value written on the <code>i<sup>th</sup></code> card and an integer <code>groupSize</code>, return <code>true</code> if she can rearrange the cards, or <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> hand = [1,2,3,6,2,3,4,7,8], groupSize = 3
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explanation:</strong> Alice's hand can be rearranged as [1,2,3],[2,3,4],[6,7,8]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> hand = [1,2,3,4,5], groupSize = 4
|
||||
|
@@ -3,21 +3,21 @@
|
||||
|
||||
|
||||
<p>Return the running sum of <code>nums</code>.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
|
||||
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
|
||||
<strong>Output:</strong> [1,3,6,10]
|
||||
|
||||
|
||||
<strong>Explanation:</strong> Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].</pre>
|
||||
|
||||
|
||||
|
@@ -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,13 +1,13 @@
|
||||
<p>Given an integer array <code>nums</code>, <em>find three numbers whose product is maximum and return the maximum product</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]
|
||||
<strong>Output:</strong> 6
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [1,2,3,4]
|
||||
<strong>Output:</strong> 24
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [-1,-2,-3]
|
||||
<strong>Output:</strong> -6
|
||||
</pre>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Return the result as a list of indices representing the starting position of each interval (<strong>0-indexed</strong>). If there are multiple answers, return the lexicographically smallest one.</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,2,6,7,5,1], k = 2
|
||||
@@ -12,7 +12,7 @@
|
||||
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,1,2,1,2,1,2,1], k = 2
|
||||
|
@@ -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>
|
||||
|
@@ -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
|
||||
|
@@ -1,24 +1,44 @@
|
||||
<p>You are given an integer array <code>nums</code>. In one move, you can choose one element of <code>nums</code> and change it by <strong>any value</strong>.</p>
|
||||
<p>You are given an integer array <code>nums</code>.</p>
|
||||
|
||||
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> after performing <strong>at most three moves</strong></em>.</p>
|
||||
<p>In one move, you can choose one element of <code>nums</code> and change it to <strong>any value</strong>.</p>
|
||||
|
||||
<p>Return <em>the minimum difference between the largest and smallest value of <code>nums</code> <strong>after performing at most three moves</strong></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,3,2,4]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> Change the array [5,3,2,4] to [<strong>2</strong>,<strong>2</strong>,2,<strong>2</strong>].
|
||||
The difference between the maximum and minimum is 2-2 = 0.
|
||||
<strong>Explanation:</strong> We can make at most 3 moves.
|
||||
In the first move, change 2 to 3. nums becomes [5,3,3,4].
|
||||
In the second move, change 4 to 3. nums becomes [5,3,3,3].
|
||||
In the third move, change 5 to 3. nums becomes [3,3,3,3].
|
||||
After performing 3 moves, the difference between the minimum and maximum is 3 - 3 = 0.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,5,0,10,14]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> Change the array [1,5,0,10,14] to [1,<strong>1</strong>,0,<strong>1</strong>,<strong>1</strong>].
|
||||
The difference between the maximum and minimum is 1-0 = 1.
|
||||
<strong>Explanation:</strong> We can make at most 3 moves.
|
||||
In the first move, change 5 to 0. nums becomes [1,0,0,10,14].
|
||||
In the second move, change 10 to 0. nums becomes [1,0,0,0,14].
|
||||
In the third move, change 14 to 1. nums becomes [1,0,0,0,1].
|
||||
After performing 3 moves, the difference between the minimum and maximum is 1 - 0 = 1.
|
||||
It can be shown that there is no way to make the difference 0 in 3 moves.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,100,20]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> We can make at most 3 moves.
|
||||
In the first move, change 100 to 7. nums becomes [3,7,20].
|
||||
In the second move, change 20 to 7. nums becomes [3,7,7].
|
||||
In the third move, change 3 to 7. nums becomes [7,7,7].
|
||||
After performing 3 moves, the difference between the minimum and maximum is 7 - 7 = 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -14,13 +14,13 @@
|
||||
<p>Note that the entire part is used when considering what binary value it represents. For example, <code>[1,1,0]</code> represents <code>6</code> in decimal, not <code>3</code>. Also, leading zeros <strong>are allowed</strong>, so <code>[0,1,1]</code> and <code>[1,1]</code> represent the same value.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> arr = [1,0,1,0,1]
|
||||
<strong>Output:</strong> [0,3]
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> arr = [1,1,0,1,1]
|
||||
<strong>Output:</strong> [-1,-1]
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> arr = [1,1,0,0,1]
|
||||
<strong>Output:</strong> [0,2]
|
||||
</pre>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p>Return <em>the total area of all three projections</em>.</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/02/shadow.png" style="width: 800px; height: 214px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,2],[3,4]]
|
||||
@@ -17,14 +17,14 @@
|
||||
<strong>Explanation:</strong> Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[2]]
|
||||
<strong>Output:</strong> 5
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,0],[0,2]]
|
||||
|
@@ -7,21 +7,21 @@
|
||||
<p><strong>Note:</strong> The bottom face of each shape counts toward its surface area.</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/01/08/tmp-grid2.jpg" style="width: 162px; height: 162px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,2],[3,4]]
|
||||
<strong>Output:</strong> 34
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/08/tmp-grid4.jpg" style="width: 242px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,1,1],[1,0,1],[1,1,1]]
|
||||
<strong>Output:</strong> 32
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/08/tmp-grid5.jpg" style="width: 242px; height: 242px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[2,2,2],[2,1,2],[2,2,2]]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on the next row.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
|
||||
@@ -16,7 +16,7 @@
|
||||
The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above).
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> triangle = [[-10]]
|
||||
|
@@ -1,18 +1,24 @@
|
||||
<p>Given an integer array <code>nums</code>, return <em>the largest perimeter of a triangle with a non-zero area, formed from three of these lengths</em>. If it is impossible to form any triangle of a non-zero area, 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> nums = [2,1,2]
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> You can form a triangle with three side lengths: 1, 2, and 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,1]
|
||||
<strong>Input:</strong> nums = [1,2,1,10]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
You cannot use the side lengths 1, 1, and 2 to form a triangle.
|
||||
You cannot use the side lengths 1, 1, and 10 to form a triangle.
|
||||
You cannot use the side lengths 1, 2, and 10 to form a triangle.
|
||||
As we cannot use any three side lengths to form a triangle of non-zero area, we return 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>An integer <code>m</code> is a <strong>divisor</strong> of <code>n</code> if there exists an integer <code>k</code> such that <code>n = k * m</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
@@ -11,7 +11,7 @@
|
||||
<strong>Explantion:</strong> 2 has only two divisors: 1 and 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<p>Return <em>the result string after sorting </em><code>s</code><em> with this algorithm</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "aaaabbbbcccc"
|
||||
@@ -27,7 +27,7 @@ After steps 1, 2 and 3 of the second iteration, result = "abccbaabc"
|
||||
After steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "rat"
|
||||
|
@@ -8,20 +8,20 @@
|
||||
| recordDate | date |
|
||||
| temperature | int |
|
||||
+---------------+---------+
|
||||
id is the primary key for this table.
|
||||
id is the column with unique values for this table.
|
||||
This table contains information about the temperature on a certain day.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write an SQL query to find all dates' <code>Id</code> with higher temperatures compared to its previous dates (yesterday).</p>
|
||||
<p>Write a solution to find all dates' <code>Id</code> with higher temperatures compared to its previous dates (yesterday).</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,7 +1,7 @@
|
||||
<p>A <strong>permutation</strong> of an array of integers is an arrangement of its members into a sequence or linear order.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, for <code>arr = [1,2,3]</code>, the following are considered permutations of <code>arr</code>: <code>[1,2,3]</code>, <code>[1,3,2]</code>, <code>[3,1,2]</code>, <code>[2,3,1]</code>.</li>
|
||||
<li>For example, for <code>arr = [1,2,3]</code>, the following are all the permutations of <code>arr</code>: <code>[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>The <strong>next permutation</strong> of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the <strong>next permutation</strong> of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).</p>
|
||||
@@ -17,21 +17,21 @@
|
||||
<p>The replacement must be <strong><a href="http://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in place</a></strong> and use only constant extra memory.</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]
|
||||
<strong>Output:</strong> [1,3,2]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,2,1]
|
||||
<strong>Output:</strong> [1,2,3]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,5]
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>Return <em>an array </em><code>ans</code><em> of length </em><code>nums1.length</code><em> such that </em><code>ans[i]</code><em> is the <strong>next greater element</strong> as described above.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [4,1,2], nums2 = [1,3,4,2]
|
||||
@@ -18,7 +18,7 @@
|
||||
- 2 is underlined in nums2 = [1,3,4,<u>2</u>]. There is no next greater element, so the answer is -1.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [2,4], nums2 = [1,2,3,4]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>The <strong>next greater number</strong> of a number <code>x</code> is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return <code>-1</code> for this number.</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]
|
||||
@@ -13,7 +13,7 @@ The number 2 can't find next greater number.
|
||||
The second 1's next greater number needs to search circularly, which is also 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,3]
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<p><strong>Note</strong> that the returned integer should fit in <strong>32-bit integer</strong>, if there is a valid answer but it does not fit in <strong>32-bit integer</strong>, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 12
|
||||
<strong>Output:</strong> 21
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> n = 21
|
||||
<strong>Output:</strong> -1
|
||||
</pre>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<p>Given an integer <code>n</code>, return <em>the <strong>smallest numerically balanced</strong> number <strong>strictly greater</strong> than </em><code>n</code><em>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1
|
||||
@@ -14,7 +14,7 @@
|
||||
It is also the smallest numerically balanced number strictly greater than 1.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1000
|
||||
@@ -27,7 +27,7 @@ It is also the smallest numerically balanced number strictly greater than 1000.
|
||||
Note that 1022 cannot be the answer because 0 appeared more than 0 times.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3000
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<p>An array <code>arr</code> is <strong>non-increasing</strong> if <code>arr[i-1] >= arr[i]</code> for every <code>1 <= i < arr.length</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]
|
||||
@@ -16,7 +16,7 @@
|
||||
The maximum distance is 2 with pair (2,4).
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [2,2,2], nums2 = [10,10,1]
|
||||
@@ -25,7 +25,7 @@ The maximum distance is 2 with pair (2,4).
|
||||
The maximum distance is 1 with pair (0,1).
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]
|
||||
|
@@ -3,10 +3,10 @@
|
||||
<p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in adjacent rows are in the same column.</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/falling-grid.jpg" style="width: 244px; height: 245px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [[1,2,3],[4,5,6],[7,8,9]]
|
||||
<strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]
|
||||
<strong>Output:</strong> 13
|
||||
<strong>Explanation:</strong>
|
||||
The possible falling paths are:
|
||||
@@ -16,7 +16,7 @@ The possible falling paths are:
|
||||
The falling path with the smallest sum is [1,5,7], so the answer is 13.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[7]]
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user