{"id":351,"date":"2023-08-30T15:44:23","date_gmt":"2023-08-30T07:44:23","guid":{"rendered":"http:\/\/lingbo.online\/?p=351"},"modified":"2023-08-30T15:44:23","modified_gmt":"2023-08-30T07:44:23","slug":"%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3%e4%b8%93%e9%a1%b9%e8%ae%ad%e7%bb%83","status":"publish","type":"post","link":"https:\/\/lingbo.online\/index.php\/uncategorized\/%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3%e4%b8%93%e9%a1%b9%e8%ae%ad%e7%bb%83\/","title":{"rendered":"\u6ed1\u52a8\u7a97\u53e3\u4e13\u9879\u8bad\u7ec3"},"content":{"rendered":"<h3>\u7b97\u6cd5\u7b80\u4ecb<\/h3>\n<p>\u6ed1\u52a8\u7a97\u53e3\uff0c\u5c31\u662f\u6709\u4e00\u4e2a\u5927\u5c0f\u53ef\u53d8\u7684\u7a97\u53e3\uff0c\u5de6\u53f3\u4e24\u7aef\u65b9\u5411\u4e00\u81f4\u7684\u5411\u524d\u6ed1\u52a8\uff08\u53f3\u7aef\u56fa\u5b9a\uff0c\u5de6\u7aef\u6ed1\u52a8\uff1b\u5de6\u7aef\u56fa\u5b9a\uff0c\u53f3\u7aef\u6ed1\u52a8\uff09\uff0c\u4e5f\u53ef\u4ee5\u60f3\u8c61\u4e3a\u961f\u5217\uff0c\u4e00\u7aef\u5728push\u5143\u7d20\uff0c\u53e6\u5916\u4e00\u6bb5\u5728pop\u5143\u7d20\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<blockquote>\n<p>\u5047\u8bbe\u6709\u6570\u7ec4[a,b,c,d,e,f,g,h]<br \/>\n\u4e00\u4e2a\u5927\u5c0f\u4e3a3\u7684\u6ed1\u52a8\u7a97\u53e3\u5728\u5176\u4e2d\u6ed1\u52a8\uff0c\u5219\u6709\uff1a<br \/>\n[a,b,c]<br \/>\n[b,c,d]<br \/>\n[c,d,e]<br \/>\n...<br \/>\n[f,g,h]<\/p>\n<\/blockquote>\n<p>\u6ed1\u52a8\u7a97\u53e3\u901a\u5e38\u7528\u5728\u5b57\u7b26\u521b\u6216\u8005\u5217\u8868\u7684\u7b97\u6cd5\u95ee\u9898\u4e2d\uff0c\u5e38\u51fa\u73b0\u7684\u5173\u952e\u8bcd\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u6ee1\u8db3XXX\u6761\u4ef6\uff08\u8ba1\u7b97\u7ed3\u679c\uff0c\u51fa\u73b0\u6b21\u6570\uff0c\u540c\u65f6\u5305\u542b\uff09<\/li>\n<li>\u6700\u957f\/\u6700\u77ed<\/li>\n<li>\u5b50\u4e32\/\u5b50\u6570\u7ec4\/\u5b50\u5e8f\u5217<br \/>\neg\uff1a\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4\u3001\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u3001\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u7b49<\/li>\n<\/ul>\n<h3>\u7b97\u6cd5\u601d\u60f3<\/h3>\n<ol>\n<li>\u5728\u5e8f\u5217\u4e2d\u4f7f\u7528\u53cc\u6307\u9488\u4e2d\u7684<code>\u5de6\u53f3\u6307\u9488<\/code>\u6280\u5de7\uff0c\u521d\u59cb\u5316<code>left=right=0<\/code>\uff0c\u628a\u7d22\u5f15\u95ed\u533a\u95f4<code>[left,right]<\/code>\u79f0\u4e3a\u4e00\u4e2a<code>\u7a97\u53e3<\/code>\u3002<\/li>\n<li>\u5148\u4e0d\u65ad\u5730<code>\u589e\u52a0right\u6307\u9488\u6269\u5927\u7a97\u53e3[left,right]<\/code>\uff0c\u76f4\u5230\u7a97\u53e3\u4e2d\u7684\u5e8f\u5217\u7b26\u5408\u8981\u6c42\u3002<\/li>\n<li>\u6b64\u65f6\uff0c\u505c\u6b62\u589e\u52a0right\uff0c\u8f6c\u800c<code>\u4e0d\u65ad\u589e\u52a0left\u6307\u9488\u7f29\u5c0f\u7a97\u53e3[left,right]<\/code>\uff0c\u76f4\u5230\u7a97\u53e3\u4e2d\u7684\u5e8f\u5217\u4e0d\u518d\u7b26\u5408\u8981\u6c42\u3002\u540c\u65f6\uff0c<code>\u6bcf\u6b21\u589e\u52a0left\u524d\uff0c\u90fd\u8981\u66f4\u65b0\u4e00\u8f6e\u7ed3\u679c<\/code>\u3002<\/li>\n<\/ol>\n<p>\u603b\u7ed3\u4ee5\u4e0a\u6b65\u9aa4\uff1a\u7b2c\u4e8c\u6b65\u76f8\u5f53\u4e8e\u5728\u5bfb\u627e\u4e00\u4e2a<code>\u53ef\u884c\u89e3<\/code>\uff0c\u7136\u540e\u5728\u7b2c\u4e09\u6b65<code>\u4f18\u5316\u8fd9\u4e2a\u53ef\u884c\u89e3<\/code>\uff0c\u6700\u7ec8\u627e\u5230<code>\u6700\u4f18\u89e3<\/code>\u3002\u5de6\u53f3\u6307\u9488\u8f6e\u6d41\u524d\u8fdb\uff0c\u7a97\u53e3\u5927\u5c0f\u589e\u589e\u51cf\u51cf\uff0c\u7a97\u53e3\u4e0d\u65ad\u5411\u53f3\u6ed1\u52a8\u3002<\/p>\n<h3>\u7b97\u6cd5\u6a21\u677f<\/h3>\n<h4>\u5355\u5c42\u5faa\u73af<\/h4>\n<pre><code class=\"language-python\">def template():\n    #\u521d\u59cb\u5316\u6ed1\u52a8\u7a97\u53e3\u4e24\u7aef\n    left=right=0\n\n    #\u5e8f\u5217\u53ca\u5e8f\u5217\u957f\u5ea6\n    seq,seq_len=xx,xx\n\n    #\u6ed1\u52a8\u7a97\u53e3\u5e8f\u5217\n    slide_win=[]\n\n    #\u7ed3\u679c\u503c\n    rst=XX\n\n    while right&lt;seq_len:\n        slide_win.append(seq[right])\n        #\u8fd8\u6ca1\u627e\u5230\u4e00\u4e2a\u53ef\u884c\u89e3\n        if not avaliable(slide_win):\n            #\u6269\u5927\u7a97\u53e3\n            right+=1\n        else:\n            #\u627e\u5230\u4e00\u4e2a\u53ef\u884c\u89e3\uff0c\u66f4\u65b0\u7ed3\u679c\u503c\n            rst.update()\n            #\u7f29\u5c0f\u7a97\u53e3\n            left+=1<\/code><\/pre>\n<h4>\u53cc\u5c42\u5faa\u73af<\/h4>\n<pre><code class=\"language-python\">def template():\n    #\u521d\u59cb\u5316\u6ed1\u52a8\u7a97\u53e3\u4e24\u7aef\n    left=right=0\n\n    #\u5e8f\u5217\u53ca\u5e8f\u5217\u957f\u5ea6\n    seq,seq_len=xx,xx\n\n    #\u6ed1\u52a8\u7a97\u53e3\u5e8f\u5217\n    slide_win=[]\n\n    #\u7ed3\u679c\u503c\n    rst=xx\n\n    while right&lt;seq_len:\n        slide_win.append(seq[right])\n        #\u8fd8\u6ca1\u627e\u5230\u4e00\u4e2a\u53ef\u884c\u89e3\n        if not avaliable(slide_win):\n            #\u6269\u5927\u7a97\u53e3\n            right+=1\n            continue\n\n        #\u5faa\u73af\u66f4\u65b0\u53ef\u884c\u89e3\n        while avaliable(slide_win):\n            #\u627e\u5230\u4e00\u4e2a\u53ef\u884c\u89e3\uff0c\u66f4\u65b0\u7ed3\u679c\u503c\n            rst=update()\n            #\u7f29\u5c0f\u7a97\u53e3\n            left+=1<\/code><\/pre>\n<h3>\u7b97\u6cd5\u6848\u4f8b<\/h3>\n<h4>\u5251\u6307Offer48. \u6700\u957f\u4e0d\u542b\u91cd\u590d\u5b57\u7b26\u7684\u5b50\u5b57\u7b26\u4e32<\/h4>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof\/description\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof\/description\/<\/a><\/p>\n<h5>\u9898\u89e3<\/h5>\n<pre><code class=\"language-python\">class Solution:\n    def lengthOfLongestSubstring(self, s: str) -&gt; int:\n        n=len(s)\n\n        lookup=set()\n\n        left=0\n        right=0\n\n        max_len=0\n        cur_len=0\n\n        #\u4e00\u5c42\u5faa\u73af\uff0c\u5bfb\u627e\u53ef\u884c\u89e3\n        while right&lt;=n-1:\n            if s[right] not in lookup:\n                lookup.add(s[right])\n                cur_len+=1\n                right+=1\n            #\u56fa\u5b9a\u53f3\u6307\u9488\uff0c\u79fb\u52a8\u5de6\u6307\u9488\uff0c\u66f4\u65b0\u6700\u4f18\u89e3\n            else:\n                max_len=max(max_len,cur_len)\n                lookup.remove(s[left])\n                left+=1\n                cur_len-=1\n\n        max_len=max(max_len,cur_len)\n\n        return max_len\n<\/code><\/pre>\n<h4>Leecode.1438 \u7edd\u5bf9\u5dee\u4e0d\u8d85\u8fc7\u9650\u5236\u7684\u6700\u957f\u8fde\u7eed\u5b50\u6570\u7ec4<\/h4>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit\/<\/a><\/p>\n<h5>\u9898\u89e3<\/h5>\n<pre><code class=\"language-python\">class Solution:\n    def longestSubarray(self, nums: List[int], limit: int) -&gt; int:\n        if not nums:\n            return 0\n\n        len_nums=len(nums)\n\n        #\u56e0\u4e3a\u9700\u8981\u6bd4\u8f83\u5b50\u5217\u8868\u4e2d\u7684\u6700\u5927\u5dee\u503c\uff0c\u6240\u4ee5\u9700\u8981\u77e5\u9053\u5b57\u5217\u8868\u7684\u6700\u5927\u3001\u6700\u5c0f\u503c\n        #\u91c7\u7528\u5355\u8c03\u961f\u5217\n        queMax,queMin=deque(),deque()\n\n        # \u6ed1\u52a8\u7a97\u53e3\u7684\u524d\u540e\u7d22\u5f15\n        left=0\n        right=0\n\n        #\u7ed3\u679c\n        ret=0\n\n        #\u6ed1\u52a8\u7a97\u53e3\u957f\u5ea6\n        max_win=1\n        while right&lt;len_nums:\n\n            #\u5c06\u5f53\u524d\u5143\u7d20\u53ca\u5176\u7d22\u5f15\u653e\u5165\u5355\u8c03\u961f\u5217\u4e2d\n            while queMax and queMax[-1]&lt;nums[right]:\n                queMax.pop()\n            while queMin and queMin[-1]&gt;nums[right]:\n                queMin.pop()\n\n            queMax.append(nums[right])\n            queMin.append(nums[right])\n\n            #\u5982\u679c\u6570\u7ec4\u5185\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u4e4b\u5dee\u4e0d\u6ee1\u8db3limit\u8981\u6c42\n            while queMax and queMin and queMax[0]-queMin[0]&gt;limit:\n                #\u5982\u679c\u5de6\u6307\u9488\u5bf9\u5e94\u5f53\u524d\u7684\u6700\u5927\u503c\u6216\u8005\u6700\u5c0f\u503c\n                if nums[left]==queMin[0]:\n                    queMin.popleft()\n                if nums[left]==queMax[0]:\n                    queMax.popleft()\n                left+=1\n\n            ret=max(ret,right-left+1)\n            right+=1\n        return ret<\/code><\/pre>\n<h4>Leecode.151 \u53cd\u8f6c\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u8bcd<\/h4>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/reverse-words-in-a-string\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/leetcode.cn\/problems\/reverse-words-in-a-string\/<\/a><\/p>\n<h5>\u9898\u89e3<\/h5>\n<pre><code class=\"language-python\">class Solution:\n    def characterReplacement(self, s: str, k: int) -&gt; int:\n        num=[0]*26\n        n=len(s)\n\n        max_len=left=right=0\n\n        while right&lt;n:\n            #\u66f4\u65b0\u5f53\u524d\u5b57\u6bcd\u5bf9\u5e94\u7684\u8ba1\u6570\n            num[ord(s[right])-ord(&#039;A&#039;)]+=1\n            #\u5224\u65ad\u6700\u5927\u957f\u5ea6\u662f\u5426\u4e3a\u5f53\u524d\u5b57\u6bcd\u7684\u8ba1\u6570\n            max_len=max(max_len,num[ord(s[right])-ord(&#039;A&#039;)])\n            #\u5982\u679c\u53f3-\u5de6\u533a\u95f4\u7684\u5b57\u6bcd\u8ba1\u6570-\u6700\u5927\u957f\u5ea6\u5b57\u6bcd\u7684\u8ba1\u6570&gt;k\u4e2a\uff0c\u5373k\u6b21\u64cd\u4f5c\u65e0\u6cd5\u5c06\u533a\u95f4\u5185\u5168\u90e8\u5b57\u6bcd\u7edf\u4e00\n            if right-left+1-max_len&gt;k:\n                #\u79fb\u52a8\u5de6\u4fa7\u6307\u9488\uff0c\u51cf\u5c11\u5bf9\u5e94\u7684\u5b57\u6bcd\u8ba1\u6570\n                num[ord(s[left])-ord(&#039;A&#039;)]-=1\n                left+=1\n            right+=1\n        return right-left<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b97\u6cd5\u7b80\u4ecb \u6ed1\u52a8\u7a97\u53e3\uff0c\u5c31\u662f\u6709\u4e00\u4e2a\u5927\u5c0f\u53ef\u53d8\u7684\u7a97\u53e3\uff0c\u5de6\u53f3\u4e24\u7aef\u65b9\u5411\u4e00\u81f4\u7684\u5411\u524d\u6ed1\u52a8\uff08\u53f3\u7aef\u56fa\u5b9a\uff0c\u5de6\u7aef\u6ed1\u52a8\uff1b\u5de6\u7aef\u56fa\u5b9a\uff0c\u53f3\u7aef\u6ed1\u52a8\uff09\uff0c\u4e5f\u53ef\u4ee5\u60f3\u8c61\u4e3a\u961f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":2,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/351\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}