input :
output :
조건 :
Solution explain : Solution1
item = s[end]
해서 값을 가져 왔을 떄 초기화 하는 것을 추천한다.class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
alpha = dict()
start = 0
ret = 0
for end in range(len(s)):
item = s[end]
if item not in alpha:
alpha[item] = 0
if alpha[item] == 1:
while alpha[item] != 0:
alpha[s[start]] -= 1
start += 1
alpha[item] += 1
ret = max(ret, end - start + 1)
return ret
#
# s = Solution()
# print(s.lengthOfLongestSubstring("abcabcbb"))
# print(s.lengthOfLongestSubstring("bbbbb"))
# print(s.lengthOfLongestSubstring("pwwkew"))
# print(s.lengthOfLongestSubstring(""))
# print(s.lengthOfLongestSubstring(" "))