-
Notifications
You must be signed in to change notification settings - Fork 6
/
0706.cpp
50 lines (36 loc) · 943 Bytes
/
0706.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class MyHashMap {
vector<pair<int, int>> map;
public:
MyHashMap() {
}
void put(int key, int value) {
if(get(key) != -1)
remove(key);
map.push_back(make_pair(key, value));
}
int get(int key) {
for(auto c : map)
if(c.first == key)
return c.second;
return -1;
}
void remove(int key) {
if(get(key) != -1){
auto it = map.begin();
while(true){
if(it -> first == key){
map.erase(it);
break;
}
it++;
}
}
}
};
/**
* Your MyHashMap object will be instantiated and called as such:
* MyHashMap* obj = new MyHashMap();
* obj->put(key,value);
* int param_2 = obj->get(key);
* obj->remove(key);
*/