Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Note that the answer must be a su
My code:
class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
length=len(s)
tmp_dict={}
tmp_len=length
start=0
result=0
i=0
while i<length:
if s[i] not in tmp_dict.keys():
tmp_dict[s[i]]=1
i=i+1
if result<i-start:
result=i-start
else:
tmp_dict.pop(s[start])
start+=1
return result
Solution:
https://leetcode.com/problems/longest-substring-without-repeating-characters/