deno.land / x / masx200_leetcode_test@10.6.5 / sum-lists-lcci / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ListNode } from "../reverse-linked-list/ListNode.ts";
function addTwoNumbers( l1: ListNode | null, l2: ListNode | null,): ListNode | null { if (!l1) { return l2; } if (!l2) { return l1; }
const head = new ListNode(0); let temp: ListNode | null = head; let p1: ListNode | null = l1; let p2: ListNode | null = l2; let carry = 0; while (p1 || p2 || carry) { if (p1) { carry += p1.val; p1 = p1.next; } if (p2) { carry += p2.val; p2 = p2.next; } temp.next = new ListNode(carry % 10); temp = temp.next; carry = Math.floor(carry / 10); } return head.next;}export default addTwoNumbers;
masx200_leetcode_test

Version Info

Tagged at
a year ago