Share JavaScript code


  • 0
    X
    /**
     * @param {number[]} nums
     * @param {number} target
     * @return {number[]}
     */
    var twoSum = function(nums, target) {
        for (let i = 0; i < nums.length; i++) {
            if (nums.indexOf(target - nums[i]) != -1 && nums.indexOf(target - nums[i]) != i) {
                return [i, nums.indexOf(target - nums[i])];
            }
        }
    };
    

Log in to reply
 

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