Java/696. Count Binary Substrings 计数二进制子串

题目

Java/696. Count Binary Substrings 计数二进制子串_第1张图片


Java/696. Count Binary Substrings 计数二进制子串_第2张图片

 

 

 

代码部分(13ms 99.26%)

class Solution {
    public int countBinarySubstrings(String s) {
        char[] ch = s.toCharArray();
        int res, last, cur;
        last = res = 0;
        cur = 1;
        
        for(int i = 1; i < ch.length; i++){
            if(ch[i] == ch[i - 1]){
                cur++;
            }else{
                last = cur; 
                cur = 1;
            }
            if(last >= cur) res++;
        }
        
        
        return res;
    }
}

 

你可能感兴趣的:(算法,简单,Count,Binary,Substrings,计数二进制子串)