Longer Contiguous Segments of Ones than Zeros LeetCode solution in Java
1class Solution {2public boolean checkZeroOnes(String s) {3int length1 = 0;4int length0 = 0;56int i = 0;7while (i < s.length()) {8int temp = 0;9while (i < s.length() && s.charAt(i) == '1') { // counting 1s10temp++;11i++;12}13length1 = Math.max(temp, length1);14temp = 0;15while (i < s.length() && s.charAt(i) == '0') { // counting 0s16temp++;17i++;18}19length0 = Math.max(temp, length0);20}21return length1 > length0;22}23}