705. Design HashSet
class MyHashSet {
Integer[] set;
public MyHashSet() {
this.set = new Integer[1000000];
}
public void add(int key) {
int index = computeHash(key);
if (!contains(key)) {
this.set[index] = key;
}
}
public void remove(int key) {
int index = computeHash(key);
if (contains(key)) {
this.set[index] = null;
}
}
public boolean contains(int key) {
int index = computeHash(key);
if (this.set[index] != null) {
return true;
} else {
return false;
}
}
public int computeHash(int key) {
return key % this.set.length;
}
}