@@ -0,0 +1,548 @@
+import java.util.Random;%0A%0Apublic class _382LinkedListRandomNode %7B%0A%09ListNode head;%0A%09Random r;%0A%09%0A%09public _382LinkedListRandomNode(ListNode head) %7B%0A        this.head = head;%0A        r = new Random();%0A    %7D%0A    %0A    public int getRandom() %7B%0A    %09ListNode thisN = head;%0A    %09ListNode result = null;%0A        for (int n = 1; thisN != null; n++) %7B%0A        %09if (r.nextInt(n) == 0) result = thisN;%0A        %09thisN = thisN.next;%0A        %7D%0A    %09return result.val;%0A    %7D%0A%09%0A%09public class ListNode %7B%0A%09%09int val;%0A%09%09ListNode next;%0A%09%09ListNode(int x) %7B val = x; %7D%0A%09%7D%0A%7D%0A

Add 382 solution