登录 注册
当前位置:主页 > 资源下载 > 9 > leetcode2sumc-LeetCode-3.Longest_Substring_Without_Repeating_Characters下载

leetcode2sumc-LeetCode-3.Longest_Substring_Without_Repeating_Characters下载

  • 更新:2024-11-03 22:52:08
  • 大小:916B
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:其它 - 开发技术
  • 格式:ZIP

资源介绍

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