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