Leetcode 525 Solution
This article provides solution to leetcode question 525 (contiguous-array)
Access this page by simply typing in "lcs 525" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/contiguous-array
Solution
class Solution:
def findMaxLength(self, nums: List[int]) -> int:
m = {0:-1}
s = 0
ans = 0
for i, num in enumerate(nums):
s += 2 * num - 1
if s in m:
ans = max(ans, i - m[s])
else:
m[s] = i
return ans