-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathProblem5.java
More file actions
39 lines (32 loc) · 814 Bytes
/
Problem5.java
File metadata and controls
39 lines (32 loc) · 814 Bytes
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
// Time Complexity : O(1)
// Space Complexity : O(N)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : No
class MyHashMap {
int[] map;
boolean[] exists;
public MyHashMap() {
map = new int[1000001];
exists = new boolean[1000001];
}
public void put(int key, int value) {
map[key] = value;
exists[key] = true;
}
public int get(int key) {
if (exists[key]) {
return map[key];
}
return -1;
}
public void remove(int key) {
exists[key] = false;
}
}
/**
* 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);
*/