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 6885833 commit caac245Copy full SHA for caac245
1 file changed
โgroup-anagrams/essaysir.javaโ
@@ -0,0 +1,23 @@
1
+class Solution {
2
+ public List<List<String>> groupAnagrams(String[] strs) {
3
+ // ์๋๊ทธ๋จ์ ๊ทธ๋ฃน๋ณ๋ก ๋ง๋ค์ด๋ผ
4
+ // ์๋๊ทธ๋จ -> ๊ฐ string ์ ๋ฐฐ์นํด์ ๋ง๋ค ์ ์๋ ๊ฐ ?
5
+ // ๊ฐ ์ํ๋ฒณ์ด ๋ช๊ฐ๊ฐ ์๋ ๊ฐ ?
6
+ List<List<String>> answer = new ArrayList<>();
7
+ Map<String, List<String>> map = new HashMap<>();
8
+
9
+ for ( int i = 0; i < strs.length; i ++) {
10
+ char[] chars = strs[i].toCharArray();
11
+ Arrays.sort(chars);
12
13
+ String s = new String(chars);
14
+ map.computeIfAbsent(s, k -> new ArrayList<>()).add(strs[i]);
15
+ }
16
17
+ for (List<String> group : map.values()) {
18
+ answer.add(group);
19
20
21
+ return answer;
22
23
+}
0 commit comments