My javascript solution.


  • 0
    C
    var res=new ListNode(null);
    var pointer=res;
    while(l1||l2){
        l1===null?l1=new ListNode(0):l1;
        l2===null?l2=new ListNode(0):l2;
        var sum=l1.val+l2.val;
        pointer.next=new ListNode(sum%10);
        if(l1.val+l2.val>=10){
            var f=Math.floor(sum/10);
            l1.next?l1.next.val+=f:l1.next=new ListNode(f);
        }
        l1=l1.next;
        l2=l2.next;
        pointer=pointer.next;
    }
    return res.next;

Log in to reply
 

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