C++ 6ms


  • 0
    T
    class Solution {
    public:
        vector<int> twoSum(vector<int>& nums, int target) {
            unordered_map<int,int> m;
            for (int i = 0; i < nums.size(); ++i) {
                if (m.find(target-nums[i]) != m.end())
                    return {m[target-nums[i]], i};
                m[nums[i]] = i;
            }
            return {};
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.