Leetcode - 424. Longest Repeating Character Replacement

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

풀이

슬라이딩 윈도우 풀이

class Solution:
    def characterReplacement(self, s, k):
        max_freq = res = 0
        count = collections.Counter()

        left = right = 0

        while right < len(s):
            count[s[right]] += 1
            max_freq = max(max_freq, count[s[right]])

            if res < max_freq + k:
                res += 1
            else:
                count[s[right - res]] -= 1
                left += 1

            right += 1
        return res