Back to course home
0% completed
Vote For New Content
from collections import Counterclass Solution: def characterReplacement(self,...
Austin McDaniel
Nov 3, 2022
from collections import Counter class Solution: def characterReplacement(self, s: str, k: int) -> int: char_count = Counter() max_string = 0 w_start = 0
for i in range(len(s)): char_count[s[i]] += 1 max_char = max(char_count.values())
if i - w_start + 1 - max_char > k: char_count[s[w_start]] -= 1 w_start += 1 else: max_string = max(max_string, i - w_start + 1)
return max_string
I personally think this code is easier to read.
0
0
Comments
Comments
On this page