Longer Contiguous Segments of Ones than Zeros LeetCode solution in Java

1
class Solution {
2
public boolean checkZeroOnes(String s) {
3
int length1 = 0;
4
int length0 = 0;
5

6
int i = 0;
7
while (i < s.length()) {
8
int temp = 0;
9
while (i < s.length() && s.charAt(i) == '1') { // counting 1s
10
temp++;
11
i++;
12
}
13
length1 = Math.max(temp, length1);
14
temp = 0;
15
while (i < s.length() && s.charAt(i) == '0') { // counting 0s
16
temp++;
17
i++;
18
}
19
length0 = Math.max(temp, length0);
20
}
21
return length1 > length0;
22
}
23
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0