二值化
azl397985856 opened this issue · comments
- [525] 连续数组
前缀和
class Solution:
def findMaxLength(self, A: List[int]) -> int:
A = [-1 if a == 0 else 1 for a in A]
acc = 0
ans = 0
mapper = {0: -1}
for i, a in enumerate(A):
acc += a
if acc not in mapper:
mapper[acc] = i
else:
ans = max(ans, i - mapper[acc])
return ans
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.