//3.无重复字符的最长子串
func lengthOfLongestSubstring(s string) int {
res := 0
left := 0
m := make(map[byte]int)
for i := 0; i < len(s); i++ {
if idx, ok := m[s[i]]; ok && idx >= left {
left = idx + 1
}
m[s[i]] = i
res = max(res,i - left + 1)
}
return res
}
//438、找到字符串中所有字母异位词
func findAnagrams(s string, p string) []int {
slen, plen := len(s), len(p)
scount, pcount := [26]int{}, [26]int{}
res := []int{}
if plen > slen {
return res
}
for i, v := range p {
scount[s[i]-'a']++
pcount[v-'a']++
}
if scount == pcount {
res = append(res, 0)
}
for i, ch := range s[:slen-plen] {
scount[ch-'a']--
scount[s[i+plen]-'a']++
if scount == pcount {
res = append(res, i+1)//注意这里从i+1统计
}
}
return res
}