485. Max Consecutive Ones

485
[思路]:

寻找0.1序列中连续为1的子序列的长度;

  • 遍历一次,统计;
    int findMaxConsecutiveOnes(vector& nums) {
        int maxc = 0, cnt = 0;
        for(auto &num:nums){
            if(num == 1) cnt++;
            else cnt=0;
            maxc = max(maxc, cnt);
        }
        return maxc;
    }

你可能感兴趣的:(485. Max Consecutive Ones)