题目描述:
image.png
示例:
image.png
解题思路:
可以用数组,时间复杂度小,但是空间复杂度大,而且要事先知道key的范

解:

class MyHashSet {

boolean[] hashSet=null;

public MyHashSet() {

hashSet =new boolean[1000001];

}

public void add(int key) {

hashSet[key]=true;

}

public void remove(int key) {

hashSet[key]=false;

}

public boolean contains(int key) {

return hashSet[key];

}

}