# 485.Max Consecutive Ones

**485.Max Consecutive Ones**

难度:Easy

> 给定一个二进制数组， 计算其中最大连续1的个数。

示例 1:

输入: \[1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1，所以最大连续1的个数是 3. 注意：

输入的数组只包含 0 和1。 输入数组的长度是正整数，且不超过 10,000。

简单题，

```
class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int res=0;
        int tmp=0;
        for(auto i :nums)
        {
            if(i)
                tmp++;
            else
            {
                res=max(tmp,res);
                tmp=0;
            }
        }
        res=max(tmp,res);
        return res;
    }
};
```

> 执行用时 : 68 ms, 在Max Consecutive Ones的C++提交中击败了37.24% 的用户\
> 内存消耗 : 11.8 MB, 在Max Consecutive Ones的C++提交中击败了66.17% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/485.max_consecutive_ones.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
