We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9a3440c commit 65cac1eCopy full SHA for 65cac1e
dart/0242-valid-anagram.dart
@@ -0,0 +1,24 @@
1
+// Time Complexity: O(s + t)
2
+// Space Complexity: O(1)
3
+
4
+class Solution {
5
+ bool isAnagram(String s, String t) {
6
+ if (s.length != t.length) return false;
7
8
+ final counter = List.filled(26, 0);
9
10
+ for (int i = 0; i < s.length; i++) {
11
+ counter[s[i].codeUnitAt(0) - 'a'.codeUnitAt(0)]++;
12
+ }
13
14
+ for (int i = 0; i < t.length; i++) {
15
+ counter[t[i].codeUnitAt(0) - 'a'.codeUnitAt(0)]--;
16
17
18
+ for (int val in counter) {
19
+ if (val != 0) return false;
20
21
22
+ return true;
23
24
+}
0 commit comments