package leetcode;

/**
 * https://leetcode.com/problems/random-pick-index/
 */
public class Problem398 {
    public static class Solution {

        public Solution(int[] nums) {

        }

        public int pick(int target) {
            // TODO
            return 0;
        }
    }

    public static void main(String[] args) {
        // TODO
    }
}

@@ -16,128 +16,378 @@
 e;%0A%0A
-/**%0A * https://leetcode.com/problems/random-pick-index/%0A */%0Apublic class Problem398 %7B%0A    public static class Solution %7B
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Random;%0A%0A/**%0A * https://leetcode.com/problems/random-pick-index/%0A */%0Apublic class Problem398 %7B%0A    public static class Solution %7B%0A        private final Map%3CInteger, List%3CInteger%3E%3E map = new HashMap%3C%3E();%0A        private final Random random = new Random();
 %0A%0A  
@@ -422,25 +422,24 @@
 nums) %7B%0A
-%0A
         
 %7D%0A%0A     
@@ -434,91 +434,158 @@
     
-%7D%0A%0A
     
-    public int pick(int target) %7B%0A            // TODO%0A            return 0;%0A
+for (int i = 0; i %3C nums.length; i++) %7B%0A                map.putIfAbsent(nums%5Bi%5D, new ArrayList%3C%3E());%0A                map.get(nums%5Bi%5D).add(i);%0A    
     
@@ -590,16 +590,20 @@
       %7D%0A
+    
     %7D%0A%0A 
@@ -609,64 +609,195 @@
     
+ 
+   
 public 
-static void main(String%5B%5D args) %7B%0A        // TODO
+int pick(int target) %7B%0A            List%3CInteger%3E indices = map.get(target);%0A            int idx = random.nextInt(indices.size());%0A            return indices.get(idx);%0A        %7D
 %0A   

Solve problem 398