3-line C++ O(n) Solution

  • 0

    The problem is not challenging, so make the solution as short as possible.

    class Solution {
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int m=0, r=0; // m is max
            for(int n:nums) n?m=max(++r,m):r=0;
            return m;

Log in to reply

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