Longer Contiguous Segments of Ones than Zeros LeetCode solution in C++

1
class Solution {
2
public:
3
bool checkZeroOnes(string s) {
4
int count1 = 0;
5
int count2 = 0;
6
int max1 = 0;
7
int max2 = 0;
8
for (int i = 0; i < s.size(); i++) {
9
if (s[i] == '1') {
10
count1++;
11
if (s[i + 1] != s[i]) {
12
max1 = max(count1, max1);
13
count1 = 0;
14
}
15
}
16

17
if (s[i] == '0') {
18
count2++;
19
if (s[i + 1] != s[i]) {
20
max2 = max(count2, max2);
21
count2 = 0;
22
}
23
}
24
}
25

26
if (max1 > max2) return true;
27
return false;
28
}
29
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0