import java.util.*;
public class Solution {
/**
*
* @param numbers int整型一维数组
* @param target int整型
* @return int整型一维数组
*/
public int[] twoSum (int[] numbers, int target) {
// write code here
HashMap<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < numbers.length; i++){
if(!map.containsKey(target - numbers[i])){
map.put(numbers[i], i);
}else{
int[] list = new int[2];
list[0] = map.get(target - numbers[i]) + 1;
list[1] = i + 1;
return list;
}
}
return new int[0];
}
}
牛客TOP101-BM50
最新推荐文章于 2024-08-20 17:09:37 发布