leetcode705+使用陣列來模擬hashset
阿新 • • 發佈:2018-11-01
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); */