class Solution:
    def findMaxConsecutiveOnes(self, nums):
        n = len(nums)
        if n==0: return 0
        if sum(nums) == 0:return 1
        if sum(nums) == n:return n
        res = []
        count = 0
        for i in range(n):
            if nums[i] == 1:
                count += 1
            elif count !=0:
                res.append(count)
                count = 0
            else:
                if 0<i<n:
                    if nums[i-1] != 1 or nums[i+1] != 1:
                        if len(res) and res[-1]!=0:
                            res.append(0)
        if count: res.append(count)
        if len(res) <= 1: return sum(res)+1
        temp = 0
        for i in range(1, len(res)):
            temp = max(temp, res[i-1] + res[i])
        return temp+1