首页 > 学院 > 开发设计 > 正文

leetcode485

2019-11-08 01:29:20
字体:
来源:转载
供稿:网友

毫无技巧,注意细节。提交了两次才通过。

class Solution {public: int findMaxConsecutiveOnes(vector<int>& nums) { int newCount=0; int oldCount=0; int countFlag=0; for(int i=0;i<nums.size();i++) { if(nums[i]==1&&countFlag==0) { countFlag=1; newCount++; } else if(nums[i]==1&&countFlag==1) newCount++; else if(nums[i]==0&&countFlag==1) { if(newCount>oldCount) { oldCount=newCount; cout<<oldCount<<" "; } newCount=0; countFlag=0; } else {} } if(oldCount>newCount) return oldCount; else return newCount; }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表