1. 程式人生 > >485. Max Consecutive Ones(陣列)

485. Max Consecutive Ones(陣列)

題目:求出最大的連續1的個數

思路:直接求解

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int max = 0,index = 0;
        while(index < nums.size()){
             int temp = 0;
             while(nums[index] && index < nums.size()) index++,temp++;
             max = max > temp?max:temp;
             index++;
        }
        return
max; } };