import java.util.*; public class Solution { /** * * @param numbers int整型一维数组 * @param target int整型 * @return int整型一维数组 */ public int[] twoSum (int[] numbers, int target) { Map<Integer, Integer> map = new HashMap<>(); int[] result = {-1, -1}; for (int i = 0; i < numbers.length; i++) { int sum = target - numbers[i]; if (map.get(sum) != null) { return new int[]{map.get(sum) + 1, i + 1}; } map.put(numbers[i], i); } return result; } }