C++ simple


  • 0
    B
    class Solution {
    public:
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int ans = 0, count = 0;
            for(auto e : nums)
            {
                if(e != 1)
                {
                    ans = max(ans, count);
                    count = 0;
                }
                else
                count++;
            }
            return max(ans, count);
        }
    };

Log in to reply
 

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