题解 | #最长无重复子数组#

最长无重复子数组

http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4

#
# 
# @param arr int整型一维数组 the array
# @return int整型
#
class Solution:
    def maxLength(self , arr ):
        # write code here
        right = 0
        left = 0
        maxLen = -1
        dic = {}
        a = len(arr)
        while right < a:
            if arr[right] not in dic:
                dic[arr[right]] = right
                maxLen = max(maxLen, right - left +1)
                right += 1
            else:
                dic.pop(arr[left])
                left += 1
        return maxLen
            
            
           
                
            
            
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务