Files
LeetCode-Go/leetcode/0424.Longest-Repeating-Character-Replacement/424. Longest Repeating Character Replacement.go
halfrost 46faa66642 Merge pull request #60 from halfrost/code_quality_improvement
optimization code quality level from A to A+
2020-08-27 17:41:27 +08:00

23 lines
418 B
Go

package leetcode
func characterReplacement(s string, k int) int {
res, left, counter, freq := 0, 0, 0, make([]int, 26)
for right := 0; right < len(s); right++ {
freq[s[right]-'A']++
counter = max(counter, freq[s[right]-'A'])
for right-left+1-counter > k {
freq[s[left]-'A']--
left++
}
res = max(res, right-left+1)
}
return res
}
func max(a int, b int) int {
if a > b {
return a
}
return b
}