class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> hashTable;
for(int i = 0; i < nums.size(); i++){
auto item = hashTable.find(target - nums[i]);
if(item != hashTable.end()){
return {item->second, i};
}
hashTable[nums[i]] = i;
}
return {};
}
};
LeetCode Hot100 1.两数之和
最新推荐文章于 2024-11-13 11:37:20 发布