Given a string s, find the length of the longest substring without repeating characters.
class Solution: def lengthOfLongestSubstring(self, s: str) -> int: curr_str = {} start = 0 max_len = 0 curr_len = 0 for i in range(start,len(s)-start): if s[i] not in curr_str.keys(): curr_str[s[i]] = i elif s[i] in curr_str.keys(): max_len = max(max_len, len(curr_str)) start = curr_str[s[i]] + 1 curr_len = 0 for j in range(0,start): curr_str.pop(s[j], None) # print(f" after del {curr_str}") max_len = max(max_len, len(curr_str)) return max_len
https://stackoverflow.com/questions/66575477/stuck-on-some-use-cases-for-this-problem-like-aab March 11, 2021 at 10:03AM
没有评论:
发表评论