Skip to content

Commit 292816e

Browse files
authored
Create Longer Contiguous Segments of Ones than Zeros.java
1 parent 39d9e0a commit 292816e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public boolean checkZeroOnes(String s) {
3+
int zeroBlock = 0;
4+
int oneBlock = 0;
5+
int idx = 0;
6+
int n = s.length();
7+
while (idx < n) {
8+
char c = s.charAt(idx);
9+
int currCount = 0;
10+
while (idx < n && s.charAt(idx) == c) {
11+
currCount++;
12+
idx++;
13+
}
14+
if (c == '0') {
15+
zeroBlock = Math.max(zeroBlock, currCount);
16+
} else {
17+
oneBlock = Math.max(oneBlock, currCount);
18+
}
19+
}
20+
return oneBlock > zeroBlock;
21+
}
22+
}

0 commit comments

Comments
 (0)