mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
feat(go 0242): 添加 0242 golang的新解法
Signed-off-by: cndoit18 <cndoit18@outlook.com>
This commit is contained in:
@ -173,6 +173,22 @@ func isAnagram(s string, t string) bool {
|
||||
}
|
||||
```
|
||||
|
||||
Go写法二(没有使用slice作为哈希表,用数组来代替):
|
||||
|
||||
```go
|
||||
func isAnagram(s string, t string) bool {
|
||||
record := [26]int{}
|
||||
for _, r := range s {
|
||||
record[r-rune('a')]++
|
||||
}
|
||||
for _, r := range t {
|
||||
record[r-rune('a')]--
|
||||
}
|
||||
|
||||
return record == [26]int{}
|
||||
}
|
||||
```
|
||||
|
||||
javaScript:
|
||||
|
||||
```js
|
||||
|
Reference in New Issue
Block a user