和为S的两个数字:
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def FindNumbersWithSum(self, array, tsum): 4 n = len(array) 5 i,j = 0,n-1 6 while i<j: 7 cur = array[i] + array[j] 8 if cur == tsum: 9 return [array[i],array[j]] 10 if cur < tsum: 11 i += 1 12 else: 13 j -= 1 14 return [] 15 # write code here