Skip to content

Commit 628cc1a

Browse files
committed
Easy String
1 parent d8603c8 commit 628cc1a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

242.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#242
2+
from collections import defaultdict,Counter
3+
class Solution:
4+
def isAnagram(self, s: str, t: str) -> bool:
5+
## Comparing the sorted strings
6+
return sorted(s) == sorted(t)
7+
## Comparing two hash maps
8+
return Counter(s) == Counter(t)
9+
10+
## intutive solution
11+
dic = {}
12+
13+
for a in s:
14+
if a in dic:
15+
dic[a] += 1
16+
else:
17+
dic[a] = 1
18+
for b in t:
19+
if b in dic:
20+
dic[b] -= 1
21+
else:
22+
dic[b] = -1
23+
#print(max(dic.values()))
24+
if max(dic.values()) == 0 and min(dic.values()) == 0:
25+
return True
26+
## for video pl watch : https://www.youtube.com/watch?v=9UtInBqnCgA
27+

0 commit comments

Comments
 (0)