Golang | Leetcode Golang题解之第424题替换后的最长重复字符
题目:
题解:
func characterReplacement(s string, k int) int {cnt := [26]int{}maxCnt, left := 0, 0for right, ch := range s {cnt[ch-'A']++maxCnt = max(maxCnt, cnt[ch-'A'])if right-left+1-maxCnt > k {cnt[s[left]-'A']--left++}}return len(s) - left
}func max(a, b int) int {if a > b {return a}return b
}