Easy
target-cur
的坐标即可。坐标+1
和目标值的坐标+1
以上,尝试写一下代码,AC!
python3
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
for left,v in enumerate(numbers):
offset = bisect.bisect_left(numbers[left+1:],target-v)
right = offset + left + 1
if right >= len(numbers):
continue
if v + numbers[right] == target:
return [left+1,right+1]
以上,尝试写一下代码,AC!
python3
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
i = 0
j = len(numbers) - 1
for _ in range(len(numbers)):
t = numbers[i] + numbers[j]
if t < target:
i += 1
elif t == target:
return [i+1,j+1]
else:
j -= 1
return [0,0]