You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/18. 4Sum.md
+42-2Lines changed: 42 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
## 18. 4Sum
2
+
### Question:
3
+
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
4
+
5
+
Note:
6
+
7
+
* The solution set must not contain duplicate quadruplets.
8
+
2
9
### Thinking:
3
-
* Method:
10
+
* Method:
4
11
It is very similar to 3sum, but we use one more index to iterate.
5
12
It is very important to remove duplicate elements.
6
13
```Java
@@ -21,7 +28,7 @@ It is very important to remove duplicate elements.
21
28
while(left < right && nums[left-1] == nums[left]) left++;
22
29
while(left < right && nums[right+1] == nums[right]) right--;
23
30
}elseif(temp < target){
24
-
left++;
31
+
left++;
25
32
}else{
26
33
right--;
27
34
}
@@ -33,4 +40,37 @@ It is very important to remove duplicate elements.
0 commit comments