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 026e627 commit e343f20Copy full SHA for e343f20
valid-anagram/Totschka.ts
@@ -0,0 +1,34 @@
1
+// https://leetcode.com/problems/valid-anagram/
2
+
3
+/**
4
+ * @SC `O(N)`
5
+ * @TC `O(N)`
6
+ */
7
+namespace use_hashmap {
8
+ function isAnagram(s: string, t: string): boolean {
9
+ if (s.length !== t.length) {
10
+ return false;
11
+ }
12
+ const counter = {};
13
+ for (const char of s) {
14
+ counter[char] = (counter[char] || 0) + 1;
15
16
+ for (const char of t) {
17
+ if (!counter[char]) {
18
19
20
+ counter[char] = counter[char] - 1;
21
22
+ return true;
23
24
+}
25
26
27
28
+ * @TC `O(Nlog(N))`
29
30
+namespace naive_approach {
31
32
+ return [...s].sort().join('') === [...t].sort().join('');
33
34
0 commit comments