Created
April 14, 2020 07:11
-
-
Save munguial/30e20035d50aca2c75e69ba424b21289 to your computer and use it in GitHub Desktop.
Day 13 - Contiguous Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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