Beautiful Binary String

  • + 0 comments

    Python solution without any tricks :-

    def beautifulBinaryString(b):
        num = 0
        while len(b)>=3:
            if b[:3] == '010':
                num += 1
                b = b[3:]
            else:
               b = b[1:]
        return num