标签:返回值 int numbers two sum throw ++ i++ tar target
水题
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map=new HashMap();
for (int i=0; i<nums.length; i++){
int tmp=target-nums[i];
if (map.containsKey(tmp)){
int idx=map.get(tmp);
if (i!=idx) return new int[]{idx, i};
}map.put(nums[i], i);
}
throw new IllegalArgumentException();
}
}
标签:返回值 int numbers two sum throw ++ i++ tar target
原文地址:https://www.cnblogs.com/tanglizi/p/11493520.html