class Solution {
public int[] twoSum(int[] nums, int target) {
int[] index = new int[2];
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for(int i =0;i<nums.length;i++)
{
if(map.get(target-nums[i])!=null)
{
index[0] = i;
index[1] = map.get(target-nums[i]);
break;
}
map.put(nums[i],i);
}
return index;
}
}
LeetCode-01两数之和
最新推荐文章于 2023-07-04 23:59:38 发布