考场上没啥纠结的,直接双循环暴力解决 也可以拿到分!注意数组下标就行了
两数之和
http://www.nowcoder.com/questionTerminal/20ef0972485e41019e39543e8e895b7f
public int[] twoSum (int[] numbers, int target) { // write code here int [] twoindex = new int[2]; for(int i = 0;i<numbers.length-1;i++){ for(int j = i+1;j<numbers.length;j++){ if((numbers[i]+numbers[j])==target){ twoindex[0]=i+1; twoindex[1]=j+1; return twoindex; } } } return null; }