{"id":2703,"date":"2020-01-10T12:29:47","date_gmt":"2020-01-10T04:29:47","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2703"},"modified":"2020-01-10T12:29:47","modified_gmt":"2020-01-10T04:29:47","slug":"%e3%80%90leetcode%e3%80%910003%e6%97%a0%e9%87%8d%e5%a4%8d%e5%ad%97%e7%ac%a6%e7%9a%84%e6%9c%80%e9%95%bf%e5%ad%90%e4%b8%b2","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2703\/","title":{"rendered":"\u3010LeetCode\u30110003\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/median-of-two-sorted-arrays\/\">https:\/\/leetcode-cn.com\/problems\/median-of-two-sorted-arrays\/<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<br \/>class Solution(object):<br \/>    def lengthOfLongestSubstring(self, s):<br \/>        <em>\"\"\"<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> s: str<br \/><\/em><em>        <\/em><strong><em>:rtype<\/em><\/strong><em>: int<br \/><\/em><em>        \"\"\"<br \/><\/em><em>        <\/em>st = {}<br \/>        i, ans = 0, 0<br \/>        for j in range(len(s)):<br \/>            if s[j] in st:<br \/>                i = max(st[s[j]], i)<br \/>            ans = max(ans, j - i + 1)<br \/>            st[s[j]] = j + 1<br \/>        return ans<br \/><br \/>    <br \/><br \/>if __name__ == '__main__':<br \/>    str1 = 'abcabcbb'<br \/>    print(Solution().lengthOfLongestSubstring1(str1))<br \/><\/pre>\n\n\n<p><strong>\u601d\u8def\uff1a<\/strong>\u8bb0\u5f55\u76f8\u540c\u5b57\u6bcd\u4e0a\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u5e76\u4f7f\u7528\u53d8\u91cfans\u8bb0\u5f55\u8fd9\u4e9b\u4f4d\u7f6e\u7684\u6700\u5927\u95f4\u8ddd\uff0c\u5373\u4e3a\u6574\u4f53\u5b57\u7b26\u4e32\u6700\u957f\u65e0\u91cd\u590d\u5b50\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/median-of-two-sor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1339,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2703"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2703"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2703\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}