class MyHashSet {
public:
    /** Initialize your data structure here. */
    MyHashSet() {
        
    }
    
    void add(int key) {
        if(set[key] == 0)
            set[key]++;
    }
    
    void remove(int key) {
        if(set[key] > 0)
            set[key]--;
    }
    
    /** Returns true if this set contains the specified element */
    bool contains(int key) {
        if(set[key] > 0)
            return true;
        return false;
    }
private:
    int set[1000010] = {0};
};

 

posted on 2018-10-01 12:49  Sempron2800+  阅读(129)  评论(0编辑  收藏  举报