x/masx200_leetcode_test/linked-list-random-node/index.ts
12345678910111213141516171819const 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;