#include<iostream>
#include<algorithm>
using namespace std;
#include<vector>
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int count = 0, maxcount = 0;
for (int i = 0; i < nums.size(); i++)
{
if (nums[i] == 1)
{
count = count + 1;
}
else
{
maxcount = max(maxcount, count);
count = 0;
}
}
maxcount = max(maxcount, count);
return maxcount;
}
};
void test01() {
vector<int> m_num;
m_num.push_back(1);
m_num.push_back(0);
m_num.push_back(1);
m_num.push_back(1);
m_num.push_back(0);
m_num.push_back(1);
Solution S;
int result = S.findMaxConsecutiveOnes(m_num);
cout << result << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
Leetcode刷题-485最大连续1的个数
于 2022-04-17 19:54:48 首次发布