705. Design HashSet
HashSet
add contains next notes HashSet O(1) O(1) O(h/n) h is the table
HashMap
get containsKey next Notes HashMap O(1) O(1) O(h/n) h is the table
Last updated
add contains next notes
HashSet O(1) O(1) O(h/n) h is the table get containsKey next Notes
HashMap O(1) O(1) O(h/n) h is the table Last updated
class MyHashSet {
boolean[] set;
/** Initialize your data structure here. */
public MyHashSet() {
set = new boolean[1000001];
}
public void add(int key) {
set[key] = true;
}
public void remove(int key) {
set[key] = false;
}
/** Returns true if this set contains the specified element */
public boolean contains(int key) {
return set[key];
}
}