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 933ca4a commit af2a864Copy full SHA for af2a864
swift/242-Valid-Anagrams.swift
@@ -0,0 +1,25 @@
1
+/**
2
+ * Question Link: https://leetcode.com/problems/valid-anagram/
3
+ */
4
+
5
+class ValidAnagram {
6
+ func isAnagram(_ s: String, _ t: String) -> Bool {
7
+ if s.count != t.count {
8
+ return false
9
+ }
10
+ var countS = [Int:Int]()
11
+ var countT = [Int:Int]()
12
+ let sChars = Array(s)
13
+ let tChars = Array(t)
14
+ for i in 0..<sChars.count {
15
+ countS[Int(sChars[i].asciiValue!)] = 1 + countS[Int(sChars[i].asciiValue!), default: 0]
16
+ countT[Int(tChars[i].asciiValue!)] = 1 + countT[Int(tChars[i].asciiValue!), default: 0]
17
18
+ for (key, _) in countS {
19
+ if countS[key] != countT[key, default: 0] {
20
21
22
23
+ return true
24
25
+}
0 commit comments