Skip to content

Commit c3f6c97

Browse files
Create 001_two_sum.py
0 parents  commit c3f6c97

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

001_two_sum.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
3+
def twoSum(self, nums, target):
4+
# two point
5+
nums_index = [(v, index) for index, v in enumerate(nums)]
6+
nums_index.sort()
7+
begin, end = 0, len(nums) - 1
8+
while begin < end:
9+
curr = nums_index[begin][0] + nums_index[end][0]
10+
if curr == target:
11+
return [nums_index[begin][1], nums_index[end][1]]
12+
elif curr < target:
13+
begin += 1
14+
else:
15+
end -= 1

0 commit comments

Comments
 (0)