Accepted JavaScript solution


  • 0
    M
    var twoSum = function(nums, target) {
            let result = [];
            for (let i = 0; i < nums.length; i++){
                if (nums.indexOf(target - nums[i]) !== -1){
                    let index1 = nums.indexOf(target - nums[i])
                    result .push(i)
                    result .push(index1)
                    return result 
                }
            }
            return false;
        }
    

Log in to reply
 

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