@@ -57,13 +57,77 @@ hashMap.get(2); // returns -1 (not foun
57
57
### ** Python3**
58
58
59
59
``` python
60
-
60
+ class MyHashMap :
61
+
62
+ def __init__ (self ):
63
+ """
64
+ Initialize your data structure here.
65
+ """
66
+ self .data = [- 1 ] * 1000001
67
+
68
+ def put (self , key : int , value : int ) -> None :
69
+ """
70
+ value will always be non-negative.
71
+ """
72
+ self .data[key] = value
73
+
74
+ def get (self , key : int ) -> int :
75
+ """
76
+ Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
77
+ """
78
+ return self .data[key]
79
+
80
+ def remove (self , key : int ) -> None :
81
+ """
82
+ Removes the mapping of the specified value key if this map contains a mapping for the key
83
+ """
84
+ self .data[key] = - 1
85
+
86
+
87
+
88
+ # Your MyHashMap object will be instantiated and called as such:
89
+ # obj = MyHashMap()
90
+ # obj.put(key,value)
91
+ # param_2 = obj.get(key)
92
+ # obj.remove(key)
61
93
```
62
94
63
95
### ** Java**
64
96
65
97
``` java
66
-
98
+ class MyHashMap {
99
+
100
+ private int [] data;
101
+
102
+ /* * Initialize your data structure here. */
103
+ public MyHashMap () {
104
+ data = new int [1000001 ];
105
+ Arrays . fill(data, - 1 );
106
+ }
107
+
108
+ /* * value will always be non-negative. */
109
+ public void put (int key , int value ) {
110
+ data[key] = value;
111
+ }
112
+
113
+ /* * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
114
+ public int get (int key ) {
115
+ return data[key];
116
+ }
117
+
118
+ /* * Removes the mapping of the specified value key if this map contains a mapping for the key */
119
+ public void remove (int key ) {
120
+ data[key] = - 1 ;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Your MyHashMap object will be instantiated and called as such:
126
+ * MyHashMap obj = new MyHashMap();
127
+ * obj.put(key,value);
128
+ * int param_2 = obj.get(key);
129
+ * obj.remove(key);
130
+ */
67
131
```
68
132
69
133
### ** ...**
0 commit comments