Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
471 B
3
Indexable
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> num_map;
        for(int i = 0; i < nums.size(); i++) {
            if (num_map.find(target - nums[i]) != num_map.end()) {
                vector<int> rv{num_map.find(target - nums[i])->second, i};
                return rv;
            }
            num_map.insert({nums[i], i});
        }
        vector<int> rv{};
        return rv;
    }
};