deno.land / x / masx200_leetcode_test@10.6.5 / merge-nodes-in-between-zeros / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { ArrayToListNode } from "../reverse-linked-list/ArrayToListNode.ts";import { ListNode } from "../reverse-linked-list/ListNode.ts";import { ListNodeIterator } from "./ListNodeIterator.ts";
export default function mergeNodes(head: ListNode | null): ListNode | null { const result: number[] = []; let sum = 0; for (const num of ListNodeIterator(head)) { if (num === 0) { if (sum > 0) { result.push(sum); } sum = 0; } else { sum += num; } } return ArrayToListNode(result);}
masx200_leetcode_test

Version Info

Tagged at
a year ago