Javascript Problem


  • 0
    B

    Hi,

    I am attempting the problem in Javascript. Below is what I came up with but it doesnt seem to be working. Can anyone let me know what the problem is?

    Thanks in advance

    var addTwoNumbers = function(l1, l2) {
        
        var arr_one = [l1.val]
        var runner = l1.next
        while(runner !== null ){
          arr_one.push(runner.val)
          runner=runner.next
        }
        
        var arr_two = [l2.val]
        var runner2 = l2.next
        while(runner2 !== null ){
          arr_two.push(runner2.val)
          runner2=runner2.next
        }
        
        return Number(arr_one.reverse().join()) + Number (arr_two.reverse().join())
    };
    
    

Log in to reply
 

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