前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LeetCode - 003

LeetCode - 003

作者头像
咸鱼学Python
发布2019-06-03 15:53:37
3640
发布2019-06-03 15:53:37
举报
文章被收录于专栏:咸鱼学Python咸鱼学Python
原题

https://leetcode.com/problems/longest-substring-without-repeating-characters/description/

题干

Given a string, find the length of the longest substring without repeating characters.

Example 1:

Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:

Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3:

Input: "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的

这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的这是占字数的

代码语言:javascript
复制
class Solution:    def lengthOfLongestSubstring(self, s: str) -> int:      if not s:        return 0      end = 0      start = 0      res = 0      lookup = set()      while start < len(s) and end < len(s):        if s[end] not in lookup:          lookup.add(s[end])          res = max(res, end - start+1)          end += 1        else:          lookup.discard(s[start])          start += 1      return res
代码语言:javascript
复制
# 还有更好的解法  不过我没想到
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-05-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 咸鱼学Python 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 原题
  • 题干
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档