public class Solution {
    public int CharacterReplacement(string s, int k) {
        int len = s.Length;
            int[] count = new int[26];
            int start = 0, maxCount = 0, maxLength = 0;
            for (int end = 0; end < len; end++)
            {
                maxCount = Math.Max(maxCount, ++count[s[end] - 'A']);
                while (end - start + 1 - maxCount > k)
                {
                    count[s[start] - 'A']--;
                    start++;
                }
                maxLength = Math.Max(maxLength, end - start + 1);
            }
            return maxLength;
    }
}

https://leetcode.com/problems/longest-repeating-character-replacement/#/description

posted on 2017-06-09 09:16  Sempron2800+  阅读(131)  评论(0编辑  收藏  举报