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/

发布了286 篇原创文章 · 获赞 57 · 访问量 324万+

猜你喜欢

转载自blog.csdn.net/L1558198727/article/details/102846952
今日推荐