(int[] nums, int target)
| 24 | // } |
| 25 | |
| 26 | public int[] twoSum(int[] nums, int target) { |
| 27 | int len = nums.length; |
| 28 | HashMap<Integer, Integer> map = new HashMap<>(); |
| 29 | for (int i = 0; i < len; ++i) { |
| 30 | final Integer value = map.get(nums[i]); |
| 31 | if (value != null) { |
| 32 | return new int[] { value, i }; |
| 33 | } |
| 34 | map.put(target - nums[i], i); |
| 35 | } |
| 36 | return null; |
| 37 | } |
| 38 | |
| 39 | public static void main(String[] args) { |
| 40 | Solution solution = new Solution(); |