-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2609.cpp
More file actions
34 lines (30 loc) · 725 Bytes
/
2609.cpp
File metadata and controls
34 lines (30 loc) · 725 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
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int findTheLongestBalancedSubstring(string s) {
const int size = s.size();
int count0 = 0, count1 = 0;
int result = 0;
for(int i = 0; i < size; ++i) {
if(s[i] == '0') {
if(i > 0 && s[i-1] == '1') {
count0 = 0;
}
++ count0;
count1 = 0;
}
else {
++ count1;
}
if(count1 != 0 && count1 <= count0) {
result = max(result, 2count1);
}
}
return result;
}
};
int main() {
Solution solution;
return 0;
}