连续未排序01数相同最长子数组_python3
未排序数组中累加和为给定值的最长子数组系列问题补2
http://www.nowcoder.com/questionTerminal/ab190c44af0141d58037c3f95109d722
同上一题
def solve(l, n): m = {0:-1} a = ans = 0 for i in range(n): a += 1 if l[i] else -1 if a not in m.keys(): m[a] = i else: ans = max(ans, i - m[a]) return ans while True: try: n = int(input()) l = list(map(int, input().split())) print(solve(l, n)) except EOFError: break