gistfile1.txt import java.util.ArrayList;import java.util.Scanner;import java.util.*;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] array = {2, 7, 11, 5}; int t = sc.nextInt(); System
import java.util.ArrayList; import java.util.Scanner; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] array = {2, 7, 11, 5}; int t = sc.nextInt(); System.out.println(Arrays.toString(twoSum(array, t))); } public static int[] twoSum(int[] numbers, int target) { int[] a = new int[2]; HashMapmap = new HashMap (); for (int i = 0; i < numbers.length; i++) { if (map.containsKey(numbers[i])) { a[0] = map.get(numbers[i]); a[1] = i ; return a; } //存储差值为key,下标为value map.put(target - numbers[i], i ); } return a; } }