> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/485.max_consecutive_ones.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
