HashSet implementation

    0

    0

    Mansimar Anand

    class HashSet {
    private:
        int size = 1e6+2;
        vector<bool> v;
    public:
        /** Initialize your data structure here. */
        HashSet() {
            v.resize(size, false);
        }
        void add(int key) {
            v[key] = true;
        }
        void remove(int key) {
            v[key] = false;
        }
        /** Returns true if this set contains the specified element */
        bool contains(int key) {
            return v[key];
        }
    };
    /**
     * Your HashSet object will be instantiated and called as such:
     * Your HashSet object will be instantiated and called as such:
     * HashSet* obj = new HashSet();
     * HashSet* obj = new HashSet();
     * obj->add(key);
     * obj->add(key);
     * obj->remove(key);
     * obj->remove(key);
     * bool param_3 = obj->contains(key);
     * bool param_3 = obj->contains(key);
     */
     */
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.