Skip to content

Commit e7b8456

Browse files
49. Group Anagrams (java)
1 parent 80f0577 commit e7b8456

File tree

1 file changed

+13
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)