LeeCode 705. 設計哈希集合

設計哈希集合
日後再補

class MyHashSet {
public:
    /** Initialize your data structure here. */
    bool vis[1000010];
    MyHashSet() {
        memset(vis,0,sizeof(vis));
    }
    
    void add(int key) {
        vis[key] = 1;
    }
    
    void remove(int key) {
        vis[key] = 0;
    }
    
    /** Returns true if this set contains the specified element */
    bool contains(int key) {
        return vis[key];
    }
};

/**
 * Your MyHashSet object will be instantiated and called as such:
 * MyHashSet* obj = new MyHashSet();
 * obj->add(key);
 * obj->remove(key);
 * bool param_3 = obj->contains(key);
 */
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章