Accepted Javascript Solution (top 90%)


  • 0
    J

    https://leetcode.com/submissions/detail/86462989/

    /**
     * @param {number[]} nums
     * @param {number} target
     * @return {number[]}
     */
    var twoSum = function(nums, target) {
        const map = {};
        let compliment;
        for (let idx = 0; idx < nums.length; idx++) {
            compliment = target - nums[idx];
            if (compliment in map) return [map[compliment], idx];
            map[nums[idx]] = idx;
        }
    };
    

Log in to reply
 

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