leetcode Longest Substring Without Repeating Characters python
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ if len(s) <= 0: return 0 res = list() maxLen = 0 for i in s: if i in res: tmpLen = len(res) if tmpLen > maxLen: maxLen = tmpLen while True: tmp = res.pop(0) if tmp == i: break res.append(i) else: res.append(i) cnt = len(res) if cnt > maxLen: maxLen = cnt return maxLen