Leetcode696 Count Binary Substrings

题目

class Solution {
public:
    int countBinarySubstrings(string s) {
        int result = 0;
        int prev = 0;
        int current = 1;
        int n=s.size();
        for(int i = 1 ; i < n ; i++){
            if(s[i] == s[i-1]){
                current++;
            }else{
                prev = current;
                current = 1;
            }
            if(current <= prev){
                result++;
            }
        }
        return result;
    }
};

体会

"连续"的联想:
(1)利用首尾/个数
(2)变化意味着突变

posted @ 2020-08-10 19:24  飞翔的菜鸟123  阅读(111)  评论(0编辑  收藏  举报