C++ solution


  • 0
    J
    class Solution {
    public:
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int result = 0, max = 0;
            for(int num : nums)
            {
                if(num)
                {
                    result++;
                    if(result > max)
                        max = result;
                }
                else
                    result = 0;
            }
            return max;
        }
    };
    

Log in to reply
 

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