deno.land / x / masx200_leetcode_test@10.6.5 / copy-list-with-random-pointer / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Node } from "./Node.ts";
const cachedNode = new WeakMap<Node, Node>();export default function copyRandomList(head: Node | null): Node | null { if (head === null) { return null; } if (!cachedNode.has(head)) { const cloned = new Node(); cachedNode.set(head, cloned);
cloned.val = head.val; cloned.next = copyRandomList(head.next); cloned.random = copyRandomList(head.random); return cloned; } const result = cachedNode.get(head); return result ? result : null;}
masx200_leetcode_test

Version Info

Tagged at
a year ago