-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path167.py
40 lines (27 loc) · 759 Bytes
/
167.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
'''167. Two Sum II - Input Array Is Sorted
Created on 2024-12-02 22:19:37
2024-12-02 22:36:54
@author: MilkTea_shih
'''
#%% Packages
#%% Variable
#%% Functions
class Solution:
def twoSum(self, numbers: list[int], target: int) -> list[int]:
left, right = 0, len(numbers) - 1 #two-pointer
while left < right:
answer: int = numbers[left] + numbers[right]
if answer < target:
left += 1
elif answer > target:
right -= 1
else:
left += 1 #1-indexed
right += 1 #1-indexed
break #match!
return [left, right]
#%% Main Function
#%% Main
if __name__ == '__main__':
pass
#%%