4. 485 : Max Consecutive Ones
https://leetcode.com/problems/max-consecutive-ones/submissions/
예외 처리에 주의해야겠다.
class Solution(object):
def findMaxConsecutiveOnes(self, nums):
cnt = 0
max = 0
for i in range(len(nums)):
if nums[i] == 1:
cnt += 1
else:
if max < cnt:
max = cnt
cnt = 0
if max < cnt:
max = cnt
return max
"""
:type nums: List[int]
:rtype: int
"""
'Algorithm > LeetCode 문제 풀이' 카테고리의 다른 글
[LeetCode 200. Number of Islands] C++ , C++로 전향하기로 결정했다. (0) | 2019.04.03 |
---|---|
[Leetcode 492. Construct the Rectangle] Java (0) | 2019.04.02 |
[LeetCode 283] python 리스트(큐/스택) 이용하기 (0) | 2019.04.02 |
[LeetCode 232, 283, 290 - 완료, 485, 492] python (0) | 2019.03.31 |
[LeetCode 542. 01 Matrix] [python] 4. 재귀 함수 (0) | 2019.03.31 |