Skip to content

Commit e4704af

Browse files
authored
feat: add cpp solution to lc problem: No.706 (doocs#802)
No.0706.Design HashMap/README.md * Add cpp solution * Add cpp solution * Added Solution file
1 parent 03714d3 commit e4704af

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

solution/0700-0799/0706.Design HashMap/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,37 @@ class MyHashMap {
168168
*/
169169
```
170170

171-
### **...**
171+
### **C++**
172172

173-
```
173+
```cpp
174+
class MyHashMap {
175+
public:
176+
int hash[1000010];
177+
178+
MyHashMap() {
179+
memset(hash, -1, sizeof hash);
180+
}
181+
182+
void put(int key, int value) {
183+
hash[key] = value;
184+
}
185+
186+
int get(int key) {
187+
return hash[key];
188+
}
189+
190+
void remove(int key) {
191+
hash[key] = -1;
192+
}
193+
};
174194

195+
/**
196+
* Your MyHashMap object will be instantiated and called as such:
197+
* MyHashMap* obj = new MyHashMap();
198+
* obj->put(key,value);
199+
* int param_2 = obj->get(key);
200+
* obj->remove(key);
201+
*/
175202
```
176203
177204
<!-- tabs:end -->

solution/0700-0799/0706.Design HashMap/README_EN.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,37 @@ class MyHashMap {
156156
*/
157157
```
158158

159-
### **...**
159+
### **C++**
160160

161-
```
161+
```cpp
162+
class MyHashMap {
163+
public:
164+
int hash[1000010];
165+
166+
MyHashMap() {
167+
memset(hash, -1, sizeof hash);
168+
}
169+
170+
void put(int key, int value) {
171+
hash[key] = value;
172+
}
173+
174+
int get(int key) {
175+
return hash[key];
176+
}
177+
178+
void remove(int key) {
179+
hash[key] = -1;
180+
}
181+
};
162182

183+
/**
184+
* Your MyHashMap object will be instantiated and called as such:
185+
* MyHashMap* obj = new MyHashMap();
186+
* obj->put(key,value);
187+
* int param_2 = obj->get(key);
188+
* obj->remove(key);
189+
*/
163190
```
164191
165192
<!-- tabs:end -->
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class MyHashMap {
2+
public:
3+
int hash[1000010];
4+
5+
MyHashMap() {
6+
memset(hash, -1, sizeof hash);
7+
}
8+
9+
void put(int key, int value) {
10+
hash[key] = value;
11+
}
12+
13+
int get(int key) {
14+
return hash[key];
15+
}
16+
17+
void remove(int key) {
18+
hash[key] = -1;
19+
}
20+
};
21+
22+
/**
23+
* Your MyHashMap object will be instantiated and called as such:
24+
* MyHashMap* obj = new MyHashMap();
25+
* obj->put(key,value);
26+
* int param_2 = obj->get(key);
27+
* obj->remove(key);
28+
*/

0 commit comments

Comments
 (0)