Skip to content

Commit 5ab2803

Browse files
committed
feat: update lc problems
1 parent 00ac913 commit 5ab2803

File tree

40 files changed

+122
-129
lines changed

40 files changed

+122
-129
lines changed

solution/0000-0099/0001.Two Sum/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Solution:
8888
class Solution {
8989
public int[] twoSum(int[] nums, int target) {
9090
Map<Integer, Integer> m = new HashMap<>();
91-
for (int i = 0; ; ++i) {
91+
for (int i = 0;; ++i) {
9292
int x = nums[i];
9393
int y = target - x;
9494
if (m.containsKey(y)) {

solution/0000-0099/0001.Two Sum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Solution:
6969
class Solution {
7070
public int[] twoSum(int[] nums, int target) {
7171
Map<Integer, Integer> m = new HashMap<>();
72-
for (int i = 0; ; ++i) {
72+
for (int i = 0;; ++i) {
7373
int x = nums[i];
7474
int y = target - x;
7575
if (m.containsKey(y)) {

solution/0000-0099/0001.Two Sum/Solution.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Solution {
22
public:
33
vector<int> twoSum(vector<int>& nums, int target) {
44
unordered_map<int, int> m;
5-
for (int i = 0; ; ++i) {
5+
for (int i = 0;; ++i) {
66
int x = nums[i];
77
int y = target - x;
88
if (m.count(y)) {

solution/0000-0099/0001.Two Sum/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Solution {
22
public int[] twoSum(int[] nums, int target) {
33
Map<Integer, Integer> m = new HashMap<>();
4-
for (int i = 0; ; ++i) {
4+
for (int i = 0;; ++i) {
55
int x = nums[i];
66
int y = target - x;
77
if (m.containsKey(y)) {

solution/0100-0199/0136.Single Number/Solution.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int singleNumber(int *nums, int numsSize) {
1+
int singleNumber(int* nums, int numsSize) {
22
int ans = 0;
33
for (int i = 0; i < numsSize; i++) {
44
ans ^= nums[i];

solution/0100-0199/0137.Single Number II/Solution.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int singleNumber(int *nums, int numsSize) {
1+
int singleNumber(int* nums, int numsSize) {
22
int ans = 0;
33
for (int i = 0; i < 32; i++) {
44
int count = 0;

solution/0100-0199/0182.Duplicate Emails/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Each row of this table contains an email. The emails will not contain uppercase
1919

2020
<p>&nbsp;</p>
2121

22-
<p>Write an SQL query to report all the duplicate emails.</p>
22+
<p>Write an SQL query to report all the duplicate emails. Note that it&#39;s guaranteed that the email&nbsp;field is not NULL.</p>
2323

2424
<p>Return the result table in <strong>any order</strong>.</p>
2525

solution/0400-0499/0410.Split Array Largest Sum/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public int splitArray(int[] nums, int k) {
1515
}
1616
return left;
1717
}
18-
18+
1919
private boolean check(int[] nums, int mx, int k) {
2020
int s = 1 << 30, cnt = 0;
2121
for (int x : nums) {

solution/0400-0499/0465.Optimal Account Balancing/README.md

+27-35
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,46 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>一群朋友在度假期间会相互借钱。比如说,小爱同学支付了小新同学的午餐共计 10 美元。如果小明同学支付了小爱同学的出租车钱共计 5 美元。我们可以用一个三元组 (x, y, z) 表示一次交易,表示 x 借给 y 共计 z 美元。用 0, 1, 2 表示小爱同学、小新同学和小明同学(0, 1, 2 为人的标号),上述交易可以表示为 <code>[[0, 1, 10], [2, 0, 5]]</code>。</p>
9+
<p>给你一个表示交易的数组 <code>transactions</code> ,其中 <code>transactions[i] = [from<sub>i</sub>, to<sub>i</sub>, amount<sub>i</sub>]</code> 表示 <code>ID = from<sub>i</sub></code> 的人给&nbsp;<code>ID = to<sub>i</sub></code> 的人共计 <code>amount<sub>i</sub> $</code> 。</p>
1010

11-
<p>给定一群人之间的交易信息列表,计算能够还清所有债务的最小次数。</p>
12-
13-
<p><strong>注意:</strong></p>
14-
15-
<ol>
16-
<li>一次交易会以三元组 (x, y, z) 表示,并有&nbsp;<code>x &ne; y</code>&nbsp;且&nbsp;<code>z &gt; 0</code>。</li>
17-
<li>人的标号可能不是按顺序的,例如标号可能为 0, 1, 2 也可能为 0, 2, 6。</li>
18-
</ol>
11+
<p>请你计算并返回还清所有债务的最小交易笔数。</p>
1912

2013
<p>&nbsp;</p>
2114

22-
<p><strong>示例 1:</strong></p>
15+
<p><strong class="example">示例 1:</strong></p>
2316

24-
<pre><strong>输入:</strong>
25-
[[0,1,10], [2,0,5]]
17+
<pre>
18+
<strong>输入:</strong>transactions = [[0,1,10],[2,0,5]]
19+
<strong>输出:</strong>2
20+
<strong>解释:</strong>
21+
#0 给 #1 $10 。
22+
#2 给 #0 $5 。
23+
需要进行两笔交易。一种结清债务的方式是 #1 给 #0 和 #2 各 $5 。</pre>
2624

27-
<strong>输出:</strong>
28-
2
25+
<p><strong class="example">示例 2:</strong></p>
2926

27+
<pre>
28+
<strong>输入:</strong>transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]
29+
<strong>输出:</strong>1
3030
<strong>解释:</strong>
31-
人 #0 给人 #1 共计 10 美元。
32-
人 #2 给人 #0 共计 5 美元。
33-
34-
需要两次交易。一种方式是人 #1 分别给人 #0 和人 #2 各 5 美元。
31+
#0 给 #1 $10 。
32+
#1 给 #0 $1 。
33+
#1 给 #2 $5 。
34+
#2 给 #0 $5 。
35+
因此,#1 只需要给 #0 $4 ,所有的债务即可还清。
3536
</pre>
3637

3738
<p>&nbsp;</p>
3839

39-
<p><strong>示例 2:</strong></p>
40-
41-
<pre><strong>输入:</strong>
42-
[[0,1,10], [1,0,1], [1,2,5], [2,0,5]]
43-
44-
<strong>输出:</strong>
45-
1
40+
<p><strong>提示:</strong></p>
4641

47-
<strong>解释:</strong>
48-
人 #0 给人 #1 共计 10 美元。Person #0 gave person #1 $10.
49-
人 #1 给人 #0 共计 1 美元。Person #1 gave person #0 $1.
50-
人 #1 给人 #2 共计 5 美元。Person #1 gave person #2 $5.
51-
人 #2 给人 #0 共计 5 美元。Person #2 gave person #0 $5.
52-
53-
因此,人 #1 需要给人 #0 共计 4 美元,所有的债务即可还清。
54-
</pre>
55-
56-
<p>&nbsp;</p>
42+
<ul>
43+
<li><code>1 &lt;= transactions.length &lt;= 8</code></li>
44+
<li><code>transactions[i].length == 3</code></li>
45+
<li><code>0 &lt;= from<sub>i</sub>, to<sub>i</sub> &lt; 12</code></li>
46+
<li><code>from<sub>i</sub> != to<sub>i</sub></code></li>
47+
<li><code>1 &lt;= amount<sub>i</sub> &lt;= 100</code></li>
48+
</ul>
5749

5850
## 解法
5951

solution/0800-0899/0831.Masking Personal Information/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ class Solution {
166166
s = sb.toString();
167167
int cnt = s.length() - 10;
168168
String suf = "***-***-" + s.substring(s.length() - 4);
169-
return cnt == 0 ? suf : "+" + "*".repeat(cnt) + "-" + suf;
169+
return cnt == 0 ? suf
170+
: "+"
171+
+ "*".repeat(cnt) + "-" + suf;
170172
}
171173
}
172174
```

solution/0800-0899/0831.Masking Personal Information/README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class Solution {
135135
s = sb.toString();
136136
int cnt = s.length() - 10;
137137
String suf = "***-***-" + s.substring(s.length() - 4);
138-
return cnt == 0 ? suf : "+" + "*".repeat(cnt) + "-" + suf;
138+
return cnt == 0 ? suf
139+
: "+"
140+
+ "*".repeat(cnt) + "-" + suf;
139141
}
140142
}
141143
```

solution/0800-0899/0831.Masking Personal Information/Solution.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public String maskPII(String s) {
1414
s = sb.toString();
1515
int cnt = s.length() - 10;
1616
String suf = "***-***-" + s.substring(s.length() - 4);
17-
return cnt == 0 ? suf : "+" + "*".repeat(cnt) + "-" + suf;
17+
return cnt == 0 ? suf
18+
: "+"
19+
+ "*".repeat(cnt) + "-" + suf;
1820
}
1921
}

solution/0800-0899/0833.Find And Replace in String/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Solution {
122122
}
123123
}
124124
StringBuilder ans = new StringBuilder();
125-
for (int i = 0; i < n; ) {
125+
for (int i = 0; i < n;) {
126126
if (d[i] >= 0) {
127127
ans.append(targets[d[i]]);
128128
i += sources[d[i]].length();

solution/0800-0899/0833.Find And Replace in String/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Solution {
102102
}
103103
}
104104
StringBuilder ans = new StringBuilder();
105-
for (int i = 0; i < n; ) {
105+
for (int i = 0; i < n;) {
106106
if (d[i] >= 0) {
107107
ans.append(targets[d[i]]);
108108
i += sources[d[i]].length();

solution/0800-0899/0833.Find And Replace in String/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public String findReplaceString(String s, int[] indices, String[] sources, Strin
1111
}
1212
}
1313
StringBuilder ans = new StringBuilder();
14-
for (int i = 0; i < n; ) {
14+
for (int i = 0; i < n;) {
1515
if (d[i] >= 0) {
1616
ans.append(targets[d[i]]);
1717
i += sources[d[i]].length();

solution/0800-0899/0871.Minimum Number of Refueling Stops/README.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,55 @@
88

99
<p>汽车从起点出发驶向目的地,该目的地位于出发位置东面 <code>target</code>&nbsp;英里处。</p>
1010

11-
<p>沿途有加油站,每个&nbsp;<code>station[i]</code>&nbsp;代表一个加油站,它位于出发位置东面&nbsp;<code>station[i][0]</code>&nbsp;英里处,并且有&nbsp;<code>station[i][1]</code>&nbsp;升汽油。</p>
11+
<p>沿途有加油站,用数组&nbsp;<code>stations</code> 表示。其中 <code>stations[i] = [position<sub>i</sub>, fuel<sub>i</sub>]</code> 表示第 <code>i</code> 个加油站位于出发位置东面&nbsp;<code>position<sub>i</sub></code> 英里处,并且有&nbsp;<code>fuel<sub>i</sub></code>&nbsp;升汽油。</p>
1212

13-
<p>假设汽车油箱的容量是无限的,其中最初有&nbsp;<code>startFuel</code>&nbsp;升燃料。它每行驶 1 英里就会用掉 1 升汽油。</p>
14-
15-
<p>当汽车到达加油站时,它可能停下来加油,将所有汽油从加油站转移到汽车中。</p>
13+
<p>假设汽车油箱的容量是无限的,其中最初有&nbsp;<code>startFuel</code>&nbsp;升燃料。它每行驶 1 英里就会用掉 1 升汽油。当汽车到达加油站时,它可能停下来加油,将所有汽油从加油站转移到汽车中。</p>
1614

1715
<p>为了到达目的地,汽车所必要的最低加油次数是多少?如果无法到达目的地,则返回 <code>-1</code> 。</p>
1816

19-
<p>注意:如果汽车到达加油站时剩余燃料为 0,它仍然可以在那里加油。如果汽车到达目的地时剩余燃料为 0,仍然认为它已经到达目的地。</p>
17+
<p>注意:如果汽车到达加油站时剩余燃料为 <code>0</code>,它仍然可以在那里加油。如果汽车到达目的地时剩余燃料为 <code>0</code>,仍然认为它已经到达目的地。</p>
2018

2119
<p>&nbsp;</p>
2220

2321
<p><strong>示例 1:</strong></p>
2422

25-
<pre><strong>输入:</strong>target = 1, startFuel = 1, stations = []
23+
<pre>
24+
<strong>输入:</strong>target = 1, startFuel = 1, stations = []
2625
<strong>输出:</strong>0
27-
<strong>解释:</strong>我们可以在不加油的情况下到达目的地
26+
<strong>解释:</strong>可以在不加油的情况下到达目的地
2827
</pre>
2928

3029
<p><strong>示例 2:</strong></p>
3130

32-
<pre><strong>输入:</strong>target = 100, startFuel = 1, stations = [[10,100]]
31+
<pre>
32+
<strong>输入:</strong>target = 100, startFuel = 1, stations = [[10,100]]
3333
<strong>输出:</strong>-1
34-
<strong>解释:</strong>我们无法抵达目的地,甚至无法到达第一个加油站。
34+
<strong>解释:</strong>无法抵达目的地,甚至无法到达第一个加油站。
3535
</pre>
3636

3737
<p><strong>示例 3:</strong></p>
3838

39-
<pre><strong>输入:</strong>target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]
39+
<pre>
40+
<strong>输入:</strong>target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]
4041
<strong>输出:</strong>2
4142
<strong>解释:</strong>
42-
我们出发时有 10 升燃料。
43-
我们开车来到距起点 10 英里处的加油站,消耗 10 升燃料。将汽油从 0 升加到 60 升。
44-
然后,我们从 10 英里处的加油站开到 60 英里处的加油站(消耗 50 升燃料),
45-
并将汽油从 10 升加到 50 升。然后我们开车抵达目的地
46-
我们沿途在1两个加油站停靠,所以返回 2 。
43+
出发时有 10 升燃料。
44+
开车来到距起点 10 英里处的加油站,消耗 10 升燃料。将汽油从 0 升加到 60 升。
45+
然后, 10 英里处的加油站开到 60 英里处的加油站(消耗 50 升燃料),
46+
并将汽油从 10 升加到 50 升。然后开车抵达目的地
47+
沿途在两个加油站停靠,所以返回 2 。
4748
</pre>
4849

4950
<p>&nbsp;</p>
5051

5152
<p><strong>提示:</strong></p>
5253

53-
<ol>
54-
<li><code>1 &lt;= target, startFuel, stations[i][1] &lt;= 10^9</code></li>
54+
<ul>
55+
<li><code>1 &lt;= target, startFuel &lt;= 10<sup>9</sup></code></li>
5556
<li><code>0 &lt;= stations.length &lt;= 500</code></li>
56-
<li><code>0 &lt; stations[0][0] &lt; stations[1][0] &lt; ... &lt; stations[stations.length-1][0] &lt; target</code></li>
57-
</ol>
57+
<li><code>1 &lt;= position<sub>i</sub> &lt; position<sub>i+1</sub> &lt; target</code></li>
58+
<li><code>1 &lt;= fuel<sub>i</sub> &lt; 10<sup>9</sup></code></li>
59+
</ul>
5860

5961
## 解法
6062

solution/0800-0899/0876.Middle of the Linked List/README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,35 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定一个头结点为 <code>head</code> 的非空单链表,返回链表的中间结点。</p>
9+
<p>给你单链表的头结点 <code>head</code> ,请你找出并返回链表的中间结点。</p>
1010

1111
<p>如果有两个中间结点,则返回第二个中间结点。</p>
1212

13-
<p> </p>
14-
15-
<p><strong>示例 1:</strong></p>
13+
<p>&nbsp;</p>
1614

15+
<p><strong class="example">示例 1:</strong></p>
16+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/images/lc-midlist1.jpg" style="width: 544px; height: 65px;" />
1717
<pre>
18-
<strong>输入:</strong>[1,2,3,4,5]
19-
<strong>输出:</strong>此列表中的结点 3 (序列化形式:[3,4,5])
20-
返回的结点值为 3 。 (测评系统对该结点序列化表述是 [3,4,5])。
21-
注意,我们返回了一个 ListNode 类型的对象 ans,这样:
22-
ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next = NULL.
18+
<strong>输入:</strong>head = [1,2,3,4,5]
19+
<strong>输出:</strong>[3,4,5]
20+
<strong>解释:</strong>链表只有一个中间结点,值为 3 。
2321
</pre>
2422

25-
<p><strong>示例 2:</strong></p>
26-
23+
<p><strong class="example">示例 2:</strong></p>
24+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0800-0899/0876.Middle%20of%20the%20Linked%20List/images/lc-midlist2.jpg" style="width: 664px; height: 65px;" />
2725
<pre>
28-
<strong>输入:</strong>[1,2,3,4,5,6]
29-
<strong>输出:</strong>此列表中的结点 4 (序列化形式:[4,5,6])
30-
由于该列表有两个中间结点,值分别为 3 和 4,我们返回第二个结点
26+
<strong>输入:</strong>head = [1,2,3,4,5,6]
27+
<strong>输出:</strong>[4,5,6]
28+
<strong>解释:</strong>该链表有两个中间结点,值分别为 3 和 4 ,返回第二个结点
3129
</pre>
3230

33-
<p> </p>
31+
<p>&nbsp;</p>
3432

3533
<p><strong>提示:</strong></p>
3634

3735
<ul>
38-
<li>给定链表的结点数介于 <code>1</code> 和 <code>100</code> 之间。</li>
36+
<li>链表的结点数范围是 <code>[1, 100]</code></li>
37+
<li><code>1 &lt;= Node.val &lt;= 100</code></li>
3938
</ul>
4039

4140
## 解法

solution/1000-1099/1043.Partition Array for Maximum Sum/README.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给你一个整数数组 <code>arr</code>,请你将该数组分隔为长度最多为 k 的一些(连续)子数组。分隔完成后,每个子数组的中的所有值都会变为该子数组中的最大值。</p>
9+
<p>给你一个整数数组 <code>arr</code>,请你将该数组分隔为长度 <strong>最多 </strong>为 k 的一些(连续)子数组。分隔完成后,每个子数组的中的所有值都会变为该子数组中的最大值。</p>
1010

11-
<p>返回将数组分隔变换后能够得到的元素最大和。</p>
11+
<p>返回将数组分隔变换后能够得到的元素最大和。本题所用到的测试用例会确保答案是一个 32 位整数。</p>
1212

13-
<p> </p>
14-
15-
<p><strong>注意,</strong>原数组和分隔后的数组对应顺序应当一致,也就是说,你只能选择分隔数组的位置而不能调整数组中的顺序。</p>
16-
17-
<p> </p>
13+
<p>&nbsp;</p>
1814

1915
<p><strong>示例 1:</strong></p>
2016

2117
<pre>
2218
<strong>输入:</strong>arr = [1,15,7,9,2,5,10], k = 3
2319
<strong>输出:</strong>84
24-
<strong>解释:</strong>
25-
因为 k=3 可以分隔成 [1,15,7] [9] [2,5,10],结果为 [15,15,15,9,10,10,10],和为 84,是该数组所有分隔变换后元素总和最大的。
26-
若是分隔成 [1] [15,7,9] [2,5,10],结果就是 [1, 15, 15, 15, 10, 10, 10] 但这种分隔方式的元素总和(76)小于上一种。 </pre>
20+
<strong>解释:</strong>数组变为 [15,15,15,9,10,10,10]</pre>
2721

2822
<p><strong>示例 2:</strong></p>
2923

@@ -39,14 +33,14 @@
3933
<strong>输出:</strong>1
4034
</pre>
4135

42-
<p> </p>
36+
<p>&nbsp;</p>
4337

4438
<p><strong>提示:</strong></p>
4539

4640
<ul>
47-
<li><code>1 <= arr.length <= 500</code></li>
48-
<li><code>0 <= arr[i] <= 10<sup>9</sup></code></li>
49-
<li><code>1 <= k <= arr.length</code></li>
41+
<li><code>1 &lt;= arr.length &lt;= 500</code></li>
42+
<li><code>0 &lt;= arr[i] &lt;= 10<sup>9</sup></code></li>
43+
<li><code>1 &lt;= k &lt;= arr.length</code></li>
5044
</ul>
5145

5246
## 解法

solution/1100-1199/1105.Filling Bookcase Shelves/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1105.Filling%20Bookcase%20Shelves/images/shelves.png" style="width: 337px; height: 500px;" /></p>
3030

3131
<pre>
32-
<strong>输入:</strong>books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4
32+
<strong>输入:</strong>books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelfWidth = 4
3333
<strong>输出:</strong>6
3434
<strong>解释:</strong>
3535
3 层书架的高度和为 1 + 3 + 2 = 6 。

0 commit comments

Comments
 (0)