leetcode 705. 设计哈希集合

看了范围不是很大使用了数组,不是正规解法

class MyHashSet {
public:
    /** Initialize your data structure here. */
    bool * hx;
    MyHashSet() {
        hx = new bool [1000001];
        memset( hx,0,1000001 );
    }

    void add(int key) {
        hx[key] = true;
    }

    void remove(int key) {
        hx[key] = false;
    }

    /** Returns true if this set contains the specified element */
    bool contains(int key) {
        return hx[key];
    }
};

在这里插入图片描述

有时间学习正规的解法吧:(拖延症)
https://leetcode-cn.com/problems/design-hashset/comments/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章