【leetcode】706. 设计哈希映射

 

typedef struct {
    int hash[1000001];
} MyHashMap;

/** Initialize your data structure here. */

MyHashMap* myHashMapCreate() {
    MyHashMap* obj=(MyHashMap*)malloc(sizeof(MyHashMap)*1);
    memset(obj->hash,-1,1000001*sizeof(int));
    return obj;
}

/** value will always be non-negative. */
void myHashMapPut(MyHashMap* obj, int key, int value) {
    obj->hash[key]=value;
}

/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
int myHashMapGet(MyHashMap* obj, int key) {
    return obj->hash[key];
}

/** Removes the mapping of the specified value key if this map contains a mapping for the key */
void myHashMapRemove(MyHashMap* obj, int key) {
    obj->hash[key]=-1;
}

void myHashMapFree(MyHashMap* obj) {
    free(obj);
}

 

posted @ 2020-11-22 12:06  温暖了寂寞  阅读(124)  评论(0编辑  收藏  举报