Skip to content

Commit 0835de8

Browse files
committed
Updated 3 md files.
1 parent 2cdd9b1 commit 0835de8

File tree

6 files changed

+90
-81
lines changed

6 files changed

+90
-81
lines changed

en/1-1000/209-minimum-size-subarray-sum.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,48 @@ Given an array of positive integers `nums` and a positive integer `target`, retu
2929
- `1 <= nums[i] <= 10000`
3030

3131
## Intuition
32-
For **subarray** problems, you can consider using **Sliding Window Technique**, which is similar to the **Fast and Slow Pointers Technique**.
32+
For **subarray** problems, you can consider using **Sliding Window Technique**, which is similar to the **Fast & Slow Pointers Approach**.
3333

3434
## Steps
35-
1. Iterate over the `nums` array, the `index` of the element is named `fastIndex`. Although inconspicuous, this is the most important logic of the _Fast and Slow Pointers Technique_. Please memorize it.
36-
2. `sum += nums[fast_index]`.
37-
```java
38-
var minLength = Integer.MAX_VALUE;
39-
var sum = 0;
40-
var slowIndex = 0;
41-
42-
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) { // This line the most important logic of the `Fast and Slow Pointers Technique`.
43-
sum += nums[fastIndex]; // 1
44-
}
45-
46-
return minLength;
47-
```
48-
49-
3. Control of `slowIndex`:
50-
```java
51-
var minLength = Integer.MAX_VALUE;
52-
var sum = 0;
53-
var slowIndex = 0;
35+
1. Iterate over the `nums` array, the `index` of the element is named `fastIndex`. Although inconspicuous, this is the most important logic of the *Fast & Slow Pointers Approach*. Please memorize it.
5436

55-
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) {
56-
sum += nums[fastIndex];
37+
2. `sum += nums[fast_index]`.
5738

58-
while (sum >= target) { // 1
59-
minLength = Math.min(minLength, fastIndex - slowIndex + 1); // 2
60-
sum -= nums[slowIndex]; // 3
61-
slowIndex++; // 4
39+
```java
40+
var minLength = Integer.MAX_VALUE;
41+
var sum = 0;
42+
var slowIndex = 0;
43+
44+
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) { // This line the most important logic of the `Fast and Slow Pointers Technique`.
45+
sum += nums[fastIndex]; // 1
6246
}
63-
}
47+
48+
return minLength;
49+
```
6450

65-
if (minLength == Integer.MAX_VALUE) { // 5
66-
return 0; // 6
67-
}
51+
3. Control of `slowIndex`:
6852

69-
return minLength;
70-
```
53+
```java
54+
var minLength = Integer.MAX_VALUE;
55+
var sum = 0;
56+
var slowIndex = 0;
57+
58+
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) {
59+
sum += nums[fastIndex];
60+
61+
while (sum >= target) { // 1
62+
minLength = Math.min(minLength, fastIndex - slowIndex + 1); // 2
63+
sum -= nums[slowIndex]; // 3
64+
slowIndex++; // 4
65+
}
66+
}
67+
68+
if (minLength == Integer.MAX_VALUE) { // 5
69+
return 0; // 6
70+
}
71+
72+
return minLength;
73+
```
7174

7275
## Complexity
7376
* Time: `O(n)`.
@@ -129,7 +132,7 @@ class Solution:
129132

130133
## JavaScript
131134
```javascript
132-
var minSubArrayLen = function(target, nums) {
135+
var minSubArrayLen = function (target, nums) {
133136
let minLength = Number.MAX_SAFE_INTEGER
134137
let sum = 0
135138
let slowIndex = 0

en/1-1000/59-spiral-matrix-ii.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ Output: [[1]]
2727

2828
## Steps to the Solution
2929
1. Initialize `increments` and `increment_index`:
30+
3031
```python
3132
increments = [(0, 1), (1, 0), (0, -1), (-1, 0)] # (i, j) right, down, left, up
3233
increment_index = 0
3334
```
3435

3536
2. Core logic:
37+
3638
```python
3739
while num <= n * n:
3840
matrix[i][j] = num
@@ -44,20 +46,21 @@ Output: [[1]]
4446
```
4547

4648
3. For function `get_increment(i, j)`, it should return a pair like `[0, 1]`. First verify whether the current increment is valid. If not, use the next increment.
49+
4750
```python
4851
def get_increment(i, j):
4952
increment = increments[increment_index]
5053
i += increment[0]
5154
j += increment[1]
52-
55+
5356
if (
5457
i < 0 or i >= len(matrix) or
5558
j < 0 or j >= len(matrix) or
5659
matrix[i][j] is not None
5760
): # not valid, use next increment
5861
increment_index += 1
5962
increment_index %= len(self.increments)
60-
63+
6164
return increments[increment_index]
6265
```
6366

en/1-1000/977-squares-of-a-sorted-array.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LeetCode link: [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array)
33

44
## LeetCode problem description
5-
Given an integer array `nums` sorted in **non-decreasing** order, return _an array of **the squares of each number** sorted in non-decreasing order._
5+
Given an integer array `nums` sorted in **non-decreasing** order, return *an array of* ***the squares of each number*** *sorted in non-decreasing order.*
66

77
### Example 1
88
```ruby

zh/1-1000/209-minimum-size-subarray-sum.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,49 @@
3131
- `1 <= nums[i] <= 10000`
3232

3333
## 思路
34-
1. 对于**子数组**问题,可以考虑使用**滑动窗口技术**,它类似于**快速和慢速指针技术**
34+
1. 对于**子数组**问题,可以考虑使用**滑动窗口技术**,它类似于**快慢双指针方法**
3535

3636

3737
## 步骤
3838
1. **遍历** `nums` 数组,元素的 `index` 可命名为 `fastIndex`。虽然不起眼,但这是 `快慢指针技术` **最重要**的逻辑。请最好记住它。
39-
2. `sum += nums[fast_index]`.
40-
```java
41-
var minLength = Integer.MAX_VALUE;
42-
var sum = 0;
43-
var slowIndex = 0;
44-
45-
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) { // 本行是`快慢指针技术`最重要的逻辑
46-
sum += nums[fastIndex]; // 1
47-
}
48-
49-
return minLength;
50-
```
51-
52-
3. 控制`slowIndex`
53-
```java
54-
var minLength = Integer.MAX_VALUE;
55-
var sum = 0;
56-
var slowIndex = 0;
5739

58-
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) {
59-
sum += nums[fastIndex];
40+
2. `sum += nums[fast_index]`.
6041

61-
while (sum >= target) { // 1
62-
minLength = Math.min(minLength, fastIndex - slowIndex + 1); // 2
63-
sum -= nums[slowIndex]; // 3
64-
slowIndex++; // 4
42+
```java
43+
var minLength = Integer.MAX_VALUE;
44+
var sum = 0;
45+
var slowIndex = 0;
46+
47+
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) { // 本行是`快慢指针技术`最重要的逻辑
48+
sum += nums[fastIndex]; // 1
6549
}
66-
}
50+
51+
return minLength;
52+
```
6753

68-
if (minLength == Integer.MAX_VALUE) { // 5
69-
return 0; // 6
70-
}
54+
3. 控制`slowIndex`。
7155

72-
return minLength;
73-
```
56+
```java
57+
var minLength = Integer.MAX_VALUE;
58+
var sum = 0;
59+
var slowIndex = 0;
60+
61+
for (var fastIndex = 0; fastIndex < nums.length; fastIndex++) {
62+
sum += nums[fastIndex];
63+
64+
while (sum >= target) { // 1
65+
minLength = Math.min(minLength, fastIndex - slowIndex + 1); // 2
66+
sum -= nums[slowIndex]; // 3
67+
slowIndex++; // 4
68+
}
69+
}
70+
71+
if (minLength == Integer.MAX_VALUE) { // 5
72+
return 0; // 6
73+
}
74+
75+
return minLength;
76+
```
7477

7578
## 复杂度
7679
* 时间: `O(n)`.

zh/1-1000/59-spiral-matrix-ii.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ Output: [[1]]
2626
* You only need to use a `get_increment(i, j)` function to specifically control the index of the next two-dimensional array.
2727

2828
## Steps to the Solution
29-
1. Initialize `increments` and `increment_index`:
29+
1. 初始化 `increments``increment_index`:
30+
3031
```python
3132
increments = [(0, 1), (1, 0), (0, -1), (-1, 0)] # (i, j) right, down, left, up
3233
increment_index = 0
3334
```
3435

35-
2. Core logic:
36+
2. 核心逻辑:
37+
3638
```python
3739
while num <= n * n:
3840
matrix[i][j] = num
@@ -43,9 +45,10 @@ Output: [[1]]
4345
j += increment[1]
4446
```
4547

46-
3. For function `get_increment(i, j)`, it should return a pair like `[0, 1]`. First verify whether the current increment is valid. If not, use the next increment.
47-
```python
48-
def get_increment(i, j):
48+
3. 对于函数 `get_increment(i, j)`,它应该返回一对 `[0, 1]`。首先验证当前增量是否有效。如果无效,则使用下一个增量。
49+
50+
```python
51+
def get_increment(i, j):
4952
increment = increments[increment_index]
5053
i += increment[0]
5154
j += increment[1]
@@ -54,12 +57,12 @@ Output: [[1]]
5457
i < 0 or i >= len(matrix) or
5558
j < 0 or j >= len(matrix) or
5659
matrix[i][j] is not None
57-
): # not valid, use next increment
60+
): # 当前增量无效,使用下一个增量
5861
increment_index += 1
5962
increment_index %= len(self.increments)
6063

6164
return increments[increment_index]
62-
```
65+
```
6366

6467
## Complexity
6568
* Time: `O(n * n)`.

zh/1-1000/704-binary-search.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
LeetCode link: [704. Binary Search](https://leetcode.com/problems/binary-search)
33

44
## LeetCode problem description
5-
Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`. If `target` exists, then return its `index`. Otherwise, return `-1`.
6-
7-
You must write an algorithm with `O(log n)` runtime complexity.
5+
给定一个 `n` 个元素有序的(升序)整型数组 `nums` 和一个目标值 `target` ,写一个函数搜索 `nums` 中的 `target`,如果目标值存在返回下标,否则返回 `-1`
86

97
### Example 1
108
```ruby
@@ -21,10 +19,9 @@ Explanation: 2 does not exist in nums so return -1
2119
```
2220

2321
### Constraints
24-
- `1 <= nums.length <= 10000`
25-
- `104 < nums[i], target < 10000`
26-
- All the integers in `nums` are **unique**.
27-
- `nums` is sorted in ascending order.
22+
- 你可以假设 `nums` 中的所有元素是不重复的。
23+
- `n` 将在 `[1, 10000]` 之间。
24+
- `nums` 的每个元素都将在 `[-9999, 9999]` 之间。
2825

2926
## Intuition
3027
Because it is an already sorted array, by using the middle value for comparison, half of the numbers can be eliminated each time.

0 commit comments

Comments
 (0)