public class Solution { public int[] twoSum(int[] numbers, int target) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. int[] results = 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){ results[0] = i + 1; results[1] = j + 1; return results; } } } return results; } }
原文:http://www.cnblogs.com/RazerLu/p/3533416.html