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 c8870f6 commit 2973412Copy full SHA for 2973412
valid-anagram/flynn.py
@@ -0,0 +1,25 @@
1
+'''
2
+For N, length of the given strings,
3
+
4
+Time Complexity: O(N)
5
+- first iteration: O(N)
6
+- second iteration: O(N)
7
8
+Space Compelxity: O(N)
9
+- dictionaries for each strings: O(N)
10
11
12
+class Solution:
13
+ def isAnagram(self, s: str, t: str) -> bool:
14
+ if len(s) != len(t):
15
+ return False
16
17
+ count_s, count_t = {}, {}
18
+ for i in range(len(s)):
19
+ count_s[s[i]] = count_s.get(s[i], 0) + 1
20
+ count_t[t[i]] = count_t.get(t[i], 0) + 1
21
22
+ for c in count_s:
23
+ if c not in count_t or count_s[c] != count_t[c]:
24
25
+ return True
0 commit comments