题目
代码分析
两层循环
代码实现
public static int[] twoSum(int[] nums, int target) { int[] res = new int[2]; for (int i = 0; i < nums.length-1; i++) { int temp = target - nums[i]; for (int j = i+1 ; j < nums.length; j++) { if (nums[j] == temp) { res[0] = i; res[1] = j; break; } } } return res; }