Given a binary array, find the maximum number of consecutive 1s in this array.

Example 1:

Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
    The maximum number of consecutive 1s is 3.



Note:

The input array will only contain 0 and 1.
The length of input array is a positive integer and will not exceed 10,000

Difficulty: introductory

Starter code:

class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        

Solutions:
class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         if nums == []:
             return 0
         
         count = 0
         countMax =0
         for ele in nums:
             if ele == 1:
                 count += 1
             else:
                 if count > countMax:
                     countMax = count
                 count = 0
         
         if count > countMax:
             countMax = count
         
         return countMax


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         cur=0
         ans=0
         for num in nums:
             if num==1:
                 cur=cur+1
                 ans = max(ans,cur)
             else:cur=0
         return ans
                 
         


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         count = 0
         max_count = 0
         for num in nums:
             if num == 1:
                 count += 1
             else:
                 if count > max_count:
                     max_count = count
                 count = 0
                 
         if count > max_count:
                     max_count = count
                 
         return max_count

class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         cnt = 0
         max_cnt = 0
         for x in nums:
             if x == 1:
                 cnt+=1
             else:
                 if max_cnt < cnt:
                     max_cnt = cnt
                 cnt = 0
         if max_cnt < cnt:
             max_cnt = cnt
         return max_cnt

class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         ans=0
         c= 0
         for i in nums:
             c=i*c+i
             if c >ans:
                 ans = c
         return ans

class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         max_c = 0
         cur = 0
         
         for n in nums:
             if n == 1:
                 cur += 1
             
             if n == 0:
                 max_c = max(max_c, cur)
                 cur = 0
             
         max_c = max(max_c, cur)
                 
         return max_c


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         max_c = 0
         cur = 0
         
         for n in nums:
             if n == 1:
                 cur += 1
             
             if n == 0:
                 max_c = max(max_c, cur)
                 cur = 0
             
         max_c = max(max_c, cur)
                 
         return max_c


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         max_c = 0
         cur = 0
         
         for n in nums:
             if n == 1:
                 cur += 1
             
             if n == 0:
                 max_c = max(max_c, cur)
                 cur = 0
             
         max_c = max(max_c, cur)
                 
         return max_c


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         """
         :type nums: List[int]
         :rtype: int
         """
         sum = 0
         max = 0
         for i in range(0,len(nums)):
             if nums[i]==1:
                 sum += 1
             else:
                 sum = 0
             if sum > max:
                 max = sum
             else:
                 max = max
         return max
             
         


class Solution:
     def findMaxConsecutiveOnes(self, nums):
         max_final = 0
         max_here = 0
         
         for num in nums:
             if num == 1:
                 max_here+=1
                 max_final = max(max_final, max_here)
             else:
                 max_here = 0
         return max_final