Simple C++ solution and clean code with no tricks.


  • 0
    D
    int findMaxSubArrayOfConsicutiveOnes(vector < int >& nums) {
        int res = 0;
        int count = 0;
        for(int num : nums) {
            if(num == 1) {
                count++;
                res = max(count, res);
            } else {
                count = 0;
            }
        }
        return res;
    }
    

Log in to reply
 

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