class MyHashMap {
private:vector<int> hashmap;
public:
/** Initialize your data structure here. */
MyHashMap() {
hashmap = vector<int> (100000,-1);
}
/** value will always be non-negative. */
void put(int key, int value) {
hashmap[key] = value;
return;
}
/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
int get(int key) {
return hashmap[key];
}
/** Removes the mapping of the specified value key if this map contains a mapping for the key */
void remove(int key) {
hashmap[key] = -1;
return;
}
};
/**
* 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);
*/
leetcode刷题 706 设计哈希映射 (C++)
最新推荐文章于 2021-11-20 17:41:18 发布