File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 6ms
3+ * Time Complexity: O(n x k log k)
4+ * - n: ๋ฌธ์์ด ๊ฐ์
5+ * - k: ๋ฌธ์์ด ์ต๋ ๊ธธ์ด
6+ * - k log k: ๊ฐ ๋ฌธ์์ด์ ์ ๋ ฌํ๋ ์๊ฐ
7+ *
8+ * Memory: 49.30MB
9+ * Space Complexity: O(n x k)
10+ * - ์ต๋ n๊ฐ์ ํค-๊ฐ
11+ *
12+ * Approach: ์ ๋ ฌ๋ ๋ฌธ์์ด์ ํค๋ก ์ฌ์ฉํด์ ๊ฐ์ ์ ๋๊ทธ๋จ๋ผ๋ฆฌ ๊ทธ๋ฃนํ
13+ */
14+ class Solution {
15+ public List <List <String >> groupAnagrams (String [] strs ) {
16+ Map <String , List <String >> anagramMap = new HashMap <>();
17+
18+ for (String str : strs ) {
19+ char [] chs = str .toCharArray ();
20+ Arrays .sort (chs );
21+ String key = new String (chs );
22+
23+ anagramMap .computeIfAbsent (key , k -> new ArrayList <>())
24+ .add (str );
25+ }
26+
27+ return new ArrayList <>(anagramMap .values ());
28+ }
29+ }
You canโt perform that action at this time.
0 commit comments