package leetcode;

/**
 * https://leetcode.com/problems/random-pick-with-weight/
 */
public class Problem528 {
    public static class Solution {
        public Solution(int[] w) {
        }

        public int pickIndex() {
            // TODO
            return 0;
        }
    }

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

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Random;%0A%0A
 /**%0A * h
@@ -178,33 +178,181 @@
    p
-ublic Solution(int%5B%5D w) %7B
+rivate final Random random = new Random();%0A        private int sum;%0A%0A        public Solution(int%5B%5D w) %7B%0A            for (int i : w) %7B%0A                sum += i;%0A            %7D
 %0A   
@@ -408,15 +408,40 @@
     
-// TODO
+int index = random.nextInt(sum);
 %0A   

Update problem 528