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 f1aa488 commit 4230e0bCopy full SHA for 4230e0b
1 file changed
โgroup-anagrams/gcount85.pyโ
@@ -0,0 +1,21 @@
1
+"""
2
+# Approach
3
+strs ๋ฐฐ์ด์ ์ํํ๋ฉฐ ๋ฌธ์์ด์ ์ ๊ทํ(์ ๋ ฌ)ํ๊ณ ,
4
+์ ๊ทํ ๊ฐ์ด ๊ฐ์ ์์๋ค๋ผ๋ฆฌ ๋ชจ์ด๋๋ก ๋์ ๋๋ฆฌ์ ์ถ๊ฐํ์ฌ ์ต์ข ๊ฐ์ ๋ฐํํ๋ค.
5
+
6
+# Complexity
7
+strs์ ๊ธธ์ด๋ฅผ N, ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ K๋ผ๊ณ ํ ๋,
8
9
+- Time complexity: O(N*KlogK)
10
+- Space complexity: O(N*K)
11
12
13
+from collections import defaultdict
14
15
16
+class Solution:
17
+ def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
18
+ anagram = defaultdict(list) # normalized str : str list
19
+ for s in strs:
20
+ anagram["".join(sorted(s))].append(s)
21
+ return list(anagram.values())
0 commit comments