Leetcode 696. Count Binary Substrings

2021-05-18 16:19:59 浏览数 (1)

1. Description

2. Solution

  • Version 1
代码语言:javascript复制
class Solution:
    def countBinarySubstrings(self, s: str) -> int:
        length = len(s)
        count = 0
        pre = 0
        curr = 1
        for i in range(1, length):
            if s[i] == s[i - 1]:
                curr  = 1
            else:
                count  = min(pre, curr)
                pre = curr
                curr = 1
        count  = min(pre, curr)
        return count

Reference

  1. https://leetcode.com/problems/count-binary-substrings/

0 人点赞