Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
分析思路:
1. 最简单的方法是用两个循环进行暴力搜索,显然这样的方法复杂度比较高 O(n^2)
2. 可以先sort,然后从左右两边进行sum,如果最左边的值(最小值)加最右边的值(最大值)大于target的值,我们可以从右边的最大值往左移动,反之,如果