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 typing import *
2+
3+
4+ class Solution :
5+ """
6+ ํ์ด:
7+ s์ t ๊ธธ์ด๊ฐ ๋ค๋ฅด๋ฉด anagram ์๋๋ฏ๋ก False๋ก early return
8+ set์ผ๋ก s์ ์ค๋ณต ๋ฌธ์ ์ ๊ฑฐ
9+ set์ ์ํํ๋ฉด์ ๊ฐ ๋ฌธ์๊ฐ s์ t์์ ๋ฑ์ฅํ๋ ํ์๊ฐ ๋์ผํ์ง ํ์ธ
10+ ๋ค๋ฅด๋ฉด False, ๋๊น์ง ํต๊ณผํ๋ฉด True
11+
12+ TC: O(n+m)
13+ - if len(s) != len(t): O(1)
14+ - ss = set(s): O(n)
15+ - for c in ss: ์ต๋ 26ํ ๋ฐ๋ณต โ O(1)
16+ - s.count(c): O(n)
17+ - t.count(c): O(m)
18+ - ์ต์ข
: O(n+m)
19+
20+ SC: O(n)
21+ - ss = set(s): ์ต์
์ ๊ฒฝ์ฐ O(n)
22+ - ๊ทธ ์ธ ์์: O(1)
23+ - ์ต์ข
: O(n)
24+ """
25+ def isAnagram (self , s : str , t : str ) -> bool :
26+ if len (s ) != len (t ):
27+ return False
28+
29+ ss = set (s )
30+ for c in ss :
31+ if s .count (c ) != t .count (c ):
32+ return False
33+
34+ return True
You canโt perform that action at this time.
0 commit comments