File tree 1 file changed +0
-34
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +0
-34
lines changed Original file line number Diff line number Diff line change 6
6
import java .util .Map ;
7
7
import java .util .Random ;
8
8
9
- /**
10
- * 380. Insert Delete GetRandom O(1)
11
- * Design a data structure that supports all following operations in average O(1) time.
12
- *
13
- * insert(val): Inserts an item val to the set if not already present.
14
- * remove(val): Removes an item val from the set if present.
15
- * getRandom: Returns a random element from current set of elements. Each element must have the same probability of being returned.
16
- * Example:
17
- *
18
- * // Init an empty set.
19
- * RandomizedSet randomSet = new RandomizedSet();
20
- *
21
- * // Inserts 1 to the set. Returns true as 1 was inserted successfully.
22
- * randomSet.insert(1);
23
- *
24
- * // Returns false as 2 does not exist in the set.
25
- * randomSet.remove(2);
26
- *
27
- * // Inserts 2 to the set, returns true. Set now contains [1,2].
28
- * randomSet.insert(2);
29
- *
30
- * // getRandom should return either 1 or 2 randomly.
31
- * randomSet.getRandom();
32
- *
33
- * // Removes 1 from the set, returns true. Set now contains [2].
34
- * randomSet.remove(1);
35
- *
36
- * // 2 was already in the set, so return false.
37
- * randomSet.insert(2);
38
- *
39
- * // Since 2 is the only number in the set, getRandom always return 2.
40
- * randomSet.getRandom();
41
- */
42
-
43
9
public class _380 {
44
10
45
11
public static class Solution1 {
You can’t perform that action at this time.
0 commit comments