/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} l1
* @param {ListNode} l2
* @return {ListNode}
*/
var addTwoNumbers = function(l1, l2) {
var temp=(l1.val+l2.val)>=10?1:0;
var listNode=new ListNode((l1.val+l2.val)%10);
var L1=l1;
var L2=l2;
var ls=listNode;
while(L1.next||L2.next||temp==1){
L11=L1.next?L1.next.val:0;
L21=L2.next?L2.next.val:0
ls.next=new ListNode((L11+L21+temp)%10)
ls =ls.next;
temp=(L11+L21+temp)>=10?1:0;
L1=L1.next?L1.next:L1;
L2=L2.next?L2.next:L2
listNode.next==ls;
}
if(temp==1){
listNode.next =temp
return
}
return listNode;
};
javascript leetcode 两数相加
最新推荐文章于 2021-08-26 12:37:34 发布