Skip to content

Commit daa00f5

Browse files
committed
feat: update lc problems
1 parent 05e7b5f commit daa00f5

File tree

82 files changed

+571
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+571
-533
lines changed

solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ for (int i = 0; i < k; i++) {
5454
<p><strong>提示:</strong></p>
5555

5656
<ul>
57-
<li><code>0 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
57+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
5858
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
5959
<li><code>nums</code> 已按 <strong>升序</strong> 排列</li>
6060
</ul>

solution/0000-0099/0030.Substring with Concatenation of All Words/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class Solution {
238238
++wordsDict[word];
239239
}
240240
}
241-
241+
242242
var wordOfS = new string[s.Length];
243243
var wordLength = words[0].Length;
244244
var wordCount = words.Length;
@@ -250,7 +250,7 @@ public class Solution {
250250
wordOfS[i] = substring;
251251
}
252252
}
253-
253+
254254
var result = new List<int>();
255255
for (var i = 0; i <= s.Length - wordLength * wordCount; ++i)
256256
{
@@ -273,7 +273,7 @@ public class Solution {
273273
result.Add(i);
274274
}
275275
}
276-
276+
277277
return result;
278278
}
279279
}

solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public class Solution {
225225
++wordsDict[word];
226226
}
227227
}
228-
228+
229229
var wordOfS = new string[s.Length];
230230
var wordLength = words[0].Length;
231231
var wordCount = words.Length;
@@ -237,7 +237,7 @@ public class Solution {
237237
wordOfS[i] = substring;
238238
}
239239
}
240-
240+
241241
var result = new List<int>();
242242
for (var i = 0; i <= s.Length - wordLength * wordCount; ++i)
243243
{
@@ -260,7 +260,7 @@ public class Solution {
260260
result.Add(i);
261261
}
262262
}
263-
263+
264264
return result;
265265
}
266266
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
/**
2-
* @param {number[][]} grid
3-
* @return {number}
4-
*/
5-
var minPathSum = function (grid) {
6-
let m = grid.length,
7-
n = grid[0].length;
8-
let dp = Array.from({ length: m }, v => new Array(n).fill(0));
9-
dp[0][0] = grid[0][0];
10-
for (let i = 1; i < m; ++i) {
11-
dp[i][0] = dp[i - 1][0] + grid[i][0];
12-
}
13-
for (let j = 1; j < n; ++j) {
14-
dp[0][j] = dp[0][j - 1] + grid[0][j];
15-
}
16-
for (let i = 1; i < m; ++i) {
17-
for (let j = 1; j < n; ++j) {
18-
dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
19-
}
20-
}
21-
return dp[m - 1][n - 1];
22-
};
1+
/**
2+
* @param {number[][]} grid
3+
* @return {number}
4+
*/
5+
var minPathSum = function (grid) {
6+
let m = grid.length,
7+
n = grid[0].length;
8+
let dp = Array.from({ length: m }, v => new Array(n).fill(0));
9+
dp[0][0] = grid[0][0];
10+
for (let i = 1; i < m; ++i) {
11+
dp[i][0] = dp[i - 1][0] + grid[i][0];
12+
}
13+
for (let j = 1; j < n; ++j) {
14+
dp[0][j] = dp[0][j - 1] + grid[0][j];
15+
}
16+
for (let i = 1; i < m; ++i) {
17+
for (let j = 1; j < n; ++j) {
18+
dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
19+
}
20+
}
21+
return dp[m - 1][n - 1];
22+
};

solution/0000-0099/0080.Remove Duplicates from Sorted Array II/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

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

9-
<p>给你一个有序数组 <code>nums</code> ,请你<strong><a href="http://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地</a></strong> 删除重复出现的元素,使每个元素 <strong>最多出现两次</strong> ,返回删除后数组的新长度。</p>
9+
<p>给你一个有序数组 <code>nums</code> ,请你<strong><a href="http://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地</a></strong> 删除重复出现的元素,使得出现次数超过两次的元素<strong>只出现两次</strong> ,返回删除后数组的新长度。</p>
1010

1111
<p>不要使用额外的数组空间,你必须在 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地 </a>修改输入数组 </strong>并在使用 O(1) 额外空间的条件下完成。</p>
1212

13-
<p> </p>
13+
<p>&nbsp;</p>
1414

1515
<p><strong>说明:</strong></p>
1616

@@ -26,12 +26,12 @@ int len = removeDuplicates(nums);
2626

2727
// 在函数里修改输入数组对于调用者是可见的。
2828
// 根据你的函数返回的长度, 它会打印出数组中<strong> 该长度范围内</strong> 的所有元素。
29-
for (int i = 0; i < len; i++) {
30-
    print(nums[i]);
29+
for (int i = 0; i &lt; len; i++) {
30+
&nbsp; &nbsp; print(nums[i]);
3131
}
3232
</pre>
3333

34-
<p> </p>
34+
<p>&nbsp;</p>
3535

3636
<p><strong>示例 1:</strong></p>
3737

@@ -46,16 +46,16 @@ for (int i = 0; i < len; i++) {
4646
<pre>
4747
<strong>输入:</strong>nums = [0,0,1,1,1,1,2,3,3]
4848
<strong>输出:</strong>7, nums = [0,0,1,1,2,3,3]
49-
<strong>解释:</strong>函数应返回新长度 length = <strong><code>7</code></strong>, 并且原数组的前五个元素被修改为 <strong><code>0</code></strong>, <strong>0</strong>, <strong>1</strong>, <strong>1</strong>, <strong>2</strong>, <strong>3</strong>, <strong>3 。</strong> 不需要考虑数组中超出新长度后面的元素。
49+
<strong>解释:</strong>函数应返回新长度 length = <strong><code>7</code></strong>, 并且原数组的前五个元素被修改为&nbsp;<strong><code>0</code></strong>, <strong>0</strong>, <strong>1</strong>, <strong>1</strong>, <strong>2</strong>, <strong>3</strong>, <strong>3 。</strong> 不需要考虑数组中超出新长度后面的元素。
5050
</pre>
5151

52-
<p> </p>
52+
<p>&nbsp;</p>
5353

5454
<p><strong>提示:</strong></p>
5555

5656
<ul>
57-
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
58-
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
57+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
58+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
5959
<li><code>nums</code> 已按升序排列</li>
6060
</ul>
6161

Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
/**
2-
* @param {number[][]} matrix
3-
* @param {number} target
4-
* @return {boolean}
5-
*/
6-
var searchMatrix = function (matrix, target) {
7-
const n = matrix[0].length;
8-
for (const row of matrix) {
9-
let left = 0,
10-
right = n;
11-
while (left < right) {
12-
const mid = (left + right) >> 1;
13-
if (row[mid] >= target) {
14-
right = mid;
15-
} else {
16-
left = mid + 1;
17-
}
18-
}
19-
if (left != n && row[left] == target) {
20-
return true;
21-
}
22-
}
23-
return false;
24-
};
1+
/**
2+
* @param {number[][]} matrix
3+
* @param {number} target
4+
* @return {boolean}
5+
*/
6+
var searchMatrix = function (matrix, target) {
7+
const n = matrix[0].length;
8+
for (const row of matrix) {
9+
let left = 0,
10+
right = n;
11+
while (left < right) {
12+
const mid = (left + right) >> 1;
13+
if (row[mid] >= target) {
14+
right = mid;
15+
} else {
16+
left = mid + 1;
17+
}
18+
}
19+
if (left != n && row[left] == target) {
20+
return true;
21+
}
22+
}
23+
return false;
24+
};
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/**
2-
* @param {number[]} nums
3-
* @return {number}
4-
*/
5-
var findDuplicate = function (nums) {
6-
let left = 1,
7-
right = nums.length - 1;
8-
while (left < right) {
9-
const mid = (left + right) >> 1;
10-
let cnt = 0;
11-
for (let v of nums) {
12-
if (v <= mid) {
13-
++cnt;
14-
}
15-
}
16-
if (cnt > mid) {
17-
right = mid;
18-
} else {
19-
left = mid + 1;
20-
}
21-
}
22-
return left;
23-
};
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var findDuplicate = function (nums) {
6+
let left = 1,
7+
right = nums.length - 1;
8+
while (left < right) {
9+
const mid = (left + right) >> 1;
10+
let cnt = 0;
11+
for (let v of nums) {
12+
if (v <= mid) {
13+
++cnt;
14+
}
15+
}
16+
if (cnt > mid) {
17+
right = mid;
18+
} else {
19+
left = mid + 1;
20+
}
21+
}
22+
return left;
23+
};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* @param {number[]} nums
3-
* @param {number} target
4-
* @return {number}
5-
*/
6-
var combinationSum4 = function (nums, target) {
7-
const dp = new Array(target + 1).fill(0);
8-
dp[0] = 1;
9-
for (let i = 1; i <= target; ++i) {
10-
for (let v of nums) {
11-
if (i >= v) {
12-
dp[i] += dp[i - v];
13-
}
14-
}
15-
}
16-
return dp[target];
17-
};
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} target
4+
* @return {number}
5+
*/
6+
var combinationSum4 = function (nums, target) {
7+
const dp = new Array(target + 1).fill(0);
8+
dp[0] = 1;
9+
for (let i = 1; i <= target; ++i) {
10+
for (let v of nums) {
11+
if (i >= v) {
12+
dp[i] += dp[i - v];
13+
}
14+
}
15+
}
16+
return dp[target];
17+
};
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/**
2-
* @param {number} n
3-
* @return {number[]}
4-
*/
5-
var lexicalOrder = function (n) {
6-
let ans = [];
7-
function dfs(u) {
8-
if (u > n) {
9-
return;
10-
}
11-
ans.push(u);
12-
for (let i = 0; i < 10; ++i) {
13-
dfs(u * 10 + i);
14-
}
15-
}
16-
for (let i = 1; i < 10; ++i) {
17-
dfs(i);
18-
}
19-
return ans;
20-
};
1+
/**
2+
* @param {number} n
3+
* @return {number[]}
4+
*/
5+
var lexicalOrder = function (n) {
6+
let ans = [];
7+
function dfs(u) {
8+
if (u > n) {
9+
return;
10+
}
11+
ans.push(u);
12+
for (let i = 0; i < 10; ++i) {
13+
dfs(u * 10 + i);
14+
}
15+
}
16+
for (let i = 1; i < 10; ++i) {
17+
dfs(i);
18+
}
19+
return ans;
20+
};

solution/0400-0499/0409.Longest Palindrome/README_EN.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,15 @@
1414
<pre>
1515
<strong>Input:</strong> s = &quot;abccccdd&quot;
1616
<strong>Output:</strong> 7
17-
<strong>Explanation:</strong>
18-
One longest palindrome that can be built is &quot;dccaccd&quot;, whose length is 7.
17+
<strong>Explanation:</strong> One longest palindrome that can be built is &quot;dccaccd&quot;, whose length is 7.
1918
</pre>
2019

2120
<p><strong>Example 2:</strong></p>
2221

2322
<pre>
2423
<strong>Input:</strong> s = &quot;a&quot;
2524
<strong>Output:</strong> 1
26-
</pre>
27-
28-
<p><strong>Example 3:</strong></p>
29-
30-
<pre>
31-
<strong>Input:</strong> s = &quot;bb&quot;
32-
<strong>Output:</strong> 2
25+
<strong>Explanation:</strong> The longest palindrome that can be built is &quot;a&quot;, whose length is 1.
3326
</pre>
3427

3528
<p>&nbsp;</p>

0 commit comments

Comments
 (0)