class Solution: # @return an integer def lengthOfLongestSubstring(self, s): start=0 n=len(s) substr='' maxlen=0 for end in range(n): if s[end] not in substr: substr+=s[end] else: substr='' maxlen=max(maxlen,end-start) for i in xrange(start,end): if s[end]==s[i]: start=i+1 substr=s[start:end+1] break maxlen=max(maxlen,n-start) return maxlen
Thursday, September 18, 2014
Leetcode: Longest Substring Without Repeating Characters @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment