mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update
This commit is contained in:
@ -21,7 +21,8 @@ LeetCode 最强题解(持续更新中):
|
|||||||
|[0209.长度最小的子数组](https://github.com/youngyangyang04/leetcode/blob/master/problems/0209.长度最小的子数组.md) |数组 | **暴力** **滑动窗口**|
|
|[0209.长度最小的子数组](https://github.com/youngyangyang04/leetcode/blob/master/problems/0209.长度最小的子数组.md) |数组 | **暴力** **滑动窗口**|
|
||||||
|[0237.删除链表中的节点](https://github.com/youngyangyang04/leetcode/blob/master/problems/0237.删除链表中的节点.md) |链表 | **原链表移除** **添加虚拟节点** 递归|
|
|[0237.删除链表中的节点](https://github.com/youngyangyang04/leetcode/blob/master/problems/0237.删除链表中的节点.md) |链表 | **原链表移除** **添加虚拟节点** 递归|
|
||||||
|[0383.赎金信](https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md) |数组 |**暴力** **字典计数**|
|
|[0383.赎金信](https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md) |数组 |**暴力** **字典计数**|
|
||||||
|[0575.分糖果.md](https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md) |哈希表 |**模拟**|
|
|[0575.分糖果.md](https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md) |哈希表 |**哈希**|
|
||||||
|
|[0705.设计哈希集合.md](https://github.com/youngyangyang04/leetcode/blob/master/problems/0705.设计哈希集合.md) |哈希表 |**模拟**|
|
||||||
|[0707.设计链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0707.设计链表.md) |链表 |**模拟**|
|
|[0707.设计链表](https://github.com/youngyangyang04/leetcode/blob/master/problems/0707.设计链表.md) |链表 |**模拟**|
|
||||||
|
|
||||||
|
|
||||||
|
33
problems/0705.设计哈希集合.md
Normal file
33
problems/0705.设计哈希集合.md
Normal 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];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
Reference in New Issue
Block a user