Skip to content

Commit e1e3a2f

Browse files
committed
Time: 88 ms (97.13%), Space: 188.7 MB (16.95%) - LeetHub
1 parent a542245 commit e1e3a2f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

design-hashmap/design-hashmap.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#define N 1000007
2+
class MyHashMap {
3+
vector<int> vec;
4+
public:
5+
6+
/** Initialize your data structure here. */
7+
MyHashMap() {
8+
vec.assign(N, -1);
9+
}
10+
11+
/** value will always be non-negative. */
12+
void put(int key, int value) {
13+
vec[key] = value;
14+
}
15+
16+
/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
17+
int get(int key) {
18+
return vec[key];
19+
}
20+
21+
/** Removes the mapping of the specified value key if this map contains a mapping for the key */
22+
void remove(int key) {
23+
vec[key] = -1;
24+
}
25+
};
26+
27+
/**
28+
* Your MyHashMap object will be instantiated and called as such:
29+
* MyHashMap* obj = new MyHashMap();
30+
* obj->put(key,value);
31+
* int param_2 = obj->get(key);
32+
* obj->remove(key);
33+
*/

0 commit comments

Comments
 (0)