@@ -0,0 +1,830 @@
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class LeetCode0380 %7B%0A%0A%09private Map%3CInteger, Integer%3E map;%0A%09private List%3CInteger%3E list;%0A%0A%09public LeetCode0380() %7B%0A%09%09map = new HashMap%3CInteger, Integer%3E();%0A%09%09list = new ArrayList%3CInteger%3E();%0A%0A%09%7D%0A%0A%09public boolean insert(int val) %7B%0A%09%09if (map.containsKey(val)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09map.put(val, list.size());%0A%09%09list.add(val);%0A%09%09return true;%0A%09%7D%0A%0A%09public boolean remove(int val) %7B%0A%09%09if (!map.containsKey(val)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09int index = map.get(val);%0A%09%09int lastIndex = list.size() - 1;%0A%09%09list.set(index, list.get(lastIndex));%0A%09%09map.put(list.get(lastIndex), index);%0A%09%09list.remove(lastIndex);%0A%09%09map.remove(val);%0A%09%09return true;%0A%09%7D%0A%0A%09public int getRandom() %7B%0A%09%09return list.get((int) (Math.random() * list.size()));%0A%09%7D%0A%7D%0A

Add LeetCode0380.java