Skip to content

Commit 1a95812

Browse files
authored
Create 167-Two-Sum-II.py
1 parent a3fd151 commit 1a95812

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

167-Two-Sum-II.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def twoSum(self, numbers: List[int], target: int) -> List[int]:
3+
l, r = 0, len(numbers) - 1
4+
5+
while l < r:
6+
curSum = numbers[l] + numbers[r]
7+
8+
if curSum > target:
9+
r -= 1
10+
elif curSum < target:
11+
l += 1
12+
else:
13+
return [l + 1, r + 1]

0 commit comments

Comments
 (0)