一个数组储存key
另一个数组储存value
class MyHashMap {
private int [] map=new int[100000];
private int [] mark=new int[100000];
/** Initialize your data structure here. */
public MyHashMap() {
}
/** value will always be non-negative. */
public void aput(int key, int value) {
map[key]=value;
mark[key]=1;
}
/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
public int get(int key) {
if(mark[key]==1){
return map[key];
}
return -1;
}
/** Removes the mapping of the specified value key if this map contains a mapping for the key */
public void remove(int key) {
mark[key]=0;
}
}
/**
* 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);
*/