-
Notifications
You must be signed in to change notification settings - Fork 0
/
15.py
43 lines (37 loc) · 947 Bytes
/
15.py
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
class Solution(object):
def threeSum(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums.sort()
ans=[]
if nums.count(0)>=3:
ans.append([0,0,0])
while nums.count(0)>1:
nums.remove(0)
for i in range(len(nums)-2):
# if i>0 and nums[i]==nums[i-1]:
# continue
l,r = i+1,len(nums)-1
while l<r:
if nums[l]+nums[r]==-nums[i]:
arr=sorted([nums[i],nums[r],nums[l]])
if arr not in ans:
ans.append(arr)
# break
l+=1
elif nums[l]+nums[r]>-nums[i]:
r-=1
else:
l+=1
return ans
#%% test
nums = [-2,0,1,1,2]
x=Solution
x.threeSum(x,nums)
#%%
a=[0,0,0,0]
a.count(0)
#%%
a.replace(0,1)