-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
22 lines (22 loc) · 655 Bytes
/
Copy path1.py
File metadata and controls
22 lines (22 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
originnums = nums[:]
nums.sort()
pt1 = 0
pt2 = len(nums)-1
(res1, res2) = (nums[pt1], nums[pt2])
while(True):
if nums[pt1]+nums[pt2] < target:
pt1 += 1
res1 = nums[pt1]
elif nums[pt1]+nums[pt2] > target:
pt2 -= 1
res2 = nums[pt2]
else:
break;
return [originnums.index(res1), len(nums)-originnums[::-1].index(res2)-1]