经典的twos m问题变种,传入已排序的序列 题目如下 given an array of integers that is already sorted in ascending order, find two n mbers s ch that they add p to a specific target n mber. the f nction twos m sho ld ret rn indices of the two n mbers s ch that they add p to the target, where index1 m st be less than index2. note: yo r ret rned answers (both index1 and index2) are not zero-based. yo may ass me that each inp t wo ld have exactly one sol tion and yo may not se the same element twice. example: inp t: n mbers = [2,7,11,15], target = 9 o tp t: [1,2] explanation: the s m of 2 and 7 is 9. therefore index1 = 1, index2 = 2. 第一种解法,利用二分查找 时间复杂度o(n*log(n)) 空间复杂度o(1) 解题思路: 由于传入的是已排序序列,所以我们可以利用二分查找的高性能来帮助我们优化查找另一个数的过程. 插入一个二分查找的介绍 二分查找: binary search compares the target val e to the middle element of the array;