5 line c++ code


  • 0
    X
    class Solution {
    public:
    
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int maxcount=0;        int currentct=0;
            for(int i=0;i<nums.size();i++){
                if(nums[i]==1)  currentct++;
                else            currentct=0;
                if(maxcount<currct)   maxcount=currct;
            }
            return currentct; 
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.