We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 80d28c8 commit 8bccad8Copy full SHA for 8bccad8
scala/0242-valid-anagram.scala
@@ -0,0 +1,33 @@
1
+// Time Complexity: O(s + t)
2
+// Space Comeplexity: O(s + t)
3
+
4
+import scala.collection.mutable.Map
5
6
+object Solution {
7
+ def isAnagram(s: String, t: String): Boolean = {
8
+ if (s.length() != t.length())
9
+ return false
10
11
+ var charCount = Map[Char, Int]()
12
13
+ for (c <- s) {
14
+ if (charCount.contains(c))
15
+ charCount(c) = charCount(c) + 1
16
+ else
17
+ charCount += (c -> 1)
18
+ }
19
20
+ for (c <- t) {
21
22
+ charCount(c) = charCount(c) - 1
23
24
25
26
27
+ for ((_, v) <- charCount)
28
+ if (v != 0)
29
30
31
+ return true
32
33
+}
0 commit comments