zoukankan      html  css  js  c++  java
  • 【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);
    }
  • 相关阅读:
    常见名词解释
    主板结构解析
    计算机网络原理的总结
    Nginx的介绍
    优雅的python
    python小技巧
    python列表小程序
    学会浏览器查东西
    列表推导式
    深度优先算法与广度优先算法
  • 原文地址:https://www.cnblogs.com/ganxiang/p/14018781.html
Copyright © 2011-2022 走看看