We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f0a962d commit c27793aCopy full SHA for c27793a
valid-anagram/changhyumm.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def isAnagram(self, s: str, t: str) -> bool:
3
+ if len(s) != len(t):
4
+ return False
5
+ # sorted_s = sorted(s)
6
+ # sorted_t = sorted(t)
7
+ # for i in range(len(s)):
8
+ # if sorted_s[i] != sorted_t[i]:
9
+ # return False
10
+ # return True
11
+ # 시간복잡도가 O(nlog(n))
12
+
13
+ # Hashmap 사용하는 방법으로 변경
14
+ counter = {}
15
+ for char in s:
16
+ counter[char] = counter.get(char, 0) + 1
17
+ for char in t:
18
+ if char in counter and counter[char] != 0:
19
+ counter[char] -= 1
20
+ elif char in counter and counter[char] == 0:
21
22
+ else:
23
24
+ # 시간복잡도 O(n)
25
+ # 공간복잡도 O(n)
26
+ return True
0 commit comments