class Solution { public int countBinarySubstrings(String s) { int n = s.length(); int res = 0; int pre = 0, cur = 1; for(int i = 1; i < n; i++) { if(s.charAt(i) == s.charAt(i-1)) cur++; else { pre = cur; cur = 1; } if(cur <= pre) res++; } return res; } }