Skip to content

Commit 2f62efd

Browse files
committed
adding valid-anagram
1 parent 35a8d68 commit 2f62efd

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

valid-anagram/daiyongg-kim.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class Solution:
2+
def isAnagram(self, s: str, t: str) -> bool:
3+
first = {}
4+
second = {}
5+
6+
for c in s:
7+
if c in first:
8+
first[c] += 1
9+
else:
10+
first[c] = 1
11+
12+
for c in t:
13+
if c in second:
14+
second[c] += 1
15+
else:
16+
second[c] = 1
17+
18+
return first == second
19+
20+
21+
# class Solution:
22+
# def isAnagram(self, s: str, t: str) -> bool:
23+
# first = {}
24+
25+
# if len(s) != len(t):
26+
# return False
27+
28+
# for i in range(len(s)):
29+
# if s[i] in first:
30+
# first[s[i]] += 1
31+
# else:
32+
# first[s[i]] = 1
33+
34+
# for i in range(len(t)):
35+
# if t[i] in first:
36+
# first[t[i]] -= 1
37+
# else:
38+
# return False
39+
40+
# for i in first.values():
41+
# if i != 0:
42+
# return False
43+
44+
# return True

0 commit comments

Comments
 (0)