(python)leetcode刷题笔记03 Longest Substring Without Repeating Characters
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的更多相关文章
- 【leetcode刷题笔记】Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- (python)leetcode刷题笔记05 Longest Palindromic Substring
5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...
- LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters
LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...
- LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List
题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...
- leetcode笔记:Longest Substring Without Repeating Characters
一. 题目描写叙述 Given a string, find the length of the longest substring without repeating characters. For ...
- leetcode-【中等题】3. Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...
- 【Leetcode】【Medium】Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【leetcode刷题笔记】Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- 预防onion比特币勒索病毒,如何快速关闭135,137,138,139,445端口
预防onion比特币勒索病毒,如何快速关闭135,137,138,139,445等端口 如果这种网络端口关闭方法行不通,可以尝试一种新的关闭网络端口方法(比较繁琐)见106楼,补丁安装教程见126 ...
- appium测试准备记录
一 获取应用程序包名(手机中不安装apk) windows 环境下: aapt工具 使用aapt工具,适合给程序自动获取apk的相关信息. //aapt 是sdk自带的一个工具,在SDK/buildt ...
- codeforge免费下载账号 积分账号 共享账号
codeforge网站下载代码很好,没有积分怎么办?那么多好的matlab代码,matlab程序,C,JAVA等等,都要充值啊!!! 请用下面共享的codeforge账号密码========> ...
- vue.js介绍,常用指令,事件,以及制作简易留言版
一.vue是什么? 一个mvvm框架(库).和angular类似,比较容易上手.小巧,让我们的代码更加专注于业务逻辑,而不是去关注DOM操作 二.vue和angular之间的区别 vue--简单易学 ...
- 数据结构之【栈】+十进制转d进制(堆栈数组模拟)
其实这篇文章开出来主要是水文章%% %% 栈--后进先出的婊 特点:只能在某一端插入和删除的特殊的线性表 操作:进栈--PUSH->向栈顶插入元素 出栈--POP-->将栈顶元素删除 实现 ...
- javac 小记
javac 到底是什么? javac 就是一个编译器,它把 Java 源代码编译成 Java 字节码,即 JVM 能够识别的二进制形式的文件. javac 由什么构成? 词法分析器:识别源代码中的 J ...
- C++ stack
stack 栈,一种后进先出的数据结构,在c++ stl里作为容器适配器,string,vector,deque,在内存中是连续的 声明方式 stack<int,deque<T>&g ...
- Java内存模型—JMM
有时候编译器.处理器的优化会导致runtime与我们设想的不一样,为此Java对编译器和处理器做了一些限制,JAVA内存模型(JMM)将这些抽象出来,这样编写代码时就无需考虑那么多底层细节,并保证& ...
- IEEE Trans 2007 Signal Recovery From Random Measurements via OMP
看了一篇IEEE Trans上的关于CS图像重构的OMP算法的文章,大部分..看不懂,之前在看博客的时候对流程中的一些标号看不太懂,看完论文之后对流程有了一定的了解,所以在这里解释一下流程,其余的如果 ...
- 前端开发JavaScript清除浏览器缓存的方法
查看和删除浏览器缓存的方法=====>打开 最近在开发项目中发现有时候总要频繁地清除浏览器缓存,不然总是显示的过时的信息 浏览器缓存有利有弊,有些数据需要缓存下来使得页面打开更快提高网站性能,但 ...