382. Linked List Random Node 发表于 2022-01-16 12345678910111213141516171819202122class Solution { private final ListNode head; public Solution(ListNode head) { this.head = head; } public int getRandom() { int bound = 1, res = 0; ListNode node = head; while (node != null) { if (ThreadLocalRandom.current().nextInt(bound) == 0) { res = node.val; } bound++; node = node.next; } return res; }} Reference382. Linked List Random Node