File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from collections import Counter
2+
3+ class Solution :
4+ def isAnagram (self , s : str , t : str ) -> bool :
5+ """
6+ s์ t๊ฐ ์๋๊ทธ๋จ์ธ์ง ํ์ธํ๋ ํจ์.
7+ ์๋๊ทธ๋จ์ ๋ฌธ์์ด์ ๋ฌธ์๋ค์ด ๋์ผํ์ง๋ง ์์๊ฐ ๋ค๋ฅธ ๊ฒฝ์ฐ๋ฅผ ๋งํจ. ๋์๋ฌธ์๋ ๊ตฌ๋ถํ์ง ์์ง๋ง, ์ธ์ด๋ง๋ค์ ํน์ ๊ธฐํธ ๋ฑ์ ๊ณ ๋ คํด์ผ ํจ.
8+
9+ ๋ฐฉ๋ฒ:
10+ 1. s์ t๋ฅผ ์ ๋ ฌํ์ฌ ๋น๊ต; o(nlogn) ์๊ฐ๋ณต์ก๋
11+ 2. s์ t์ ๊ฐ ๋ฌธ์์ ๋น๋์๋ฅผ ์ธ์ด ๋น๊ต; o(n) ์๊ฐ๋ณต์ก๋
12+ -> ์ค์ dict๋ก ๊ตฌํํ๊ธฐ๋ณด๋ค Counter๋ฅผ ์ฌ์ฉํ๋ฉด o(n)์์๋ ์ฝ๊ฐ ๋น ๋ฅด๊ฒ ๊ตฌํ ๊ฐ๋ฅ
13+
14+ * ์ธ์ด๋ง๋ค์ ํน์ ๋ฌธ์/๊ธฐํธ๋ฅผ ๊ณ ๋ คํด์ผ ํด, casefold()๋ฅผ ์ฌ์ฉ.
15+
16+ Args:
17+ s (str): ๋น๊ตํ ๋ฌธ์์ด 1
18+ t (str): ๋น๊ตํ ๋ฌธ์์ด 2
19+
20+ Returns:
21+ bool: s์ t๊ฐ ์๋๊ทธ๋จ์ด๋ฉด True, ์๋๋ฉด False
22+ """
23+ return Counter (s .casefold ()) == Counter (t .casefold ())
You canโt perform that action at this time.
0 commit comments