美文网首页
Leetcode 之 Longest Substring Wi

Leetcode 之 Longest Substring Wi

作者: nkuhero | 来源:发表于2017-11-07 18:41 被阅读0次
class Solution:
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        ans = 0
        left = 0
        last = {}
        for i in range(len(s)):
            if s[i] in last and last[s[i]] >= left:
                left = last[s[i]] + 1
            last[s[i]] = i
            ans = max(ans, i - left + 1)
        return ans

相关文章

网友评论

      本文标题:Leetcode 之 Longest Substring Wi

      本文链接:https://www.haomeiwen.com/subject/zoojmxtx.html