java beat 97%


  • 0
    A
    public int countBinarySubstrings(String s) {
        if(s==null || s.length()<=1) return 0;
        int res =0;
        int preCnt = 0, curCnt = 1;
        char[] crs = s.toCharArray();
        for(int i=1; i<crs.length; i++){
            if(crs[i]==crs[i-1]) curCnt++;
            else {preCnt = curCnt; curCnt = 1;}
            if(preCnt>=curCnt) res++;
        }
        return res;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.