public class twoSum {
public static int[] twoSum(int[] nums, int target) {
int[] res = new int[2];
Map<Integer,Integer> map = new HashMap<>();
for(int i = 0 ; i < nums.length ;i++){
if(map.containsKey(target-nums[i])){
res[0] = i;
res[1] = map.get(target-nums[i]);
}
map.put(nums[i],i);
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入数组长度");
int n = sc.nextInt();
int[] nums = new int[n];
for(int i = 0 ; i < n;i++){
nums[i] = sc.nextInt();
}
System.out.println("输入目标和");
int target = sc.nextInt();
int[] forRes = twoSum(nums,target);
for(int i : forRes){
System.out.print(i+" ");
}
}
}