Linked List Random Node LeetCode solution in Python

1
class Solution:
2
def __init__(self, head: Optional[ListNode]):
3
self.ll = []
4
while head:
5
self.ll.append(head.val)
6
head = head.next
7

8
def getRandom(self) -> int:
9
return self.ll[randint(0, len(self.ll) - 1)]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0