Skip to content

Commit a64b61f

Browse files
committed
[LC] feat: 240824 is_anagram
1 parent b9ae750 commit a64b61f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

valid-anagram/hajunyoo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import defaultdict
2+
3+
4+
class Solution:
5+
def isAnagram(self, s: str, t: str) -> bool:
6+
char_map = defaultdict(int)
7+
for s1 in s:
8+
char_map[s1] += 1
9+
10+
contrast_map = defaultdict(int)
11+
for t1 in t:
12+
contrast_map[t1] += 1
13+
14+
for key, val in char_map.items():
15+
contrast_val = contrast_map[key]
16+
if contrast_val != val:
17+
return False
18+
19+
for key, val in contrast_map.items():
20+
char_val = char_map[key]
21+
if char_val != val:
22+
return False
23+
24+
return True
25+

0 commit comments

Comments
 (0)