-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW_20June.java
32 lines (28 loc) · 1.16 KB
/
HW_20June.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
public class HW_20June {
public Map<Set<Character>, List<String>> sameset(List<String> lst){
Map<Set<Character>, List<String>> mapp = new HashMap<>();
for (String s : lst) {
Set<Character> charset = new HashSet<>();
for (int j = 0; j < s.length(); j++) {
charset.add(s.charAt(j));
}
if (mapp.containsKey(charset)) {
mapp.get(charset).add(s);
} else if (!mapp.containsKey(charset)) {
List<String> tmp = new ArrayList<>();
tmp.add(s);
mapp.put(charset, tmp);
}
}
return mapp;
}
public static void main(String[] args) {
HW_20June hw = new HW_20June();
List<String> lst = new ArrayList<>(List.of("may", "student", "students", "dog", "studentssess", "god", "cat", "act",
"tab", "bat", "flow", "wolf", "lambs", "amy", "yam", "balms", "looped", "poodle", "tac"));
Map<Set<Character>, List<String>> megamap = hw.sameset(lst);
System.out.println(megamap);
System.out.println("Wow");
}
}