Javascript O(n^2) I am happay because it works correctly


  • 0
    S

    var twoSum = function(nums, target) {
    let i=0,j=0,len;
    len = nums.length;
    for(i=0;i<len-1;i++){
    for(j=i+1;j<len;j++){
    if( target == (nums[i] + nums[j]) ){
    return [i,j]
    }
    }
    }
    };


Log in to reply
 

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