File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ ๏ปฟ #ํด์
2
+ #๋ฌธ์์ด s์ ์ฌ๋ฐฐ์น๋ก ๋ฌธ์์ด t๋ฅผ ๊ตฌ์ฑํ ์ ์์ผ๋ฉด anagram์ผ๋ก return true.
3
+ #s์ t๋ฅผ list๋ก ๋ฐ๊พธ๊ณ sortํ์ฌ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ์ํจ๋ค, ๋์ด ๊ฐ์ผ๋ฉด ๊ฐ์ ๋ฌธ์๋ฅผ ๊ฐ์ง ๋ฌธ์์ด ๋ฆฌ์คํธ์ด๋ฏ๋ก return true
4
+
5
+ #Big O
6
+ #N: ์ฃผ์ด์ง ๋ฌธ์์ด s์ t์ ๊ธธ์ด(N)
7
+
8
+ #Time Complexity: O(N)
9
+ #- ๋ฌธ์์ด์ list๋ก ๋ณํํ๋ ์์
: O(N)
10
+ #- ์ ๋ ฌ์์
: NO(log N)
11
+ #- ๋ฆฌ์คํธ ๋น๊ต ์์
, s์ t์ ๊ฐ ๋ฌธ์๊ฐ ์๋ก ์ผ์นํ๋์ง ์ฒดํฌํ๋ค : O(N)
12
+ #- ์ต์ข
: O(N)
13
+
14
+ #Space Complexity: O(N)
15
+ #- list s์ t๋ ์ฃผ์ด์ง ๋ฌธ์์ด s์ t์ ๊ธฐ๋ฐํ์ฌ ์๋ก์ด list ๊ฐ์ฒด๋ก ํ ๋น๋๋ค: O(N)
16
+
17
+ class Solution (object ):
18
+ def isAnagram (self , s , t ):
19
+ """
20
+ :type s: str
21
+ :type t: str
22
+ :rtype: bool
23
+ """
24
+ s = list (s ) #Convert string to list
25
+ t = list (t )
26
+ s .sort () #Sort the list
27
+ t .sort ()
28
+
29
+ return s == t #If the s and t are same, return true(anagram)
30
+
31
+
32
+
You canโt perform that action at this time.
0 commit comments