//知识点:哈希/vector
#include<iostream>
using namespace std;
#include<vector>
class MyHashSet {
public:
MyHashSet() {
hashset.resize(1000001, 0);
}
void add(int key) {
hashset[key] = true;
}
void remove(int key) {
hashset[key] = false;
}
bool contains(int key) {
return hashset[key];
}
private:
vector<int> hashset;
};
/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet* obj = new MyHashSet();
* obj->add(key);
* obj->remove(key);
* bool param_3 = obj->contains(key);
*/
void test01() {
MyHashSet S;
S.add(1);
bool jd = S.contains(2);
cout << jd << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
Leetcode刷题-705设计哈希集合
最新推荐文章于 2024-08-15 05:02:54 发布