第三题在这里https://leetcode-cn.com/problems/contiguous-array/ 发一个python哈希表+前缀后解法 时间复杂度O(n) class Solution: def findMaxLength(self, nums: List[int]) -> int: lookup = {0:-1} total = 0 max_len = 0 for i in range(len(nums)): total += 1 if nums[i]==1 else -1 if total in lookup: max_len = max(max_len, i-lookup[total]) else: lookup[total]=i return max_len
点赞 评论
牛客网
牛客企业服务