publicclassTwoSum{ publicint[] twoSum(int[] nums, int target) { Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { int key = target - nums[i];
if (map.contains(key)) returnnewint[]{map.get(key), i};
map.put(nums[i], i); } thrownew IllegalArgumentException("No two sum solution"); } }