Validate Binary Search Tree (Python)
Binary Tree Maximum Path Sum (Python)

Longest Substring Without Repeating Characters (Python)

kitt posted @ 2014年2月11日 01:44 in LeetCode , 3515 阅读
class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        L, res, lastAppear = -1, 0, [-1] * 128
        for R, char in enumerate(s):
            pos = ord(char)
            if lastAppear[pos] > L:
                L = lastAppear[pos]
            else:
                res = max(res, R - L)
            lastAppear[pos] = R
        return res

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter