This commit is contained in:
youngyangyang04
2020-06-27 15:15:26 +08:00
parent 865c4c317c
commit 6738cf2473
2 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,33 @@
## 题目地址
https://leetcode-cn.com/problems/design-hashset/
## 思路
使用数组便可以实现这个哈希集合
## 代码
```
class MyHashSet {
public:
vector<int> hashTable;
/** Initialize your data structure here. */
MyHashSet() {
vector<int> table(1000001, 0);
hashTable = table;
}
void add(int key) {
hashTable[key] = 1;
}
void remove(int key) {
hashTable[key] = 0;
}
/** Returns true if this set contains the specified element */
bool contains(int key) {
return hashTable[key];
}
};
```