其他分享
首页 > 其他分享> > 167. 两数之和 II - 输入有序数组

167. 两数之和 II - 输入有序数组

作者:互联网

# 前后两个指针往中间靠
class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: i = 0 j = len(numbers) - 1 result = [] while i < j: if numbers[i] + numbers[j] > target: j -= 1 elif numbers[i] + numbers[j] < target: i += 1 else: result.append(i+1) result.append(j+1) break return result

 

标签:target,int,List,append,II,numbers,167,两数,result
来源: https://www.cnblogs.com/bidesen/p/16220226.html