Short and Simple, C++


  • 0
    R
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int,int> map;
        for(int i=0;i<nums.size();i++){
            map[nums[i]]=i;
        }
        for(int i=0;i<nums.size();i++){
            if(map.find(target-nums[i])!=map.end()&&i!=map[target-nums[i]])
                return {i,map[target-nums[i]]};
        }
    }

Log in to reply
 

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