mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
@ -198,6 +198,29 @@ var isAnagram = function(s, t) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Swift:
|
||||||
|
```Swift
|
||||||
|
func isAnagram(_ s: String, _ t: String) -> Bool {
|
||||||
|
if s.count != t.count {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var record = Array(repeating: 0, count: 26)
|
||||||
|
let aUnicodeScalar = "a".unicodeScalars.first!.value
|
||||||
|
for c in s.unicodeScalars {
|
||||||
|
record[Int(c.value - aUnicodeScalar)] += 1
|
||||||
|
}
|
||||||
|
for c in t.unicodeScalars {
|
||||||
|
record[Int(c.value - aUnicodeScalar)] -= 1
|
||||||
|
}
|
||||||
|
for value in record {
|
||||||
|
if value != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 相关题目
|
## 相关题目
|
||||||
|
|
||||||
* 383.赎金信
|
* 383.赎金信
|
||||||
|
Reference in New Issue
Block a user