003 Longest Substring Without Repeating Characters
来源:互联网 发布:杰洛特的母亲 知乎 编辑:程序博客网 时间:2024/05/29 16:22
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.
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ m=n=0 b={} for i in range(len(s)): if s[i] not in b or b[s[i]]<i-n: n=n+1 b[s[i]]=i else: n=i-b[s[i]] b[s[i]]=i m=max(m,n) return m
阅读全文
0 0
- LeetCode 003 Longest Substring Without Repeating Characters
- LeetCode-003 Longest Substring Without Repeating Characters
- 【leetcode】003 Longest Substring Without Repeating Characters
- LeetCode 003 Longest Substring Without Repeating Characters
- LeetCode 003-Longest Substring Without Repeating Characters
- [LeetCode]-003-Longest Substring Without Repeating Characters
- LeetCode #003 Longest Substring Without Repeating Characters
- LeetCode 003 Longest Substring Without Repeating Characters
- 003 Longest Substring Without Repeating Characters [Leetcode]
- 003 - Longest Substring Without Repeating Characters
- [LeetCode]003-Longest Substring Without Repeating Characters
- 003Longest Substring Without Repeating Characters (C)
- LeetCode 003 Longest Substring Without Repeating Characters
- LeetCode 003: Longest Substring Without Repeating Characters
- leetcode-003 Longest Substring Without Repeating Characters
- 003 Longest Substring Without Repeating Characters
- LeetCode-003 Longest Substring Without Repeating Characters
- leetcode 003 Longest Substring Without Repeating Characters
- Python任务调度模块 – APScheduler
- 由"=="所引起的“您提交的程序没有通过所有的测试用例”
- JSF复习系列(3)--JSF、Primefaces标签与Html的内嵌使用
- RN-第三方之-react-native-fs
- requirejs页面刷新失效js报错问题解决方案
- 003 Longest Substring Without Repeating Characters
- Apache Kafka 入门
- java、web项目建立与删除-20170626
- 专题:冒泡排序与快速排序
- Windows PE 工具
- 清华山维EPS二次开发VBS基础篇
- python3 自动化部署javaweb系统到远程tomcat
- 响铃:DR钻戒神曲有毒?谁才是品牌借势的解药?
- Android 加载成功、加载失败、加载中、无数据四个不同界面的切换