Skip to content

Commit 2a1e092

Browse files
Added solution
1 parent d6162d4 commit 2a1e092

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

167.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Runtime: 20 ms, faster than 100.00% of Python online submissions for Two Sum II - Input array is sorted.
2+
# Difficulty: Easy
3+
4+
class Solution(object):
5+
def twoSum(self, numbers, target):
6+
"""
7+
:type numbers: List[int]
8+
:type target: int
9+
:rtype: List[int]
10+
"""
11+
pointer1, pointer2 = 0, len(numbers) - 1
12+
while pointer1 != pointer2:
13+
sum = numbers[pointer1] + numbers[pointer2]
14+
if sum == target:
15+
return [pointer1 + 1, pointer2 + 1]
16+
elif sum > target:
17+
pointer2 -= 1
18+
else:
19+
pointer1 += 1

0 commit comments

Comments
 (0)