编辑代码

public class Java {
  /**
      运行时间 0ms
      内存消耗 38.7MB
   */
  public static int[] twoSum(int[] nums, int target) {
    int length = nums.length;
    int result[] = {0, 0};
    for (int i = 0; i < length - 1; i ++) {
      for (int j = i + 1; j < length; j ++) {
        if (nums[i] + nums[j] == target) {
          result[0] = i;
          result[1] = j;
          return result;
        }
      }
    }
    return result;
  }

  // 以下是测试代码 -----------------------
  
  public static void main(String[] args) {
    int nums[] = {2, 7, 1, 0, 11, 15};
    int target = 2;
    int result[] = twoSum(nums, target);

    for (int i : result) {
			System.out.print(i + " ");
    }
  }
}