We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d8603c8 commit 628cc1aCopy full SHA for 628cc1a
242.py
@@ -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
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