class Solution {
public:
int countBinarySubstrings(string s) {
vector<int> count;
int cnt = 1;
if(s.size() == 0) return 0;
char last = s[0];
for(int i = 1; i < s.size(); i ++ ){
if(s[i] == last) cnt ++ ;
else{
count.push_back(cnt);
last = s[i];
cnt = 1;
}
}
count.push_back(cnt);
int res =0;
for(int i = 1; i < count.size(); i ++ ){
res += min(count[i], count[i - 1]);
}
return res;
}
};