题解 | #两数之和#
两数之和
http://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
双指针遍历:
import java.util.*;
public class Solution {
/**
*
* @param numbers int整型一维数组
* @param target int整型
* @return int整型一维数组
*/
public int[] twoSum (int[] numbers, int target) {
int[] res = {0,0};
int k = 0;
for (int i = 0; i < numbers.length; i++){
for (int j = numbers.length-1; j > 0; j--){
if (i != j && i < j && numbers[i] + numbers[j] == target){
res[0] = i+1;
res[1] = j+1;
}
}
}
return res;
}
}