- 这是一链表的运算
var addTwoNumbers = function(l1, l2) {
let dummy = new ListNode()
let curr = dummy
let cotree = 0
while(l1!==null || l2 !==null){
let sum = 0
if(l1!==null){
sum += l1.val
l1 = l1.next
}
if(l2!==null){
sum += l2.val
l2 = l2.next
}
sum+=cotree
curr.next = new ListNode(sum % 10)
cotree=Math.floor(sum / 10)
curr = curr.next
}
if(cotree>0){
curr.next = new ListNode(cotree)
}
return dummy.next
};
- 表达的应该清楚了吗,不清楚大家讨论下