Skip to content

Commit d864148

Browse files
authored
Create 696. Count Binary Substrings
1 parent fb8913c commit d864148

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

696. Count Binary Substrings

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int countBinarySubstrings(String s) {
3+
int count = 0, i = 1, prev = 0, curr = 1;
4+
while(i < s.length()) {
5+
//11000110
6+
if(s.charAt(i-1) != s.charAt(i)) {
7+
count+=Math.min(prev, curr);
8+
prev = curr;
9+
curr = 1;
10+
}
11+
else {
12+
curr++;
13+
}
14+
i++;
15+
}
16+
17+
return count+=Math.min(prev, curr);
18+
}
19+
}

0 commit comments

Comments
 (0)