File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ LeetCode 最强题解(持续更新中):
2121| [ 0209.长度最小的子数组] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0209.长度最小的子数组.md ) | 数组 | ** 暴力** ** 滑动窗口** |
2222| [ 0237.删除链表中的节点] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0237.删除链表中的节点.md ) | 链表 | ** 原链表移除** ** 添加虚拟节点** 递归|
2323| [ 0383.赎金信] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md ) | 数组 | ** 暴力** ** 字典计数** |
24- | [ 0575.分糖果.md] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md ) | 哈希表 | ** 模拟** |
24+ | [ 0575.分糖果.md] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0575.分糖果.md ) | 哈希表 | ** 哈希** |
25+ | [ 0705.设计哈希集合.md] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0705.设计哈希集合.md ) | 哈希表 | ** 模拟** |
2526| [ 0707.设计链表] ( https://github.com/youngyangyang04/leetcode/blob/master/problems/0707.设计链表.md ) | 链表 | ** 模拟** |
2627
2728
Original file line number Diff line number Diff line change 1+ ## 题目地址
2+ https://leetcode-cn.com/problems/design-hashset/
3+
4+ ## 思路
5+
6+ 使用数组便可以实现这个哈希集合
7+
8+ ## 代码
9+ ```
10+ class MyHashSet {
11+
12+ public:
13+ vector<int> hashTable;
14+ /** Initialize your data structure here. */
15+ MyHashSet() {
16+ vector<int> table(1000001, 0);
17+ hashTable = table;
18+ }
19+
20+ void add(int key) {
21+ hashTable[key] = 1;
22+ }
23+
24+ void remove(int key) {
25+ hashTable[key] = 0;
26+ }
27+
28+ /** Returns true if this set contains the specified element */
29+ bool contains(int key) {
30+ return hashTable[key];
31+ }
32+ };
33+ ```
You can’t perform that action at this time.
0 commit comments