leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0424.cpp (617B)


0 class Solution {
1 public:
2 int characterReplacement(string s, int k) {
3 vector<int> counts(26, 0);
4 int n = s.length(), start = 0, maxi = 0, result = 0;
5 for_each(s.begin(), s.end(), [](char &c) { c -= 'A'; });
7 for (int end = 0; end < n; end++) {
8 maxi = max(maxi, ++counts[s[end]]);
9 while (end - start - maxi + 1 > k) {
10 counts[s[start++]]--;
11 for (int i = 0; i < 26; i++)
12 maxi = max(maxi, counts[i]);
13 }
14 result = max(result, end - start + 1);
15 }
16 return result;
17 }
18 };