-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2981.cpp
More file actions
28 lines (24 loc) · 676 Bytes
/
Copy path2981.cpp
File metadata and controls
28 lines (24 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
int maximumLength(const string &s) const {
static int count[26][3];
int cnt = 0, prev = s[0];
memset(count, 0xFF, sizeof(count));
for (const char c : s) {
if (c == prev)
cnt++;
else {
prev = c;
cnt = 1;
}
const int idx = c - 'a';
auto mini = min_element(count[idx], count[idx] + 3);
if (cnt > *mini) *mini = cnt;
}
int res = -1;
for (int i = 0; i < 26; i++) {
res = max(res, *min_element(count[i], count[i] + 3));
}
return res;
}
};