Skip to content

Instantly share code, notes, and snippets.

@munguial
Created April 14, 2020 07:11
Show Gist options
  • Save munguial/30e20035d50aca2c75e69ba424b21289 to your computer and use it in GitHub Desktop.
Save munguial/30e20035d50aca2c75e69ba424b21289 to your computer and use it in GitHub Desktop.
Day 13 - Contiguous Array
class Solution:
def findMaxLength(self, nums: List[int]) -> int:
history = {0: -1}
balance = 0
res = 0
for i in range(len(nums)):
balance += 1 if nums[i] else -1
if balance in history:
res = max(res, i - history[balance])
else:
history[balance] = i
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment