mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-01 08:46:25 +08:00
规范格式
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
package leetcode
|
||||
|
||||
func findAnagrams(s string, p string) []int {
|
||||
var freq [256]int
|
||||
result := []int{}
|
||||
if len(s) == 0 || len(s) < len(p) {
|
||||
return result
|
||||
}
|
||||
for i := 0; i < len(p); i++ {
|
||||
freq[p[i]-'a']++
|
||||
}
|
||||
left, right, count := 0, 0, len(p)
|
||||
|
||||
for right < len(s) {
|
||||
if freq[s[right]-'a'] >= 1 {
|
||||
count--
|
||||
}
|
||||
freq[s[right]-'a']--
|
||||
right++
|
||||
if count == 0 {
|
||||
result = append(result, left)
|
||||
}
|
||||
if right-left == len(p) {
|
||||
if freq[s[left]-'a'] >= 0 {
|
||||
count++
|
||||
}
|
||||
freq[s[left]-'a']++
|
||||
left++
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user