Skip to content

Commit fe06cdd

Browse files
committed
18-4sum.md Separated Chinese and English solutions.
1 parent 00cad4e commit fe06cdd

File tree

3 files changed

+57
-114
lines changed

3 files changed

+57
-114
lines changed

en/1-1000/18-4sum.md

+10-45
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
# 18. 4Sum - LeetCode Solution
2-
LeetCode problem link: [18. 4Sum](https://leetcode.com/problems/4sum),
3-
[18. 四数之和](https://leetcode.cn/problems/4sum)
1+
# 18. 4Sum - LeetCode Solution Best Practice
2+
LeetCode link: [18. 4Sum](https://leetcode.com/problems/4sum), difficulty: **Medium**
43

5-
[中文题解](#中文题解)
6-
7-
## LeetCode problem description
4+
## Description of "18. 4Sum"
85
Given an array `nums` of `n` integers, return _an array of all the **unique** quadruplets_ `[nums[a], nums[b], nums[c], nums[d]]` such that:
96

107
* `0 <= a, b, c, d < n`
118
* `a`, `b`, `c`, and `d` are **distinct**.
129
* `nums[a] + nums[b] + nums[c] + nums[d] == target`
1310
* You may return the answer in **any order**.
1411

15-
Difficulty: **Medium**
16-
1712
### [Example 1]
1813
**Input**: `nums = [1,0,-1,0,-2,2], target = 0`
1914

@@ -30,21 +25,14 @@ Difficulty: **Medium**
3025
- `-10**9 <= target <= 10**9`
3126

3227
## Intuition
33-
[中文题解](#中文题解)
34-
3528
1. The idea of this question is the same as [15. 3Sum](15-3sum.md), please click the link to view.
3629
2. The difference is that `three numbers` becomes `four numbers`, and processing `four numbers` only requires **one more nested loop**.
3730
3. In addition, the `target` parameter is added, which needs to be brought in as a condition during calculation.
3831
4. You may have already seen that no matter it is `two numbers`, `three numbers` or `four numbers`, the `Two Pointers Technique` can be used.
3932

4033
## Complexity
41-
* Time: `O(n**3)`.
42-
* Space: `O(n)`.
43-
44-
## Java
45-
```java
46-
// Welcome to create a PR to complete the code of this language, thanks!
47-
```
34+
* Time: `O(N**3)`.
35+
* Space: `O(N)`.
4836

4937
## Python
5038
```python
@@ -82,6 +70,11 @@ class Solution:
8270
return list(results)
8371
```
8472

73+
## Java
74+
```java
75+
// Welcome to create a PR to complete the code of this language, thanks!
76+
```
77+
8578
## C++
8679
```cpp
8780
// Welcome to create a PR to complete the code of this language, thanks!
@@ -131,31 +124,3 @@ class Solution:
131124
```
132125
// Welcome to create a PR to complete the code of this language, thanks!
133126
```
134-
135-
## 力扣问题描述
136-
[18. 四数之和](https://leetcode.cn/problems/4sum), 难度: **中等**
137-
138-
给你一个由 `n` 个整数组成的数组 `nums` ,和一个目标值 `target` 。请你找出并返回满足下述全部条件且**不重复**的四元组 `[nums[a], nums[b], nums[c], nums[d]]` (若两个四元组元素一一对应,则认为两个四元组重复):
139-
140-
- `0 <= a, b, c, d < n`
141-
- `a``b``c``d` **互不相同**
142-
- `nums[a] + nums[b] + nums[c] + nums[d] == target`
143-
144-
你可以按 **任意顺序** 返回答案 。
145-
146-
### [示例 1]
147-
**输入**: `nums = [1,0,-1,0,-2,2], target = 0`
148-
149-
**输出**: `[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]`
150-
151-
### [示例 2]
152-
**输入**: `nums = [2,2,2,2,2], target = 8`
153-
154-
**输出**: `[[2,2,2,2]]`
155-
156-
# 中文题解
157-
## 思路
158-
1. 本题思路同[15. 三数之和](15-3sum.md), 请点链接查看。
159-
2. 区别是`三数``四数`,处理`四数`,只需要**多加一重嵌套的循环**
160-
3. 另外增加了`target`参数,计算时需要把它做为条件带入。
161-
4. 你可能已经看出来了,不管它是`两数``三数`还是`四数`,都可以用`双指针技术`

en/3001-4000/unorganized.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ You want to query information by a student's name.
1515
`boolean mark` solution.
1616

1717
## Other Algorithms
18-
### Binary Search Algorithm
19-
704
20-
21-
### Fast and Slow Pointers
22-
27
23-
18+
### Recursion
19+
* Recursion steps:
20+
1. Determine the parameters
21+
2. Determine the recursion logic
22+
3. Determine the return value
23+
4. Determine the exit logic
2424

2525
## Dynamic programming
2626
- [647. Palindromic Substrings](https://leetcode.cn/problems/palindromic-substrings/)
@@ -63,12 +63,17 @@ The improved way with a queue is commonly more efficient. Relaxing **All Edges**
6363
* Find all the prime numbers within 1000000.
6464

6565
## Skipped problems/solutions
66+
- 704 Binary Search Algorithm
67+
- 27 Fast and Slow Pointers
68+
6669
- 1047 https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/
6770
- 150 https://leetcode.cn/problems/evaluate-reverse-polish-notation/
6871
- 239 https://leetcode.cn/problems/sliding-window-maximum/ tag `monotonic queue`
6972
- 347 https://leetcode.cn/problems/top-k-frequent-elements/ tag `heap sort`
7073

7174
### Binary Tree
75+
* Remember to add the recursion steps (described above in this doc) first
76+
7277
- 144 https://leetcode.cn/problems/binary-tree-preorder-traversal/
7378
- 94 https://leetcode.cn/problems/binary-tree-inorder-traversal/
7479
- 145 https://leetcode.cn/problems/binary-tree-postorder-traversal/
@@ -81,6 +86,7 @@ The improved way with a queue is commonly more efficient. Relaxing **All Edges**
8186
- 116 https://leetcode.cn/problems/populating-next-right-pointers-in-each-node/
8287
- 117 https://leetcode.cn/problems/populating-next-right-pointers-in-each-node-ii/
8388
- 111 https://leetcode.cn/problems/minimum-depth-of-binary-tree/
89+
- 513 https://leetcode.cn/problems/find-bottom-left-tree-value
8490

8591
- 104 https://leetcode.cn/problems/maximum-depth-of-binary-tree/
8692
- 226 https://leetcode.cn/problems/invert-binary-tree/
@@ -90,8 +96,14 @@ The improved way with a queue is commonly more efficient. Relaxing **All Edges**
9096

9197
- 222 https://leetcode.cn/problems/count-complete-tree-nodes/
9298
- 110 https://leetcode.cn/problems/balanced-binary-tree/ 2 ways
93-
- 257 https://leetcode.cn/problems/binary-tree-paths/description/
99+
- 257 https://leetcode.cn/problems/binary-tree-paths/
94100
- 404 https://leetcode.cn/problems/sum-of-left-leaves/
101+
- 112 https://leetcode.cn/problems/path-sum/
102+
- 105 https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
103+
- 106 https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
104+
- 654 https://leetcode.cn/problems/maximum-binary-tree/
105+
- 617 https://leetcode.cn/problems/merge-two-binary-trees/
106+
- 700 https://leetcode.cn/problems/search-in-a-binary-search-tree/
95107

96108
### Failed in 2 rounds
97109
- 222 https://leetcode.cn/problems/count-complete-tree-nodes/

zh/1-1000/18-4sum.md

+28-62
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,39 @@
1-
# 18. 4Sum - LeetCode Solution
2-
LeetCode problem link: [18. 4Sum](https://leetcode.com/problems/4sum),
3-
[18. 四数之和](https://leetcode.cn/problems/4sum)
1+
# 18. 四数之和 - 力扣题解最佳实践
2+
力扣链接:[18. 四数之和](https://leetcode.cn/problems/4sum), 难度: **中等**
43

5-
[中文题解](#中文题解)
6-
7-
## LeetCode problem description
8-
Given an array `nums` of `n` integers, return _an array of all the **unique** quadruplets_ `[nums[a], nums[b], nums[c], nums[d]]` such that:
4+
## 力扣“18. 四数之和”问题描述
5+
给你一个由 `n` 个整数组成的数组 `nums` ,和一个目标值 `target` 。请你找出并返回满足下述全部条件且**不重复**的四元组 `[nums[a], nums[b], nums[c], nums[d]]` (若两个四元组元素一一对应,则认为两个四元组重复):
96

10-
* `0 <= a, b, c, d < n`
11-
* `a`, `b`, `c`, and `d` are **distinct**.
12-
* `nums[a] + nums[b] + nums[c] + nums[d] == target`
13-
* You may return the answer in **any order**.
7+
- `0 <= a, b, c, d < n`
8+
- `a``b``c``d` **互不相同**
9+
- `nums[a] + nums[b] + nums[c] + nums[d] == target`
1410

15-
Difficulty: **Medium**
11+
你可以按 **任意顺序** 返回答案 。
1612

17-
### [Example 1]
18-
**Input**: `nums = [1,0,-1,0,-2,2], target = 0`
13+
### [示例 1]
14+
**输入**: `nums = [1,0,-1,0,-2,2], target = 0`
1915

20-
**Output**: `[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]`
16+
**输出**: `[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]`
2117

22-
### [Example 2]
23-
**Input**: `nums = [2,2,2,2,2], target = 8`
18+
### [示例 2]
19+
**输入**: `nums = [2,2,2,2,2], target = 8`
2420

25-
**Output**: `[[2,2,2,2]]`
21+
**输出**: `[[2,2,2,2]]`
2622

27-
### [Constraints]
23+
### [约束]
2824
- `1 <= nums.length <= 200`
2925
- `-10**9 <= nums[i] <= 10**9`
3026
- `-10**9 <= target <= 10**9`
3127

32-
## Intuition
33-
[中文题解](#中文题解)
34-
35-
1. The idea of this question is the same as [15. 3Sum](15-3sum.md), please click the link to view.
36-
2. The difference is that `three numbers` becomes `four numbers`, and processing `four numbers` only requires **one more nested loop**.
37-
3. In addition, the `target` parameter is added, which needs to be brought in as a condition during calculation.
38-
4. You may have already seen that no matter it is `two numbers`, `three numbers` or `four numbers`, the `Two Pointers Technique` can be used.
39-
40-
## Complexity
41-
* Time: `O(n**3)`.
42-
* Space: `O(n)`.
28+
## 思路
29+
1. 本题思路同[15. 三数之和](15-3sum.md), 请点链接查看。
30+
2. 区别是`三数``四数`,处理`四数`,只需要**多加一重嵌套的循环**
31+
3. 另外增加了`target`参数,计算时需要把它做为条件带入。
32+
4. 你可能已经看出来了,不管它是`两数``三数`还是`四数`,都可以用`双指针技术`
4333

44-
## Java
45-
```java
46-
// Welcome to create a PR to complete the code of this language, thanks!
47-
```
34+
## 复杂度
35+
* 时间:`O(N**3)`
36+
* 空间:`O(N)`
4837

4938
## Python
5039
```python
@@ -82,6 +71,11 @@ class Solution:
8271
return list(results)
8372
```
8473

74+
## Java
75+
```java
76+
// Welcome to create a PR to complete the code of this language, thanks!
77+
```
78+
8579
## C++
8680
```cpp
8781
// Welcome to create a PR to complete the code of this language, thanks!
@@ -131,31 +125,3 @@ class Solution:
131125
```
132126
// Welcome to create a PR to complete the code of this language, thanks!
133127
```
134-
135-
## 力扣问题描述
136-
[18. 四数之和](https://leetcode.cn/problems/4sum), 难度: **中等**
137-
138-
给你一个由 `n` 个整数组成的数组 `nums` ,和一个目标值 `target` 。请你找出并返回满足下述全部条件且**不重复**的四元组 `[nums[a], nums[b], nums[c], nums[d]]` (若两个四元组元素一一对应,则认为两个四元组重复):
139-
140-
- `0 <= a, b, c, d < n`
141-
- `a``b``c``d` **互不相同**
142-
- `nums[a] + nums[b] + nums[c] + nums[d] == target`
143-
144-
你可以按 **任意顺序** 返回答案 。
145-
146-
### [示例 1]
147-
**输入**: `nums = [1,0,-1,0,-2,2], target = 0`
148-
149-
**输出**: `[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]`
150-
151-
### [示例 2]
152-
**输入**: `nums = [2,2,2,2,2], target = 8`
153-
154-
**输出**: `[[2,2,2,2]]`
155-
156-
# 中文题解
157-
## 思路
158-
1. 本题思路同[15. 三数之和](15-3sum.md), 请点链接查看。
159-
2. 区别是`三数``四数`,处理`四数`,只需要**多加一重嵌套的循环**
160-
3. 另外增加了`target`参数,计算时需要把它做为条件带入。
161-
4. 你可能已经看出来了,不管它是`两数``三数`还是`四数`,都可以用`双指针技术`

0 commit comments

Comments
 (0)