Skip to content

Commit b8af01d

Browse files
committed
solve valid anagram
1 parent 37b336c commit b8af01d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

valid-anagram/delight010.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
func isAnagram(_ s: String, _ t: String) -> Bool {
3+
var sDictionary: [Character: Int] = [:]
4+
var tDictionary: [Character: Int] = [:]
5+
for char in s {
6+
sDictionary[char] = (sDictionary[char] ?? 0) + 1
7+
}
8+
for char in t {
9+
tDictionary[char] = (tDictionary[char] ?? 0) + 1
10+
}
11+
return sDictionary == tDictionary
12+
}
13+
}
14+

0 commit comments

Comments
 (0)