分析:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> hash; //这里哈希表存的是值对下标的映射
for (int i = 0; i < nums.size(); i ++) {
int r = target - nums[i];
if (hash.count(r)) return {hash[r], i};
hash[nums[i]] = i; // 把nums[i]插入到哈希表中
}
return {};
}
};