3. Longest Substring Without Repeating Characters

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

Examples:

Given "abcabcbb", the answer is "abc", which the length is .

Given "bbbbb", the answer is "b", with the length of .

Given "pwwkew", the answer is "wke", with the length of . Note that the answer must be a substring, "pwke" is a subsequence and not a substring

ANSWER:

 class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
if s:
i=
max_sub =s[]
len_s=len(s)
while i<len(s):
j=i+
for index in range(j,len_s):
if s[index] not in s[i:index]:
if len(s[i:index+])>len(max_sub):
max_sub=s[i:index+]
else:
break
i+=
return len(max_sub)
else:
return

code

 def main(s):
if s:
i=
max_sub =s[]
len_s=len(s)
while i<len(s):
j=i+
for index in range(j,len_s):
if s[index] not in s[i:index]:
if len(s[i:index+])>len(max_sub):
max_sub=s[i:index+]
else:
break
i+=
return len(max_sub)
else:
return
if __name__ == '__main__':
s='pwwke'
print(main(s))

调试代码

(python)leetcode刷题笔记03 Longest Substring Without Repeating Characters的更多相关文章

  1. 【leetcode刷题笔记】Longest Substring Without Repeating Characters

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

  2. (python)leetcode刷题笔记05 Longest Palindromic Substring

    5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...

  3. LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters

    LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...

  4. LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters

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

  5. LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List

    题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...

  6. leetcode笔记:Longest Substring Without Repeating Characters

    一. 题目描写叙述 Given a string, find the length of the longest substring without repeating characters. For ...

  7. leetcode-【中等题】3. Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...

  8. 【Leetcode】【Medium】Longest Substring Without Repeating Characters

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

  9. 【leetcode刷题笔记】Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. iOS生成Bundle包及使用

    什么是Bundle文件? 简单理解,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个Bundle文件.方便在其他项目中引用包内的资源. Bundle文件的特点? Bundle是静 ...

  2. LeetCode90:Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  3. SpringMVC+Mybatis架构中的问题记录

    2014/08/16 记录 今天遇到个问题.折腾了我大约4个小时,好坑啊由于之前没遇到过 我的包是这么分的:com.project名.模块名.service.impl     在spring 配置这个 ...

  4. Oracle ROWID具体解释

    1.ROWID定义 ROWID:数据库中行的全局唯一地址 对于数据中的每一行,rowid伪列返回行的地址.rowid值主要包括下面信息: 对象的数据对象编号 该行所在的数据文件里的数据块 该行中数据块 ...

  5. JAVA入门[9]-mybatis多表关联查询

    概要 本节要实现的是多表关联查询的简单demo.场景是根据id查询某商品分类信息,并展示该分类下的商品列表. 一.Mysql测试数据 新建表Category(商品分类)和Product(商品),并插入 ...

  6. Asp.Net Web API(一)

    什么是Web API HTTP不仅仅服务于Web Pages.他也是一个创建展示服务和数据的API的强大平台.HTTP是简单的,灵活的,无处不在的.你能够想象到几乎任何的平台都会有HTTP服务库.HT ...

  7. spring cloud ribbon和fegin

    一开始接触spring cloud的时候,还没有听说过微服务这个概念,对于服务直接的沟通是什么个情况,怎么组成微服务的完全懵逼,看到网上的教程都是用ribbong和fegin来调用接口,然后官网也给的 ...

  8. iOS cocos2d游戏引擎的了解之一

    ios游戏引擎之Cocos2d(一) cocos2d是一个免费开源的ios游戏开发引擎,并且完全采用object-c进行编写,这对于已经用惯object-c进行ios应用开发的童鞋来说非常容易上手.这 ...

  9. Python Web框架

    本节对Python Web框架学习 一.MTVModel: 存放所有数据库相关文件Template:模板文件,存放html文件View: 业务处理,即函数文件 二.MVCmodel: 存放数据库相关文 ...

  10. CSS line-height概念与举例

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/37 定义 两行文字基线之间的距离. 基线的大体位置 基线的位置可 ...