您的位置:首页 > 其它

Max Consecutive Ones[LeetCode 485]

2017-12-04 10:02 330 查看

Ans

#include <iostream>
#include <vector>

using namespace std;

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