js solution


  • 0
    N
    var twoSum = function(nums, target) {
        var ret = [], temp = [];
        outer:
        for(var i = 0; i < nums.length; i++){
            if(temp[target - nums[i]] != undefined){
                ret.push(temp[target - nums[i]], i);
                break outer;     
            }
            temp[nums[i]] = i;
        }
        return ret;
    };
    

Log in to reply
 

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