public int[] twoSum (int[] numbers, int target) {
HashMap<Integer ,Integer> map = new HashMap<>();
for(int i = 0 ;i < numbers.length ;i++){
if (map.containsKey(target - numbers[i]))
return new int[]{map.get(target - numbers[i])+1,i+1};
map.put(numbers[i],i);
}
return new int[2];
}
牛客 NC61 两数之和(哈希表)
最新推荐文章于 2024-08-15 14:47:41 发布