func countBinarySubstrings(s string) int { n, cnt := len(s), 0 if n < 2 { return cnt } for i := 0; i < n-1; i++ { if s[i] == s[i+1] { continue } cnt++ for j := 1; 0 <= i-j && i+j+1 < n; j++ { if s[i-j] == s[i] && s[i+j+1] == s[i+1] { cnt++ } else { i += j - 1 break } } } return cnt }