Leetcode 696. Count Binary Substrings
Posted SnailTyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 696. Count Binary Substrings相关的知识,希望对你有一定的参考价值。
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
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
以上是关于Leetcode 696. Count Binary Substrings的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 696. Count Binary Substrings
Leetcode 696. Count Binary Substrings
[leetcode]String-696. Count Binary Substrings
[LeetCode&Python] Problem 696. Count Binary Substrings