Concise C++ solution


  • 2
    D
    public:
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int count = 0, max = 0;
            for (int i = 0; i < nums.size(); ++i){
                if (nums[i]){
                    if (++count > max) max = count;
                }
                else count = 0;
            }
            return max;
        }
    };

Log in to reply
 

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