mirror of https://github.com/doocs/leetcode.git
feat: update lc problems (#3494)
This commit is contained in:
parent
e7d8237c20
commit
35d66aa152
|
|
@ -26,7 +26,7 @@ tags:
|
|||
|
||||
<pre>
|
||||
<strong>输入: </strong>s = "abcabcbb"
|
||||
<strong>输出: </strong>3
|
||||
<strong>输出: </strong>3
|
||||
<strong>解释:</strong> 因为无重复字符的最长子串是 <code>"abc"</code>,所以其长度为 3。
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ tags:
|
|||
| num | varchar |
|
||||
+-------------+---------+
|
||||
In SQL, id is the primary key for this table.
|
||||
id is an autoincrement column.
|
||||
id is an autoincrement column starting from 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ tags:
|
|||
<strong>解释:</strong>
|
||||
NumArray numArray = new NumArray([-2, 0, 3, -5, 2, -1]);
|
||||
numArray.sumRange(0, 2); // return 1 ((-2) + 0 + 3)
|
||||
numArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1))
|
||||
numArray.sumRange(2, 5); // return -1 (3 + (-5) + 2 + (-1))
|
||||
numArray.sumRange(0, 5); // return -3 ((-2) + 0 + 3 + (-5) + 2 + (-1))
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ tags:
|
|||
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0300-0399/0304.Range%20Sum%20Query%202D%20-%20Immutable/images/1626332422-wUpUHT-image.png" style="width: 200px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
<strong>输入:</strong>
|
||||
["NumMatrix","sumRegion","sumRegion","sumRegion"]
|
||||
[[[[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]]],[2,1,4,3],[1,1,2,2],[1,2,2,4]]
|
||||
<strong>输出:</strong>
|
||||
<strong>输出:</strong>
|
||||
[null, 8, 11, 12]
|
||||
|
||||
<strong>解释:</strong>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ tags:
|
|||
<li><code>3 <= equation.length <= 1000</code></li>
|
||||
<li><code>equation</code> has exactly one <code>'='</code>.</li>
|
||||
<li><code>equation</code> consists of integers with an absolute value in the range <code>[0, 100]</code> without any leading zeros, and the variable <code>'x'</code>.</li>
|
||||
<li>The input is generated that if there is a single solution, it will be an integer.</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>A robot on an infinite XY-plane starts at point <code>(0, 0)</code> facing north. The robot can receive a sequence of these three possible types of <code>commands</code>:</p>
|
||||
<p>A robot on an infinite XY-plane starts at point <code>(0, 0)</code> facing north. The robot receives an array of integers <code>commands</code>, which represents a sequence of moves that it needs to execute. There are only three possible types of instructions the robot can receive:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>-2</code>: Turn left <code>90</code> degrees.</li>
|
||||
|
|
@ -26,59 +26,83 @@ tags:
|
|||
<li><code>1 <= k <= 9</code>: Move forward <code>k</code> units, one unit at a time.</li>
|
||||
</ul>
|
||||
|
||||
<p>Some of the grid squares are <code>obstacles</code>. The <code>i<sup>th</sup></code> obstacle is at grid point <code>obstacles[i] = (x<sub>i</sub>, y<sub>i</sub>)</code>. If the robot runs into an obstacle, then it will instead stay in its current location and move on to the next command.</p>
|
||||
<p>Some of the grid squares are <code>obstacles</code>. The <code>i<sup>th</sup></code> obstacle is at grid point <code>obstacles[i] = (x<sub>i</sub>, y<sub>i</sub>)</code>. If the robot runs into an obstacle, it will stay in its current location (on the block adjacent to the obstacle) and move onto the next command.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum Euclidean distance</strong> that the robot ever gets from the origin <strong>squared</strong> (i.e. if the distance is </em><code>5</code><em>, return </em><code>25</code><em>)</em>.</p>
|
||||
<p>Return the <strong>maximum squared Euclidean distance</strong> that the robot reaches at any point in its path (i.e. if the distance is <code>5</code>, return <code>25</code>).</p>
|
||||
|
||||
<p><strong>Note:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>There can be an obstacle at <code>(0, 0)</code>. If this happens, the robot will ignore the obstacle until it has moved off the origin. However, it will be unable to return to <code>(0, 0)</code> due to the obstacle.</li>
|
||||
<li>North means +Y direction.</li>
|
||||
<li>East means +X direction.</li>
|
||||
<li>South means -Y direction.</li>
|
||||
<li>West means -X direction.</li>
|
||||
<li>There can be obstacle in [0,0].</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> commands = [4,-1,3], obstacles = []
|
||||
<strong>Output:</strong> 25
|
||||
<strong>Explanation:</strong> The robot starts at (0, 0):
|
||||
1. Move north 4 units to (0, 4).
|
||||
2. Turn right.
|
||||
3. Move east 3 units to (3, 4).
|
||||
The furthest point the robot ever gets from the origin is (3, 4), which squared is 3<sup>2</sup> + 4<sup>2</sup> = 25 units away.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">commands = [4,-1,3], obstacles = []</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">25</span></p>
|
||||
|
||||
<p><strong>Explanation: </strong></p>
|
||||
|
||||
<p>The robot starts at <code>(0, 0)</code>:</p>
|
||||
|
||||
<ol>
|
||||
<li>Move north 4 units to <code>(0, 4)</code>.</li>
|
||||
<li>Turn right.</li>
|
||||
<li>Move east 3 units to <code>(3, 4)</code>.</li>
|
||||
</ol>
|
||||
|
||||
<p>The furthest point the robot ever gets from the origin is <code>(3, 4)</code>, which squared is <code>3<sup>2</sup> + 4<sup>2 </sup>= 25</code> units away.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> commands = [4,-1,4,-2,4], obstacles = [[2,4]]
|
||||
<strong>Output:</strong> 65
|
||||
<strong>Explanation:</strong> The robot starts at (0, 0):
|
||||
1. Move north 4 units to (0, 4).
|
||||
2. Turn right.
|
||||
3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).
|
||||
4. Turn left.
|
||||
5. Move north 4 units to (1, 8).
|
||||
The furthest point the robot ever gets from the origin is (1, 8), which squared is 1<sup>2</sup> + 8<sup>2</sup> = 65 units away.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">commands = [4,-1,4,-2,4], obstacles = [[2,4]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">65</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The robot starts at <code>(0, 0)</code>:</p>
|
||||
|
||||
<ol>
|
||||
<li>Move north 4 units to <code>(0, 4)</code>.</li>
|
||||
<li>Turn right.</li>
|
||||
<li>Move east 1 unit and get blocked by the obstacle at <code>(2, 4)</code>, robot is at <code>(1, 4)</code>.</li>
|
||||
<li>Turn left.</li>
|
||||
<li>Move north 4 units to <code>(1, 8)</code>.</li>
|
||||
</ol>
|
||||
|
||||
<p>The furthest point the robot ever gets from the origin is <code>(1, 8)</code>, which squared is <code>1<sup>2</sup> + 8<sup>2</sup> = 65</code> units away.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> commands = [6,-1,-1,6], obstacles = []
|
||||
<strong>Output:</strong> 36
|
||||
<strong>Explanation:</strong> The robot starts at (0, 0):
|
||||
1. Move north 6 units to (0, 6).
|
||||
2. Turn right.
|
||||
3. Turn right.
|
||||
4. Move south 6 units to (0, 0).
|
||||
The furthest point the robot ever gets from the origin is (0, 6), which squared is 6<sup>2</sup> = 36 units away.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">commands = [6,-1,-1,6], obstacles = [[0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">36</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The robot starts at <code>(0, 0)</code>:</p>
|
||||
|
||||
<ol>
|
||||
<li>Move north 6 units to <code>(0, 6)</code>.</li>
|
||||
<li>Turn right.</li>
|
||||
<li>Turn right.</li>
|
||||
<li>Move south 5 units and get blocked by the obstacle at <code>(0,0)</code>, robot is at <code>(0, 1)</code>.</li>
|
||||
</ol>
|
||||
|
||||
<p>The furthest point the robot ever gets from the origin is <code>(0, 6)</code>, which squared is <code>6<sup>2</sup> = 36</code> units away.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ weight is the weight of the person in kilograms.
|
|||
|
||||
<p>Write a solution to find the <code>person_name</code> of the <strong>last person</strong> that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.</p>
|
||||
|
||||
<p><strong>Note</strong> that <em>only one</em> person can board the bus at any given turn.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
|
|
|
|||
|
|
@ -23,25 +23,25 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个 <code>m x n</code> 的矩阵 <code>matrix</code> ,请你返回一个新的矩阵<em> </em><code>answer</code> ,其中<em> </em><code>answer[row][col]</code> 是 <code>matrix[row][col]</code> 的秩。</p>
|
||||
<p>给你一个 <code>m x n</code> 的矩阵 <code>matrix</code> ,请你返回一个新的矩阵<em> </em><code>answer</code> ,其中<em> </em><code>answer[row][col]</code> 是 <code>matrix[row][col]</code> 的秩。</p>
|
||||
|
||||
<p>每个元素的 <b>秩</b> 是一个整数,表示这个元素相对于其他元素的大小关系,它按照如下规则计算:</p>
|
||||
<p>每个元素的 <b>秩</b> 是一个整数,表示这个元素相对于其他元素的大小关系,它按照如下规则计算:</p>
|
||||
|
||||
<ul>
|
||||
<li>秩是从 1 开始的一个整数。</li>
|
||||
<li>如果两个元素 <code>p</code> 和 <code>q</code> 在 <strong>同一行</strong> 或者 <strong>同一列</strong> ,那么:
|
||||
<li>如果两个元素 <code>p</code> 和 <code>q</code> 在 <strong>同一行</strong> 或者 <strong>同一列</strong> ,那么:
|
||||
<ul>
|
||||
<li>如果 <code>p < q</code> ,那么 <code>rank(p) < rank(q)</code></li>
|
||||
<li>如果 <code>p == q</code> ,那么 <code>rank(p) == rank(q)</code></li>
|
||||
<li>如果 <code>p > q</code> ,那么 <code>rank(p) > rank(q)</code></li>
|
||||
<li>如果 <code>p < q</code> ,那么 <code>rank(p) < rank(q)</code></li>
|
||||
<li>如果 <code>p == q</code> ,那么 <code>rank(p) == rank(q)</code></li>
|
||||
<li>如果 <code>p > q</code> ,那么 <code>rank(p) > rank(q)</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><b>秩</b> 需要越 <strong>小</strong> 越好。</li>
|
||||
<li><b>秩</b> 需要越 <strong>小</strong> 越好。</li>
|
||||
</ul>
|
||||
|
||||
<p>题目保证按照上面规则 <code>answer</code> 数组是唯一的。</p>
|
||||
<p>题目保证按照上面规则 <code>answer</code> 数组是唯一的。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/images/rank1.jpg" style="width: 442px; height: 162px;" />
|
||||
|
|
@ -50,9 +50,9 @@ tags:
|
|||
<b>输出:</b>[[1,2],[2,3]]
|
||||
<strong>解释:</strong>
|
||||
matrix[0][0] 的秩为 1 ,因为它是所在行和列的最小整数。
|
||||
matrix[0][1] 的秩为 2 ,因为 matrix[0][1] > matrix[0][0] 且 matrix[0][0] 的秩为 1 。
|
||||
matrix[1][0] 的秩为 2 ,因为 matrix[1][0] > matrix[0][0] 且 matrix[0][0] 的秩为 1 。
|
||||
matrix[1][1] 的秩为 3 ,因为 matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0] 且 matrix[0][1] 和 matrix[1][0] 的秩都为 2 。
|
||||
matrix[0][1] 的秩为 2 ,因为 matrix[0][1] > matrix[0][0] 且 matrix[0][0] 的秩为 1 。
|
||||
matrix[1][0] 的秩为 2 ,因为 matrix[1][0] > matrix[0][0] 且 matrix[0][0] 的秩为 1 。
|
||||
matrix[1][1] 的秩为 3 ,因为 matrix[1][1] > matrix[0][1], matrix[1][1] > matrix[1][0] 且 matrix[0][1] 和 matrix[1][0] 的秩都为 2 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
|
@ -69,22 +69,17 @@ matrix[1][1] 的秩为 3 ,因为 matrix[1][1] > matrix[0][1], matrix[1][1] >
|
|||
<b>输出:</b>[[4,2,3],[1,3,4],[5,1,6],[1,3,4]]
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 4:</strong></p>
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1632.Rank%20Transform%20of%20a%20Matrix/images/rank4.jpg" style="width: 601px; height: 242px;" />
|
||||
<pre>
|
||||
<b>输入:</b>matrix = [[7,3,6],[1,4,5],[9,8,2]]
|
||||
<b>输出:</b>[[5,1,4],[1,2,3],[6,3,1]]
|
||||
</pre>
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == matrix.length</code></li>
|
||||
<li><code>n == matrix[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 500</code></li>
|
||||
<li><code>-10<sup>9</sup> <= matrix[row][col] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= m, n <= 500</code></li>
|
||||
<li><code>-10<sup>9</sup> <= matrix[row][col] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ tags:
|
|||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2132.Stamping%20the%20Grid/images/ex2.png" style="width: 170px; height: 179px;"></p>
|
||||
|
||||
<pre><b>输入:</b>grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2
|
||||
<b>输出:</b>false
|
||||
<pre><b>输入:</b>grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>没办法放入邮票覆盖所有的空格子,且邮票不超出网格图以外。
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ tags:
|
|||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2132.Stamping%20the%20Grid/images/ex2.png" style="width: 170px; height: 179px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2
|
||||
<strong>Output:</strong> false
|
||||
<strong>Input:</strong> grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> There is no way to fit the stamps onto all the empty cells without the stamps going outside the grid.
|
||||
</pre>
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ tags:
|
|||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [2470. 最小公倍数为 K 的子数组数目](https://leetcode.cn/problems/number-of-subarrays-with-lcm-equal-to-k)
|
||||
# [2470. 最小公倍数等于 K 的子数组数目](https://leetcode.cn/problems/number-of-subarrays-with-lcm-equal-to-k)
|
||||
|
||||
[English Version](/solution/2400-2499/2470.Number%20of%20Subarrays%20With%20LCM%20Equal%20to%20K/README_EN.md)
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ tags:
|
|||
<strong>输入:</strong>words = ["aba","aabb","abcd","bac","aabc"]
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>共有 2 对满足条件:
|
||||
- i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 3 且 j = 4 :words[3] 和 words[4] 只由字符 'a'、'b' 和 'c' 。
|
||||
- i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 3 且 j = 4 :words[3] 和 words[4] 只由字符 'a'、'b' 和 'c' 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
|
@ -51,9 +51,9 @@ tags:
|
|||
<strong>输入:</strong>words = ["aabb","ab","ba"]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>共有 3 对满足条件:
|
||||
- i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 0 且 j = 2 :words[0] 和 words[2] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 1 且 j = 2 :words[1] 和 words[2] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 0 且 j = 2 :words[0] 和 words[2] 只由字符 'a' 和 'b' 组成。
|
||||
- i = 1 且 j = 2 :words[1] 和 words[2] 只由字符 'a' 和 'b' 组成。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ tags:
|
|||
<strong>Input:</strong> words = ["aba","aabb","abcd","bac","aabc"]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> There are 2 pairs that satisfy the conditions:
|
||||
- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
|
||||
- i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.
|
||||
- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
|
||||
- i = 3 and j = 4 : both words[3] and words[4] only consist of characters 'a', 'b', and 'c'.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
|
@ -50,7 +50,7 @@ tags:
|
|||
<strong>Input:</strong> words = ["aabb","ab","ba"]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There are 3 pairs that satisfy the conditions:
|
||||
- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
|
||||
- i = 0 and j = 1 : both words[0] and words[1] only consist of characters 'a' and 'b'.
|
||||
- i = 0 and j = 2 : both words[0] and words[2] only consist of characters 'a' and 'b'.
|
||||
- i = 1 and j = 2 : both words[1] and words[2] only consist of characters 'a' and 'b'.
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ setTimeout(cancelFn, cancelTimeMs)
|
|||
|
||||
<p>The function <code>fn</code> should be called with <code>args</code> immediately and then called again every <code>t</code> milliseconds until <code>cancelFn</code> is called at <code>cancelTimeMs</code> ms.</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: 第 351 场周赛 Q3
|
|||
tags:
|
||||
- 数组
|
||||
- 数学
|
||||
- 动态规划
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: Weekly Contest 351 Q3
|
|||
tags:
|
||||
- Array
|
||||
- Math
|
||||
- Dynamic Programming
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个整数数组 <code>nums</code> 和一个 <strong>非负</strong> 整数 <code>k</code> 。如果一个整数序列 <code>seq</code> 满足在范围下标范围 <code>[0, seq.length - 2]</code> 中存在 <strong>不超过</strong> <code>k</code> 个下标 <code>i</code> 满足 <code>seq[i] != seq[i + 1]</code> ,那么我们称这个整数序列为 <strong>好</strong> 序列。</p>
|
||||
<p>给你一个整数数组 <code>nums</code> 和一个 <strong>非负</strong> 整数 <code>k</code> 。如果一个整数序列 <code>seq</code> 满足在下标范围 <code>[0, seq.length - 2]</code> 中 <strong>最多只有</strong> <code>k</code> 个下标 <code>i</code> 满足 <code>seq[i] != seq[i + 1]</code> ,那么我们称这个整数序列为 <strong>好</strong> 序列。</p>
|
||||
|
||||
<p>请你返回 <code>nums</code> 中 <strong>好</strong> <span data-keyword="subsequence-array">子序列</span> 的最长长度</p>
|
||||
<p>请你返回 <code>nums</code> 中 <strong>好</strong> <span data-keyword="subsequence-array">子序列</span> 的最长长度。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ tags:
|
|||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>最长好子序列为 <code>[<em><strong>1</strong></em>,<em><strong>2</strong></em>,<strong><em>1</em></strong>,<em><strong>1</strong></em>,3]</code> 。</p>
|
||||
<p>最长好子序列为 <code>[<u>1</u>,<u>2</u>,<u>1</u>,<u>1</u>,3]</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
|
@ -47,7 +47,7 @@ tags:
|
|||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>最长好子序列为 <code>[<strong><em>1</em></strong>,2,3,4,5,<strong><em>1</em></strong>]</code> 。</p>
|
||||
<p>最长好子序列为 <code>[<u>1</u>,2,3,4,5,<u>1</u>]</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3280. 将日期转换为二进制表示](https://leetcode.cn/problems/convert-date-to-binary)
|
||||
|
||||
[English Version](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README_EN.md)
|
||||
|
||||
## 题目描述
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个字符串 <code>date</code>,它的格式为 <code>yyyy-mm-dd</code>,表示一个公历日期。</p>
|
||||
|
||||
<p><code>date</code> 可以重写为二进制表示,只需要将年、月、日分别转换为对应的二进制表示(不带前导零)并遵循 <code>year-month-day</code> 的格式。</p>
|
||||
|
||||
<p>返回 <code>date</code> 的 <strong>二进制</strong> 表示。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">date = "2080-02-29"</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">"100000100000-10-11101"</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><span class="example-io">100000100000, 10 和 11101 分别是 2080, 02 和 29 的二进制表示。</span></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">date = "1900-01-01"</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">"11101101100-1-1"</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><span class="example-io">11101101100, 1 和 1 分别是 1900, 1 和 1 的二进制表示。</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>date.length == 10</code></li>
|
||||
<li><code>date[4] == date[7] == '-'</code>,其余的 <code>date[i]</code> 都是数字。</li>
|
||||
<li>输入保证 <code>date</code> 代表一个有效的公历日期,日期范围从 1900 年 1 月 1 日到 2100 年 12 月 31 日(包括这两天)。</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## 解法
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### 方法一:模拟
|
||||
|
||||
我们先将字符串 $\textit{date}$ 按照 `-` 分割,然后将每个部分转换为二进制表示,最后将这三个部分用 `-` 连接起来即可。
|
||||
|
||||
时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串 $\textit{date}$ 的长度。
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def convertDateToBinary(self, date: str) -> str:
|
||||
return "-".join(f"{int(s):b}" for s in date.split("-"))
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
public String convertDateToBinary(String date) {
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (var s : date.split("-")) {
|
||||
int x = Integer.parseInt(s);
|
||||
ans.add(Integer.toBinaryString(x));
|
||||
}
|
||||
return String.join("-", ans);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
string convertDateToBinary(string date) {
|
||||
auto bin = [](string s) -> string {
|
||||
string t = bitset<32>(stoi(s)).to_string();
|
||||
return t.substr(t.find('1'));
|
||||
};
|
||||
return bin(date.substr(0, 4)) + "-" + bin(date.substr(5, 2)) + "-" + bin(date.substr(8, 2));
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func convertDateToBinary(date string) string {
|
||||
ans := []string{}
|
||||
for _, s := range strings.Split(date, "-") {
|
||||
x, _ := strconv.Atoi(s)
|
||||
ans = append(ans, strconv.FormatUint(uint64(x), 2))
|
||||
}
|
||||
return strings.Join(ans, "-")
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function convertDateToBinary(date: string): string {
|
||||
return date
|
||||
.split('-')
|
||||
.map(s => (+s).toString(2))
|
||||
.join('-');
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README_EN.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3280. Convert Date to Binary](https://leetcode.com/problems/convert-date-to-binary)
|
||||
|
||||
[中文文档](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README.md)
|
||||
|
||||
## Description
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p>
|
||||
|
||||
<p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in <code>year-month-day</code> format.</p>
|
||||
|
||||
<p>Return the <strong>binary</strong> representation of <code>date</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">date = "2080-02-29"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"100000100000-10-11101"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><span class="example-io">100000100000, 10, and 11101 are the binary representations of 2080, 02, and 29 respectively.</span></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">date = "1900-01-01"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"11101101100-1-1"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><span class="example-io">11101101100, 1, and 1 are the binary representations of 1900, 1, and 1 respectively.</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>date.length == 10</code></li>
|
||||
<li><code>date[4] == date[7] == '-'</code>, and all other <code>date[i]</code>'s are digits.</li>
|
||||
<li>The input is generated such that <code>date</code> represents a valid Gregorian calendar date between Jan 1<sup>st</sup>, 1900 and Dec 31<sup>st</sup>, 2100 (both inclusive).</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## Solutions
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### Solution 1: Simulation
|
||||
|
||||
We first split the string $\textit{date}$ by `-`, then convert each part to its binary representation, and finally join these three parts with `-`.
|
||||
|
||||
The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string $\textit{date}$.
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def convertDateToBinary(self, date: str) -> str:
|
||||
return "-".join(f"{int(s):b}" for s in date.split("-"))
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
public String convertDateToBinary(String date) {
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (var s : date.split("-")) {
|
||||
int x = Integer.parseInt(s);
|
||||
ans.add(Integer.toBinaryString(x));
|
||||
}
|
||||
return String.join("-", ans);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
string convertDateToBinary(string date) {
|
||||
auto bin = [](string s) -> string {
|
||||
string t = bitset<32>(stoi(s)).to_string();
|
||||
return t.substr(t.find('1'));
|
||||
};
|
||||
return bin(date.substr(0, 4)) + "-" + bin(date.substr(5, 2)) + "-" + bin(date.substr(8, 2));
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func convertDateToBinary(date string) string {
|
||||
ans := []string{}
|
||||
for _, s := range strings.Split(date, "-") {
|
||||
x, _ := strconv.Atoi(s)
|
||||
ans = append(ans, strconv.FormatUint(uint64(x), 2))
|
||||
}
|
||||
return strings.Join(ans, "-")
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function convertDateToBinary(date: string): string {
|
||||
return date
|
||||
.split('-')
|
||||
.map(s => (+s).toString(2))
|
||||
.join('-');
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class Solution {
|
||||
public:
|
||||
string convertDateToBinary(string date) {
|
||||
auto bin = [](string s) -> string {
|
||||
string t = bitset<32>(stoi(s)).to_string();
|
||||
return t.substr(t.find('1'));
|
||||
};
|
||||
return bin(date.substr(0, 4)) + "-" + bin(date.substr(5, 2)) + "-" + bin(date.substr(8, 2));
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
func convertDateToBinary(date string) string {
|
||||
ans := []string{}
|
||||
for _, s := range strings.Split(date, "-") {
|
||||
x, _ := strconv.Atoi(s)
|
||||
ans = append(ans, strconv.FormatUint(uint64(x), 2))
|
||||
}
|
||||
return strings.Join(ans, "-")
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
class Solution {
|
||||
public String convertDateToBinary(String date) {
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (var s : date.split("-")) {
|
||||
int x = Integer.parseInt(s);
|
||||
ans.add(Integer.toBinaryString(x));
|
||||
}
|
||||
return String.join("-", ans);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Solution:
|
||||
def convertDateToBinary(self, date: str) -> str:
|
||||
return "-".join(f"{int(s):b}" for s in date.split("-"))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
function convertDateToBinary(date: string): string {
|
||||
return date
|
||||
.split('-')
|
||||
.map(s => (+s).toString(2))
|
||||
.join('-');
|
||||
}
|
||||
|
|
@ -0,0 +1,235 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3281. 范围内整数的最大得分](https://leetcode.cn/problems/maximize-score-of-numbers-in-ranges)
|
||||
|
||||
[English Version](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README_EN.md)
|
||||
|
||||
## 题目描述
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个整数数组 <code>start</code> 和一个整数 <code>d</code>,代表 <code>n</code> 个区间 <code>[start[i], start[i] + d]</code>。</p>
|
||||
|
||||
<p>你需要选择 <code>n</code> 个整数,其中第 <code>i</code> 个整数必须属于第 <code>i</code> 个区间。所选整数的 <strong>得分</strong> 定义为所选整数两两之间的 <strong>最小 </strong>绝对差。</p>
|
||||
|
||||
<p>返回所选整数的 <strong>最大可能得分 </strong>。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">start = [6,0,3], d = 2</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>可以选择整数 8, 0 和 4 获得最大可能得分,得分为 <code>min(|8 - 0|, |8 - 4|, |0 - 4|)</code>,等于 4。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>输入:</strong> <span class="example-io">start = [2,6,13,13], d = 5</span></p>
|
||||
|
||||
<p><strong>输出:</strong> <span class="example-io">5</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>可以选择整数 2, 7, 13 和 18 获得最大可能得分,得分为 <code>min(|2 - 7|, |2 - 13|, |2 - 18|, |7 - 13|, |7 - 18|, |13 - 18|)</code>,等于 5。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= start.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= start[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= d <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## 解法
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### 方法一:排序 + 二分查找
|
||||
|
||||
我们不妨先对 $\textit{start}$ 数组进行排序,然后我们考虑从左到右选择整数,那么得分就等于我们选择的相邻两个整数的差值的最小值。
|
||||
|
||||
如果一个差值 $x$ 满足条件,那么对于任意 $x' \lt x$,也一定满足条件。因此我们可以使用二分查找的方法来找到最大的满足条件的差值。
|
||||
|
||||
我们定义二分查找的左边界 $l = 0$,右边界 $r = \textit{start}[-1] + d - \textit{start}[0]$,然后我们每次取中间值 $mid = \left\lfloor \frac{l + r + 1}{2} \right\rfloor$,然后判断是否满足条件。
|
||||
|
||||
我们定义一个函数 $\text{check}(mi)$ 来判断是否满足条件,具体实现如下:
|
||||
|
||||
- 我们定义一个变量 $\textit{last} = -\infty$,表示上一个选择的整数。
|
||||
- 我们遍历 $\textit{start}$ 数组,如果 $\textit{last} + \textit{mi} > \textit{st} + d$,那么说明我们无法选择整数 $\textit{st}$,返回 $\text{false}$。否则,我们更新 $\textit{last} = \max(\textit{st}, \textit{last} + \textit{mi})$。
|
||||
- 如果遍历完整个 $\textit{start}$ 数组都满足条件,那么返回 $\text{true}$。
|
||||
|
||||
时间复杂度 $O(n \times \log M)$,其中 $n$ 和 $M$ 分别是 $\textit{start}$ 数组的长度和最大值。空间复杂度 $O(1)$。
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def maxPossibleScore(self, start: List[int], d: int) -> int:
|
||||
def check(mi: int) -> bool:
|
||||
last = -inf
|
||||
for st in start:
|
||||
if last + mi > st + d:
|
||||
return False
|
||||
last = max(st, last + mi)
|
||||
return True
|
||||
|
||||
start.sort()
|
||||
l, r = 0, start[-1] + d - start[0]
|
||||
while l < r:
|
||||
mid = (l + r + 1) >> 1
|
||||
if check(mid):
|
||||
l = mid
|
||||
else:
|
||||
r = mid - 1
|
||||
return l
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
private int[] start;
|
||||
private int d;
|
||||
|
||||
public int maxPossibleScore(int[] start, int d) {
|
||||
Arrays.sort(start);
|
||||
this.start = start;
|
||||
this.d = d;
|
||||
int n = start.length;
|
||||
int l = 0, r = start[n - 1] + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = (l + r + 1) >>> 1;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private boolean check(int mi) {
|
||||
long last = Long.MIN_VALUE;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
int maxPossibleScore(vector<int>& start, int d) {
|
||||
ranges::sort(start);
|
||||
auto check = [&](int mi) -> bool {
|
||||
long long last = LLONG_MIN;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = max((long long) st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
int l = 0, r = start.back() + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = l + (r - l + 1) / 2;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func maxPossibleScore(start []int, d int) int {
|
||||
check := func(mi int) bool {
|
||||
last := math.MinInt64
|
||||
for _, st := range start {
|
||||
if last+mi > st+d {
|
||||
return false
|
||||
}
|
||||
last = max(st, last+mi)
|
||||
}
|
||||
return true
|
||||
}
|
||||
sort.Ints(start)
|
||||
l, r := 0, start[len(start)-1]+d-start[0]
|
||||
for l < r {
|
||||
mid := (l + r + 1) >> 1
|
||||
if check(mid) {
|
||||
l = mid
|
||||
} else {
|
||||
r = mid - 1
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function maxPossibleScore(start: number[], d: number): number {
|
||||
start.sort((a, b) => a - b);
|
||||
let [l, r] = [0, start.at(-1)! + d - start[0]];
|
||||
const check = (mi: number): boolean => {
|
||||
let last = -Infinity;
|
||||
for (const st of start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
while (l < r) {
|
||||
const mid = l + ((r - l + 1) >> 1);
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README_EN.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3281. Maximize Score of Numbers in Ranges](https://leetcode.com/problems/maximize-score-of-numbers-in-ranges)
|
||||
|
||||
[中文文档](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README.md)
|
||||
|
||||
## Description
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p>
|
||||
|
||||
<p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interval. The <strong>score</strong> of the chosen integers is defined as the <strong>minimum</strong> absolute difference between any two integers that have been chosen.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> <em>possible score</em> of the chosen integers.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">start = [6,0,3], d = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum possible score can be obtained by choosing integers: 8, 0, and 4. The score of these chosen integers is <code>min(|8 - 0|, |8 - 4|, |0 - 4|)</code> which equals 4.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">start = [2,6,13,13], d = 5</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum possible score can be obtained by choosing integers: 2, 7, 13, and 18. The score of these chosen integers is <code>min(|2 - 7|, |2 - 13|, |2 - 18|, |7 - 13|, |7 - 18|, |13 - 18|)</code> which equals 5.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= start.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= start[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= d <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## Solutions
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### Solution 1: Sorting + Binary Search
|
||||
|
||||
We can first sort the $\textit{start}$ array. Then, we consider selecting integers from left to right, where the score is equal to the minimum difference between any two adjacent selected integers.
|
||||
|
||||
If a difference $x$ satisfies the condition, then any $x' < x$ will also satisfy the condition. Therefore, we can use binary search to find the largest difference that satisfies the condition.
|
||||
|
||||
We define the left boundary of the binary search as $l = 0$ and the right boundary as $r = \textit{start}[-1] + d - \textit{start}[0]$. Each time, we take the middle value $mid = \left\lfloor \frac{l + r + 1}{2} \right\rfloor$ and check whether it satisfies the condition.
|
||||
|
||||
We define a function $\text{check}(mi)$ to determine whether the condition is satisfied, implemented as follows:
|
||||
|
||||
- We define a variable $\textit{last} = -\infty$, representing the last selected integer.
|
||||
- We traverse the $\textit{start}$ array. If $\textit{last} + \textit{mi} > \textit{st} + d$, it means we cannot select the integer $\textit{st}$, and we return $\text{false}$. Otherwise, we update $\textit{last} = \max(\textit{st}, \textit{last} + \textit{mi})$.
|
||||
- If we traverse the entire $\textit{start}$ array and all conditions are satisfied, we return $\text{true}$.
|
||||
|
||||
The time complexity is $O(n \times \log M)$, where $n$ and $M$ are the length and the maximum value of the $\textit{start}$ array, respectively. The space complexity is $O(1)$.
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def maxPossibleScore(self, start: List[int], d: int) -> int:
|
||||
def check(mi: int) -> bool:
|
||||
last = -inf
|
||||
for st in start:
|
||||
if last + mi > st + d:
|
||||
return False
|
||||
last = max(st, last + mi)
|
||||
return True
|
||||
|
||||
start.sort()
|
||||
l, r = 0, start[-1] + d - start[0]
|
||||
while l < r:
|
||||
mid = (l + r + 1) >> 1
|
||||
if check(mid):
|
||||
l = mid
|
||||
else:
|
||||
r = mid - 1
|
||||
return l
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
private int[] start;
|
||||
private int d;
|
||||
|
||||
public int maxPossibleScore(int[] start, int d) {
|
||||
Arrays.sort(start);
|
||||
this.start = start;
|
||||
this.d = d;
|
||||
int n = start.length;
|
||||
int l = 0, r = start[n - 1] + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = (l + r + 1) >>> 1;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private boolean check(int mi) {
|
||||
long last = Long.MIN_VALUE;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
int maxPossibleScore(vector<int>& start, int d) {
|
||||
ranges::sort(start);
|
||||
auto check = [&](int mi) -> bool {
|
||||
long long last = LLONG_MIN;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = max((long long) st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
int l = 0, r = start.back() + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = l + (r - l + 1) / 2;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func maxPossibleScore(start []int, d int) int {
|
||||
check := func(mi int) bool {
|
||||
last := math.MinInt64
|
||||
for _, st := range start {
|
||||
if last+mi > st+d {
|
||||
return false
|
||||
}
|
||||
last = max(st, last+mi)
|
||||
}
|
||||
return true
|
||||
}
|
||||
sort.Ints(start)
|
||||
l, r := 0, start[len(start)-1]+d-start[0]
|
||||
for l < r {
|
||||
mid := (l + r + 1) >> 1
|
||||
if check(mid) {
|
||||
l = mid
|
||||
} else {
|
||||
r = mid - 1
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function maxPossibleScore(start: number[], d: number): number {
|
||||
start.sort((a, b) => a - b);
|
||||
let [l, r] = [0, start.at(-1)! + d - start[0]];
|
||||
const check = (mi: number): boolean => {
|
||||
let last = -Infinity;
|
||||
for (const st of start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
while (l < r) {
|
||||
const mid = l + ((r - l + 1) >> 1);
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
class Solution {
|
||||
public:
|
||||
int maxPossibleScore(vector<int>& start, int d) {
|
||||
ranges::sort(start);
|
||||
auto check = [&](int mi) -> bool {
|
||||
long long last = LLONG_MIN;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = max((long long) st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
int l = 0, r = start.back() + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = l + (r - l + 1) / 2;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
func maxPossibleScore(start []int, d int) int {
|
||||
check := func(mi int) bool {
|
||||
last := math.MinInt64
|
||||
for _, st := range start {
|
||||
if last+mi > st+d {
|
||||
return false
|
||||
}
|
||||
last = max(st, last+mi)
|
||||
}
|
||||
return true
|
||||
}
|
||||
sort.Ints(start)
|
||||
l, r := 0, start[len(start)-1]+d-start[0]
|
||||
for l < r {
|
||||
mid := (l + r + 1) >> 1
|
||||
if check(mid) {
|
||||
l = mid
|
||||
} else {
|
||||
r = mid - 1
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
class Solution {
|
||||
private int[] start;
|
||||
private int d;
|
||||
|
||||
public int maxPossibleScore(int[] start, int d) {
|
||||
Arrays.sort(start);
|
||||
this.start = start;
|
||||
this.d = d;
|
||||
int n = start.length;
|
||||
int l = 0, r = start[n - 1] + d - start[0];
|
||||
while (l < r) {
|
||||
int mid = (l + r + 1) >>> 1;
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private boolean check(int mi) {
|
||||
long last = Long.MIN_VALUE;
|
||||
for (int st : start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
class Solution:
|
||||
def maxPossibleScore(self, start: List[int], d: int) -> int:
|
||||
def check(mi: int) -> bool:
|
||||
last = -inf
|
||||
for st in start:
|
||||
if last + mi > st + d:
|
||||
return False
|
||||
last = max(st, last + mi)
|
||||
return True
|
||||
|
||||
start.sort()
|
||||
l, r = 0, start[-1] + d - start[0]
|
||||
while l < r:
|
||||
mid = (l + r + 1) >> 1
|
||||
if check(mid):
|
||||
l = mid
|
||||
else:
|
||||
r = mid - 1
|
||||
return l
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
function maxPossibleScore(start: number[], d: number): number {
|
||||
start.sort((a, b) => a - b);
|
||||
let [l, r] = [0, start.at(-1)! + d - start[0]];
|
||||
const check = (mi: number): boolean => {
|
||||
let last = -Infinity;
|
||||
for (const st of start) {
|
||||
if (last + mi > st + d) {
|
||||
return false;
|
||||
}
|
||||
last = Math.max(st, last + mi);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
while (l < r) {
|
||||
const mid = l + ((r - l + 1) >> 1);
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3282. 到达数组末尾的最大得分](https://leetcode.cn/problems/reach-end-of-array-with-max-score)
|
||||
|
||||
[English Version](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README_EN.md)
|
||||
|
||||
## 题目描述
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>你的目标是从下标 <code>0</code> 出发,到达下标 <code>n - 1</code> 处。每次你只能移动到 <strong>更大</strong> 的下标处。</p>
|
||||
|
||||
<p>从下标 <code>i</code> 跳到下标 <code>j</code> 的得分为 <code>(j - i) * nums[i]</code> 。</p>
|
||||
|
||||
<p>请你返回你到达最后一个下标处能得到的 <strong>最大总得分</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>nums = [1,3,1,5]</span></p>
|
||||
|
||||
<p><b>输出:</b>7</p>
|
||||
|
||||
<p><b>解释:</b></p>
|
||||
|
||||
<p>一开始跳到下标 1 处,然后跳到最后一个下标处。总得分为 <code>1 * 1 + 2 * 3 = 7</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>nums = [4,3,1,3,2]</span></p>
|
||||
|
||||
<p><b>输出:</b>16</p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>直接跳到最后一个下标处。总得分为 <code>4 * 4 = 16</code> 。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</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>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## 解法
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### 方法一:贪心
|
||||
|
||||
假设我们从下标 $i$,跳到下标 $j$,那么得分为 $(j - i) \times \text{nums}[i]$。这相当于我们走了 $j - i$ 步,每一步都得到了 $\text{nums}[i]$ 的得分。然后我们从 $j$ 继续跳到下一个下标 $k$,得分为 $(k - j) \times \text{nums}[j]$,以此类推。如果 $nums[i] \gt nums[j]$,那么我们就不应该从 $i$ 跳到 $j$,因为这样得到的得分一定比从 $i$ 直接跳到 $k$ 得到的得分要少。因此,我们每一次应该跳到下一个比当前下标对应的值更大的下标。
|
||||
|
||||
我们可以维护一个变量 $mx$,表示当前为止,我们遇到的最大的 $\text{nums}[i]$ 的值。然后我们从左到右遍历数组,直到倒数第二个元素,每次更新 $mx$,并且累加得分。
|
||||
|
||||
遍历结束后,我们得到的就是最大的总得分。
|
||||
|
||||
时间复杂度 $O(n)$,其中 $n$ 为数组 $\text{nums}$ 的长度。空间复杂度 $O(1)$。
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def findMaximumScore(self, nums: List[int]) -> int:
|
||||
ans = mx = 0
|
||||
for x in nums[:-1]:
|
||||
mx = max(mx, x)
|
||||
ans += mx
|
||||
return ans
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
public long findMaximumScore(List<Integer> nums) {
|
||||
long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = Math.max(mx, nums.get(i));
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
long long findMaximumScore(vector<int>& nums) {
|
||||
long long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = max(mx, nums[i]);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func findMaximumScore(nums []int) (ans int64) {
|
||||
mx := 0
|
||||
for _, x := range nums[:len(nums)-1] {
|
||||
mx = max(mx, x)
|
||||
ans += int64(mx)
|
||||
}
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function findMaximumScore(nums: number[]): number {
|
||||
let [ans, mx]: [number, number] = [0, 0];
|
||||
for (const x of nums.slice(0, -1)) {
|
||||
mx = Math.max(mx, x);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README_EN.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3282. Reach End of Array With Max Score](https://leetcode.com/problems/reach-end-of-array-with-max-score)
|
||||
|
||||
[中文文档](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README.md)
|
||||
|
||||
## Description
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p>
|
||||
|
||||
<p>The score for a jump from index <code>i</code> to index <code>j</code> is calculated as <code>(j - i) * nums[i]</code>.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> possible <b>total score</b> by the time you reach the last index.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,1,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 7</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>First, jump to index 1 and then jump to the last index. The final score is <code>1 * 1 + 2 * 3 = 7</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,3,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 16</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Jump directly to the last index. The final score is <code>4 * 4 = 16</code>.</p>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## Solutions
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### Solution 1: Greedy
|
||||
|
||||
Suppose we jump from index $i$ to index $j$, then the score is $(j - i) \times \text{nums}[i]$. This is equivalent to taking $j - i$ steps, and each step earns a score of $\text{nums}[i]$. Then we continue to jump from $j$ to the next index $k$, and the score is $(k - j) \times \text{nums}[j]$, and so on. If $\text{nums}[i] \gt \text{nums}[j]$, then we should not jump from $i$ to $j$, because the score obtained this way is definitely less than the score obtained by jumping directly from $i$ to $k$. Therefore, each time we should jump to the next index with a value greater than the current index.
|
||||
|
||||
We can maintain a variable $mx$ to represent the maximum value of $\text{nums}[i]$ encountered so far. Then we traverse the array from left to right until the second-to-last element, updating $mx$ each time and accumulating the score.
|
||||
|
||||
After the traversal, the result is the maximum total score.
|
||||
|
||||
The time complexity is $O(n)$, where $n$ is the length of the array $\text{nums}$. The space complexity is $O(1)$.
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def findMaximumScore(self, nums: List[int]) -> int:
|
||||
ans = mx = 0
|
||||
for x in nums[:-1]:
|
||||
mx = max(mx, x)
|
||||
ans += mx
|
||||
return ans
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
public long findMaximumScore(List<Integer> nums) {
|
||||
long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = Math.max(mx, nums.get(i));
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
class Solution {
|
||||
public:
|
||||
long long findMaximumScore(vector<int>& nums) {
|
||||
long long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = max(mx, nums[i]);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
func findMaximumScore(nums []int) (ans int64) {
|
||||
mx := 0
|
||||
for _, x := range nums[:len(nums)-1] {
|
||||
mx = max(mx, x)
|
||||
ans += int64(mx)
|
||||
}
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
#### TypeScript
|
||||
|
||||
```ts
|
||||
function findMaximumScore(nums: number[]): number {
|
||||
let [ans, mx]: [number, number] = [0, 0];
|
||||
for (const x of nums.slice(0, -1)) {
|
||||
mx = Math.max(mx, x);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
class Solution {
|
||||
public:
|
||||
long long findMaximumScore(vector<int>& nums) {
|
||||
long long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = max(mx, nums[i]);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
func findMaximumScore(nums []int) (ans int64) {
|
||||
mx := 0
|
||||
for _, x := range nums[:len(nums)-1] {
|
||||
mx = max(mx, x)
|
||||
ans += int64(mx)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
class Solution {
|
||||
public long findMaximumScore(List<Integer> nums) {
|
||||
long ans = 0;
|
||||
int mx = 0;
|
||||
for (int i = 0; i + 1 < nums.size(); ++i) {
|
||||
mx = Math.max(mx, nums.get(i));
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class Solution:
|
||||
def findMaximumScore(self, nums: List[int]) -> int:
|
||||
ans = mx = 0
|
||||
for x in nums[:-1]:
|
||||
mx = max(mx, x)
|
||||
ans += mx
|
||||
return ans
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
function findMaximumScore(nums: number[]): number {
|
||||
let [ans, mx]: [number, number] = [0, 0];
|
||||
for (const x of nums.slice(0, -1)) {
|
||||
mx = Math.max(mx, x);
|
||||
ans += mx;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3283. 吃掉所有兵需要的最多移动次数](https://leetcode.cn/problems/maximum-number-of-moves-to-kill-all-pawns)
|
||||
|
||||
[English Version](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README_EN.md)
|
||||
|
||||
## 题目描述
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个 <code>50 x 50</code> 的国际象棋棋盘,棋盘上有 <strong>一个</strong> 马和一些兵。给你两个整数 <code>kx</code> 和 <code>ky</code> ,其中 <code>(kx, ky)</code> 表示马所在的位置,同时还有一个二维数组 <code>positions</code> ,其中 <code>positions[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 表示第 <code>i</code> 个兵在棋盘上的位置。</p>
|
||||
|
||||
<p>Alice 和 Bob 玩一个回合制游戏,Alice 先手。玩家的一次操作中,可以执行以下操作:</p>
|
||||
|
||||
<ul>
|
||||
<li>玩家选择一个仍然在棋盘上的兵,然后移动马,通过 <strong>最少</strong> 的 <strong>步数</strong> 吃掉这个兵。<strong>注意</strong> ,玩家可以选择 <strong>任意</strong> 一个兵,<strong>不一定</strong> 要选择从马的位置出发 <strong>最少</strong> 移动步数的兵。</li>
|
||||
<li><span>在马吃兵的过程中,马 <strong>可能</strong> 会经过一些其他兵的位置,但这些兵 <strong>不会</strong> 被吃掉。<strong>只有</strong> 选中的兵在这个回合中被吃掉。</span></li>
|
||||
</ul>
|
||||
|
||||
<p>Alice 的目标是 <strong>最大化</strong> 两名玩家的 <strong>总</strong> 移动次数,直到棋盘上不再存在兵,而 Bob 的目标是 <strong>最小化</strong> 总移动次数。</p>
|
||||
|
||||
<p>假设两名玩家都采用 <strong>最优</strong> 策略,请你返回 Alice 可以达到的 <strong>最大</strong> 总移动次数。</p>
|
||||
|
||||
<p>在一次 <strong>移动</strong> 中,如下图所示,马有 8 个可以移动到的位置,每个移动位置都是沿着坐标轴的一个方向前进 2 格,然后沿着垂直的方向前进 1 格。</p>
|
||||
|
||||
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/chess_knight.jpg" style="width: 275px; height: 273px;" /></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>kx = 1, ky = 1, positions = [[0,0]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/gif3.gif" style="width: 275px; height: 275px;" /></p>
|
||||
|
||||
<p>马需要移动 4 步吃掉 <code>(0, 0)</code> 处的兵。</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>kx = 0, ky = 2, positions = [[1,1],[2,2],[3,3]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>8</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/gif4.gif" style="width: 320px; height: 320px;" /></strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Alice 选择 <code>(2, 2)</code> 处的兵,移动马吃掉它需要 2 步:<code>(0, 2) -> (1, 4) -> (2, 2)</code> 。</li>
|
||||
<li>Bob 选择 <code>(3, 3)</code> 处的兵,移动马吃掉它需要 2 步:<code>(2, 2) -> (4, 1) -> (3, 3)</code> 。</li>
|
||||
<li>Alice 选择 <code>(1, 1)</code> 处的兵,移动马吃掉它需要 4 步:<code>(3, 3) -> (4, 1) -> (2, 2) -> (0, 3) -> (1, 1)</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><span class="example-io"><b>输入:</b>kx = 0, ky = 0, positions = [[1,2],[2,4]]</span></p>
|
||||
|
||||
<p><span class="example-io"><b>输出:</b>3</span></p>
|
||||
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Alice 选择 <code>(2, 4)</code> 处的兵,移动马吃掉它需要 2 步:<code>(0, 0) -> (1, 2) -> (2, 4)</code> 。注意,<code>(1, 2)</code> 处的兵不会被吃掉。</li>
|
||||
<li>Bob 选择 <code>(1, 2)</code> 处的兵,移动马吃掉它需要 1 步:<code>(2, 4) -> (1, 2)</code> 。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= kx, ky <= 49</code></li>
|
||||
<li><code>1 <= positions.length <= 15</code></li>
|
||||
<li><code>positions[i].length == 2</code></li>
|
||||
<li><code>0 <= positions[i][0], positions[i][1] <= 49</code></li>
|
||||
<li><code>positions[i]</code> 两两互不相同。</li>
|
||||
<li>输入保证对于所有 <code>0 <= i < positions.length</code> ,都有 <code>positions[i] != [kx, ky]</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## 解法
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### 方法一
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README_EN.md
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3283. Maximum Number of Moves to Kill All Pawns](https://leetcode.com/problems/maximum-number-of-moves-to-kill-all-pawns)
|
||||
|
||||
[中文文档](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README.md)
|
||||
|
||||
## Description
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>There is a <code>50 x 50</code> chessboard with <strong>one</strong> knight and some pawns on it. You are given two integers <code>kx</code> and <code>ky</code> where <code>(kx, ky)</code> denotes the position of the knight, and a 2D array <code>positions</code> where <code>positions[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> denotes the position of the pawns on the chessboard.</p>
|
||||
|
||||
<p>Alice and Bob play a <em>turn-based</em> game, where Alice goes first. In each player's turn:</p>
|
||||
|
||||
<ul>
|
||||
<li>The player <em>selects </em>a pawn that still exists on the board and captures it with the knight in the <strong>fewest</strong> possible <strong>moves</strong>. <strong>Note</strong> that the player can select <strong>any</strong> pawn, it <strong>might not</strong> be one that can be captured in the <strong>least</strong> number of moves.</li>
|
||||
<li><span>In the process of capturing the <em>selected</em> pawn, the knight <strong>may</strong> pass other pawns <strong>without</strong> capturing them</span>. <strong>Only</strong> the <em>selected</em> pawn can be captured in <em>this</em> turn.</li>
|
||||
</ul>
|
||||
|
||||
<p>Alice is trying to <strong>maximize</strong> the <strong>sum</strong> of the number of moves made by <em>both</em> players until there are no more pawns on the board, whereas Bob tries to <strong>minimize</strong> them.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> <em>total</em> number of moves made during the game that Alice can achieve, assuming both players play <strong>optimally</strong>.</p>
|
||||
|
||||
<p>Note that in one <strong>move, </strong>a chess knight has eight possible positions it can move to, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.</p>
|
||||
|
||||
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/chess_knight.jpg" style="width: 275px; height: 273px;" /></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">kx = 1, ky = 1, positions = [[0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/gif3.gif" style="width: 275px; height: 275px;" /></p>
|
||||
|
||||
<p>The knight takes 4 moves to reach the pawn at <code>(0, 0)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">kx = 0, ky = 2, positions = [[1,1],[2,2],[3,3]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">8</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/images/gif4.gif" style="width: 320px; height: 320px;" /></strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Alice picks the pawn at <code>(2, 2)</code> and captures it in two moves: <code>(0, 2) -> (1, 4) -> (2, 2)</code>.</li>
|
||||
<li>Bob picks the pawn at <code>(3, 3)</code> and captures it in two moves: <code>(2, 2) -> (4, 1) -> (3, 3)</code>.</li>
|
||||
<li>Alice picks the pawn at <code>(1, 1)</code> and captures it in four moves: <code>(3, 3) -> (4, 1) -> (2, 2) -> (0, 3) -> (1, 1)</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">kx = 0, ky = 0, positions = [[1,2],[2,4]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Alice picks the pawn at <code>(2, 4)</code> and captures it in two moves: <code>(0, 0) -> (1, 2) -> (2, 4)</code>. Note that the pawn at <code>(1, 2)</code> is not captured.</li>
|
||||
<li>Bob picks the pawn at <code>(1, 2)</code> and captures it in one move: <code>(2, 4) -> (1, 2)</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= kx, ky <= 49</code></li>
|
||||
<li><code>1 <= positions.length <= 15</code></li>
|
||||
<li><code>positions[i].length == 2</code></li>
|
||||
<li><code>0 <= positions[i][0], positions[i][1] <= 49</code></li>
|
||||
<li>All <code>positions[i]</code> are unique.</li>
|
||||
<li>The input is generated such that <code>positions[i] != [kx, ky]</code> for all <code>0 <= i < positions.length</code>.</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## Solutions
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### Solution 1
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### Python3
|
||||
|
||||
```python
|
||||
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
```java
|
||||
|
||||
```
|
||||
|
||||
#### C++
|
||||
|
||||
```cpp
|
||||
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
```go
|
||||
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 212 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 597 KiB |
|
|
@ -26,6 +26,13 @@ comments: true
|
|||
|
||||
## 往期竞赛
|
||||
|
||||
#### 第 414 场周赛(2024-09-08 10:30, 90 分钟) 参赛人数 3236
|
||||
|
||||
- [3280. 将日期转换为二进制表示](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README.md)
|
||||
- [3281. 范围内整数的最大得分](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README.md)
|
||||
- [3282. 到达数组末尾的最大得分](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README.md)
|
||||
- [3283. 吃掉所有兵需要的最多移动次数](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README.md)
|
||||
|
||||
#### 第 413 场周赛(2024-09-01 10:30, 90 分钟) 参赛人数 2875
|
||||
|
||||
- [3274. 检查棋盘方格颜色是否相同](/solution/3200-3299/3274.Check%20if%20Two%20Chessboard%20Squares%20Have%20the%20Same%20Color/README.md)
|
||||
|
|
@ -1016,7 +1023,7 @@ comments: true
|
|||
#### 第 319 场周赛(2022-11-13 10:30, 90 分钟) 参赛人数 6175
|
||||
|
||||
- [2469. 温度转换](/solution/2400-2499/2469.Convert%20the%20Temperature/README.md)
|
||||
- [2470. 最小公倍数为 K 的子数组数目](/solution/2400-2499/2470.Number%20of%20Subarrays%20With%20LCM%20Equal%20to%20K/README.md)
|
||||
- [2470. 最小公倍数等于 K 的子数组数目](/solution/2400-2499/2470.Number%20of%20Subarrays%20With%20LCM%20Equal%20to%20K/README.md)
|
||||
- [2471. 逐层排序二叉树所需的最少操作数目](/solution/2400-2499/2471.Minimum%20Number%20of%20Operations%20to%20Sort%20a%20Binary%20Tree%20by%20Level/README.md)
|
||||
- [2472. 不重叠回文子字符串的最大数目](/solution/2400-2499/2472.Maximum%20Number%20of%20Non-overlapping%20Palindrome%20Substrings/README.md)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ If you want to estimate your score changes after the contest ends, you can visit
|
|||
|
||||
## Past Contests
|
||||
|
||||
#### Weekly Contest 414
|
||||
|
||||
- [3280. Convert Date to Binary](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README_EN.md)
|
||||
- [3281. Maximize Score of Numbers in Ranges](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README_EN.md)
|
||||
- [3282. Reach End of Array With Max Score](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README_EN.md)
|
||||
- [3283. Maximum Number of Moves to Kill All Pawns](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README_EN.md)
|
||||
|
||||
#### Weekly Contest 413
|
||||
|
||||
- [3274. Check if Two Chessboard Squares Have the Same Color](/solution/3200-3299/3274.Check%20if%20Two%20Chessboard%20Squares%20Have%20the%20Same%20Color/README_EN.md)
|
||||
|
|
|
|||
|
|
@ -2480,7 +2480,7 @@
|
|||
| 2467 | [树上最大得分和路径](/solution/2400-2499/2467.Most%20Profitable%20Path%20in%20a%20Tree/README.md) | `树`,`深度优先搜索`,`广度优先搜索`,`图`,`数组` | 中等 | 第 91 场双周赛 |
|
||||
| 2468 | [根据限制分割消息](/solution/2400-2499/2468.Split%20Message%20Based%20on%20Limit/README.md) | `字符串`,`二分查找` | 困难 | 第 91 场双周赛 |
|
||||
| 2469 | [温度转换](/solution/2400-2499/2469.Convert%20the%20Temperature/README.md) | `数学` | 简单 | 第 319 场周赛 |
|
||||
| 2470 | [最小公倍数为 K 的子数组数目](/solution/2400-2499/2470.Number%20of%20Subarrays%20With%20LCM%20Equal%20to%20K/README.md) | `数组`,`数学`,`数论` | 中等 | 第 319 场周赛 |
|
||||
| 2470 | [最小公倍数等于 K 的子数组数目](/solution/2400-2499/2470.Number%20of%20Subarrays%20With%20LCM%20Equal%20to%20K/README.md) | `数组`,`数学`,`数论` | 中等 | 第 319 场周赛 |
|
||||
| 2471 | [逐层排序二叉树所需的最少操作数目](/solution/2400-2499/2471.Minimum%20Number%20of%20Operations%20to%20Sort%20a%20Binary%20Tree%20by%20Level/README.md) | `树`,`广度优先搜索`,`二叉树` | 中等 | 第 319 场周赛 |
|
||||
| 2472 | [不重叠回文子字符串的最大数目](/solution/2400-2499/2472.Maximum%20Number%20of%20Non-overlapping%20Palindrome%20Substrings/README.md) | `字符串`,`动态规划` | 困难 | 第 319 场周赛 |
|
||||
| 2473 | [购买苹果的最低成本](/solution/2400-2499/2473.Minimum%20Cost%20to%20Buy%20Apples/README.md) | `图`,`数组`,`最短路`,`堆(优先队列)` | 中等 | 🔒 |
|
||||
|
|
@ -2760,7 +2760,7 @@
|
|||
| 2747 | [统计没有收到请求的服务器数目](/solution/2700-2799/2747.Count%20Zero%20Request%20Servers/README.md) | `数组`,`哈希表`,`排序`,`滑动窗口` | 中等 | 第 107 场双周赛 |
|
||||
| 2748 | [美丽下标对的数目](/solution/2700-2799/2748.Number%20of%20Beautiful%20Pairs/README.md) | `数组`,`哈希表`,`数学`,`计数`,`数论` | 简单 | 第 351 场周赛 |
|
||||
| 2749 | [得到整数零需要执行的最少操作数](/solution/2700-2799/2749.Minimum%20Operations%20to%20Make%20the%20Integer%20Zero/README.md) | `位运算`,`脑筋急转弯` | 中等 | 第 351 场周赛 |
|
||||
| 2750 | [将数组划分成若干好子数组的方式](/solution/2700-2799/2750.Ways%20to%20Split%20Array%20Into%20Good%20Subarrays/README.md) | `数组`,`数学` | 中等 | 第 351 场周赛 |
|
||||
| 2750 | [将数组划分成若干好子数组的方式](/solution/2700-2799/2750.Ways%20to%20Split%20Array%20Into%20Good%20Subarrays/README.md) | `数组`,`数学`,`动态规划` | 中等 | 第 351 场周赛 |
|
||||
| 2751 | [机器人碰撞](/solution/2700-2799/2751.Robot%20Collisions/README.md) | `栈`,`数组`,`排序`,`模拟` | 困难 | 第 351 场周赛 |
|
||||
| 2752 | [在连续天数上进行了最多交易次数的顾客](/solution/2700-2799/2752.Customers%20with%20Maximum%20Number%20of%20Transactions%20on%20Consecutive%20Days/README.md) | `数据库` | 困难 | 🔒 |
|
||||
| 2753 | [计算一个环形街道上的房屋数量 II](/solution/2700-2799/2753.Count%20Houses%20in%20a%20Circular%20Street%20II/README.md) | | 困难 | 🔒 |
|
||||
|
|
@ -3290,6 +3290,10 @@
|
|||
| 3277 | [查询子数组最大异或值](/solution/3200-3299/3277.Maximum%20XOR%20Score%20Subarray%20Queries/README.md) | `数组`,`动态规划` | 困难 | 第 413 场周赛 |
|
||||
| 3278 | [寻找数据科学家职位的候选人 II](/solution/3200-3299/3278.Find%20Candidates%20for%20Data%20Scientist%20Position%20II/README.md) | `数据库` | 中等 | 🔒 |
|
||||
| 3279 | [Maximum Total Area Occupied by Pistons](/solution/3200-3299/3279.Maximum%20Total%20Area%20Occupied%20by%20Pistons/README.md) | | 困难 | 🔒 |
|
||||
| 3280 | [将日期转换为二进制表示](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README.md) | | 简单 | 第 414 场周赛 |
|
||||
| 3281 | [范围内整数的最大得分](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README.md) | | 中等 | 第 414 场周赛 |
|
||||
| 3282 | [到达数组末尾的最大得分](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README.md) | | 中等 | 第 414 场周赛 |
|
||||
| 3283 | [吃掉所有兵需要的最多移动次数](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README.md) | | 困难 | 第 414 场周赛 |
|
||||
|
||||
## 版权
|
||||
|
||||
|
|
|
|||
|
|
@ -2758,7 +2758,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 2747 | [Count Zero Request Servers](/solution/2700-2799/2747.Count%20Zero%20Request%20Servers/README_EN.md) | `Array`,`Hash Table`,`Sorting`,`Sliding Window` | Medium | Biweekly Contest 107 |
|
||||
| 2748 | [Number of Beautiful Pairs](/solution/2700-2799/2748.Number%20of%20Beautiful%20Pairs/README_EN.md) | `Array`,`Hash Table`,`Math`,`Counting`,`Number Theory` | Easy | Weekly Contest 351 |
|
||||
| 2749 | [Minimum Operations to Make the Integer Zero](/solution/2700-2799/2749.Minimum%20Operations%20to%20Make%20the%20Integer%20Zero/README_EN.md) | `Bit Manipulation`,`Brainteaser` | Medium | Weekly Contest 351 |
|
||||
| 2750 | [Ways to Split Array Into Good Subarrays](/solution/2700-2799/2750.Ways%20to%20Split%20Array%20Into%20Good%20Subarrays/README_EN.md) | `Array`,`Math` | Medium | Weekly Contest 351 |
|
||||
| 2750 | [Ways to Split Array Into Good Subarrays](/solution/2700-2799/2750.Ways%20to%20Split%20Array%20Into%20Good%20Subarrays/README_EN.md) | `Array`,`Math`,`Dynamic Programming` | Medium | Weekly Contest 351 |
|
||||
| 2751 | [Robot Collisions](/solution/2700-2799/2751.Robot%20Collisions/README_EN.md) | `Stack`,`Array`,`Sorting`,`Simulation` | Hard | Weekly Contest 351 |
|
||||
| 2752 | [Customers with Maximum Number of Transactions on Consecutive Days](/solution/2700-2799/2752.Customers%20with%20Maximum%20Number%20of%20Transactions%20on%20Consecutive%20Days/README_EN.md) | `Database` | Hard | 🔒 |
|
||||
| 2753 | [Count Houses in a Circular Street II](/solution/2700-2799/2753.Count%20Houses%20in%20a%20Circular%20Street%20II/README_EN.md) | | Hard | 🔒 |
|
||||
|
|
@ -3288,6 +3288,10 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 3277 | [Maximum XOR Score Subarray Queries](/solution/3200-3299/3277.Maximum%20XOR%20Score%20Subarray%20Queries/README_EN.md) | `Array`,`Dynamic Programming` | Hard | Weekly Contest 413 |
|
||||
| 3278 | [Find Candidates for Data Scientist Position II](/solution/3200-3299/3278.Find%20Candidates%20for%20Data%20Scientist%20Position%20II/README_EN.md) | `Database` | Medium | 🔒 |
|
||||
| 3279 | [Maximum Total Area Occupied by Pistons](/solution/3200-3299/3279.Maximum%20Total%20Area%20Occupied%20by%20Pistons/README_EN.md) | | Hard | 🔒 |
|
||||
| 3280 | [Convert Date to Binary](/solution/3200-3299/3280.Convert%20Date%20to%20Binary/README_EN.md) | | Easy | Weekly Contest 414 |
|
||||
| 3281 | [Maximize Score of Numbers in Ranges](/solution/3200-3299/3281.Maximize%20Score%20of%20Numbers%20in%20Ranges/README_EN.md) | | Medium | Weekly Contest 414 |
|
||||
| 3282 | [Reach End of Array With Max Score](/solution/3200-3299/3282.Reach%20End%20of%20Array%20With%20Max%20Score/README_EN.md) | | Medium | Weekly Contest 414 |
|
||||
| 3283 | [Maximum Number of Moves to Kill All Pawns](/solution/3200-3299/3283.Maximum%20Number%20of%20Moves%20to%20Kill%20All%20Pawns/README_EN.md) | | Hard | Weekly Contest 414 |
|
||||
|
||||
## Copyright
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue