3.Longest Substring Without Repeating Characters-python
来源:互联网 发布:java技术总监岗位职责 编辑:程序博客网 时间:2024/06/15 22:53
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given “abcabcbb”, the answer is “abc”, which the length is 3.
Given “bbbbb”, the answer is “b”, with the length of 1.
Given “pwwkew”, 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.
Code
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ max=0 curmax=0 substr="" #当前的子字符串 i=0 length = len(s) while i<length: ind = substr.find(s[i]) if ind==-1:#no containing item substr+=s[i] curmax+=1 else: if max < curmax: max = curmax i = i - len(substr) + ind #回溯 substr="" curmax = 0 i+=1 if max < curmax: max = curmax return max
阅读全文
2 0
- 3.Longest Substring Without Repeating Characters-python
- Leetcode -- Python -- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters [Python解]
- 【Leetcode】【python】Longest Substring Without Repeating Characters
- LeetCode 3. Longest Substring Without Repeating Characters (C++/python)
- 3.Longest Substring Without Repeating Characters Leetcode Python
- [Leetcode]3. Longest Substring Without Repeating Characters @python
- Leetcode题解(Python): 3.Longest Substring Without Repeating Characters
- [leetcode: Python]3. Longest Substring Without Repeating Characters
- LeetCode 3. Longest Substring Without Repeating Characters题解python
- 【leetcode】3. Longest Substring Without Repeating Characters(Python & C++)
- [LeetCode]3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- 各大公司后端java面试题总结
- 多线程——————停止线程
- 在shiro当设置sessionIdCookie配置的domain和访问url不匹配时,每次请求都会重新生成session
- HTML 标签解释大全
- 学习Linux命令(51)
- 3.Longest Substring Without Repeating Characters-python
- Android强大的数据库开源框架LitePal
- Ceph新长支持稳定版本Luminous(12.x.x)新功能总结
- CSS入门
- toad 启动时长时间 checking feedback server
- java中的mvc三层结构究竟有什么关系
- Linux 文件名和路径的最大长度
- Nginx详细的安装教程(linux)
- andriod系统源码编译之1---制作U盘