LeetCode.485. Max Consecutive Ones
找出陣列中最長的連續 1
https://leetcode.com/problems/max-consecutive-ones/description/
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int result = 0,tmp=0;
for(auto x: nums){
if(x==1){
tmp++;
}else{
tmp=0;
}
if(result<tmp){
result = tmp;
}
}
return result;
}
};
留言
張貼留言