class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int,int> mp;
for(size_t i=0;i<nums.size();++i){
auto it=mp.find(target-nums[i]);
if(it!=mp.end())
return {it->second,i};
else mp[nums[i]]=i;
}
return {-1,-1};
}
};
1. 两数之和
最新推荐文章于 2021-12-22 14:49:33 发布