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 it = hashtable.find(target - nums[i]); // 查找value(index)
if (it != hashtable.end()) { // 判断value是否在字典中
return {it->second, i}; // it->first和it->second, 分别得到key和value
}
hashtable[nums[i]] = i;
}
return {};
}
};