标签:shm put two sum ++ ash red hashmap tco for
1 class Solution { 2 public int[] twoSum(int[] nums, int target) { 3 Map<Integer, Integer> map = new HashMap<>(); 4 for (int i = 0; i < nums.length; i++) { 5 int desired = target - nums[i]; 6 if (map.containsKey(desired)) { 7 return new int[] {map.get(desired), i}; 8 } else { 9 map.put(nums[i], i); 10 } 11 } 12 return new int[2]; 13 } 14 }
标签:shm put two sum ++ ash red hashmap tco for
原文地址:https://www.cnblogs.com/eniac-inner/p/12468851.html