7 Lines C++ Solution (Using unordered_map,O(n) )


  • 0
    K
            unordered_map<int, int> map;
            for (int i = 0; i < nums.size(); i++) {
                int k=map[target-nums[i]];
                if(k!=0)
                    return {k-1,i};
                map[nums[i]]=i+1;}
            return vector<int> ();
        }```

Log in to reply
 

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