{"id":327,"date":"2023-01-03T21:23:30","date_gmt":"2023-01-03T13:23:30","guid":{"rendered":"https:\/\/dmoe.nicolite.cn\/?p=327"},"modified":"2023-01-11T18:09:17","modified_gmt":"2023-01-11T10:09:17","slug":"leetcode3-%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":"https:\/\/dmoe.nicolite.cn\/?p=327","title":{"rendered":"LeetCode 3. \u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5730\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/leetcode.cn\/problems\/longest-substring-without-repeating-characters\/\" data-type=\"URL\" data-id=\"https:\/\/leetcode.cn\/problems\/longest-substring-without-repeating-characters\/\" target=\"_blank\">3. \u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u666e\u901a\u601d\u8def\u89e3\u6cd5\uff08\u6a21\u62df\u8fc7\u7a0b\uff09\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\n    public int lengthOfLongestSubstring(String s) {\n        if (s == null || s.length() == 0) {\n            return 0;\n        }\n\n        int max = 0;\n        int count = 0;\n        int point = 0;\n        int index = 0;\n        Map&lt;Character, Integer&gt; map = new HashMap&lt;&gt;();\n\n        int len = s.length() - 1;\n\n        while(point &lt;= len &amp;&amp; index &lt;= len) {\n            char c = s.charAt(index);\n            if(!map.containsKey(c)) {\n                map.put(c, index);\n                count++;\n                index++;\n            } else {\n                if(count &gt; max) {\n                    max = count;\n                }\n                count = 0;\n\n                point++;\n                index = point;\n\n                map.clear();\n            }\n        }\n\n        if(count &gt; max) {\n            max = count;\n        }\n\n        return max;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ed1\u52a8\u7a97\u53e3\u89e3\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ef4\u62a4\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u7a97\u53e3\uff0c\u6bcf\u6b21\u627e\u5230\u91cd\u590d\u7684\u5c31\u5de6\u79fb\u5230\u5df2\u8bb0\u5f55\u7684\u91cd\u590d\u5b57\u7b26\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u672a\u627e\u5230\u5c31\u53f3\u79fb\uff0c\u8bb0\u5f55\u7b26\u5408\u8981\u6c42\u7684\u6700\u957f\u5b50\u4e32\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution {\n    public int lengthOfLongestSubstring(String s) {\n        if(s == null || s.length() == 0) {\n            return 0;\n        }\n\n        int point = 0;\n        int max = 0;\n        Map&lt;Character, Integer&gt; map = new HashMap&lt;&gt;();\n\n        for(int i = 0; i &lt; s.length(); i++) {\n            char c = s.charAt(i);\n            int cIndex = map.getOrDefault(c, -1);\n            if(cIndex != -1) {\n                point = Math.max(point, cIndex + 1);\n            }\n\n            map.put(c, i);\n            max = Math.max(max, i - point + 1);\n        }\n\n        return max;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5730\u5740\uff1a3. \u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32 \u666e\u901a\u601d\u8def\u89e3\u6cd5\uff08\u6a21\u62df\u8fc7\u7a0b\uff09\uff1a \u6ed1\u52a8\u7a97\u53e3\u89e3\u6cd5\uff1a \u7ef4\u62a4\u4e00\u4e2a\u7b26\u5408\u8981\u6c42\u7684\u7a97\u53e3\uff0c\u6bcf\u6b21\u627e\u5230 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,15],"tags":[17,31,30,27],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-leetcode","category-15","tag-leetcode","tag-31","tag-30","tag-27"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":0,"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dmoe.nicolite.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}