leetCode 两数相加

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function(l1, l2) {

    let list = new ListNode()
    let current = list
    let next = 0
    while(l1||l2||next){
        let x = l1 ? l1.val : 0
        let y = l2 ? l2.val : 0
        let val = x + y + next
        if( val >= 10 ){
            val = val-10
            next = 1
        }else{
            next = 0
        }
        current.val = val
        current.next = null
        l1 = l1 ? l1.next : null
        l2 = l2 ? l2.next : null
        if(l1||l2||next){
            current.next = new ListNode()
            current = current.next
        }
        
    }

    return list
    
};