Skip to content

Commit d89fefb

Browse files
committed
Add group anagrams Solution - s0ooo0k
1 parent 15a6639 commit d89fefb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

group-anagrams/s0ooo0k.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public List<List<String>> groupAnagrams(String[] strs) {
3+
HashMap<String, List<String>> map = new HashMap<>();
4+
5+
for(String s : strs) {
6+
char[] c = s.toCharArray();
7+
Arrays.sort(c);
8+
9+
String key = new String(c);
10+
if(!map.containsKey(key)) {
11+
map.put(key, new ArrayList<>());
12+
}
13+
14+
map.get(key).add(s);
15+
}
16+
return new ArrayList<>(map.values());
17+
}
18+
}
19+
20+

0 commit comments

Comments
 (0)