485. Max Consecutive Ones 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011class Solution {public: int findMaxConsecutiveOnes(vector<int>& nums) { int count = 0, ret = 0; for(int n:nums){ if(n==1) count++; else {ret= max(ret, count); count= 0;} } return max(ret, count); }}; analysis time complexity O(n) space complexity O(1)