File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Blind 75 - Group Anagrams
3+ LeetCode Problem: https://leetcode.com/problems/group-anagrams/
4+ ์๊ฐ๋ณต์ก๋ : O(N * K) (N์ strs์ ๊ธธ์ด, K๋ strs ๋ด ๋ฌธ์์ด์ ์ต๋ ๊ธธ์ด)
5+ ๊ณต๊ฐ๋ณต์ก๋ : O(N * K)
6+ ํ์ด : ํด์๋งต์ ์ด์ฉํ ํ์ด
7+ ASCII ๋ฌธ์๋ฅผ ์ด์ฉํ์ฌ ๊ฐ ๋ฌธ์์ด์ ๋ฌธ์ ๊ฐ์๋ฅผ ์ธ์ด ์ด๋ฅผ ํค๋ก ์ฌ์ฉํ์ฌ ํด์๋งต์ ์ ์ฅํ๋ค
8+
9+ """
10+
11+ from typing import List
12+ from collections import defaultdict
13+ class Solution :
14+ def groupAnagrams (self , strs : List [str ]) -> List [List [str ]]:
15+ anagrams = defaultdict (list )
16+
17+ for s in strs :
18+ count = [0 ] * 26
19+ for char in s :
20+ count [ord (char ) - ord ('a' )] += 1
21+ anagrams [tuple (count )].append (s )
22+
23+ return list (anagrams .values ())
24+
You canโt perform that action at this time.
0 commit comments