Skip to content

Commit 71d9ea1

Browse files
author
yangdi
committed
add 4Sum
1 parent 94f5377 commit 71d9ea1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src2/4Sum/4Sum.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
3+
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target?
4+
Find all unique quadruplets in the array which gives the sum of target.
5+
6+
Note:
7+
Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a <= b <= c <= d)
8+
The solution set must not contain duplicate quadruplets.
9+
10+
For example, given array S = {1 0 -1 0 -2 2}, and target = 0.
11+
12+
A solution set is:
13+
(-1, 0, 0, 1)
14+
(-2, -1, 1, 2)
15+
(-2, 0, 0, 2)
16+
'''
17+
18+
class Solution:
19+
# @return a list of lists of length 4, [[val1,val2,val3,val4]]
20+
def fourSum(self, num, target):
21+
num.sort()
22+
return num
23+
24+
if __name__ == '__main__':
25+
print Solution().fourSum([1, 0, -1, 0, -2, 2], 0)

0 commit comments

Comments
 (0)