Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def findMaxLength(self, nums: List[int]) -> int:
- res = ps = 0
- #ps = no. of ones - no. of zeros
- hm = {0: -1}
- for i, e in enumerate(nums):
- ps += 2*e - 1
- if ps in hm:
- res = max(i-hm[ps], res)
- else:
- hm[ps] = i
- return res
Add Comment
Please, Sign In to add comment