485. Max Consecutive Ones
来源:互联网 发布:mac怎么创建网页 编辑:程序博客网 时间:2024/04/28 16:32
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int a=0,b=0;
for(int i=0;i<nums.size();i++)
{
if((nums[i]==1)&&(i!=nums.size()-1)) a++;
if(nums[i]==0){
if(a>b){
b=a;
a=0;
}
if(a<=b){
a=0;
}
}
if(nums[i]==1&&(i==nums.size()-1)){
a+=1;
if(a>b){
b=a;
a=0;
}
if(a<=b){
a=0;
}
}
}
return b;
}
};
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int a=0,b=0;
for(int i=0;i<nums.size();i++)
{
if((nums[i]==1)&&(i!=nums.size()-1)) a++;
if(nums[i]==0){
if(a>b){
b=a;
a=0;
}
if(a<=b){
a=0;
}
}
if(nums[i]==1&&(i==nums.size()-1)){
a+=1;
if(a>b){
b=a;
a=0;
}
if(a<=b){
a=0;
}
}
}
return b;
}
};
0 0
- 485. Max Consecutive Ones*
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485.Max Consecutive Ones
- test1
- 算法训练 数组排序去重
- Spring-ApplicationContext事件机制
- Linux基础知识
- OpenSSl
- 485. Max Consecutive Ones
- 第一次Linux作业
- 算法训练 数组查找及替换
- 用异步任务实现简单的新闻资讯
- Fork/Join初识
- TypeError: 'numpy.float64' object is not iterablex
- T-SQL语言分类
- Java8 新日期时间类(2)
- python实现半双工聊天