Contiguous Array LeetCode solution in Python
1class Solution:2def findMaxLength(self, nums: List[int]) -> int:3# dictionary4prefixSum = {0: -1}5total = 06maxlength = 078for index, value in enumerate(nums):9if value == 0:10total -= 111else:12total += 113if total not in prefixSum.keys():14prefixSum[total] = index15else:16maxlength = max(maxlength, index - prefixSum[total])17return maxlength