Skip to content

Commit 5631412

Browse files
authored
feat: add solutions to lc problem: No.3431 (#3988)
No.3431.Minimum Unlocked Indices to Sort Nums
1 parent 5c1ede2 commit 5631412

File tree

21 files changed

+700
-27
lines changed

21 files changed

+700
-27
lines changed

solution/2000-2099/2011.Final Value of Variable After Performing Operations/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ X++:X 加 1 ,X = 0 + 1 = 1
5050
<pre>
5151
<strong>输入:</strong>operations = ["++X","++X","X++"]
5252
<strong>输出:</strong>3
53-
<strong>解释:</strong>操作按下述步骤执行:
53+
<strong>解释:</strong>操作按下述步骤执行:
5454
最初,X = 0
5555
++X:X 加 1 ,X = 0 + 1 = 1
5656
++X:X 加 1 ,X = 1 + 1 = 2

solution/2100-2199/2151.Maximum Good People Based on Statements/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ tags:
8686
- <strong>在认为 0 是坏人但说真话的情况下,这组玩家中没有一个好人。</strong>
8787
- 说假话。在这种情况下,1 是好人。
8888
- <strong>在认为 0 是坏人且说假话的情况下,这组玩家中只有一个好人。</strong>
89-
在最佳情况下,至多有一个好人,所以返回 1 。
89+
在最佳情况下,至多有一个好人,所以返回 1 。
9090
注意,能得到此结论的方法不止一种。
9191
</pre>
9292

solution/2100-2199/2165.Smallest Value of the Rearranged Number/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tags:
3131
<pre>
3232
<strong>Input:</strong> num = 310
3333
<strong>Output:</strong> 103
34-
<strong>Explanation:</strong> The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
34+
<strong>Explanation:</strong> The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
3535
The arrangement with the smallest value that does not contain any leading zeros is 103.
3636
</pre>
3737

solution/2100-2199/2169.Count Operations to Obtain Zero/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tags:
3535
<pre>
3636
<strong>Input:</strong> num1 = 2, num2 = 3
3737
<strong>Output:</strong> 3
38-
<strong>Explanation:</strong>
38+
<strong>Explanation:</strong>
3939
- Operation 1: num1 = 2, num2 = 3. Since num1 &lt; num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.
4040
- Operation 2: num1 = 2, num2 = 1. Since num1 &gt; num2, we subtract num2 from num1.
4141
- Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.
@@ -48,7 +48,7 @@ So the total number of operations required is 3.
4848
<pre>
4949
<strong>Input:</strong> num1 = 10, num2 = 10
5050
<strong>Output:</strong> 1
51-
<strong>Explanation:</strong>
51+
<strong>Explanation:</strong>
5252
- Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.
5353
Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.
5454
So the total number of operations required is 1.

solution/2100-2199/2178.Maximum Split of Positive Even Integers/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Thus, we return an empty array.
5353
<pre>
5454
<strong>Input:</strong> finalSum = 28
5555
<strong>Output:</strong> [6,8,2,12]
56-
<strong>Explanation:</strong> The following are valid splits: <code>(2 + 26)</code>, <code>(6 + 8 + 2 + 12)</code>, and <code>(4 + 24)</code>.
56+
<strong>Explanation:</strong> The following are valid splits: <code>(2 + 26)</code>, <code>(6 + 8 + 2 + 12)</code>, and <code>(4 + 24)</code>.
5757
<code>(6 + 8 + 2 + 12)</code> has the maximum number of integers, which is 4. Thus, we return [6,8,2,12].
5858
Note that [10,2,4,12], [6,2,4,16], etc. are also accepted.
5959
</pre>

solution/2200-2299/2206.Divide Array Into Equal Pairs/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tags:
3838
<pre>
3939
<strong>Input:</strong> nums = [3,2,3,2,2,2]
4040
<strong>Output:</strong> true
41-
<strong>Explanation:</strong>
41+
<strong>Explanation:</strong>
4242
There are 6 elements in nums, so they should be divided into 6 / 2 = 3 pairs.
4343
If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy all the conditions.
4444
</pre>
@@ -48,7 +48,7 @@ If nums is divided into the pairs (2, 2), (3, 3), and (2, 2), it will satisfy al
4848
<pre>
4949
<strong>Input:</strong> nums = [1,2,3,4]
5050
<strong>Output:</strong> false
51-
<strong>Explanation:</strong>
51+
<strong>Explanation:</strong>
5252
There is no way to divide nums into 4 / 2 = 2 pairs such that the pairs satisfy every condition.
5353
</pre>
5454

solution/2200-2299/2229.Check if an Array Is Consecutive/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ tags:
4141
<strong>输入:</strong>nums = [1,3]
4242
<strong>输出:</strong>false
4343
<strong>解释:
44-
</strong>最小值是 1 ,数组长度为 2 。
45-
范围 [x, x + n - 1] 中的所有值没有都出现在 nums 中:[1, 1 + 2 - 1] = [1, 2] = (1, 2) 。
46-
因此,nums 不是一个连贯数组。
44+
</strong>最小值是 1 ,数组长度为 2 。
45+
范围 [x, x + n - 1] 中的所有值没有都出现在 nums 中:[1, 1 + 2 - 1] = [1, 2] = (1, 2) 。
46+
因此,nums 不是一个连贯数组。
4747
</pre>
4848

4949
<p><strong>示例 3:</strong></p>

solution/2200-2299/2243.Calculate Digit Sum of a String/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ tags:
3939
<strong>输出:</strong>"135"
4040
<strong>解释:</strong>
4141
- 第一轮,将 s 分成:"111"、"112"、"222" 和 "23" 。
42-
接着,计算每一组的数字和:1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。
42+
接着,计算每一组的数字和:1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。
4343
&nbsp; 这样,s 在第一轮之后变成 "3" + "4" + "6" + "5" = "3465" 。
4444
- 第二轮,将 s 分成:"346" 和 "5" 。
4545
&nbsp; 接着,计算每一组的数字和:3 + 4 + 6 = 13 、5 = 5 。
46-
&nbsp; 这样,s 在第二轮之后变成 "13" + "5" = "135" 。
46+
&nbsp; 这样,s 在第二轮之后变成 "13" + "5" = "135" 。
4747
现在,s.length &lt;= k ,所以返回 "135" 作为答案。
4848
</pre>
4949

@@ -53,7 +53,7 @@ tags:
5353
<strong>输出:</strong>"000"
5454
<strong>解释:</strong>
5555
将 "000", "000", and "00".
56-
接着,计算每一组的数字和:0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。
56+
接着,计算每一组的数字和:0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。
5757
s 变为 "0" + "0" + "0" = "000" ,其长度等于 k ,所以返回 "000" 。
5858
</pre>
5959

solution/2200-2299/2243.Calculate Digit Sum of a String/README_EN.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ tags:
3737
<pre>
3838
<strong>Input:</strong> s = &quot;11111222223&quot;, k = 3
3939
<strong>Output:</strong> &quot;135&quot;
40-
<strong>Explanation:</strong>
40+
<strong>Explanation:</strong>
4141
- For the first round, we divide s into groups of size 3: &quot;111&quot;, &quot;112&quot;, &quot;222&quot;, and &quot;23&quot;.
42-
​​​​​Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
42+
​​​​​Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
4343
&nbsp; So, s becomes &quot;3&quot; + &quot;4&quot; + &quot;6&quot; + &quot;5&quot; = &quot;3465&quot; after the first round.
4444
- For the second round, we divide s into &quot;346&quot; and &quot;5&quot;.
45-
&nbsp; Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
46-
&nbsp; So, s becomes &quot;13&quot; + &quot;5&quot; = &quot;135&quot; after second round.
45+
&nbsp; Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
46+
&nbsp; So, s becomes &quot;13&quot; + &quot;5&quot; = &quot;135&quot; after second round.
4747
Now, s.length &lt;= k, so we return &quot;135&quot; as the answer.
4848
</pre>
4949

@@ -52,9 +52,9 @@ Now, s.length &lt;= k, so we return &quot;135&quot; as the answer.
5252
<pre>
5353
<strong>Input:</strong> s = &quot;00000000&quot;, k = 3
5454
<strong>Output:</strong> &quot;000&quot;
55-
<strong>Explanation:</strong>
55+
<strong>Explanation:</strong>
5656
We divide s into &quot;000&quot;, &quot;000&quot;, and &quot;00&quot;.
57-
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
57+
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
5858
s becomes &quot;0&quot; + &quot;0&quot; + &quot;0&quot; = &quot;000&quot;, whose length is equal to k, so we return &quot;000&quot;.
5959
</pre>
6060

solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ tags:
5252
<strong>输入:</strong>nums = [1,2,3,4]
5353
<strong>输出:</strong>1
5454
<strong>解释:</strong>
55-
子数组按位与运算的最大值是 4 。
55+
子数组按位与运算的最大值是 4 。
5656
能得到此结果的最长子数组是 [4],所以返回 1 。
5757
</pre>
5858

solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ tags:
4141
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/images/ex1-copy.png" style="width: 60px; height: 316px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
4242
<pre>
4343
<strong>输入:</strong>edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
44-
<strong>输出:</strong>11
44+
<strong>输出:</strong>11
4545
<strong>解释:</strong>
4646
使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。
4747
使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。
4848
使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ,总积分 = 10 + floor(3 / 2) = 11 。
4949
使用第二种方法收集节点 3 上的所有金币。总积分 = 11 + floor(1 / 2) = 11.
50-
可以证明收集所有节点上的金币能获得的最大积分是 11 。
50+
可以证明收集所有节点上的金币能获得的最大积分是 11 。
5151
</pre>
5252

5353
<p><strong class="example">示例 2:</strong></p>

solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ tags:
4040
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/images/ex1-copy.png" style="width: 60px; height: 316px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
4141
<pre>
4242
<strong>Input:</strong> edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
43-
<strong>Output:</strong> 11
44-
<strong>Explanation:</strong>
43+
<strong>Output:</strong> 11
44+
<strong>Explanation:</strong>
4545
Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.
4646
Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.
4747
Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.
4848
Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.
49-
It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.
49+
It can be shown that the maximum points we can get after collecting coins from all the nodes is 11.
5050
</pre>
5151

5252
<p><strong class="example">Example 2:</strong></p>
@@ -55,7 +55,7 @@ It can be shown that the maximum points we can get after collecting coins from a
5555
<pre>
5656
<strong>Input:</strong> edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
5757
<strong>Output:</strong> 16
58-
<strong>Explanation:</strong>
58+
<strong>Explanation:</strong>
5959
Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.
6060
</pre>
6161

0 commit comments

Comments
 (0)