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/

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