Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Given a string, find the length of the longest substring without repeating characters.
- Given "abcabcbb", the answer is "abc", which the length is 3.
- Given "bbbbb", the answer is "b", with the length of 1.
- Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence
- and not a substring.
- """
- def lengthOfLongestSubstring(self, s):
- """
- :type s: str
- :rtype: int
- """
- """
- strLen: Finds the length of a substring of s with no repeated characters
- Input: s - The string to iterate over
- """
- def substrLen(s):
- letters = set()
- for l in s:
- if not l in letters:
- letters.add(l)
- else:
- break
- return len(letters)
- #Return the maximum of all recursive calls:
- max = 0
- for i in range(len(s)):
- #Look through all possible starting locations
- curr = substrLen(s[i:])
- if curr > max:
- max = curr
- return max
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement