Skip to content

Commit a956404

Browse files
refactor 705
1 parent bdd650b commit a956404

File tree

1 file changed

+24
-49
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+24
-49
lines changed

src/main/java/com/fishercoder/solutions/_705.java

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,34 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
/**
7-
* 705. Design HashSet
8-
*
9-
* Design a HashSet without using any built-in hash table libraries.
10-
*
11-
* To be specific, your design should include these functions:
12-
*
13-
* add(value): Insert a value into the HashSet.
14-
* contains(value) : Return whether the value exists in the HashSet or not.
15-
* remove(value): Remove a value in the HashSet. If the value does not exist in the HashSet, do nothing.
16-
*
17-
* Example:
18-
*
19-
* MyHashSet hashSet = new MyHashSet();
20-
* hashSet.add(1);
21-
* hashSet.add(2);
22-
* hashSet.contains(1); // returns true
23-
* hashSet.contains(3); // returns false (not found)
24-
* hashSet.add(2);
25-
* hashSet.contains(2); // returns true
26-
* hashSet.remove(2);
27-
* hashSet.contains(2); // returns false (already removed)
28-
*
29-
* Note:
30-
*
31-
* All values will be in the range of [0, 1000000].
32-
* The number of operations will be in the range of [1, 10000].
33-
* Please do not use the built-in HashSet library.
34-
*/
356
public class _705 {
36-
public static class Solution1 {
37-
class MyHashSet {
38-
Map<Integer, Integer> map;
7+
public static class Solution1 {
8+
class MyHashSet {
9+
Map<Integer, Integer> map;
3910

40-
/** Initialize your data structure here. */
41-
public MyHashSet() {
42-
map = new HashMap<>();
43-
}
11+
/**
12+
* Initialize your data structure here.
13+
*/
14+
public MyHashSet() {
15+
map = new HashMap<>();
16+
}
4417

45-
public void add(int key) {
46-
map.put(key, 0);
47-
}
18+
public void add(int key) {
19+
map.put(key, 0);
20+
}
4821

49-
public void remove(int key) {
50-
if (map.containsKey(key)) {
51-
map.remove(key);
52-
}
53-
}
22+
public void remove(int key) {
23+
if (map.containsKey(key)) {
24+
map.remove(key);
25+
}
26+
}
5427

55-
/** Returns true if this set contains the specified element */
56-
public boolean contains(int key) {
57-
return map.containsKey(key);
58-
}
28+
/**
29+
* Returns true if this set contains the specified element
30+
*/
31+
public boolean contains(int key) {
32+
return map.containsKey(key);
33+
}
34+
}
5935
}
60-
}
6136
}

0 commit comments

Comments
 (0)