1
# Runtime: 133 ms (Top 63.3%) | Memory: 16.65 MB (Top 94.0%)5
def countBinarySubstrings(self, s: str) -> int:7
# previous continuous occurrence, current continuous occurrence8
pre_cont_occ, cur_cont_occ = 0, 110
# counter for binary substrings with equal 0s and 1s13
# scan each character pair in s14
for idx in range(1, len(s)):16
if s[idx] == s[idx - 1]:18
# update current continuous occurrence22
# update counter of binary substrings between prevous character group and current character group23
counter += min(pre_cont_occ, cur_cont_occ)25
# update previous as current's continuous occurrence26
pre_cont_occ = cur_cont_occ28
# reset current continuous occurrence to 131
# update for last time32
counter += min(pre_cont_occ, cur_cont_occ)