package leetcode;

/**
 * https://leetcode.com/problems/insert-delete-getrandom-o1/
 */
public class Problem380 {
    public static class RandomizedSet {

        /** Initialize your data structure here. */
        public RandomizedSet() {

        }

        /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
        public boolean insert(int val) {
            return false;
        }

        /** Removes a value from the set. Returns true if the set contained the specified element. */
        public boolean remove(int val) {
            return false;
        }

        /** Get a random element from the set. */
        public int getRandom() {
            return 0;
        }
    }

    public static void main(String[] args) {

    }
}

@@ -16,142 +16,648 @@
 e;%0A%0A
-/**%0A * https://leetcode.com/problems/insert-delete-getrandom-o1/%0A */%0Apublic class Problem380 %7B%0A    public static class RandomizedSet %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/insert-delete-getrandom-o1/%0A */%0Apublic class Problem380 %7B%0A    private static class Value %7B%0A        private int idx;%0A        private final int val;%0A%0A        public Value(int idx, int val) %7B%0A            this.idx = idx;%0A            this.val = val;%0A        %7D%0A    %7D%0A%0A    public static class RandomizedSet %7B%0A        private final Map%3CInteger, Value%3E map = new HashMap%3C%3E();%0A        private final List%3CValue%3E list = new ArrayList%3C%3E();%0A        private final Random random = new Random();
 %0A%0A  
@@ -735,25 +735,24 @@
 izedSet() %7B%0A
-%0A
         %7D%0A%0A 
@@ -921,199 +921,826 @@
     
-return false;%0A        %7D%0A%0A        /** Removes a value from the set. Returns true if the set contained the specified element. */%0A        public boolean remove(int val) %7B%0A            return fals
+if (map.containsKey(val)) %7B%0A                return false;%0A            %7D%0A            int idx = list.size();%0A            Value value = new Value(idx, val);%0A            list.add(value);%0A            map.put(val, value);%0A            return true;%0A        %7D%0A%0A        /** Removes a value from the set. Returns true if the set contained the specified element. */%0A        public boolean remove(int val) %7B%0A            if (!map.containsKey(val)) %7B%0A                return false;%0A            %7D%0A            Value value = map.remove(val);%0A            int deletedIdx = value.idx;%0A            Value last = list.get(list.size() - 1);%0A            if (deletedIdx != last.idx) %7B%0A                last.idx = deletedIdx;%0A                list.set(deletedIdx, last);%0A            %7D%0A            list.remove(list.size() - 1);%0A            return tru
 e;%0A 
@@ -1848,16 +1848,45 @@
     
-return 0
+int idx = random.nextInt(list.size())
 ;%0A  
@@ -1895,62 +1895,80 @@
     
-%7D%0A
     
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A
+Value value = list.get(idx);%0A            return value.val;%0A        %7D
 %0A   

Solve problem 380