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--实战四