149 Longest Substring Without Repeating Characters
http://www.cnblogs.com/zuoyuan/p/3785840.html
注意找到了重複的以後要把之前的全部置-1
class Solution:
# @return an integer
def lengthOfLongestSubstring(self, s):
start = 0
maxlen = 0
dict = {}
for i in range(len(s)):
dict[s[i]] = -1
for i in range(len(s)):
if dict[s[i]] != -1:
while start <= dict[s[i]]:
dict[s[start]] = -1
start += 1
if i - start + 1 > maxlen: maxlen = i - start + 1
dict[s[i]] = i
return maxlen
相關文章
- Longest Substring Without Repeating Characters
- #3 Longest Substring Without Repeating Characters[M]
- 3. Longest Substring Without Repeating Characters
- Leetcode Longest Substring Without Repeating CharactersLeetCode
- Leetcode 3 Longest Substring Without Repeating CharactersLeetCode
- Leetcode-Longest Substring Without Repeating CharactersLeetCode
- Longest Substring Without Repeating Characters leetcode javaLeetCodeJava
- Leetcode 3. Longest Substring Without Repeating CharactersLeetCode
- LeetCode OJ : 3 Longest Substring Without Repeating CharactersLeetCode
- Leetcode javascript 3 longest-substring-without-repeating-charactersLeetCodeJavaScript
- LeetCode Longest Substring Without Repeating Characters(003)解法總結LeetCode
- [LeetCode] 3. Longest Substring Without Repeating Characters 題解LeetCode
- 【LeetCode從零單排】No 3 Longest Substring Without Repeating CharactersLeetCode
- [LeetCode] Longest Substring Without Repeating Characters 最長無重複字元的子串LeetCode字元
- LeetCode-Longest Substring with At Least K Repeating CharactersLeetCodeAST
- LeetCode3:Longest Substring Without Repeating Characters(無重複字元的最長子串)LeetCode字元
- Leet Code 3. Longest Substring Without Repeating Characters (最長的沒有重複字元的子字串)字元字串
- LeetCode-Longest Substring with At Most K Distinct CharactersLeetCode
- Leetcode-Longest Substring with At Most Two Distinct Characters.LeetCode
- 【Leetcode】3. Longest Substring Without RepeatingCharacters無重最長子串LeetCodeGC
- Leetcode Longest Palindromic SubstringLeetCode
- LeetCode 5 (Longest Palindromic Substring)LeetCode
- LintCode-Longest Common Substring
- Leetcode-Longest Palindromic SubstringLeetCode
- Longest Palindromic Substring leetcode javaLeetCodeJava
- LeetCode 5. Longest Palindromic SubstringLeetCode
- LeetCode OJ : 5 Longest Palindromic SubstringLeetCode
- LeetCode每日一題:longest palindromic substringLeetCode每日一題
- [leetcode] 1624. Largest Substring Between Two Equal CharactersLeetCode
- [LeetCode] 2414. Length of the Longest Alphabetical Continuous SubstringLeetCodeAlphabet
- [LeetCode] Longest Palindromic Substring 最長迴文子串LeetCode
- Leetcode5: Longest Palindromic Substring(最長迴文子串)LeetCode
- Js的substring和C#的SubstringJSC#
- JavaScript substring()JavaScript
- SCSS without和withCSS
- unixODBC without the GUIGUI
- Special Characters in Initialization Parameter Files
- ACM Longest Repeated SequenceACM