分析
代码
/** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode} */var addTwoNumbers=function(l1, l2) { let dummyHead = new ListNode(0), node=dummyHead; let overflow=0, a, b, c, val; while(l1!==null || l2!==null) { a=(l1===null)?0:l1.val; b=(l2===null)?0:l2.val; c=a+b+overflow; val=c%10; overflow=Math.floor(c/10); node.next=new ListNode(val); node=node.next; if(l1!==null) l1=l1.next; if(l2!==null) l2=l2.next; } if(overflow!==0) { node.next=new ListNode(overflow); } return dummyHead.next;}