Skip to content

Commit

Permalink
Time: 945 ms (33.14%), Space: 14.7 MB (50.48%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
r-rahul1 committed Feb 23, 2022
1 parent 659f6a1 commit e6d3fd3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1004-max-consecutive-ones-iii/1004-max-consecutive-ones-iii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def longestOnes(self, nums: List[int], k: int) -> int:

maxr = wstart = ml = 0

for wend in range(len(nums)):
if nums[wend] == 0:
maxr += 1
if maxr >k:
if nums[wstart] ==0:
maxr -= 1
wstart += 1
ml = max(ml,wend-wstart+1)
return ml

0 comments on commit e6d3fd3

Please sign in to comment.