Longer Contiguous Segments of Ones than Zeros LeetCode solution in C++
1class Solution {2public:3bool checkZeroOnes(string s) {4int count1 = 0;5int count2 = 0;6int max1 = 0;7int max2 = 0;8for (int i = 0; i < s.size(); i++) {9if (s[i] == '1') {10count1++;11if (s[i + 1] != s[i]) {12max1 = max(count1, max1);13count1 = 0;14}15}1617if (s[i] == '0') {18count2++;19if (s[i + 1] != s[i]) {20max2 = max(count2, max2);21count2 = 0;22}23}24}2526if (max1 > max2) return true;27return false;28}29};