Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ce2da9

Browse files
authored
revert wrong commit
1 parent86eb47b commit5ce2da9

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

‎python/0015-3sum.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
classSolution:
2-
defThreeSum(self,integers):
3-
"""
4-
:type integers: List[int]
5-
:rtype: List[List[int]]
6-
"""
7-
integers.sort()
8-
result= []
9-
forindexinrange(len(integers)):
10-
ifintegers[index]>0:
2+
defthreeSum(self,nums:List[int])->List[List[int]]:
3+
res= []
4+
nums.sort()
5+
6+
fori,ainenumerate(nums):
7+
# Skip positive integers
8+
ifa>0:
119
break
12-
ifindex>0andintegers[index]==integers[index-1]:
10+
11+
ifi>0anda==nums[i-1]:
1312
continue
14-
left,right=index+1,len(integers)-1
15-
whileleft<right:
16-
ifintegers[left]+integers[right]<0-integers[index]:
17-
left+=1
18-
elifintegers[left]+integers[right]>0-integers[index]:
19-
right-=1
13+
14+
l,r=i+1,len(nums)-1
15+
whilel<r:
16+
threeSum=a+nums[l]+nums[r]
17+
ifthreeSum>0:
18+
r-=1
19+
elifthreeSum<0:
20+
l+=1
2021
else:
21-
result.append([integers[index],integers[left],integers[right]])# After a triplet is appended, we try our best to incease the numeric value of its first element or that of its second.
22-
left+=1# The other pairs and the one we were just looking at are either duplicates or smaller than the target.
23-
right-=1# The other pairs are either duplicates or greater than the target.
24-
# We must move on if there is less than or equal to one integer in between the two integers.
25-
whileintegers[left]==integers[left-1]andleft<right:
26-
left+=1# The pairs are either duplicates or smaller than the target.
27-
returnresult
22+
res.append([a,nums[l],nums[r]])
23+
l+=1
24+
r-=1
25+
whilenums[l]==nums[l-1]andl<r:
26+
l+=1
27+
28+
returnres

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp