@@ -55,31 +55,18 @@ myHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]]
55
55
class MyHashMap :
56
56
57
57
def __init__ (self ):
58
- """
59
- Initialize your data structure here.
60
- """
61
58
self .data = [- 1 ] * 1000001
62
59
63
60
def put (self , key : int , value : int ) -> None :
64
- """
65
- value will always be non-negative.
66
- """
67
61
self .data[key] = value
68
62
69
63
def get (self , key : int ) -> int :
70
- """
71
- Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
72
- """
73
64
return self .data[key]
74
65
75
66
def remove (self , key : int ) -> None :
76
- """
77
- Removes the mapping of the specified value key if this map contains a mapping for the key
78
- """
79
67
self .data[key] = - 1
80
68
81
69
82
-
83
70
# Your MyHashMap object will be instantiated and called as such:
84
71
# obj = MyHashMap()
85
72
# obj.put(key,value)
@@ -91,26 +78,20 @@ class MyHashMap:
91
78
92
79
``` java
93
80
class MyHashMap {
81
+ private int [] data = new int [1000001 ];
94
82
95
- private int [] data;
96
-
97
- /* * Initialize your data structure here. */
98
83
public MyHashMap () {
99
- data = new int [1000001 ];
100
84
Arrays . fill(data, - 1 );
101
85
}
102
-
103
- /* * value will always be non-negative. */
86
+
104
87
public void put (int key , int value ) {
105
88
data[key] = value;
106
89
}
107
-
108
- /* * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
90
+
109
91
public int get (int key ) {
110
92
return data[key];
111
93
}
112
-
113
- /* * Removes the mapping of the specified value key if this map contains a mapping for the key */
94
+
114
95
public void remove (int key ) {
115
96
data[key] = - 1 ;
116
97
}
@@ -161,8 +142,8 @@ class MyHashMap {
161
142
``` cpp
162
143
class MyHashMap {
163
144
public:
164
- int hash[ 1000010] ;
165
-
145
+ int hash[ 1000010] ;
146
+
166
147
MyHashMap() {
167
148
memset(hash, -1, sizeof hash);
168
149
}
0 commit comments