We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
求两数相加, 链表表示 ListNode L1, ListNode L2 input 1 -> 4 -> 3, 5 -> 6 -> 4; output 6 -> 0 -> 8 ;
function addTwoNumber(l1, l2) { let pre = new ListNode(0); let cur = pre; let stash = 0; while(l1 !== null || l2 !== null) { let add; let x = l1 === null ? 0 : l1.val; let y = l2 === null ? 0 : l2.val; (add = x + y + stash) > 10 ? (stash = 1) : (stash = 0); cur.next = new ListNode(add % 10); l1 && (l1 = l1.next); l2 && (l2 = l2.next); } if(stash === 1) cur.next = new ListNode(stash); return pre.next; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
leetcode 2
求两数相加, 链表表示
ListNode L1, ListNode L2
input 1 -> 4 -> 3, 5 -> 6 -> 4;
output 6 -> 0 -> 8 ;
The text was updated successfully, but these errors were encountered: