Skip to content

Commit f353a71

Browse files
committed
success 167
1 parent 4ffa3ba commit f353a71

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def twoSum(self, numbers, target):
3+
"""
4+
:type numbers: List[int]
5+
:type target: int
6+
:rtype: List[int]
7+
"""
8+
length = len(numbers)
9+
for x in range(0, length):
10+
t = target - numbers[x]
11+
flag = self.search(numbers[(x + 1):], t)
12+
if flag != -1:
13+
return [x + 1, flag + x + 2]
14+
15+
def search(self, nums, target):
16+
low = 0
17+
high = len(nums) - 1
18+
while low <= high:
19+
mid = (low+high)//2
20+
if nums[mid] < target:
21+
low = mid + 1
22+
elif nums[mid] > target:
23+
high = mid - 1
24+
else:
25+
return mid
26+
return -1

0 commit comments

Comments
 (0)