deno.land / x / masx200_leetcode_test@10.6.5 / linked-list-random-node / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const array = Symbol();import { ListNode } from "../mod.ts";
class Solution { [array]: number[] = []; constructor(head: ListNode | null) { while (head) { this[array].push(head.val);
head = head.next; } }
getRandom(): number { return this[array][Math.floor(this[array].length * Math.random())]; }}
export default Solution;
masx200_leetcode_test

Version Info

Tagged at
a year ago