7 lines answer by javascript


  • 0
    H
    var twoSum = function(nums, target) {
        var hash = {};
        for (var i = 0, len = nums.length; i < len; i ++) {
            if (hash[target - nums[i]] !== undefined) {
                return [hash[target - nums[i]], i + 1];
            }
            hash[nums[i]] = i + 1;
        }
    };

Log in to reply
 

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