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