We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 80f0577 commit e7b8456Copy full SHA for e7b8456
solution/0049.Group Anagrams/Solution.java
@@ -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