leetcode705+使用数组来模拟hashset

xiaoxiao2025-07-13  11

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

 

转载请注明原文地址: https://www.6miu.com/read-5033035.html

最新回复(0)