Leetcode

Leetcode 696. Count Binary Subst

2021-05-06  本文已影响0人  SnailTyan

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Count Binary Substrings

2. Solution

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/
上一篇 下一篇

猜你喜欢

热点阅读