class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> ans(2,-1); //> fixed length of 2 unordered_map<int, int> table; //> hashmap int complement; for(auto i = 0; i < nums.size(); ++i) { complement = target - nums[i]; //> if the complement is already in unordered_map //> return the ans if(table.find(complement) != table.end()) { ans[0] = table[complement]; //> complement was inserted before i ans[1] = i; return ans; } //> insert to unordered_map //> key : element's value, value : index table[nums[i]] = i; } //> actually this line will never be executed return ans; } };