题解 | #最长不含重复字符的子字符串#
最长不含重复字符的子字符串
https://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return int整型 # class Solution: def lengthOfLongestSubstring(self , st: str) -> int: # write code here # 暴力破解 max=1 s_len=len(st) for l in range(s_len-1): tmp_max=1 current_str=st[l] for i in range(l+1,s_len): next_char = st[i] if next_char not in current_str: current_str = current_str+st[i] tmp_max=tmp_max+1 else : break if tmp_max > max : max=tmp_max return max """" 第一次循环 current_str 的变化 a,ab,abc,abca = 3 b,bc,bca,bcab = 3 c,ca,cab,cabc = 3 a,ab,abc,abca = 3 a,ab,abc,abca = 3 b,bc,bca,bcab = 3 c,ca,cab,cabc = 3 """