File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 5
5
* @use: holding frequency map, similar to multiset in c++
6
6
*/
7
7
class MultiSet <K > {
8
+
8
9
private HashMap <K , Integer > multiSet = new HashMap <K , Integer >();
9
10
private int size ;
10
- int get (K key ){
11
+
12
+ public int get (K key ){
11
13
return multiSet .getOrDefault (key , 0 );
12
14
}
13
15
14
- void add (K key ){
16
+ public void add (K key ){
15
17
size ++;
16
18
multiSet .put (key , get (key )+ 1 );
17
19
}
18
20
19
- void remove (K key ){
21
+ public void remove (K key ){
20
22
int freq = get (key );
21
23
size --;
22
24
if (freq == 1 ){
@@ -33,6 +35,10 @@ public int size(){
33
35
public boolean isEmpty (){
34
36
return size == 0 ;
35
37
}
38
+
39
+ public boolean containsKey (K key ){
40
+ return multiSet .containsKey (key );
41
+ }
36
42
37
43
@ Override
38
44
public String toString (){
You can’t perform that action at this time.
0 commit comments