class Solution(object):
def characterReplacement(self, s, k):
if s == "":
return 0
char = [0 for _ in range(26)]
i, j = 0, 0
maxCnt = 1
for c in s:
num = ord(c) - ord('A')
char[num] = 1 if char[num] == 0 else char[num] + 1
maxCnt = max(char)
if j - i + 1 - maxCnt > k:
char[ord(s[i]) - ord('A')] -= 1
i += 1
j += 1
return j - i
算法分析与设计第十四周:424. Longest Repeating Character Replacement
最新推荐文章于 2023-10-08 16:01:30 发布