-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththree_sum.py
More file actions
51 lines (42 loc) · 1.49 KB
/
three_sum.py
File metadata and controls
51 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#----------INCOMPLETE---------
class Solution(object):
def threeSum(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
non_zero_list = []
result_list = []
result_set = []
last = 0
second_last = 0
#find consecutive zero sums
for i in range(0, len(nums)):
if i > 1:
if last + second_last + nums[i] == 0:
if last not in result_set and second_last not in result_set and nums[i] not in result_set:
temp = []
temp.append(last)
temp.append(second_last)
temp.append(nums[i])
result_list.append(temp)
result_set.append(last)
result_set.append(second_last)
result_set.append(nums[i])
last = second_last
second_last = nums[i]
else:
last = second_last
second_last = nums[i]
non_zero_list.append(nums[i])
elif i == 0:
last = nums[i]
non_zero_list.append(nums[i])
elif i == 1:
second_last = nums[i]
non_zero_list.append(nums[i])
print result_list
print non_zero_list
print result_set
obj = Solution()
obj.threeSum([2, 3, 0, 4,-2, -2])