File tree Expand file tree Collapse file tree 3 files changed +86
-4
lines changed
solution/0700-0799/0706.Design HashMap Expand file tree Collapse file tree 3 files changed +86
-4
lines changed Original file line number Diff line number Diff line change @@ -168,10 +168,37 @@ class MyHashMap {
168
168
*/
169
169
```
170
170
171
- ### ** ... **
171
+ ### ** C++ **
172
172
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
+ };
174
194
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
+ * /
175
202
```
176
203
177
204
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -156,10 +156,37 @@ class MyHashMap {
156
156
*/
157
157
```
158
158
159
- ### ** ... **
159
+ ### ** C++ **
160
160
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
+ };
162
182
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
+ * /
163
190
```
164
191
165
192
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments