thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

LeetCode #485: Max Consecutive Ones

• 44 words • 1 min • updated

LeetCode #485: Max Consecutive Ones:

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

        prev = 0
        for num in nums:
            if num == 0:
                prev = 0

            elif num == 1:
                prev += 1
                ans = max(ans, prev)

        return ans