classSolution:deffindMaxLength(self,nums: List[int]) ->int: prefix_sum =0 prefix_hash ={0:-1}# 初始化解决了 f([0, 1]) = 2 res =0for i, num inenumerate(nums):if num ==1: prefix_sum +=1else: prefix_sum -=1if prefix_sum in prefix_hash: res =max(res, i - prefix_hash[prefix_sum])else: prefix_hash[prefix_sum]= ireturn res