class Solution(object):
def findMaxLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
presum_map = {0: -1}
presum, ans = 0, 0
for i, num in enumerate(nums):
if num == 1:
presum += 1
else:
presum -= 1
if presum in presum_map:
ans = max(ans, i - presum_map[presum])
else:
presum_map[presum] = i
return ans
02-02
2449
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-16
259
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-10
376
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-24
2643
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)