diff --git "a/HughGuo/Leetcode-02/C003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" "b/HughGuo/Leetcode-02/C003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" new file mode 100644 index 0000000..c90a041 --- /dev/null +++ "b/HughGuo/Leetcode-02/C003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.py" @@ -0,0 +1,18 @@ +class Solution: + def lengthOfLongestSubstring(self, s): + """ + :type s: str + :rtype: int + """ + temp = 0 + d = {} + start = 0 + for i in range(len(s)): + if s[i] in d and start <= d[s[i]] : + start = d[s[i]] +1 + temp = max(i-start+1,temp) + d[s[i]] = i + return temp + +## 维护两个字符串,一个是当前最大的字符串l,一个是当前字符串t,最初的时候这两个字符串都为空。每扫一个字符,如果这个字符不在字符串当中,就把当前字符串加上这个字符。如果在,当前字符串就不能再往前加字符了,然后比较当前字符串和当前最大字符串。再把当前字符串的开始地址替换掉因为不能有重复元素,##麻烦 +## 滑动窗口! 机智! diff --git a/HughGuo/readme.md b/HughGuo/readme.md index d6aa085..5d3aedf 100644 --- a/HughGuo/readme.md +++ b/HughGuo/readme.md @@ -1,3 +1,4 @@ # HughGuo贡献内容 -- 两数求和 \ No newline at end of file +- #2. 两数求和 +- #3. 无重复字符的最长子串