File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments