Updated: 2024-03-12
1 min read
On This Page
class Solution:
def findMaxLength(self, nums: List[int]) -> int:
s = res = 0
mp = {0: -1}
for i, v in enumerate(nums):
s += 1 if v == 1 else -1
if s in mp:
res = max(res, i - mp[s])
else:
mp[s] = i
return res