Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a87829e

Browse files
committed
feat(go 0242): 添加 0242 golang的新解法
Signed-off-by: cndoit18 <cndoit18@outlook.com>
1 parent 65efa57 commit a87829e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

problems/0242.有效的字母异位词.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,22 @@ func isAnagram(s string, t string) bool {
173173
}
174174
```
175175

176+
Go写法二(没有使用slice作为哈希表,用数组来代替):
177+
178+
```go
179+
func isAnagram(s string, t string) bool {
180+
record := [26]int{}
181+
for _, r := range s {
182+
record[r-rune('a')]++
183+
}
184+
for _, r := range t {
185+
record[r-rune('a')]--
186+
}
187+
188+
return record == [26]int{}
189+
}
190+
```
191+
176192
javaScript:
177193

178194
```js

0 commit comments

Comments
 (0)