<span style="font-size:18px;">public class Solution {
public static int[] twoSum(int[] numbers, int target) {
int [] idx=new int[2];
Map<Integer, Integer> m=new HashMap<Integer,Integer>();
for(int i=0;i<numbers.length;i++){
if(m.containsKey(target-numbers[i])){
idx[0]=m.get(target-numbers[i])+1;
idx[1]=i+1;
}
else{
m.put(numbers[i],i);
}
}
return idx;
}</span>
LeetCode1 TwoSum Java
最新推荐文章于 2021-03-23 00:49:15 发布