LeetCode 705. Design HashSet (设计哈希集合)
生活随笔
收集整理的这篇文章主要介绍了
LeetCode 705. Design HashSet (设计哈希集合)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目标签:HashMap
题目让我们设计一个 hashset,有add,contains,remove 功能。
建立一个boolean array,index 是数字的值,具体看code。
Java Solution:
Runtime: 58 ms, faster than 90.21%
Memory Usage: 56.3 MB, less than 68.53%
完成日期:03/18/2019
关键点:boolean array
class MyHashSet {boolean [] set;/** Initialize your data structure here. */public MyHashSet() {set = new boolean[1000001];}public void add(int key) {set[key] = true;}public void remove(int key) {set[key] = false;}/** Returns true if this set contains the specified element */public boolean contains(int key) {return set[key];} }/*** Your MyHashSet object will be instantiated and called as such:* MyHashSet obj = new MyHashSet();* obj.add(key);* obj.remove(key);* boolean param_3 = obj.contains(key);*/参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
转载于:https://www.cnblogs.com/jimmycheng/p/10888009.html
总结
以上是生活随笔为你收集整理的LeetCode 705. Design HashSet (设计哈希集合)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: ubuntu 安装 CUDA、 cuDN
- 下一篇: 一点点学习PS--实战四