File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Constraints:
3+ 1. 1 <= strs.length <= 10^4
4+ 2. 0 <= strs[i].length <= 100
5+ 3. strs[i] consists of lowercase English letters.
6+
7+ Time Complexity: O(N * K * log K)
8+ - N์ ์
๋ ฅ ๋ฌธ์์ด์ ๊ฐ์ (strs์ ๊ธธ์ด)
9+ - K๋ ๊ฐ์ฅ ๊ธด ๋ฌธ์์ด์ ๊ธธ์ด
10+ - ๊ฐ ๋ฌธ์์ด์ ์ ๋ ฌํ๋๋ฐ K * log K๊ฐ ํ์ํ๊ณ
11+ - ์ด๊ฑธ N๊ฐ์ ๋ฌธ์์ด์ ๋ํด ์ํ
12+
13+ Space Complexity: O(N * K)
14+ - N๊ฐ์ ๋ฌธ์์ด์ ์ ์ฅํด์ผ ํจ
15+ - ๊ฐ ๋ฌธ์์ด์ ๊ธธ์ด๋ ์ต๋ K
16+ - anagram_dict์ ๋ชจ๋ ๋ฌธ์์ด์ ์ ์ฅํ๊ธฐ ๋๋ฌธ
17+ """
18+
19+ class Solution :
20+ def groupAnagrams (self , strs : List [str ]) -> List [List [str ]]:
21+ anagram_dict = {}
22+
23+ for s in strs :
24+ sorted_str = '' .join (sorted (s ))
25+
26+ if sorted_str in anagram_dict :
27+ anagram_dict [sorted_str ].append (s )
28+ else :
29+ anagram_dict [sorted_str ] = [s ]
30+
31+ return list (anagram_dict .values ())
You canโt perform that action at this time.
0 commit comments