알고리즘/배열(array)

Max Consecutive Ones python

자코린이 2023. 6. 26. 21:32
class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        result = 0
        a = []
        for i in nums:
            if i == 1:
                result += 1
            else:
                a.append(result)
                result = 0
        a.append(result)
        return max(a)

1이 중복된 수를 리스트로 만들고 리스트중 최댓값 찾기