申请个很大的数组,数组的索引值代表着这个数。
class MyHashSet {
boolean[] set;
/** Initialize your data structure here. */
public MyHashSet() {
this.set = new boolean[99999];
}
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];
}
}
为啥别人都是申请1000001这么大?