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 6a0a279 commit 6e98ee9Copy full SHA for 6e98ee9
valid-anagram/hyunjung-choi.kt
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ fun isAnagram(s: String, t: String): Boolean {
3
+ if (s.length != t.length) return false
4
+
5
+ val charCount = mutableMapOf<Char, Int>()
6
7
+ s.forEach { ch ->
8
+ charCount.put(ch, charCount.getOrDefault(ch, 0) + 1)
9
+ }
10
11
+ t.forEach { ch ->
12
+ val count = charCount.getOrDefault(ch, 0)
13
+ if (count == 0) return false
14
+ charCount[ch] = count - 1
15
16
17
+ return true
18
19
+}
0 commit comments