mirror of https://github.com/doocs/leetcode.git
feat: add new lc problems (#4251)
This commit is contained in:
parent
9d3ff3f620
commit
3e4f5959b6
|
|
@ -18,7 +18,7 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个字符串 <code>s</code>,请你将<em> </em><code>s</code><em> </em>分割成一些 <span data-keyword="substring-nonempty">子串</span>,使每个子串都是 <strong><span data-keyword="palindrome-string">回文串</span></strong> 。返回 <code>s</code> 所有可能的分割方案。</p>
|
||||
<p>给你一个字符串 <code>s</code>,请你将<em> </em><code>s</code><em> </em>分割成一些子串,使每个子串都是 <strong><span data-keyword="palindrome-string">回文串</span></strong> 。返回 <code>s</code> 所有可能的分割方案。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,26 +23,41 @@ tags:
|
|||
<p>Assume that <code>file.txt</code> has the following content:</p>
|
||||
|
||||
<pre>
|
||||
|
||||
Line 1
|
||||
|
||||
Line 2
|
||||
|
||||
Line 3
|
||||
|
||||
Line 4
|
||||
|
||||
Line 5
|
||||
|
||||
Line 6
|
||||
|
||||
Line 7
|
||||
|
||||
Line 8
|
||||
|
||||
Line 9
|
||||
|
||||
Line 10
|
||||
|
||||
</pre>
|
||||
|
||||
<p>Your script should output the tenth line, which is:</p>
|
||||
|
||||
<pre>
|
||||
|
||||
Line 10
|
||||
|
||||
</pre>
|
||||
|
||||
<div class="spoilers"><b>Note:</b><br />
|
||||
|
||||
1. If the file contains less than 10 lines, what should you output?<br />
|
||||
|
||||
2. There's at least three different solutions. Try to explore all possibilities.</div>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ tags:
|
|||
<strong>输入:</strong>n = 5, bad = 4
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>
|
||||
<code>调用 isBadVersion(3) -> false
|
||||
调用 isBadVersion(5) -> true
|
||||
<code>调用 isBadVersion(3) -> false
|
||||
调用 isBadVersion(5) -> true
|
||||
调用 isBadVersion(4) -> true</code>
|
||||
<code>所以,4 是第一个错误的版本。</code>
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -20,35 +20,28 @@ tags:
|
|||
|
||||
<p>给定一个二进制数组 <code>nums</code> , 找到含有相同数量的 <code>0</code> 和 <code>1</code> 的最长连续子数组,并返回该子数组的长度。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [0,1]
|
||||
<strong>输出:</strong>2
|
||||
<strong>说明:</strong>[0, 1] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||||
<strong>输入:</strong> nums = [0,1]
|
||||
<strong>输出:</strong> 2
|
||||
<strong>说明:</strong> [0, 1] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [0,1,0]
|
||||
<strong>输出:</strong>2
|
||||
<strong>说明:</strong>[0, 1] (或 [1, 0]) 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||||
<strong>输入:</strong> nums = [0,1,0]
|
||||
<strong>输出:</strong> 2
|
||||
<strong>说明:</strong> [0, 1] (或 [1, 0]) 是具有相同数量0和1的最长连续子数组。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [0,1,1,1,1,1,0,0,0]
|
||||
<b>输出:</b>6
|
||||
<b>解释:</b>[1,1,1,0,0,0] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>nums[i]</code> 不是 <code>0</code> 就是 <code>1</code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -37,14 +37,6 @@ tags:
|
|||
<strong>Explanation:</strong> [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0,1,1,1,1,1,0,0,0]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> [1,1,1,0,0,0] is the longest contiguous subarray with equal number of 0 and 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ tags:
|
|||
<strong>输入:</strong>matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>
|
||||
在上述矩阵中, 其对角线为:
|
||||
"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]"。
|
||||
在上述矩阵中, 其对角线为:
|
||||
"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]"。
|
||||
各条对角线上的所有元素均相同, 因此答案是 True 。
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -27,35 +27,51 @@ tags:
|
|||
<p>Now after pouring some non-negative integer cups of champagne, return how full the <code>j<sup>th</sup></code> glass in the <code>i<sup>th</sup></code> row is (both <code>i</code> and <code>j</code> are 0-indexed.)</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poured = 1, query_row = 1, query_glass = 1
|
||||
|
||||
<strong>Output:</strong> 0.00000
|
||||
|
||||
<strong>Explanation:</strong> We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poured = 2, query_row = 1, query_glass = 1
|
||||
|
||||
<strong>Output:</strong> 0.50000
|
||||
|
||||
<strong>Explanation:</strong> We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poured = 100000009, query_row = 33, query_glass = 17
|
||||
|
||||
<strong>Output:</strong> 1.00000
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= poured <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= query_glass <= query_row < 100</code></li>
|
||||
|
||||
<li><code>0 <= poured <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>0 <= query_glass <= query_row < 100</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,18 +23,29 @@ tags:
|
|||
<p>A <em>defanged IP address</em> replaces every period <code>"."</code> with <code>"[.]"</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> address = "1.1.1.1"
|
||||
|
||||
<strong>Output:</strong> "1[.]1[.]1[.]1"
|
||||
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> address = "255.100.50.0"
|
||||
|
||||
<strong>Output:</strong> "255[.]100[.]50[.]0"
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The given <code>address</code> is a valid IPv4 address.</li>
|
||||
|
||||
<li>The given <code>address</code> is a valid IPv4 address.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,17 +22,25 @@ tags:
|
|||
<p>A string is a <em>valid parentheses string</em> (denoted VPS) if and only if it consists of <code>"("</code> and <code>")"</code> characters only, and:</p>
|
||||
|
||||
<ul>
|
||||
<li>It is the empty string, or</li>
|
||||
<li>It can be written as <code>AB</code> (<code>A</code> concatenated with <code>B</code>), where <code>A</code> and <code>B</code> are VPS's, or</li>
|
||||
<li>It can be written as <code>(A)</code>, where <code>A</code> is a VPS.</li>
|
||||
|
||||
<li>It is the empty string, or</li>
|
||||
|
||||
<li>It can be written as <code>AB</code> (<code>A</code> concatenated with <code>B</code>), where <code>A</code> and <code>B</code> are VPS's, or</li>
|
||||
|
||||
<li>It can be written as <code>(A)</code>, where <code>A</code> is a VPS.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>We can similarly define the <em>nesting depth</em> <code>depth(S)</code> of any VPS <code>S</code> as follows:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>depth("") = 0</code></li>
|
||||
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS's</li>
|
||||
<li><code>depth("(" + A + ")") = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
|
||||
|
||||
<li><code>depth("") = 0</code></li>
|
||||
|
||||
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS's</li>
|
||||
|
||||
<li><code>depth("(" + A + ")") = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>For example, <code>""</code>, <code>"()()"</code>, and <code>"()(()())"</code> are VPS's (with nesting depths 0, 1, and 2), and <code>")("</code> and <code>"(()"</code> are not VPS's.</p>
|
||||
|
|
|
|||
|
|
@ -28,11 +28,17 @@ tags:
|
|||
<p>We may make the following moves:</p>
|
||||
|
||||
<ul>
|
||||
<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>'!'</code> adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code> to the answer.</li>
|
||||
|
||||
<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>'!'</code> adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code> to the answer.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>(Here, the only positions that exist on the board are positions with letters on them.)</p>
|
||||
|
|
@ -40,19 +46,31 @@ tags:
|
|||
<p>Return a sequence of moves that makes our answer equal to <code>target</code> in the minimum number of moves. You may return any path that does so.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> target = "leet"
|
||||
|
||||
<strong>Output:</strong> "DDR!UURRR!!DDD!"
|
||||
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> target = "code"
|
||||
|
||||
<strong>Output:</strong> "RR!DDRR!UUL!R!"
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= target.length <= 100</code></li>
|
||||
<li><code>target</code> consists only of English lowercase letters.</li>
|
||||
|
||||
<li><code>1 <= target.length <= 100</code></li>
|
||||
|
||||
<li><code>target</code> consists only of English lowercase letters.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,27 +23,39 @@ tags:
|
|||
<p>Given a 2D <code>grid</code> of <code>0</code>s and <code>1</code>s, return the number of elements in the largest <strong>square</strong> subgrid that has all <code>1</code>s on its <strong>border</strong>, or <code>0</code> if such a subgrid doesn't exist in the <code>grid</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> grid = [[1,1,1],[1,0,1],[1,1,1]]
|
||||
|
||||
<strong>Output:</strong> 9
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> grid = [[1,1,0,0]]
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= grid.length <= 100</code></li>
|
||||
<li><code>1 <= grid[0].length <= 100</code></li>
|
||||
<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>
|
||||
|
||||
<li><code>1 <= grid.length <= 100</code></li>
|
||||
|
||||
<li><code>1 <= grid[0].length <= 100</code></li>
|
||||
|
||||
<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -25,13 +25,17 @@ tags:
|
|||
<p>Return the shortest distance between the given <code>start</code> and <code>destination</code> stops.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1.jpg" style="width: 388px; height: 240px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 1
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
<strong>Explanation:</strong> Distance between 0 and 1 is 1 or 9, minimum is 1.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
@ -41,9 +45,13 @@ tags:
|
|||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1-1.jpg" style="width: 388px; height: 240px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 2
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> Distance between 0 and 2 is 3 or 7, minimum is 3.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
@ -53,19 +61,29 @@ tags:
|
|||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1-2.jpg" style="width: 388px; height: 240px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 3
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> Distance between 0 and 3 is 6 or 4, minimum is 4.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10^4</code></li>
|
||||
<li><code>distance.length == n</code></li>
|
||||
<li><code>0 <= start, destination < n</code></li>
|
||||
<li><code>0 <= distance[i] <= 10^4</code></li>
|
||||
|
||||
<li><code>1 <= n <= 10^4</code></li>
|
||||
|
||||
<li><code>distance.length == n</code></li>
|
||||
|
||||
<li><code>0 <= start, destination < n</code></li>
|
||||
|
||||
<li><code>0 <= distance[i] <= 10^4</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,35 +23,53 @@ tags:
|
|||
<p>Given 2 integers <code>n</code> and <code>start</code>. Your task is return <strong>any</strong> permutation <code>p</code> of <code>(0,1,2.....,2^n -1) </code>such that :</p>
|
||||
|
||||
<ul>
|
||||
<li><code>p[0] = start</code></li>
|
||||
<li><code>p[i]</code> and <code>p[i+1]</code> differ by only one bit in their binary representation.</li>
|
||||
<li><code>p[0]</code> and <code>p[2^n -1]</code> must also differ by only one bit in their binary representation.</li>
|
||||
|
||||
<li><code>p[0] = start</code></li>
|
||||
|
||||
<li><code>p[i]</code> and <code>p[i+1]</code> differ by only one bit in their binary representation.</li>
|
||||
|
||||
<li><code>p[0]</code> and <code>p[2^n -1]</code> must also differ by only one bit in their binary representation.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> n = 2, start = 3
|
||||
|
||||
<strong>Output:</strong> [3,2,0,1]
|
||||
|
||||
<strong>Explanation:</strong> The binary representation of the permutation is (11,10,00,01).
|
||||
|
||||
All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> n = 3, start = 2
|
||||
|
||||
<strong>Output:</strong> [2,6,7,5,4,0,1,3]
|
||||
|
||||
<strong>Explanation:</strong> The binary representation of the permutation is (010,110,111,101,100,000,001,011).
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 16</code></li>
|
||||
<li><code>0 <= start < 2 ^ n</code></li>
|
||||
|
||||
<li><code>1 <= n <= 16</code></li>
|
||||
|
||||
<li><code>0 <= start < 2 ^ n</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,25 +27,35 @@ tags:
|
|||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1256.Encode%20Number/images/encode_number.png" style="width: 164px; height: 360px;" /></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> num = 23
|
||||
|
||||
<strong>Output:</strong> "1000"
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> num = 107
|
||||
|
||||
<strong>Output:</strong> "101100"
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= num <= 10^9</code></li>
|
||||
|
||||
<li><code>0 <= num <= 10^9</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -29,21 +29,35 @@ tags:
|
|||
<p>In case there is no path, return <code>[0, 0]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> board = ["E23","2X2","12S"]
|
||||
|
||||
<strong>Output:</strong> [7,1]
|
||||
|
||||
</pre><p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> board = ["E12","1X1","21S"]
|
||||
|
||||
<strong>Output:</strong> [4,2]
|
||||
|
||||
</pre><p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre><strong>Input:</strong> board = ["E11","XXX","11S"]
|
||||
|
||||
<strong>Output:</strong> [0,0]
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= board.length == board[i].length <= 100</code></li>
|
||||
|
||||
<li><code>2 <= board.length == board[i].length <= 100</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -19,39 +19,55 @@ tags:
|
|||
<!-- description:start -->
|
||||
|
||||
<p>Given 3 positives numbers <code>a</code>, <code>b</code> and <code>c</code>. Return the minimum flips required in some bits of <code>a</code> and <code>b</code> to make ( <code>a</code> OR <code>b</code> == <code>c</code> ). (bitwise OR operation).<br />
|
||||
|
||||
Flip operation consists of change <strong>any</strong> single bit 1 to 0 or change the bit 0 to 1 in their binary representation.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1300-1399/1318.Minimum%20Flips%20to%20Make%20a%20OR%20b%20Equal%20to%20c/images/sample_3_1676.png" style="width: 260px; height: 87px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> a = 2, b = 6, c = 5
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation: </strong>After flips a = 1 , b = 4 , c = 5 such that (<code>a</code> OR <code>b</code> == <code>c</code>)</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> a = 4, b = 2, c = 7
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> a = 1, b = 2, c = 3
|
||||
|
||||
<strong>Output:</strong> 0
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= a <= 10^9</code></li>
|
||||
<li><code>1 <= b <= 10^9</code></li>
|
||||
<li><code>1 <= c <= 10^9</code></li>
|
||||
|
||||
<li><code>1 <= a <= 10^9</code></li>
|
||||
|
||||
<li><code>1 <= b <= 10^9</code></li>
|
||||
|
||||
<li><code>1 <= c <= 10^9</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -21,46 +21,71 @@ tags:
|
|||
<!-- description:start -->
|
||||
|
||||
<p>Given a string <code>s</code>. Return all the words vertically in the same order in which they appear in <code>s</code>.<br />
|
||||
|
||||
Words are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).<br />
|
||||
|
||||
Each word would be put on only one column and that in one column there will be only one word.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> s = "HOW ARE YOU"
|
||||
|
||||
<strong>Output:</strong> ["HAY","ORO","WEU"]
|
||||
|
||||
<strong>Explanation: </strong>Each word is printed vertically.
|
||||
|
||||
"HAY"
|
||||
|
||||
"ORO"
|
||||
|
||||
"WEU"
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> s = "TO BE OR NOT TO BE"
|
||||
|
||||
<strong>Output:</strong> ["TBONTB","OEROOE"," T"]
|
||||
|
||||
<strong>Explanation: </strong>Trailing spaces is not allowed.
|
||||
|
||||
"TBONTB"
|
||||
|
||||
"OEROOE"
|
||||
|
||||
" T"
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> s = "CONTEST IS COMING"
|
||||
|
||||
<strong>Output:</strong> ["CIC","OSO","N M","T I","E N","S G","T"]
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 200</code></li>
|
||||
<li><code>s</code> contains only upper case English letters.</li>
|
||||
<li>It's guaranteed that there is only one space between 2 words.</li>
|
||||
|
||||
<li><code>1 <= s.length <= 200</code></li>
|
||||
|
||||
<li><code>s</code> contains only upper case English letters.</li>
|
||||
|
||||
<li>It's guaranteed that there is only one space between 2 words.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,48 +27,77 @@ tags:
|
|||
<p><em>Return the restaurant's “<strong>display table</strong>”</em>. The “<strong>display table</strong>” is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is “Table”, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]
|
||||
|
||||
<strong>Output:</strong> [["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]]
|
||||
|
||||
<strong>Explanation:
|
||||
|
||||
</strong>The displaying table looks like:
|
||||
|
||||
<strong>Table,Beef Burrito,Ceviche,Fried Chicken,Water</strong>
|
||||
|
||||
3 ,0 ,2 ,1 ,0
|
||||
|
||||
5 ,0 ,1 ,0 ,1
|
||||
|
||||
10 ,1 ,0 ,0 ,0
|
||||
|
||||
For the table 3: David orders "Ceviche" and "Fried Chicken", and Rous orders "Ceviche".
|
||||
|
||||
For the table 5: Carla orders "Water" and "Ceviche".
|
||||
|
||||
For the table 10: Corina orders "Beef Burrito".
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]
|
||||
|
||||
<strong>Output:</strong> [["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
|
||||
For the table 1: Adam and Brianna order "Canadian Waffles".
|
||||
|
||||
For the table 12: James, Ratesh and Amadeus order "Fried Chicken".
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]
|
||||
|
||||
<strong>Output:</strong> [["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= orders.length <= 5 * 10^4</code></li>
|
||||
<li><code>orders[i].length == 3</code></li>
|
||||
<li><code>1 <= customerName<sub>i</sub>.length, foodItem<sub>i</sub>.length <= 20</code></li>
|
||||
<li><code>customerName<sub>i</sub></code> and <code>foodItem<sub>i</sub></code> consist of lowercase and uppercase English letters and the space character.</li>
|
||||
<li><code>tableNumber<sub>i</sub> </code>is a valid integer between <code>1</code> and <code>500</code>.</li>
|
||||
|
||||
<li><code>1 <= orders.length <= 5 * 10^4</code></li>
|
||||
|
||||
<li><code>orders[i].length == 3</code></li>
|
||||
|
||||
<li><code>1 <= customerName<sub>i</sub>.length, foodItem<sub>i</sub>.length <= 20</code></li>
|
||||
|
||||
<li><code>customerName<sub>i</sub></code> and <code>foodItem<sub>i</sub></code> consist of lowercase and uppercase English letters and the space character.</li>
|
||||
|
||||
<li><code>tableNumber<sub>i</sub> </code>is a valid integer between <code>1</code> and <code>500</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -57,6 +57,13 @@ tags:
|
|||
(1,2,3,4) 4 个帽子的排列方案数为 24 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]
|
||||
<strong>输出:</strong>111
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ tags:
|
|||
|
||||
<p>Given a 2D integer array <code>hats</code>, where <code>hats[i]</code> is a list of all hats preferred by the <code>i<sup>th</sup></code> person.</p>
|
||||
|
||||
<p>Return the number of ways that <code>n</code> people can wear <strong>different</strong> hats from each other.</p>
|
||||
<p>Return <em>the number of ways that the <code>n</code> people wear different hats to each other</em>.</p>
|
||||
|
||||
<p>Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -26,17 +26,25 @@ tags:
|
|||
<p>Return the number of <strong>good</strong> nodes in the binary tree.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/images/test_sample_1.png" style="width: 263px; height: 156px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> root = [3,1,4,3,null,1,5]
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> Nodes in blue are <strong>good</strong>.
|
||||
|
||||
Root Node (3) is always a good node.
|
||||
|
||||
Node 4 -> (3,4) is the maximum value in the path starting from the root.
|
||||
|
||||
Node 5 -> (3,4,5) is the maximum value in the path
|
||||
|
||||
Node 3 -> (3,1,3) is the maximum value in the path.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
|
@ -44,23 +52,33 @@ Node 3 -> (3,1,3) is the maximum value in the path.</pre>
|
|||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1448.Count%20Good%20Nodes%20in%20Binary%20Tree/images/test_sample_2.png" style="width: 157px; height: 161px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> root = [3,3,null,4,2]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> Node 2 -> (3, 3, 2) is not good, because "3" is higher than it.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> root = [1]
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
<strong>Explanation:</strong> Root is considered as <strong>good</strong>.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the binary tree is in the range <code>[1, 10^5]</code>.</li>
|
||||
<li>Each node's value is between <code>[-10^4, 10^4]</code>.</li>
|
||||
|
||||
<li>The number of nodes in the binary tree is in the range <code>[1, 10^5]</code>.</li>
|
||||
|
||||
<li>Each node's value is between <code>[-10^4, 10^4]</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,35 +23,51 @@ tags:
|
|||
<p><em>Return the array in the form</em> <code>[x<sub>1</sub>,y<sub>1</sub>,x<sub>2</sub>,y<sub>2</sub>,...,x<sub>n</sub>,y<sub>n</sub>]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [2,5,1,3,4,7], n = 3
|
||||
|
||||
<strong>Output:</strong> [2,3,5,4,1,7]
|
||||
|
||||
<strong>Explanation:</strong> Since x<sub>1</sub>=2, x<sub>2</sub>=5, x<sub>3</sub>=1, y<sub>1</sub>=3, y<sub>2</sub>=4, y<sub>3</sub>=7 then the answer is [2,3,5,4,1,7].
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,2,3,4,4,3,2,1], n = 4
|
||||
|
||||
<strong>Output:</strong> [1,4,2,3,3,2,4,1]
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,1,2,2], n = 2
|
||||
|
||||
<strong>Output:</strong> [1,2,1,2]
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 500</code></li>
|
||||
<li><code>nums.length == 2n</code></li>
|
||||
<li><code>1 <= nums[i] <= 10^3</code></li>
|
||||
|
||||
<li><code>1 <= n <= 500</code></li>
|
||||
|
||||
<li><code>nums.length == 2n</code></li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 10^3</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -35,15 +35,14 @@ tags:
|
|||
|
||||
<ul>
|
||||
<li>例如 <code>arr = [6, -3, 7, 2, 11]</code>,<code>n = 5</code>:数组排序后得到 <code>arr = [-3, 2, 6, 7, 11]</code> ,数组的中间位置为 <code>m = ((5 - 1) / 2) = 2</code> ,中位数 <code>arr[m]</code> 的值为 <code>6</code> 。</li>
|
||||
<li>例如 <code>arr = [-7, 22, 17, 3]</code>,<code>n = 4</code>:数组排序后得到 <code>arr = [-7, 3, 17, 22]</code> ,数组的中间位置为 <code>m = ((4 - 1) / 2) = 1</code> ,中位数 <code>arr[m]</code> 的值为 <code>3</code> 。</li>
|
||||
<li>例如 <code>arr = [-7, 22, 17, 3]</code>,<code>n = 4</code>:数组排序后得到 <code>arr = [-7, 3, 17, 22]</code> ,数组的中间位置为 <code>m = ((4 - 1) / 2) = 1</code> ,中位数 <code>arr[m]</code> 的值为 <code>3</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>arr = [1,2,3,4,5], k = 2
|
||||
<pre><strong>输入:</strong>arr = [1,2,3,4,5], k = 2
|
||||
<strong>输出:</strong>[5,1]
|
||||
<strong>解释:</strong>中位数为 3,按从强到弱顺序排序后,数组变为 [5,1,4,2,3]。最强的两个元素是 [5, 1]。[1, 5] 也是正确答案。
|
||||
注意,尽管 |5 - 3| == |1 - 3| ,但是 5 比 1 更强,因为 5 > 1 。
|
||||
|
|
@ -51,19 +50,28 @@ tags:
|
|||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>arr = [1,1,3,5,5], k = 2
|
||||
<pre><strong>输入:</strong>arr = [1,1,3,5,5], k = 2
|
||||
<strong>输出:</strong>[5,5]
|
||||
<strong>解释:</strong>中位数为 3, 按从强到弱顺序排序后,数组变为 [5,5,1,1,3]。最强的两个元素是 [5, 5]。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>arr = [6,7,11,7,6,8], k = 5
|
||||
<pre><strong>输入:</strong>arr = [6,7,11,7,6,8], k = 5
|
||||
<strong>输出:</strong>[11,8,6,6,7]
|
||||
<strong>解释:</strong>中位数为 7, 按从强到弱顺序排序后,数组变为 [11,8,6,6,7,7]。
|
||||
[11,8,6,6,7] 的任何排列都是正确答案。
|
||||
[11,8,6,6,7] 的任何排列都是正确答案。</pre>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>arr = [6,-3,7,2,11], k = 3
|
||||
<strong>输出:</strong>[-3,11,2]
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 5:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>arr = [-7,22,17,3], k = 2
|
||||
<strong>输出:</strong>[22,17]
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
@ -71,8 +79,8 @@ tags:
|
|||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= arr.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= arr[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= arr.length <= 10^5</code></li>
|
||||
<li><code>-10^5 <= arr[i] <= 10^5</code></li>
|
||||
<li><code>1 <= k <= arr.length</code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,43 +22,25 @@ tags:
|
|||
|
||||
<p>Given an array of integers <code>arr</code> and an integer <code>k</code>.</p>
|
||||
|
||||
<p>A value <code>arr[i]</code> is said to be stronger than a value <code>arr[j]</code> if <code>|arr[i] - m| > |arr[j] - m|</code> where <code>m</code> is the <strong>centre</strong> of the array.<br />
|
||||
<p>A value <code>arr[i]</code> is said to be stronger than a value <code>arr[j]</code> if <code>|arr[i] - m| > |arr[j] - m|</code> where <code>m</code> is the <strong>median</strong> of the array.<br />
|
||||
If <code>|arr[i] - m| == |arr[j] - m|</code>, then <code>arr[i]</code> is said to be stronger than <code>arr[j]</code> if <code>arr[i] > arr[j]</code>.</p>
|
||||
|
||||
<p>Return <em>a list of the strongest <code>k</code></em> values in the array. return the answer <strong>in any arbitrary order</strong>.</p>
|
||||
|
||||
<p>The <strong>centre</strong> is the middle value in an ordered integer list. More formally, if the length of the list is n, the centre is the element in position <code>((n - 1) / 2)</code> in the sorted list <strong>(0-indexed)</strong>.</p>
|
||||
<p><strong>Median</strong> is the middle value in an ordered integer list. More formally, if the length of the list is n, the median is the element in position <code>((n - 1) / 2)</code> in the sorted list <strong>(0-indexed)</strong>.</p>
|
||||
|
||||
<ul>
|
||||
<li>For <code>arr = [6, -3, 7, 2, 11]</code>, <code>n = 5</code> and the centre is obtained by sorting the array <code>arr = [-3, 2, 6, 7, 11]</code> and the centre is <code>arr[m]</code> where <code>m = ((5 - 1) / 2) = 2</code>. The centre is <code>6</code>.</li>
|
||||
<li>For <code>arr = [-7, 22, 17, 3]</code>, <code>n = 4</code> and the centre is obtained by sorting the array <code>arr = [-7, 3, 17, 22]</code> and the centre is <code>arr[m]</code> where <code>m = ((4 - 1) / 2) = 1</code>. The centre is <code>3</code>.</li>
|
||||
<li>For <code>arr = [6, -3, 7, 2, 11]</code>, <code>n = 5</code> and the median is obtained by sorting the array <code>arr = [-3, 2, 6, 7, 11]</code> and the median is <code>arr[m]</code> where <code>m = ((5 - 1) / 2) = 2</code>. The median is <code>6</code>.</li>
|
||||
<li>For <code>arr = [-7, 22, 17, 3]</code>, <code>n = 4</code> and the median is obtained by sorting the array <code>arr = [-7, 3, 17, 22]</code> and the median is <code>arr[m]</code> where <code>m = ((4 - 1) / 2) = 1</code>. The median is <code>3</code>.</li>
|
||||
</ul>
|
||||
|
||||
<div class="simple-translate-system-theme" id="simple-translate">
|
||||
<div>
|
||||
<div class="simple-translate-button isShow" style="background-image: url("moz-extension://8a9ffb6b-7e69-4e93-aae1-436a1448eff6/icons/512.png"); height: 22px; width: 22px; top: 266px; left: 381px;"> </div>
|
||||
|
||||
<div class="simple-translate-panel " style="width: 300px; height: 200px; top: 0px; left: 0px; font-size: 13px;">
|
||||
<div class="simple-translate-result-wrapper" style="overflow: hidden;">
|
||||
<div class="simple-translate-move" draggable="true"> </div>
|
||||
|
||||
<div class="simple-translate-result-contents">
|
||||
<p class="simple-translate-result" dir="auto"> </p>
|
||||
|
||||
<p class="simple-translate-candidate" dir="auto"> </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,2,3,4,5], k = 2
|
||||
<strong>Output:</strong> [5,1]
|
||||
<strong>Explanation:</strong> Centre is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also <strong>accepted</strong> answer.
|
||||
<strong>Explanation:</strong> Median is 3, the elements of the array sorted by the strongest are [5,1,4,2,3]. The strongest 2 elements are [5, 1]. [1, 5] is also <strong>accepted</strong> answer.
|
||||
Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5 > 1.
|
||||
</pre>
|
||||
|
||||
|
|
@ -67,7 +49,7 @@ Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5
|
|||
<pre>
|
||||
<strong>Input:</strong> arr = [1,1,3,5,5], k = 2
|
||||
<strong>Output:</strong> [5,5]
|
||||
<strong>Explanation:</strong> Centre is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].
|
||||
<strong>Explanation:</strong> Median is 3, the elements of the array sorted by the strongest are [5,5,1,1,3]. The strongest 2 elements are [5, 5].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
|
@ -75,7 +57,7 @@ Please note that although |5 - 3| == |1 - 3| but 5 is stronger than 1 because 5
|
|||
<pre>
|
||||
<strong>Input:</strong> arr = [6,7,11,7,6,8], k = 5
|
||||
<strong>Output:</strong> [11,8,6,6,7]
|
||||
<strong>Explanation:</strong> Centre is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].
|
||||
<strong>Explanation:</strong> Median is 7, the elements of the array sorted by the strongest are [11,8,6,6,7,7].
|
||||
Any permutation of [11,8,6,6,7] is <strong>accepted</strong>.
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -25,31 +25,45 @@ tags:
|
|||
<p>Given an array of integers <code>arr</code> and an integer <code>k</code>. Find the <em>least number of unique integers</em> after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p>
|
||||
|
||||
<ol>
|
||||
|
||||
</ol>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input: </strong>arr = [5,5,4], k = 1
|
||||
|
||||
<strong>Output: </strong>1
|
||||
|
||||
<strong>Explanation</strong>: Remove the single 4, only 5 is left.
|
||||
|
||||
</pre>
|
||||
|
||||
<strong class="example">Example 2:</strong>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input: </strong>arr = [4,3,1,1,3,3,2], k = 3
|
||||
|
||||
<strong>Output: </strong>2
|
||||
|
||||
<strong>Explanation</strong>: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= arr.length <= 10^5</code></li>
|
||||
<li><code>1 <= arr[i] <= 10^9</code></li>
|
||||
<li><code>0 <= k <= arr.length</code></li>
|
||||
|
||||
<li><code>1 <= arr.length <= 10^5</code></li>
|
||||
|
||||
<li><code>1 <= arr[i] <= 10^9</code></li>
|
||||
|
||||
<li><code>0 <= k <= arr.length</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -21,25 +21,35 @@ tags:
|
|||
<p>Given two non-negative integers <code>low</code> and <code><font face="monospace">high</font></code>. Return the <em>count of odd numbers between </em><code>low</code><em> and </em><code><font face="monospace">high</font></code><em> (inclusive)</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> low = 3, high = 7
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<b>Explanation: </b>The odd numbers between 3 and 7 are [3,5,7].</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> low = 8, high = 10
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
<b>Explanation: </b>The odd numbers between 8 and 10 are [9].</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= low <= high <= 10^9</code></li>
|
||||
|
||||
<li><code>0 <= low <= high <= 10^9</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -24,10 +24,15 @@ tags:
|
|||
<p>A triplet <code>(arr[i], arr[j], arr[k])</code> is <strong>good</strong> if the following conditions are true:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < k < arr.length</code></li>
|
||||
<li><code>|arr[i] - arr[j]| <= a</code></li>
|
||||
<li><code>|arr[j] - arr[k]| <= b</code></li>
|
||||
<li><code>|arr[i] - arr[k]| <= c</code></li>
|
||||
|
||||
<li><code>0 <= i < j < k < arr.length</code></li>
|
||||
|
||||
<li><code>|arr[i] - arr[j]| <= a</code></li>
|
||||
|
||||
<li><code>|arr[j] - arr[k]| <= b</code></li>
|
||||
|
||||
<li><code>|arr[i] - arr[k]| <= c</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Where <code>|x|</code> denotes the absolute value of <code>x</code>.</p>
|
||||
|
|
@ -35,29 +40,43 @@ tags:
|
|||
<p>Return<em> the number of good triplets</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> arr = [1,1,2,2,3], a = 0, b = 0, c = 1
|
||||
|
||||
<strong>Output:</strong> 0
|
||||
|
||||
<strong>Explanation: </strong>No triplet satisfies all conditions.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= arr.length <= 100</code></li>
|
||||
<li><code>0 <= arr[i] <= 1000</code></li>
|
||||
<li><code>0 <= a, b, c <= 1000</code></li>
|
||||
|
||||
<li><code>3 <= arr.length <= 100</code></li>
|
||||
|
||||
<li><code>0 <= arr[i] <= 1000</code></li>
|
||||
|
||||
<li><code>0 <= a, b, c <= 1000</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -33,42 +33,63 @@ tags:
|
|||
<p><strong>Notice</strong> that the <strong>distance</strong> between the two cities is the number of edges in the path between them.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1617.Count%20Subtrees%20With%20Max%20Distance%20Between%20Cities/images/p1.png" style="width: 161px; height: 181px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> n = 4, edges = [[1,2],[2,3],[2,4]]
|
||||
|
||||
<strong>Output:</strong> [3,4,0]
|
||||
|
||||
<strong>Explanation:
|
||||
|
||||
</strong>The subtrees with subsets {1,2}, {2,3} and {2,4} have a max distance of 1.
|
||||
|
||||
The subtrees with subsets {1,2,3}, {1,2,4}, {2,3,4} and {1,2,3,4} have a max distance of 2.
|
||||
|
||||
No subtree has two nodes where the max distance between them is 3.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> n = 2, edges = [[1,2]]
|
||||
|
||||
<strong>Output:</strong> [1]
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> n = 3, edges = [[1,2],[2,3]]
|
||||
|
||||
<strong>Output:</strong> [2,1]
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 15</code></li>
|
||||
<li><code>edges.length == n-1</code></li>
|
||||
<li><code>edges[i].length == 2</code></li>
|
||||
<li><code>1 <= u<sub>i</sub>, v<sub>i</sub> <= n</code></li>
|
||||
<li>All pairs <code>(u<sub>i</sub>, v<sub>i</sub>)</code> are distinct.</li>
|
||||
|
||||
<li><code>2 <= n <= 15</code></li>
|
||||
|
||||
<li><code>edges.length == n-1</code></li>
|
||||
|
||||
<li><code>edges[i].length == 2</code></li>
|
||||
|
||||
<li><code>1 <= u<sub>i</sub>, v<sub>i</sub> <= n</code></li>
|
||||
|
||||
<li>All pairs <code>(u<sub>i</sub>, v<sub>i</sub>)</code> are distinct.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -26,14 +26,23 @@ tags:
|
|||
<p>The <code>FontInfo</code> interface is defined as such:</p>
|
||||
|
||||
<pre>
|
||||
|
||||
interface FontInfo {
|
||||
|
||||
// Returns the width of character ch on the screen using font size fontSize.
|
||||
|
||||
// O(1) per call
|
||||
|
||||
public int getWidth(int fontSize, char ch);
|
||||
|
||||
|
||||
|
||||
// Returns the height of any character on the screen using font size fontSize.
|
||||
|
||||
// O(1) per call
|
||||
|
||||
public int getHeight(int fontSize);
|
||||
|
||||
}</pre>
|
||||
|
||||
<p>The calculated width of <code>text</code> for some <code>fontSize</code> is the <strong>sum</strong> of every <code>getWidth(fontSize, text[i])</code> call for each <code>0 <= i < text.length</code> (<strong>0-indexed</strong>). The calculated height of <code>text</code> for some <code>fontSize</code> is <code>getHeight(fontSize)</code>. Note that <code>text</code> is displayed on a <strong>single line</strong>.</p>
|
||||
|
|
@ -43,45 +52,67 @@ interface FontInfo {
|
|||
<p>It is also guaranteed that for any font size <code>fontSize</code> and any character <code>ch</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>getHeight(fontSize) <= getHeight(fontSize+1)</code></li>
|
||||
<li><code>getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)</code></li>
|
||||
|
||||
<li><code>getHeight(fontSize) <= getHeight(fontSize+1)</code></li>
|
||||
|
||||
<li><code>getWidth(fontSize, ch) <= getWidth(fontSize+1, ch)</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the maximum font size you can use to display </em><code>text</code><em> on the screen</em>. If <code>text</code> cannot fit on the display with any font size, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> text = "helloworld", w = 80, h = 20, fonts = [6,8,10,12,14,16,18,24,36]
|
||||
|
||||
<strong>Output:</strong> 6
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> text = "leetcode", w = 1000, h = 50, fonts = [1,2,4]
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> text = "easyquestion", w = 100, h = 100, fonts = [10,15,20,25]
|
||||
|
||||
<strong>Output:</strong> -1
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= text.length <= 50000</code></li>
|
||||
<li><code>text</code> contains only lowercase English letters.</li>
|
||||
<li><code>1 <= w <= 10<sup>7</sup></code></li>
|
||||
<li><code>1 <= h <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= fonts.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= fonts[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>fonts</code> is sorted in ascending order and does not contain duplicates.</li>
|
||||
|
||||
<li><code>1 <= text.length <= 50000</code></li>
|
||||
|
||||
<li><code>text</code> contains only lowercase English letters.</li>
|
||||
|
||||
<li><code>1 <= w <= 10<sup>7</sup></code></li>
|
||||
|
||||
<li><code>1 <= h <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= fonts.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= fonts[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>fonts</code> is sorted in ascending order and does not contain duplicates.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,9 +23,13 @@ tags:
|
|||
<p>Each node has three attributes:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>coefficient</code>: an integer representing the number multiplier of the term. The coefficient of the term <code><strong>9</strong>x<sup>4</sup></code> is <code>9</code>.</li>
|
||||
<li><code>power</code>: an integer representing the exponent. The power of the term <code>9x<strong><sup>4</sup></strong></code> is <code>4</code>.</li>
|
||||
<li><code>next</code>: a pointer to the next node in the list, or <code>null</code> if it is the last node of the list.</li>
|
||||
|
||||
<li><code>coefficient</code>: an integer representing the number multiplier of the term. The coefficient of the term <code><strong>9</strong>x<sup>4</sup></code> is <code>9</code>.</li>
|
||||
|
||||
<li><code>power</code>: an integer representing the exponent. The power of the term <code>9x<strong><sup>4</sup></strong></code> is <code>4</code>.</li>
|
||||
|
||||
<li><code>next</code>: a pointer to the next node in the list, or <code>null</code> if it is the last node of the list.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>For example, the polynomial <code>5x<sup>3</sup> + 4x - 7</code> is represented by the polynomial linked list illustrated below:</p>
|
||||
|
|
@ -41,41 +45,61 @@ tags:
|
|||
<p>The input/output format is as a list of <code>n</code> nodes, where each node is represented as its <code>[coefficient, power]</code>. For example, the polynomial <code>5x<sup>3</sup> + 4x - 7</code> would be represented as: <code>[[5,3],[4,1],[-7,0]]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1634.Add%20Two%20Polynomials%20Represented%20as%20Linked%20Lists/images/ex1.png" style="width: 600px; height: 322px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poly1 = [[1,1]], poly2 = [[1,0]]
|
||||
|
||||
<strong>Output:</strong> [[1,1],[1,0]]
|
||||
|
||||
<strong>Explanation:</strong> poly1 = x. poly2 = 1. The sum is x + 1.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poly1 = [[2,2],[4,1],[3,0]], poly2 = [[3,2],[-4,1],[-1,0]]
|
||||
|
||||
<strong>Output:</strong> [[5,2],[2,0]]
|
||||
|
||||
<strong>Explanation:</strong> poly1 = 2x<sup>2</sup> + 4x + 3. poly2 = 3x<sup>2</sup> - 4x - 1. The sum is 5x<sup>2</sup> + 2. Notice that we omit the "0x" term.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> poly1 = [[1,2]], poly2 = [[-1,2]]
|
||||
|
||||
<strong>Output:</strong> []
|
||||
|
||||
<strong>Explanation:</strong> The sum is 0. We return an empty list.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= n <= 10<sup>4</sup></code></li>
|
||||
<li><code>-10<sup>9</sup> <= PolyNode.coefficient <= 10<sup>9</sup></code></li>
|
||||
<li><code>PolyNode.coefficient != 0</code></li>
|
||||
<li><code>0 <= PolyNode.power <= 10<sup>9</sup></code></li>
|
||||
<li><code>PolyNode.power > PolyNode.next.power</code></li>
|
||||
|
||||
<li><code>0 <= n <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>-10<sup>9</sup> <= PolyNode.coefficient <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>PolyNode.coefficient != 0</code></li>
|
||||
|
||||
<li><code>0 <= PolyNode.power <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>PolyNode.power > PolyNode.next.power</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,8 +27,11 @@ tags:
|
|||
<p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <strong>cost</strong> of each insertion is the <b>minimum</b> of the following:</p>
|
||||
|
||||
<ul>
|
||||
<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>
|
||||
<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>
|
||||
|
||||
<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>
|
||||
|
||||
<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>For example, if inserting element <code>3</code> into <code>nums = [1,2,3,5]</code>, the <strong>cost</strong> of insertion is <code>min(2, 1)</code> (elements <code>1</code> and <code>2</code> are less than <code>3</code>, element <code>5</code> is greater than <code>3</code>) and <code>nums</code> will become <code>[1,2,3,3,5]</code>.</p>
|
||||
|
|
@ -36,57 +39,95 @@ tags:
|
|||
<p>Return <em>the <strong>total cost</strong> to insert all elements from </em><code>instructions</code><em> into </em><code>nums</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> instructions = [1,5,6,2]
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
<strong>Explanation:</strong> Begin with nums = [].
|
||||
|
||||
Insert 1 with cost min(0, 0) = 0, now nums = [1].
|
||||
|
||||
Insert 5 with cost min(1, 0) = 0, now nums = [1,5].
|
||||
|
||||
Insert 6 with cost min(2, 0) = 0, now nums = [1,5,6].
|
||||
|
||||
Insert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].
|
||||
|
||||
The total cost is 0 + 0 + 0 + 1 = 1.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> instructions = [1,2,3,6,5,4]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> Begin with nums = [].
|
||||
|
||||
Insert 1 with cost min(0, 0) = 0, now nums = [1].
|
||||
|
||||
Insert 2 with cost min(1, 0) = 0, now nums = [1,2].
|
||||
|
||||
Insert 3 with cost min(2, 0) = 0, now nums = [1,2,3].
|
||||
|
||||
Insert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].
|
||||
|
||||
Insert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].
|
||||
|
||||
Insert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].
|
||||
|
||||
The total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> instructions = [1,3,3,3,2,4,2,1,2]
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> Begin with nums = [].
|
||||
|
||||
Insert 1 with cost min(0, 0) = 0, now nums = [1].
|
||||
|
||||
Insert 3 with cost min(1, 0) = 0, now nums = [1,3].
|
||||
|
||||
Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3].
|
||||
|
||||
Insert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].
|
||||
|
||||
Insert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].
|
||||
|
||||
Insert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].
|
||||
|
||||
Insert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].
|
||||
|
||||
Insert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].
|
||||
|
||||
Insert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].
|
||||
|
||||
The total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= instructions.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= instructions[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= instructions.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= instructions[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -29,22 +29,31 @@ tags:
|
|||
<p>The test input is read as 3 lines:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>TreeNode root</code></li>
|
||||
<li><code>int fromNode</code> (<strong>not available to </strong><code>correctBinaryTree</code>)</li>
|
||||
<li><code>int toNode</code> (<strong>not available to </strong><code>correctBinaryTree</code>)</li>
|
||||
|
||||
<li><code>TreeNode root</code></li>
|
||||
|
||||
<li><code>int fromNode</code> (<strong>not available to </strong><code>correctBinaryTree</code>)</li>
|
||||
|
||||
<li><code>int toNode</code> (<strong>not available to </strong><code>correctBinaryTree</code>)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>After the binary tree rooted at <code>root</code> is parsed, the <code>TreeNode</code> with value of <code>fromNode</code> will have its right child pointer pointing to the <code>TreeNode</code> with a value of <code>toNode</code>. Then, <code>root</code> is passed to <code>correctBinaryTree</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/images/ex1v2.png" style="width: 250px; height: 177px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> root = [1,2,3], fromNode = 2, toNode = 3
|
||||
|
||||
<strong>Output:</strong> [1,null,3]
|
||||
|
||||
<strong>Explanation:</strong> The node with value 2 is invalid, so remove it.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
|
@ -52,22 +61,35 @@ tags:
|
|||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1660.Correct%20a%20Binary%20Tree/images/ex2v3.png" style="width: 350px; height: 255px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> root = [8,3,1,7,null,9,4,2,null,null,null,5,6], fromNode = 7, toNode = 4
|
||||
|
||||
<strong>Output:</strong> [8,3,1,null,null,9,4,null,null,5,6]
|
||||
|
||||
<strong>Explanation:</strong> The node with value 7 is invalid, so remove it and the node underneath it, node 2.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the tree is in the range <code>[3, 10<sup>4</sup>]</code>.</li>
|
||||
<li><code>-10<sup>9</sup> <= Node.val <= 10<sup>9</sup></code></li>
|
||||
<li>All <code>Node.val</code> are <strong>unique</strong>.</li>
|
||||
<li><code>fromNode != toNode</code></li>
|
||||
<li><code>fromNode</code> and <code>toNode</code> will exist in the tree and will be on the same depth.</li>
|
||||
<li><code>toNode</code> is to the <strong>right</strong> of <code>fromNode</code>.</li>
|
||||
<li><code>fromNode.right</code> is <code>null</code> in the initial tree from the test data.</li>
|
||||
|
||||
<li>The number of nodes in the tree is in the range <code>[3, 10<sup>4</sup>]</code>.</li>
|
||||
|
||||
<li><code>-10<sup>9</sup> <= Node.val <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li>All <code>Node.val</code> are <strong>unique</strong>.</li>
|
||||
|
||||
<li><code>fromNode != toNode</code></li>
|
||||
|
||||
<li><code>fromNode</code> and <code>toNode</code> will exist in the tree and will be on the same depth.</li>
|
||||
|
||||
<li><code>toNode</code> is to the <strong>right</strong> of <code>fromNode</code>.</li>
|
||||
|
||||
<li><code>fromNode.right</code> is <code>null</code> in the initial tree from the test data.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,30 +27,45 @@ tags:
|
|||
<p>Return <em>the <strong>number</strong> of rectangles that can make a square with a side length of </em><code>maxLen</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> rectangles = [[5,8],[3,9],[5,12],[16,5]]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> The largest squares you can get from each rectangle are of lengths [5,3,5,5].
|
||||
|
||||
The largest possible square is of length 5, and you can get it out of 3 rectangles.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> rectangles = [[2,3],[3,7],[4,3],[3,7]]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= rectangles.length <= 1000</code></li>
|
||||
<li><code>rectangles[i].length == 2</code></li>
|
||||
<li><code>1 <= l<sub>i</sub>, w<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
<li><code>l<sub>i</sub> != w<sub>i</sub></code></li>
|
||||
|
||||
<li><code>1 <= rectangles.length <= 1000</code></li>
|
||||
|
||||
<li><code>rectangles[i].length == 2</code></li>
|
||||
|
||||
<li><code>1 <= l<sub>i</sub>, w<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>l<sub>i</sub> != w<sub>i</sub></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,26 +22,37 @@ tags:
|
|||
<p>Return <em>the <strong>maximum</strong> possible subarray sum after <strong>exactly one</strong> operation</em>. The subarray must be non-empty.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [2,-1,-4,-3]
|
||||
|
||||
<strong>Output:</strong> 17
|
||||
|
||||
<strong>Explanation:</strong> You can perform the operation on index 2 (0-indexed) to make nums = [2,-1,<strong>16</strong>,-3]. Now, the maximum subarray sum is 2 + -1 + 16 = 17.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,-1,1,1,-1,-1,1]
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> You can perform the operation on index 1 (0-indexed) to make nums = [1,<strong>1</strong>,1,1,-1,-1,1]. Now, the maximum subarray sum is 1 + 1 + 1 + 1 = 4.</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -24,45 +24,71 @@ tags:
|
|||
<p>Return <em>the merged string.</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word1 = "abc", word2 = "pqr"
|
||||
|
||||
<strong>Output:</strong> "apbqcr"
|
||||
|
||||
<strong>Explanation:</strong> The merged string will be merged as so:
|
||||
|
||||
word1: a b c
|
||||
|
||||
word2: p q r
|
||||
|
||||
merged: a p b q c r
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word1 = "ab", word2 = "pqrs"
|
||||
|
||||
<strong>Output:</strong> "apbqrs"
|
||||
|
||||
<strong>Explanation:</strong> Notice that as word2 is longer, "rs" is appended to the end.
|
||||
|
||||
word1: a b
|
||||
|
||||
word2: p q r s
|
||||
|
||||
merged: a p b q r s
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word1 = "abcd", word2 = "pq"
|
||||
|
||||
<strong>Output:</strong> "apbqcd"
|
||||
|
||||
<strong>Explanation:</strong> Notice that as word1 is longer, "cd" is appended to the end.
|
||||
|
||||
word1: a b c d
|
||||
|
||||
word2: p q
|
||||
|
||||
merged: a p b q c d
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word1.length, word2.length <= 100</code></li>
|
||||
<li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li>
|
||||
|
||||
<li><code>1 <= word1.length, word2.length <= 100</code></li>
|
||||
|
||||
<li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -24,8 +24,11 @@ tags:
|
|||
<p>A garden is <strong>valid</strong> if it meets these conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>The garden has at least two flowers.</li>
|
||||
<li>The first and the last flower of the garden have the same beauty value.</li>
|
||||
|
||||
<li>The garden has at least two flowers.</li>
|
||||
|
||||
<li>The first and the last flower of the garden have the same beauty value.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>As the appointed gardener, you have the ability to <strong>remove</strong> any (possibly none) flowers from the garden. You want to remove flowers in a way that makes the remaining garden <strong>valid</strong>. The beauty of the garden is the sum of the beauty of all the remaining flowers.</p>
|
||||
|
|
@ -33,36 +36,53 @@ tags:
|
|||
<p>Return the maximum possible beauty of some <strong>valid</strong> garden after you have removed any (possibly none) flowers.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> flowers = [1,2,3,1,2]
|
||||
|
||||
<strong>Output:</strong> 8
|
||||
|
||||
<strong>Explanation:</strong> You can produce the valid garden [2,3,1,2] to have a total beauty of 2 + 3 + 1 + 2 = 8.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> flowers = [100,1,1,-3,1]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> You can produce the valid garden [1,1,1] to have a total beauty of 1 + 1 + 1 = 3.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> flowers = [-1,-2,0,-1]
|
||||
|
||||
<strong>Output:</strong> -2
|
||||
|
||||
<strong>Explanation:</strong> You can produce the valid garden [-1,-1] to have a total beauty of -1 + -1 = -2.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= flowers.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>4</sup> <= flowers[i] <= 10<sup>4</sup></code></li>
|
||||
<li>It is possible to create a valid garden by removing some (possibly none) flowers.</li>
|
||||
|
||||
<li><code>2 <= flowers.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>-10<sup>4</sup> <= flowers[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li>It is possible to create a valid garden by removing some (possibly none) flowers.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,8 +23,11 @@ tags:
|
|||
<p>You are given a 2D integer array <code>orders</code>, where each <code>orders[i] = [price<sub>i</sub>, amount<sub>i</sub>, orderType<sub>i</sub>]</code> denotes that <code>amount<sub>i</sub></code><sub> </sub>orders have been placed of type <code>orderType<sub>i</sub></code> at the price <code>price<sub>i</sub></code>. The <code>orderType<sub>i</sub></code> is:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0</code> if it is a batch of <code>buy</code> orders, or</li>
|
||||
<li><code>1</code> if it is a batch of <code>sell</code> orders.</li>
|
||||
|
||||
<li><code>0</code> if it is a batch of <code>buy</code> orders, or</li>
|
||||
|
||||
<li><code>1</code> if it is a batch of <code>sell</code> orders.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Note that <code>orders[i]</code> represents a batch of <code>amount<sub>i</sub></code> independent orders with the same price and order type. All orders represented by <code>orders[i]</code> will be placed before all orders represented by <code>orders[i+1]</code> for all valid <code>i</code>.</p>
|
||||
|
|
@ -32,47 +35,79 @@ tags:
|
|||
<p>There is a <strong>backlog</strong> that consists of orders that have not been executed. The backlog is initially empty. When an order is placed, the following happens:</p>
|
||||
|
||||
<ul>
|
||||
<li>If the order is a <code>buy</code> order, you look at the <code>sell</code> order with the <strong>smallest</strong> price in the backlog. If that <code>sell</code> order's price is <strong>smaller than or equal to</strong> the current <code>buy</code> order's price, they will match and be executed, and that <code>sell</code> order will be removed from the backlog. Else, the <code>buy</code> order is added to the backlog.</li>
|
||||
<li>Vice versa, if the order is a <code>sell</code> order, you look at the <code>buy</code> order with the <strong>largest</strong> price in the backlog. If that <code>buy</code> order's price is <strong>larger than or equal to</strong> the current <code>sell</code> order's price, they will match and be executed, and that <code>buy</code> order will be removed from the backlog. Else, the <code>sell</code> order is added to the backlog.</li>
|
||||
|
||||
<li>If the order is a <code>buy</code> order, you look at the <code>sell</code> order with the <strong>smallest</strong> price in the backlog. If that <code>sell</code> order's price is <strong>smaller than or equal to</strong> the current <code>buy</code> order's price, they will match and be executed, and that <code>sell</code> order will be removed from the backlog. Else, the <code>buy</code> order is added to the backlog.</li>
|
||||
|
||||
<li>Vice versa, if the order is a <code>sell</code> order, you look at the <code>buy</code> order with the <strong>largest</strong> price in the backlog. If that <code>buy</code> order's price is <strong>larger than or equal to</strong> the current <code>sell</code> order's price, they will match and be executed, and that <code>buy</code> order will be removed from the backlog. Else, the <code>sell</code> order is added to the backlog.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the total <strong>amount</strong> of orders in the backlog after placing all the orders from the input</em>. Since this number can be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/images/ex1.png" style="width: 450px; height: 479px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> orders = [[10,5,0],[15,2,1],[25,1,1],[30,4,0]]
|
||||
|
||||
<strong>Output:</strong> 6
|
||||
|
||||
<strong>Explanation:</strong> Here is what happens with the orders:
|
||||
|
||||
- 5 orders of type buy with price 10 are placed. There are no sell orders, so the 5 orders are added to the backlog.
|
||||
|
||||
- 2 orders of type sell with price 15 are placed. There are no buy orders with prices larger than or equal to 15, so the 2 orders are added to the backlog.
|
||||
|
||||
- 1 order of type sell with price 25 is placed. There are no buy orders with prices larger than or equal to 25 in the backlog, so this order is added to the backlog.
|
||||
|
||||
- 4 orders of type buy with price 30 are placed. The first 2 orders are matched with the 2 sell orders of the least price, which is 15 and these 2 sell orders are removed from the backlog. The 3<sup>rd</sup> order is matched with the sell order of the least price, which is 25 and this sell order is removed from the backlog. Then, there are no more sell orders in the backlog, so the 4<sup>th</sup> order is added to the backlog.
|
||||
|
||||
Finally, the backlog has 5 buy orders with price 10, and 1 buy order with price 30. So the total number of orders in the backlog is 6.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1801.Number%20of%20Orders%20in%20the%20Backlog/images/ex2.png" style="width: 450px; height: 584px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> orders = [[7,1000000000,1],[15,3,0],[5,999999995,0],[5,1,1]]
|
||||
|
||||
<strong>Output:</strong> 999999984
|
||||
|
||||
<strong>Explanation:</strong> Here is what happens with the orders:
|
||||
|
||||
- 10<sup>9</sup> orders of type sell with price 7 are placed. There are no buy orders, so the 10<sup>9</sup> orders are added to the backlog.
|
||||
|
||||
- 3 orders of type buy with price 15 are placed. They are matched with the 3 sell orders with the least price which is 7, and those 3 sell orders are removed from the backlog.
|
||||
|
||||
- 999999995 orders of type buy with price 5 are placed. The least price of a sell order is 7, so the 999999995 orders are added to the backlog.
|
||||
|
||||
- 1 order of type sell with price 5 is placed. It is matched with the buy order of the highest price, which is 5, and that buy order is removed from the backlog.
|
||||
|
||||
Finally, the backlog has (1000000000-3) sell orders with price 7, and (999999995-1) buy orders with price 5. So the total number of orders = 1999999991, which is equal to 999999984 % (10<sup>9</sup> + 7).
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= orders.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>orders[i].length == 3</code></li>
|
||||
<li><code>1 <= price<sub>i</sub>, amount<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
<li><code>orderType<sub>i</sub></code> is either <code>0</code> or <code>1</code>.</li>
|
||||
|
||||
<li><code>1 <= orders.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>orders[i].length == 3</code></li>
|
||||
|
||||
<li><code>1 <= price<sub>i</sub>, amount<sub>i</sub> <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>orderType<sub>i</sub></code> is either <code>0</code> or <code>1</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -25,42 +25,69 @@ tags:
|
|||
<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 <= i < j < nums.length</code> and <code>low <= (nums[i] XOR nums[j]) <= high</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6
|
||||
|
||||
<strong>Output:</strong> 6
|
||||
|
||||
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
|
||||
|
||||
- (0, 1): nums[0] XOR nums[1] = 5
|
||||
|
||||
- (0, 2): nums[0] XOR nums[2] = 3
|
||||
|
||||
- (0, 3): nums[0] XOR nums[3] = 6
|
||||
|
||||
- (1, 2): nums[1] XOR nums[2] = 6
|
||||
|
||||
- (1, 3): nums[1] XOR nums[3] = 3
|
||||
|
||||
- (2, 3): nums[2] XOR nums[3] = 5
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [9,8,4,2,1], low = 5, high = 14
|
||||
|
||||
<strong>Output:</strong> 8
|
||||
|
||||
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
|
||||
|
||||
- (0, 2): nums[0] XOR nums[2] = 13
|
||||
|
||||
- (0, 3): nums[0] XOR nums[3] = 11
|
||||
|
||||
- (0, 4): nums[0] XOR nums[4] = 8
|
||||
|
||||
- (1, 2): nums[1] XOR nums[2] = 12
|
||||
|
||||
- (1, 3): nums[1] XOR nums[3] = 10
|
||||
|
||||
- (1, 4): nums[1] XOR nums[4] = 9
|
||||
|
||||
- (2, 3): nums[2] XOR nums[3] = 6
|
||||
|
||||
- (2, 4): nums[2] XOR nums[4] = 5</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= low <= high <= 2 * 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= low <= high <= 2 * 10<sup>4</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -23,8 +23,11 @@ tags:
|
|||
<p>You are given a positive integer <code>primeFactors</code>. You are asked to construct a positive integer <code>n</code> that satisfies the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>The number of prime factors of <code>n</code> (not necessarily distinct) is <strong>at most</strong> <code>primeFactors</code>.</li>
|
||||
|
||||
<li>The number of nice divisors of <code>n</code> is maximized. Note that a divisor of <code>n</code> is <strong>nice</strong> if it is divisible by every prime factor of <code>n</code>. For example, if <code>n = 12</code>, then its prime factors are <code>[2,2,3]</code>, then <code>6</code> and <code>12</code> are nice divisors, while <code>3</code> and <code>4</code> are not.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of nice divisors of</em> <code>n</code>. Since that number can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
|
@ -32,28 +35,41 @@ tags:
|
|||
<p>Note that a prime number is a natural number greater than <code>1</code> that is not a product of two smaller natural numbers. The prime factors of a number <code>n</code> is a list of prime numbers such that their product equals <code>n</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> primeFactors = 5
|
||||
|
||||
<strong>Output:</strong> 6
|
||||
|
||||
<strong>Explanation:</strong> 200 is a valid value of n.
|
||||
|
||||
It has 5 prime factors: [2,2,2,5,5], and it has 6 nice divisors: [10,20,40,50,100,200].
|
||||
|
||||
There is not other value of n that has at most 5 prime factors and more nice divisors.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> primeFactors = 8
|
||||
|
||||
<strong>Output:</strong> 18
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= primeFactors <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>1 <= primeFactors <= 10<sup>9</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ tags:
|
|||
<p>You are given an integer array <code>nums</code> (<strong>0-indexed</strong>). In one operation, you can choose an element of the array and increment it by <code>1</code>.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, if <code>nums = [1,2,3]</code>, you can choose to increment <code>nums[1]</code> to make <code>nums = [1,<u><b>3</b></u>,3]</code>.</li>
|
||||
|
||||
<li>For example, if <code>nums = [1,2,3]</code>, you can choose to increment <code>nums[1]</code> to make <code>nums = [1,<u><b>3</b></u>,3]</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of operations needed to make</em> <code>nums</code> <em><strong>strictly</strong> <strong>increasing</strong>.</em></p>
|
||||
|
|
@ -30,37 +32,55 @@ tags:
|
|||
<p>An array <code>nums</code> is <strong>strictly increasing</strong> if <code>nums[i] < nums[i+1]</code> for all <code>0 <= i < nums.length - 1</code>. An array of length <code>1</code> is trivially strictly increasing.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,1,1]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> You can do the following operations:
|
||||
|
||||
1) Increment nums[2], so nums becomes [1,1,<u><strong>2</strong></u>].
|
||||
|
||||
2) Increment nums[1], so nums becomes [1,<u><strong>2</strong></u>,2].
|
||||
|
||||
3) Increment nums[2], so nums becomes [1,2,<u><strong>3</strong></u>].
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [1,5,2,4,1]
|
||||
|
||||
<strong>Output:</strong> 14
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [8]
|
||||
|
||||
<strong>Output:</strong> 0
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 5000</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums.length <= 5000</code></li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,36 +22,59 @@ tags:
|
|||
<p>Return <em>the linked list after the deletions.</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list.jpg" style="width: 422px; height: 222px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> head = [1,2,3,2]
|
||||
|
||||
<strong>Output:</strong> [1,3]
|
||||
|
||||
<strong>Explanation:</strong> 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list-1.jpg" style="width: 422px; height: 151px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> head = [2,1,1,2]
|
||||
|
||||
<strong>Output:</strong> []
|
||||
|
||||
<strong>Explanation:</strong> 2 and 1 both appear twice. All the elements should be deleted.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1836.Remove%20Duplicates%20From%20an%20Unsorted%20Linked%20List/images/tmp-linked-list-2.jpg" style="width: 500px; height: 142px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> head = [3,2,2,1,3,2,4]
|
||||
|
||||
<strong>Output:</strong> [1,4]
|
||||
|
||||
<strong>Explanation: </strong>3 appears twice and 2 appears three times. After deleting all 3's and 2's, we are left with [1,4].
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the list is in the range <code>[1, 10<sup>5</sup>]</code></li>
|
||||
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li>The number of nodes in the list is in the range <code>[1, 10<sup>5</sup>]</code></li>
|
||||
|
||||
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -32,14 +32,19 @@ tags:
|
|||
<p>Return <em>the <strong>largest color value</strong> of any valid path in the given graph, or </em><code>-1</code><em> if the graph contains a cycle</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/images/leet1.png" style="width: 400px; height: 182px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]
|
||||
|
||||
<strong>Output:</strong> 3
|
||||
|
||||
<strong>Explanation:</strong> The path 0 -> 2 -> 3 -> 4 contains 3 nodes that are colored <code>"a" (red in the above image)</code>.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
|
@ -47,21 +52,33 @@ tags:
|
|||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1857.Largest%20Color%20Value%20in%20a%20Directed%20Graph/images/leet2.png" style="width: 85px; height: 85px;" /></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> colors = "a", edges = [[0,0]]
|
||||
|
||||
<strong>Output:</strong> -1
|
||||
|
||||
<strong>Explanation:</strong> There is a cycle from 0 to 0.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == colors.length</code></li>
|
||||
<li><code>m == edges.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= m <= 10<sup>5</sup></code></li>
|
||||
<li><code>colors</code> consists of lowercase English letters.</li>
|
||||
<li><code>0 <= a<sub>j</sub>, b<sub>j</sub> < n</code></li>
|
||||
|
||||
<li><code>n == colors.length</code></li>
|
||||
|
||||
<li><code>m == edges.length</code></li>
|
||||
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>0 <= m <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>colors</code> consists of lowercase English letters.</li>
|
||||
|
||||
<li><code>0 <= a<sub>j</sub>, b<sub>j</sub> < n</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,9 +27,13 @@ tags:
|
|||
<p>There are <code>n</code> stones arranged in a row. On each player's turn, while the number of stones is <strong>more than one</strong>, they will do the following:</p>
|
||||
|
||||
<ol>
|
||||
<li>Choose an integer <code>x > 1</code>, and <strong>remove</strong> the leftmost <code>x</code> stones from the row.</li>
|
||||
<li>Add the <strong>sum</strong> of the <strong>removed</strong> stones' values to the player's score.</li>
|
||||
<li>Place a <strong>new stone</strong>, whose value is equal to that sum, on the left side of the row.</li>
|
||||
|
||||
<li>Choose an integer <code>x > 1</code>, and <strong>remove</strong> the leftmost <code>x</code> stones from the row.</li>
|
||||
|
||||
<li>Add the <strong>sum</strong> of the <strong>removed</strong> stones' values to the player's score.</li>
|
||||
|
||||
<li>Place a <strong>new stone</strong>, whose value is equal to that sum, on the left side of the row.</li>
|
||||
|
||||
</ol>
|
||||
|
||||
<p>The game stops when <strong>only</strong> <strong>one</strong> stone is left in the row.</p>
|
||||
|
|
@ -39,48 +43,77 @@ tags:
|
|||
<p>Given an integer array <code>stones</code> of length <code>n</code> where <code>stones[i]</code> represents the value of the <code>i<sup>th</sup></code> stone <strong>from the left</strong>, return <em>the <strong>score difference</strong> between Alice and Bob if they both play <strong>optimally</strong>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> stones = [-1,2,-3,4,-5]
|
||||
|
||||
<strong>Output:</strong> 5
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
|
||||
- Alice removes the first 4 stones, adds (-1) + 2 + (-3) + 4 = 2 to her score, and places a stone of
|
||||
|
||||
value 2 on the left. stones = [2,-5].
|
||||
|
||||
- Bob removes the first 2 stones, adds 2 + (-5) = -3 to his score, and places a stone of value -3 on
|
||||
|
||||
the left. stones = [-3].
|
||||
|
||||
The difference between their scores is 2 - (-3) = 5.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> stones = [7,-6,5,10,5,-2,-6]
|
||||
|
||||
<strong>Output:</strong> 13
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
|
||||
- Alice removes all stones, adds 7 + (-6) + 5 + 10 + 5 + (-2) + (-6) = 13 to her score, and places a
|
||||
|
||||
stone of value 13 on the left. stones = [13].
|
||||
|
||||
The difference between their scores is 13 - 0 = 13.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> stones = [-10,-12]
|
||||
|
||||
<strong>Output:</strong> -22
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
|
||||
- Alice can only make one move, which is to remove both stones. She adds (-10) + (-12) = -22 to her
|
||||
|
||||
score and places a stone of value -22 on the left. stones = [-22].
|
||||
|
||||
The difference between their scores is (-22) - 0 = -22.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == stones.length</code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>4</sup> <= stones[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>n == stones.length</code></li>
|
||||
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>-10<sup>4</sup> <= stones[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -21,35 +21,51 @@ tags:
|
|||
<p>The <b>product sum </b>of two equal-length arrays <code>a</code> and <code>b</code> is equal to the sum of <code>a[i] * b[i]</code> for all <code>0 <= i < a.length</code> (<strong>0-indexed</strong>).</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, if <code>a = [1,2,3,4]</code> and <code>b = [5,2,3,1]</code>, the <strong>product sum</strong> would be <code>1*5 + 2*2 + 3*3 + 4*1 = 22</code>.</li>
|
||||
|
||||
<li>For example, if <code>a = [1,2,3,4]</code> and <code>b = [5,2,3,1]</code>, the <strong>product sum</strong> would be <code>1*5 + 2*2 + 3*3 + 4*1 = 22</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Given two arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>, return <em>the <strong>minimum product sum</strong> if you are allowed to <strong>rearrange</strong> the <strong>order</strong> of the elements in </em><code>nums1</code>. </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums1 = [5,3,4,2], nums2 = [4,2,2,5]
|
||||
|
||||
<strong>Output:</strong> 40
|
||||
|
||||
<strong>Explanation:</strong> We can rearrange nums1 to become [3,5,4,2]. The product sum of [3,5,4,2] and [4,2,2,5] is 3*4 + 5*2 + 4*2 + 2*5 = 40.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums1 = [2,1,4,5,7], nums2 = [3,2,4,8,6]
|
||||
|
||||
<strong>Output:</strong> 65
|
||||
|
||||
<strong>Explanation: </strong>We can rearrange nums1 to become [5,7,4,1,2]. The product sum of [5,7,4,1,2] and [3,2,4,8,6] is 5*3 + 7*2 + 4*4 + 1*8 + 2*6 = 65.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == nums1.length == nums2.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums1[i], nums2[i] <= 100</code></li>
|
||||
|
||||
<li><code>n == nums1.length == nums2.length</code></li>
|
||||
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums1[i], nums2[i] <= 100</code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -24,45 +24,67 @@ tags:
|
|||
<p>The <strong>pair sum</strong> of a pair <code>(a,b)</code> is equal to <code>a + b</code>. The <strong>maximum pair sum</strong> is the largest <strong>pair sum</strong> in a list of pairs.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, if we have pairs <code>(1,5)</code>, <code>(2,3)</code>, and <code>(4,4)</code>, the <strong>maximum pair sum</strong> would be <code>max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8</code>.</li>
|
||||
|
||||
<li>For example, if we have pairs <code>(1,5)</code>, <code>(2,3)</code>, and <code>(4,4)</code>, the <strong>maximum pair sum</strong> would be <code>max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Given an array <code>nums</code> of <strong>even</strong> length <code>n</code>, pair up the elements of <code>nums</code> into <code>n / 2</code> pairs such that:</p>
|
||||
|
||||
<ul>
|
||||
<li>Each element of <code>nums</code> is in <strong>exactly one</strong> pair, and</li>
|
||||
<li>The <strong>maximum pair sum </strong>is <strong>minimized</strong>.</li>
|
||||
|
||||
<li>Each element of <code>nums</code> is in <strong>exactly one</strong> pair, and</li>
|
||||
|
||||
<li>The <strong>maximum pair sum </strong>is <strong>minimized</strong>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the minimized <strong>maximum pair sum</strong> after optimally pairing up the elements</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [3,5,2,3]
|
||||
|
||||
<strong>Output:</strong> 7
|
||||
|
||||
<strong>Explanation:</strong> The elements can be paired up into pairs (3,3) and (5,2).
|
||||
|
||||
The maximum pair sum is max(3+3, 5+2) = max(6, 7) = 7.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [3,5,4,2,4,6]
|
||||
|
||||
<strong>Output:</strong> 8
|
||||
|
||||
<strong>Explanation:</strong> The elements can be paired up into pairs (3,5), (4,4), and (6,2).
|
||||
|
||||
The maximum pair sum is max(3+5, 4+4, 6+2) = max(8, 8, 8) = 8.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == nums.length</code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>n</code> is <strong>even</strong>.</li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>n == nums.length</code></li>
|
||||
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>n</code> is <strong>even</strong>.</li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,47 +22,67 @@ tags:
|
|||
<p>The <strong>alternating sum</strong> of a <strong>0-indexed</strong> array is defined as the <strong>sum</strong> of the elements at <strong>even</strong> indices <strong>minus</strong> the <strong>sum</strong> of the elements at <strong>odd</strong> indices.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, the alternating sum of <code>[4,2,5,3]</code> is <code>(4 + 5) - (2 + 3) = 4</code>.</li>
|
||||
|
||||
<li>For example, the alternating sum of <code>[4,2,5,3]</code> is <code>(4 + 5) - (2 + 3) = 4</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Given an array <code>nums</code>, return <em>the <strong>maximum alternating sum</strong> of any subsequence of </em><code>nums</code><em> (after <strong>reindexing</strong> the elements of the subsequence)</em>.</p>
|
||||
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>A <strong>subsequence</strong> of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, <code>[2,7,4]</code> is a subsequence of <code>[4,<u>2</u>,3,<u>7</u>,2,1,<u>4</u>]</code> (the underlined elements), while <code>[2,4,2]</code> is not.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [<u>4</u>,<u>2</u>,<u>5</u>,3]
|
||||
|
||||
<strong>Output:</strong> 7
|
||||
|
||||
<strong>Explanation:</strong> It is optimal to choose the subsequence [4,2,5] with alternating sum (4 + 5) - 2 = 7.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [5,6,7,<u>8</u>]
|
||||
|
||||
<strong>Output:</strong> 8
|
||||
|
||||
<strong>Explanation:</strong> It is optimal to choose the subsequence [8] with alternating sum 8.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [<u>6</u>,2,<u>1</u>,2,4,<u>5</u>]
|
||||
|
||||
<strong>Output:</strong> 10
|
||||
|
||||
<strong>Explanation:</strong> It is optimal to choose the subsequence [6,1,5] with alternating sum (6 + 5) - 1 = 10.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ tags:
|
|||
<p>The <strong>product difference</strong> between two pairs <code>(a, b)</code> and <code>(c, d)</code> is defined as <code>(a * b) - (c * d)</code>.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, the product difference between <code>(5, 6)</code> and <code>(2, 7)</code> is <code>(5 * 6) - (2 * 7) = 16</code>.</li>
|
||||
|
||||
<li>For example, the product difference between <code>(5, 6)</code> and <code>(2, 7)</code> is <code>(5 * 6) - (2 * 7) = 16</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Given an integer array <code>nums</code>, choose four <strong>distinct</strong> indices <code>w</code>, <code>x</code>, <code>y</code>, and <code>z</code> such that the <strong>product difference</strong> between pairs <code>(nums[w], nums[x])</code> and <code>(nums[y], nums[z])</code> is <strong>maximized</strong>.</p>
|
||||
|
|
@ -30,30 +32,45 @@ tags:
|
|||
<p>Return <em>the <strong>maximum</strong> such product difference</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [5,6,2,7,4]
|
||||
|
||||
<strong>Output:</strong> 34
|
||||
|
||||
<strong>Explanation:</strong> We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
|
||||
|
||||
The product difference is (6 * 7) - (2 * 4) = 34.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> nums = [4,2,5,9,7,4,8]
|
||||
|
||||
<strong>Output:</strong> 64
|
||||
|
||||
<strong>Explanation:</strong> We can choose indices 3 and 6 for the first pair (9, 8) and indices 1 and 5 for the second pair (2, 4).
|
||||
|
||||
The product difference is (9 * 8) - (2 * 4) = 64.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>4 <= nums.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>4 <= nums.length <= 10<sup>4</sup></code></li>
|
||||
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -27,37 +27,59 @@ tags:
|
|||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/ringofgrid.png" style="width: 231px; height: 258px;" /></p>
|
||||
|
||||
<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/explanation_grid.jpg" style="width: 500px; height: 268px;" />
|
||||
|
||||
<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/rod2.png" style="width: 421px; height: 191px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1
|
||||
|
||||
<strong>Output:</strong> [[10,20],[40,30]]
|
||||
|
||||
<strong>Explanation:</strong> The figures above represent the grid at every state.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/ringofgrid5.png" style="width: 231px; height: 262px;" /></strong> <strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/ringofgrid6.png" style="width: 231px; height: 262px;" /></strong> <strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1914.Cyclically%20Rotating%20a%20Grid/images/ringofgrid7.png" style="width: 231px; height: 262px;" /></strong>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2
|
||||
|
||||
<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]
|
||||
|
||||
<strong>Explanation:</strong> The figures above represent the grid at every state.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == grid.length</code></li>
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
<li><code>2 <= m, n <= 50</code></li>
|
||||
<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>
|
||||
<li><code>1 <= grid[i][j] <=<sup> </sup>5000</code></li>
|
||||
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
||||
|
||||
<li><code>m == grid.length</code></li>
|
||||
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
|
||||
<li><code>2 <= m, n <= 50</code></li>
|
||||
|
||||
<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>
|
||||
|
||||
<li><code>1 <= grid[i][j] <=<sup> </sup>5000</code></li>
|
||||
|
||||
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ tags:
|
|||
<p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
|
||||
|
||||
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>word</code> that consists of the first ten lowercase English letters (<code>'a'</code> through <code>'j'</code>), return <em>the <strong>number of wonderful non-empty substrings</strong> in </em><code>word</code><em>. If the same substring appears multiple times in </em><code>word</code><em>, then count <strong>each occurrence</strong> separately.</em></p>
|
||||
|
|
@ -32,51 +34,83 @@ tags:
|
|||
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word = "aba"
|
||||
|
||||
<strong>Output:</strong> 4
|
||||
|
||||
<strong>Explanation:</strong> The four wonderful substrings are underlined below:
|
||||
|
||||
- "<u><strong>a</strong></u>ba" -> "a"
|
||||
|
||||
- "a<u><strong>b</strong></u>a" -> "b"
|
||||
|
||||
- "ab<u><strong>a</strong></u>" -> "a"
|
||||
|
||||
- "<u><strong>aba</strong></u>" -> "aba"
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word = "aabb"
|
||||
|
||||
<strong>Output:</strong> 9
|
||||
|
||||
<strong>Explanation:</strong> The nine wonderful substrings are underlined below:
|
||||
|
||||
- "<strong><u>a</u></strong>abb" -> "a"
|
||||
|
||||
- "<u><strong>aa</strong></u>bb" -> "aa"
|
||||
|
||||
- "<u><strong>aab</strong></u>b" -> "aab"
|
||||
|
||||
- "<u><strong>aabb</strong></u>" -> "aabb"
|
||||
|
||||
- "a<u><strong>a</strong></u>bb" -> "a"
|
||||
|
||||
- "a<u><strong>abb</strong></u>" -> "abb"
|
||||
|
||||
- "aa<u><strong>b</strong></u>b" -> "b"
|
||||
|
||||
- "aa<u><strong>bb</strong></u>" -> "bb"
|
||||
|
||||
- "aab<u><strong>b</strong></u>" -> "b"
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> word = "he"
|
||||
|
||||
<strong>Output:</strong> 2
|
||||
|
||||
<strong>Explanation:</strong> The two wonderful substrings are underlined below:
|
||||
|
||||
- "<b><u>h</u></b>e" -> "h"
|
||||
|
||||
- "h<strong><u>e</u></strong>" -> "e"
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> consists of lowercase English letters from <code>'a'</code> to <code>'j'</code>.</li>
|
||||
|
||||
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>word</code> consists of lowercase English letters from <code>'a'</code> to <code>'j'</code>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -30,39 +30,65 @@ tags:
|
|||
<p>Return <em>the <strong>number of different orders</strong> you can build all the rooms in</em>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1916.Count%20Ways%20to%20Build%20Rooms%20in%20an%20Ant%20Colony/images/d1.jpg" style="width: 200px; height: 212px;" />
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> prevRoom = [-1,0,1]
|
||||
|
||||
<strong>Output:</strong> 1
|
||||
|
||||
<strong>Explanation:</strong> There is only one way to build the additional rooms: 0 → 1 → 2
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1916.Count%20Ways%20to%20Build%20Rooms%20in%20an%20Ant%20Colony/images/d2.jpg" style="width: 200px; height: 239px;" /></strong>
|
||||
|
||||
<pre>
|
||||
|
||||
<strong>Input:</strong> prevRoom = [-1,0,0,1,2]
|
||||
|
||||
<strong>Output:</strong> 6
|
||||
|
||||
<strong>Explanation:
|
||||
|
||||
</strong>The 6 ways are:
|
||||
|
||||
0 → 1 → 3 → 2 → 4
|
||||
|
||||
0 → 2 → 4 → 1 → 3
|
||||
|
||||
0 → 1 → 2 → 3 → 4
|
||||
|
||||
0 → 1 → 2 → 4 → 3
|
||||
|
||||
0 → 2 → 1 → 3 → 4
|
||||
|
||||
0 → 2 → 1 → 4 → 3
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == prevRoom.length</code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>prevRoom[0] == -1</code></li>
|
||||
<li><code>0 <= prevRoom[i] < n</code> for all <code>1 <= i < n</code></li>
|
||||
<li>Every room is reachable from room <code>0</code> once all the rooms are built.</li>
|
||||
|
||||
<li><code>n == prevRoom.length</code></li>
|
||||
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
|
||||
<li><code>prevRoom[0] == -1</code></li>
|
||||
|
||||
<li><code>0 <= prevRoom[i] < n</code> for all <code>1 <= i < n</code></li>
|
||||
|
||||
<li>Every room is reachable from room <code>0</code> once all the rooms are built.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ The total wasted space is (20 - 10) + (20 - 20) = 10.
|
|||
<strong>Input:</strong> nums = [10,20,30], k = 1
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> size = [20,20,30].
|
||||
We can set the initial size to be 20 and resize to 30 at time 2.
|
||||
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>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ tags:
|
|||
<p>A string <code>s</code> can be partitioned into groups of size <code>k</code> using the following procedure:</p>
|
||||
|
||||
<ul>
|
||||
<li>The first group consists of the first <code>k</code> characters of the string, the second group consists of the next <code>k</code> characters of the string, and so on. Each element can be a part of <strong>exactly one</strong> group.</li>
|
||||
<li>The first group consists of the first <code>k</code> characters of the string, the second group consists of the next <code>k</code> characters of the string, and so on. Each character can be a part of <strong>exactly one</strong> group.</li>
|
||||
<li>For the last group, if the string <strong>does not</strong> have <code>k</code> characters remaining, a character <code>fill</code> is used to complete the group.</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ tags:
|
|||
<p><code>nums</code> 的 <strong>串联值</strong> 最初等于 <code>0</code> 。执行下述操作直到 <code>nums</code> 变为空:</p>
|
||||
|
||||
<ul>
|
||||
<li>如果 <code>nums</code> 的长度大于 1,分别选中 <code>nums</code> 中的第一个元素和最后一个元素,将二者串联得到的值加到 <code>nums</code> 的 <strong>串联值</strong> 上,然后从 <code>nums</code> 中删除第一个和最后一个元素。例如,如果 <code>nums</code> 是 <code>[1, 2, 4, 5, 6]</code>,将 16 添加到串联值。</li>
|
||||
<li>如果 <code>nums</code> 中仅存在一个元素,则将该元素的值加到 <code>nums</code> 的串联值上,然后删除这个元素。</li>
|
||||
<li>如果 <code>nums</code> 中存在不止一个数字,分别选中 <code>nums</code> 中的第一个元素和最后一个元素,将二者串联得到的值加到 <code>nums</code> 的 <strong>串联值</strong> 上,然后从 <code>nums</code> 中删除第一个和最后一个元素。</li>
|
||||
<li>如果仅存在一个元素,则将该元素的值加到 <code>nums</code> 的串联值上,然后删除这个元素。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回执行完所有操作后<em> </em><code>nums</code> 的串联值。</p>
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ tags:
|
|||
<p>The <strong>concatenation value</strong> of <code>nums</code> is initially equal to <code>0</code>. Perform this operation until <code>nums</code> becomes empty:</p>
|
||||
|
||||
<ul>
|
||||
<li>If <code>nums</code> has a size greater than one, add the value of the concatenation of the first and the last element to the <strong>concatenation value</strong> of <code>nums</code>, and remove those two elements from <code>nums</code>. For example, if the <code>nums</code> was <code>[1, 2, 4, 5, 6]</code>, add 16 to the <code>concatenation value</code>.</li>
|
||||
<li>If only one element exists in <code>nums</code>, add its value to the <strong>concatenation value</strong> of <code>nums</code>, then remove it.</li>
|
||||
<li>If there exists more than one number in <code>nums</code>, pick the first element and last element in <code>nums</code> respectively and add the value of their concatenation to the <strong>concatenation value</strong> of <code>nums</code>, then delete the first and last element from <code>nums</code>.</li>
|
||||
<li>If one element exists, add its value to the <strong>concatenation value</strong> of <code>nums</code>, then delete it.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return<em> the concatenation value of <code>nums</code></em>.</p>
|
||||
<p>Return<em> the concatenation value of the <code>nums</code></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ tags:
|
|||
<strong>输入:</strong>n = 2, k = 6
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>可以构造数组 [1,2] ,其元素总和为 3 。
|
||||
可以证明不存在总和小于 3 的 k-avoiding 数组。
|
||||
可以证明不存在总和小于 3 的 k-avoiding 数组。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ tags:
|
|||
|
||||
<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>
|
||||
|
||||
<p><strong>Note</strong> that when you are reach a magician, you <em>must</em> take energy from them, whether it is negative or positive energy.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3432.Count%20Partitions%20with%20Even%20Sum%20Difference/README.md
|
||||
rating: 1199
|
||||
source: 第 434 场周赛 Q1
|
||||
tags:
|
||||
- 数组
|
||||
- 数学
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3432.Count%20Partitions%20with%20Even%20Sum%20Difference/README_EN.md
|
||||
rating: 1199
|
||||
source: Weekly Contest 434 Q1
|
||||
tags:
|
||||
- Array
|
||||
- Math
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3433.Count%20Mentions%20Per%20User/README.md
|
||||
rating: 1745
|
||||
source: 第 434 场周赛 Q2
|
||||
tags:
|
||||
- 数组
|
||||
- 数学
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3433.Count%20Mentions%20Per%20User/README_EN.md
|
||||
rating: 1745
|
||||
source: Weekly Contest 434 Q2
|
||||
tags:
|
||||
- Array
|
||||
- Math
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3434.Maximum%20Frequency%20After%20Subarray%20Operation/README.md
|
||||
rating: 2093
|
||||
source: 第 434 场周赛 Q3
|
||||
tags:
|
||||
- 贪心
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3434.Maximum%20Frequency%20After%20Subarray%20Operation/README_EN.md
|
||||
rating: 2093
|
||||
source: Weekly Contest 434 Q3
|
||||
tags:
|
||||
- Greedy
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3435.Frequencies%20of%20Shortest%20Supersequences/README.md
|
||||
rating: 3027
|
||||
source: 第 434 场周赛 Q4
|
||||
tags:
|
||||
- 位运算
|
||||
- 图
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3435.Frequencies%20of%20Shortest%20Supersequences/README_EN.md
|
||||
rating: 3027
|
||||
source: Weekly Contest 434 Q4
|
||||
tags:
|
||||
- Bit Manipulation
|
||||
- Graph
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3438.Find%20Valid%20Pair%20of%20Adjacent%20Digits%20in%20String/README.md
|
||||
rating: 1225
|
||||
source: 第 149 场双周赛 Q1
|
||||
tags:
|
||||
- 哈希表
|
||||
- 字符串
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3438.Find%20Valid%20Pair%20of%20Adjacent%20Digits%20in%20String/README_EN.md
|
||||
rating: 1225
|
||||
source: Biweekly Contest 149 Q1
|
||||
tags:
|
||||
- Hash Table
|
||||
- String
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3439.Reschedule%20Meetings%20for%20Maximum%20Free%20Time%20I/README.md
|
||||
rating: 1728
|
||||
source: 第 149 场双周赛 Q2
|
||||
tags:
|
||||
- 贪心
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3439.Reschedule%20Meetings%20for%20Maximum%20Free%20Time%20I/README_EN.md
|
||||
rating: 1728
|
||||
source: Biweekly Contest 149 Q2
|
||||
tags:
|
||||
- Greedy
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3440.Reschedule%20Meetings%20for%20Maximum%20Free%20Time%20II/README.md
|
||||
rating: 1997
|
||||
source: 第 149 场双周赛 Q3
|
||||
tags:
|
||||
- 贪心
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3440.Reschedule%20Meetings%20for%20Maximum%20Free%20Time%20II/README_EN.md
|
||||
rating: 1997
|
||||
source: Biweekly Contest 149 Q3
|
||||
tags:
|
||||
- Greedy
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3441.Minimum%20Cost%20Good%20Caption/README.md
|
||||
rating: 2764
|
||||
source: 第 149 场双周赛 Q4
|
||||
tags:
|
||||
- 字符串
|
||||
- 动态规划
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3441.Minimum%20Cost%20Good%20Caption/README_EN.md
|
||||
rating: 2764
|
||||
source: Biweekly Contest 149 Q4
|
||||
tags:
|
||||
- String
|
||||
- Dynamic Programming
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3442.Maximum%20Difference%20Between%20Even%20and%20Odd%20Frequency%20I/README.md
|
||||
rating: 1220
|
||||
source: 第 435 场周赛 Q1
|
||||
tags:
|
||||
- 哈希表
|
||||
- 字符串
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3442.Maximum%20Difference%20Between%20Even%20and%20Odd%20Frequency%20I/README_EN.md
|
||||
rating: 1220
|
||||
source: Weekly Contest 435 Q1
|
||||
tags:
|
||||
- Hash Table
|
||||
- String
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3443.Maximum%20Manhattan%20Distance%20After%20K%20Changes/README.md
|
||||
rating: 1855
|
||||
source: 第 435 场周赛 Q2
|
||||
tags:
|
||||
- 哈希表
|
||||
- 数学
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3443.Maximum%20Manhattan%20Distance%20After%20K%20Changes/README_EN.md
|
||||
rating: 1855
|
||||
source: Weekly Contest 435 Q2
|
||||
tags:
|
||||
- Hash Table
|
||||
- Math
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3444.Minimum%20Increments%20for%20Target%20Multiples%20in%20an%20Array/README.md
|
||||
rating: 2336
|
||||
source: 第 435 场周赛 Q3
|
||||
tags:
|
||||
- 位运算
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3444.Minimum%20Increments%20for%20Target%20Multiples%20in%20an%20Array/README_EN.md
|
||||
rating: 2336
|
||||
source: Weekly Contest 435 Q3
|
||||
tags:
|
||||
- Bit Manipulation
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3445.Maximum%20Difference%20Between%20Even%20and%20Odd%20Frequency%20II/README.md
|
||||
rating: 2693
|
||||
source: 第 435 场周赛 Q4
|
||||
tags:
|
||||
- 字符串
|
||||
- 枚举
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3445.Maximum%20Difference%20Between%20Even%20and%20Odd%20Frequency%20II/README_EN.md
|
||||
rating: 2693
|
||||
source: Weekly Contest 435 Q4
|
||||
tags:
|
||||
- String
|
||||
- Enumeration
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3446.Sort%20Matrix%20by%20Diagonals/README.md
|
||||
rating: 1372
|
||||
source: 第 436 场周赛 Q1
|
||||
tags:
|
||||
- 数组
|
||||
- 矩阵
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3446.Sort%20Matrix%20by%20Diagonals/README_EN.md
|
||||
rating: 1372
|
||||
source: Weekly Contest 436 Q1
|
||||
tags:
|
||||
- Array
|
||||
- Matrix
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3447.Assign%20Elements%20to%20Groups%20with%20Constraints/README.md
|
||||
rating: 1730
|
||||
source: 第 436 场周赛 Q2
|
||||
tags:
|
||||
- 数组
|
||||
- 哈希表
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3447.Assign%20Elements%20to%20Groups%20with%20Constraints/README_EN.md
|
||||
rating: 1730
|
||||
source: Weekly Contest 436 Q2
|
||||
tags:
|
||||
- Array
|
||||
- Hash Table
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3448.Count%20Substrings%20Divisible%20By%20Last%20Digit/README.md
|
||||
rating: 2386
|
||||
source: 第 436 场周赛 Q3
|
||||
tags:
|
||||
- 字符串
|
||||
- 动态规划
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3448.Count%20Substrings%20Divisible%20By%20Last%20Digit/README_EN.md
|
||||
rating: 2386
|
||||
source: Weekly Contest 436 Q3
|
||||
tags:
|
||||
- String
|
||||
- Dynamic Programming
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3449.Maximize%20the%20Minimum%20Game%20Score/README.md
|
||||
rating: 2748
|
||||
source: 第 436 场周赛 Q4
|
||||
tags:
|
||||
- 贪心
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3449.Maximize%20the%20Minimum%20Game%20Score/README_EN.md
|
||||
rating: 2748
|
||||
source: Weekly Contest 436 Q4
|
||||
tags:
|
||||
- Greedy
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3452.Sum%20of%20Good%20Numbers/README.md
|
||||
rating: 1199
|
||||
source: 第 150 场双周赛 Q1
|
||||
tags:
|
||||
- 数组
|
||||
---
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3452.Sum%20of%20Good%20Numbers/README_EN.md
|
||||
rating: 1199
|
||||
source: Biweekly Contest 150 Q1
|
||||
tags:
|
||||
- Array
|
||||
---
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3453.Separate%20Squares%20I/README.md
|
||||
rating: 1735
|
||||
source: 第 150 场双周赛 Q2
|
||||
tags:
|
||||
- 数组
|
||||
- 二分查找
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3453.Separate%20Squares%20I/README_EN.md
|
||||
rating: 1735
|
||||
source: Biweekly Contest 150 Q2
|
||||
tags:
|
||||
- Array
|
||||
- Binary Search
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3454.Separate%20Squares%20II/README.md
|
||||
rating: 2671
|
||||
source: 第 150 场双周赛 Q3
|
||||
tags:
|
||||
- 线段树
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3454.Separate%20Squares%20II/README_EN.md
|
||||
rating: 2671
|
||||
source: Biweekly Contest 150 Q3
|
||||
tags:
|
||||
- Segment Tree
|
||||
- Array
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3455.Shortest%20Matching%20Substring/README.md
|
||||
rating: 2303
|
||||
source: 第 150 场双周赛 Q4
|
||||
tags:
|
||||
- 双指针
|
||||
- 字符串
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3455.Shortest%20Matching%20Substring/README_EN.md
|
||||
rating: 2303
|
||||
source: Biweekly Contest 150 Q4
|
||||
tags:
|
||||
- Two Pointers
|
||||
- String
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3456.Find%20Special%20Substring%20of%20Length%20K/README.md
|
||||
rating: 1244
|
||||
source: 第 437 场周赛 Q1
|
||||
tags:
|
||||
- 字符串
|
||||
---
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3456.Find%20Special%20Substring%20of%20Length%20K/README_EN.md
|
||||
rating: 1244
|
||||
source: Weekly Contest 437 Q1
|
||||
tags:
|
||||
- String
|
||||
---
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3457.Eat%20Pizzas%21/README.md
|
||||
rating: 1704
|
||||
source: 第 437 场周赛 Q2
|
||||
tags:
|
||||
- 贪心
|
||||
- 数组
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3457.Eat%20Pizzas%21/README_EN.md
|
||||
rating: 1704
|
||||
source: Weekly Contest 437 Q2
|
||||
tags:
|
||||
- Greedy
|
||||
- Array
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue