Leetcode: Longest Substring Without Repeating Characters
2015-09-15 06:56
363 查看
Question
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.Hide Tags Hash Table Two Pointers String
Hide Similar Problems (H) Longest Substring with At Most Two Distinct Characters
My Solution
[code]class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ if s=='': return 0 res, start = 0, 0 dictn = {} for ind in range(len(s)): if s[ind] not in dictn: dictn[s[ind]] = 1 res = max(res, len(dictn)) else: while s[start]!=s[ind]: del dictn[s[start]] start += 1 start += 1 return res
相关文章推荐
- LeetCode Minimum Path Sum
- LeetCode Minimum Path Sum
- Linux常见问题汇总
- 蓝懿教育记录
- LeetCode (9): Palindrome Number
- OSChina 周二乱弹 —— 新一代开源尿床神器
- java虚拟机回收机制原理
- ZereneStacker 1.04 for Windows 焦点堆叠软件 简体中文 汉化
- ADT活動
- ASP.NET 5 Beta 7 版本
- 关于牛气轰轰的闭包
- Ugly Number II
- LeetCode Ugly Number II
- 插件开发技术说明(15)---文件自动分目录存储
- Lua的表(字典)
- LeetCode Ugly Number
- LeetCode Ugly Number
- Repeated DNA Sequences 解答
- Python二分查找详解
- JSP经典学习笔记(包含各种入门常用语法)