File tree 5 files changed +108
-0
lines changed
5 files changed +108
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ All solutions will be accepted!
212
212
| 707| [ Design Linked List] ( https://leetcode-cn.com/problems/design-linked-list/description/ ) | [ java/py/js] ( ./algorithms/DesignLinkedList ) | Easy|
213
213
| 622| [ Design Circular Queue] ( https://leetcode-cn.com/problems/design-circular-queue/description/ ) | [ java/py/js] ( ./algorithms/DesignCircularQueue ) | Easy|
214
214
| 641| [ Design Circular Deque] ( https://leetcode-cn.com/problems/design-circular-deque/description/ ) | [ java/py/js] ( ./algorithms/DesignCircularDeque ) | Easy|
215
+ | 705| [ Design Hashset] ( https://leetcode-cn.com/problems/design-hashset/description/ ) | [ java/py/js] ( ./algorithms/DesignHashset ) | Easy|
215
216
216
217
# Database
217
218
| #| Title| Solution| Difficulty|
Original file line number Diff line number Diff line change
1
+ # Design Hashset
2
+ This problem is easy to solve
Original file line number Diff line number Diff line change
1
+ class MyHashSet {
2
+ int [] buckets ;
3
+
4
+ /** Initialize your data structure here. */
5
+ public MyHashSet () {
6
+ buckets = new int [1000000 ];
7
+ }
8
+
9
+ public void add (int key ) {
10
+ buckets [key ] = 1 ;
11
+ }
12
+
13
+ public void remove (int key ) {
14
+ buckets [key ] = 0 ;
15
+ }
16
+
17
+ /** Returns true if this set did not already contain the specified element */
18
+ public boolean contains (int key ) {
19
+ return buckets [key ] == 1 ;
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Your MyHashSet object will be instantiated and called as such:
25
+ * MyHashSet obj = new MyHashSet();
26
+ * obj.add(key);
27
+ * obj.remove(key);
28
+ * boolean param_3 = obj.contains(key);
29
+ */
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Initialize your data structure here.
3
+ */
4
+ var MyHashSet = function ( ) {
5
+ this . buckets = new Array ( 1000000 )
6
+ this . buckets . fill ( 0 )
7
+ } ;
8
+
9
+ /**
10
+ * @param {number } key
11
+ * @return {void }
12
+ */
13
+ MyHashSet . prototype . add = function ( key ) {
14
+ this . buckets [ key ] = 1
15
+ } ;
16
+
17
+ /**
18
+ * @param {number } key
19
+ * @return {void }
20
+ */
21
+ MyHashSet . prototype . remove = function ( key ) {
22
+ this . buckets [ key ] = 0
23
+ } ;
24
+
25
+ /**
26
+ * Returns true if this set did not already contain the specified element
27
+ * @param {number } key
28
+ * @return {boolean }
29
+ */
30
+ MyHashSet . prototype . contains = function ( key ) {
31
+ return this . buckets [ key ] === 1
32
+ } ;
33
+
34
+ /**
35
+ * Your MyHashSet object will be instantiated and called as such:
36
+ * var obj = Object.create(MyHashSet).createNew()
37
+ * obj.add(key)
38
+ * obj.remove(key)
39
+ * var param_3 = obj.contains(key)
40
+ */
Original file line number Diff line number Diff line change
1
+ class MyHashSet (object ):
2
+
3
+ def __init__ (self ):
4
+ """
5
+ Initialize your data structure here.
6
+ """
7
+ self .buckets = [0 ] * 1000000
8
+
9
+ def add (self , key ):
10
+ """
11
+ :type key: int
12
+ :rtype: void
13
+ """
14
+ self .buckets [key ] = 1
15
+
16
+ def remove (self , key ):
17
+ """
18
+ :type key: int
19
+ :rtype: void
20
+ """
21
+ self .buckets [key ] = 0
22
+
23
+ def contains (self , key ):
24
+ """
25
+ Returns true if this set did not already contain the specified element
26
+ :type key: int
27
+ :rtype: bool
28
+ """
29
+ return self .buckets [key ] == 1
30
+
31
+
32
+ # Your MyHashSet object will be instantiated and called as such:
33
+ # obj = MyHashSet()
34
+ # obj.add(key)
35
+ # obj.remove(key)
36
+ # param_3 = obj.contains(key)
You can’t perform that action at this time.
0 commit comments