Algorithm/LeetCode 문제 풀이
[LeetCode 485] python - 예외 처리에 주의하기..
공놀이나하여보세
2019. 4. 2. 06:53
4. 485 : Max Consecutive Ones
https://leetcode.com/problems/max-consecutive-ones/submissions/
Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
예외 처리에 주의해야겠다.
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
"""