| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/pythonpeixun/LeetCode-Solutions/master/Python/contiguous-array.py | [Back] [Original] |
# Time: O(n)
# Space: O(n)
class Solution(object):
def findMaxLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
result, count = 0, 0
lookup = {0: -1}
for i, num in enumerate(nums):
count += 1 if num == 1 else -1
if count in lookup:
result = max(result, i - lookup[count])
else:
lookup[count] = i
return result
| Web Proxy Viewer | New URL | Original Page |