leetcode705+使用数组来模拟hashset

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/83378878

https://leetcode.com/problems/design-hashset/description/

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

/**
 * 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);
 */

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/83378878
今日推荐