Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created April 23, 2021 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/051896f8f09d2a90993a18524467bdfd to your computer and use it in GitHub Desktop.
Save vrat28/051896f8f09d2a90993a18524467bdfd to your computer and use it in GitHub Desktop.
Count Binary SubStrings(Py)
class Solution(object):
def countBinarySubstrings(self, s):
ans, prev, cur = 0, 0, 1
for i in xrange(1, len(s)):
if s[i-1] != s[i]:
ans += min(prev, cur)
prev, cur = cur, 1
else:
cur += 1
return ans + min(prev, cur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment