參考資訊:
https://www.cnblogs.com/grandyang/p/4130379.html
題目:
解答:
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> r; for (int i = 0; i < nums.size(); i++) { if (r.count(target - nums[i])) { return {i, r[target - nums[i]]}; } r[nums[i]] = i; } return {}; } };