美文网首页
3. Longest Substring Without Rep

3. Longest Substring Without Rep

作者: chaowwwww | 来源:发表于2018-04-09 20:41 被阅读0次
class Solution:
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        arr = [-1 for x in range(128)]
        maxx = 0
        now = 0
        for i in range(len(s)):
            now += 1
            if arr[ord(s[i])] > -1:
                now = min(now, i - arr[ord(s[i])])
                maxx = max(maxx, now)
            arr[ord(s[i])] = i
            maxx = max(maxx, now)
        return maxx

相关文章

网友评论

      本文标题:3. Longest Substring Without Rep

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