382. Linked List Random Node


https://leetcode.com/problems/linked-list-random-node/


Runtime: 116 ms, faster than 26.74% of Python3 online submissions for Linked List Random Node.
Memory Usage: 17.4 MB, less than 60.32% of Python3 online submissions for Linked List Random Node.



```python
import random

class Solution:
    def __init__(self, head: Optional[ListNode]):
        """
        @param head The linked list's head.
        Note that the head is guaranteed to be not null, so it contains at least one node.
        """
        #6:16
        self.l = []
        node = head
        while node:
            self.l.append(node.val)
            node = node.next
        #6:18

    def getRandom(self) -> int:
        """
        Returns a random node's value.
        """
        return random.choice(self.l)
```
