rosien

consecutive_ones

Oct 14th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. #https://leetcode.com/problems/max-consecutive-ones/submissions/
  2. def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
  3.         prev_count = 0
  4.         count = 0
  5.         for num in nums:
  6.             if num ==0:
  7.                 count = max(count, prev_count)
  8.                 prev_count = count
  9.                 count = 0
  10.             if num ==1:
  11.                 count +=1
  12.         return max(count, prev_count)
  13.            
Add Comment
Please, Sign In to add comment