您的位置:首页 > 其它

leetcode Max Consecutive Ones 最大连续长度

2017-09-28 19:48 417 查看
Given a binary array, find the maximum number of consecutive 1s in this array.

Note:

1、The input array will only contain 0 and 1.

2、The length of input array is a positive integer and will not exceed 10,000

题意:数字1的最大连续长度

思路:遍历

class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int max = 0;
int temp = 0;
for (int i = 0; i < nums.size(); ++i) {
if (nums[i] == 1) {
temp++;
if (temp > max)
max = temp;
}
else
temp = 0;
}
return max;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: