728x90
https://leetcode.com/problems/max-consecutive-ones/
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
max_count = 0
count = 0
for i in nums:
if i == 1:
count += 1
else:
if count > max_count:
max_count = count
count = 0
return max_count if max_count > count else count
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 977. Squares of a Sorted Array (0) | 2023.08.19 |
---|---|
[Leetcode] 1295. Find Numbers with Even Number of Digits (0) | 2023.08.19 |
[Leetcode] 1523. Count Odd Numbers in an Interval Range (0) | 2023.08.18 |
[Leetcode] 2278. Percentage of Letter in String (0) | 2023.08.16 |
[Leetcode] 175. Combine Two Tables (0) | 2023.08.16 |