File tree Expand file tree Collapse file tree 1 file changed +0
-18
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-18
lines changed Original file line number Diff line number Diff line change 6
6
import java .util .Map ;
7
7
import java .util .Random ;
8
8
9
- /**382. Linked List Random Node
10
- *
11
- Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.
12
-
13
- Follow up:
14
- What if the linked list is extremely large and its length is unknown to you? Could you solve this efficiently without using extra space?
15
-
16
- Example:
17
-
18
- // Init a singly linked list [1,2,3].
19
- ListNode head = new ListNode(1);
20
- head.next = new ListNode(2);
21
- head.next.next = new ListNode(3);
22
- Solution solution = new Solution(head);
23
-
24
- // getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning.
25
- solution.getRandom();
26
- */
27
9
public class _382 {
28
10
29
11
public static class Solution1 {
You can’t perform that action at this time.
0 commit comments