leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2982.cpp (676B)
0 class Solution {
1 public:
2 int maximumLength(const string &s) const {
3 static int count[26][3];
4 int cnt = 0, prev = s[0];
6 memset(count, 0xFF, sizeof(count));
7 for (const char c : s) {
8 if (c == prev)
9 cnt++;
10 else {
11 prev = c;
12 cnt = 1;
13 }
15 const int idx = c - 'a';
16 auto mini = min_element(count[idx], count[idx] + 3);
17 if (cnt > *mini) *mini = cnt;
18 }
20 int res = -1;
21 for (int i = 0; i < 26; i++) {
22 res = max(res, *min_element(count[i], count[i] + 3));
23 }
25 return res;
26 }
27 };