Simple C++ Solution with only 4 line


  • -1
    W

    class Solution {
    public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
    int len=0,maxlong=0;
    for(int n:nums)
    {
    n?len++:len=0;
    maxlong=max(maxlong,len);
    }
    return maxlong;
    }
    };


Log in to reply
 

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