feat(go 0242): 添加 0242 golang的新解法

Signed-off-by: cndoit18 <cndoit18@outlook.com>
This commit is contained in:
cndoit18
2021-12-16 14:56:59 +08:00
parent 65efa574a4
commit a87829edeb

View File

@ -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