leetcode485. Max Consecutive Ones

Posted happyamyhope

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode485. Max Consecutive Ones相关的知识,希望对你有一定的参考价值。

problem

485. Max Consecutive Ones

solution1:

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        if(nums.empty()) return 0;
        int ans = 0, max = INT_MIN;
        for(int i=0; i<nums.size(); i++)
        {
            if(nums[i]==1) ans++;
            else if(nums[i]!=1)
            {
                if(max<ans) max = ans;
                ans = 0;
            }
        }
        return max>ans ? max : ans;
    }
};

 

 

参考

1. Leetcode_485. Max Consecutive Ones;

以上是关于leetcode485. Max Consecutive Ones的主要内容,如果未能解决你的问题,请参考以下文章

leetcode485. Max Consecutive Ones

[leetcode-485-Max Consecutive Ones]

LeetCode-485. Max Consecutive Ones

LeetCode 485. Max Consecutive Ones

leetcode 485. Max Consecutive Ones

[Leetcode]485. Max Consecutive Ones