Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.
Note:
Your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution and you may not use the same element twice.
1 注意此题不是zero-based的,不过因为在原list中的相对位置是固定的,所以还是可以以zero-based coding,只是最后返回值的时候都加上1就可以了
2 还需注意的时候,返回的index需要按从小到大的顺序排
3 依旧用dictionary减少时间复杂度
4 依次遍历numbers中的number,如果target-number在dict中,说明找到配对的了,返回index,如果不在,则讲number加在dic中去。注意这里是判断target-number在不在dict中,不是判断number。
5 添加元素到dic中,使用dic[a] =i,这样同时添加了index和value