leetcode2sumc-LeetCode-3.Longest_Substring_Without_Repeating_Characters

时间:2021-06-30 17:51:26
【文件属性】:
文件名称:leetcode2sumc-LeetCode-3.Longest_Substring_Without_Repeating_Characters
文件大小:916B
文件格式:ZIP
更新时间:2021-06-30 17:51:26
系统开源 leetcode 2 和 c LeetCode-3.Longest_Substring_Without_Repeating_Characters 给定一个字符串,找出没有重复字符的最长子字符串的长度。 示例 1: 输入:“abcabcbb” 输出:3 解释:答案是“abc”,长度为 3。 解决方案 Python3:类解决方案: def lengthOfLongestSubstring(self, s): dicts = {} maxlength = start = 0 for i,value in enumerate(s): # "abcabcbb" # "bbbbb" if value in dicts: sums = dicts[value] + 1 if sums > start: start = sums num = i - start + 1 if num > maxlength: maxlength = num dicts[value] = i # dicts = {a:1}, maxlength = 1 # dicts = {a:1,b:2}, maxlength = 2
【文件预览】:
LeetCode-3.Longest_Substring_Without_Repeating_Characters-master
----README.md(981B)

网友评论