Not sure why this question is locked.....it is apparently easier....
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. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
// Since the array is already sorted, two pointer then....
See http://blog.youkuaiyun.com/github_34333284/article/details/51102967
本文介绍了一种在已排序的整数数组中寻找两个数使其和等于特定目标值的方法。该方法利用了双指针技巧,使得查找过程更加高效。文章还提及了题目的一些约束条件,例如解的存在唯一性和返回的索引要求。
211

被折叠的 条评论
为什么被折叠?



