{"id":82,"date":"2025-09-06T10:48:44","date_gmt":"2025-09-06T02:48:44","guid":{"rendered":"https:\/\/yxzhangcoco.xyz\/?p=82"},"modified":"2025-09-14T17:35:21","modified_gmt":"2025-09-14T09:35:21","slug":"%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/yxzhangcoco.xyz\/index.php\/2025\/09\/06\/%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3\/","title":{"rendered":"\u6ed1\u52a8\u7a97\u53e3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u8ff7\u4e0a\u4e86leetcode\u5237\u9898\uff0c\u6ed1\u52a8\u7a97\u53e3\u53ef\u4ee5\u8bf4\u662fleetcode\u5165\u95e8\u5fc5\u4f1a\u6280\u5de7\u4e86\uff0c\u8fd9\u91cc\u901a\u8fc7\u5199\u9898\u7684\u8fc7\u7a0b\u91cd\u65b0\u590d\u4e60\u4e00\u904d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode\uff1aLCR 016<a href=\"https:\/\/leetcode.cn\/problems\/wtcaE1\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/wtcaE1\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\">\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b57\u4e32<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\uff0c\u8bf7\u4f60\u627e\u51fa\u5176\u4e2d\u4e0d\u542b\u6709\u91cd\u590d\u5b57\u7b26\u7684&nbsp;<strong>\u6700\u957f\u8fde\u7eed\u5b50\u5b57\u7b26\u4e32&nbsp;<\/strong>\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165: <\/strong>s = &#8220;abcabcbb&#8221;<br><strong>\u8f93\u51fa: <\/strong>3 <br><strong>\u89e3\u91ca:<\/strong> \u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f &#8220;abc&#8221;\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165: <\/strong>s = &#8220;bbbbb&#8221;<br><strong>\u8f93\u51fa: <\/strong>1<br><strong>\u89e3\u91ca: <\/strong>\u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u5b57\u7b26\u4e32\u662f &#8220;b&#8221;\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 1\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165: <\/strong>s = &#8220;pwwkew&#8221;<br><strong>\u8f93\u51fa: <\/strong>3<br><strong>\u89e3\u91ca: <\/strong>\u56e0\u4e3a\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u662f&nbsp;&#8220;wke&#8221;\uff0c\u6240\u4ee5\u5176\u957f\u5ea6\u4e3a 3\u3002<br>&nbsp;    \u8bf7\u6ce8\u610f\uff0c\u4f60\u7684\u7b54\u6848\u5fc5\u987b\u662f <strong>\u5b50\u4e32 <\/strong>\u7684\u957f\u5ea6\uff0c&#8221;pwke&#8221;&nbsp;\u662f\u4e00\u4e2a<em>\u5b50\u5e8f\u5217\uff0c<\/em>\u4e0d\u662f\u5b50\u4e32\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 4\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165: <\/strong>s = &#8220;&#8221;\n<strong>\u8f93\u51fa: <\/strong>0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u5206\u6790\u4e00\u8fb9\u9898\u76ee\uff0c\u9898\u76ee\u8981\u6c42\u7ed9\u5b9a\u5b57\u7b26\u4e32\u65e0\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b57\u4e32\uff0c\u6ce8\u610f\uff0c\u5b57\u4e32\u5fc5\u987b\u662f\u5185\u90e8\u8fde\u7eed\u7684\uff0c\u4e0d\u80fd\u8df3\u8dc3\uff0c\u8fd9\u5c31\u7ed9\u4e86\u6ed1\u52a8\u6570\u7ec4\u53d1\u6325\u7a7a\u95f4\u3002<br>\u5728\u4f7f\u7528\u6ed1\u52a8\u6570\u7ec4\u4e4b\u524d\u8981\u786e\u8ba4\u51e0\u4ef6\u4e8b\u60c5\uff1a<br>1\uff0c\u6570\u7ec4\u957f\u5ea6\u662f\u5426\u53ef\u53d8<br>2\uff0c\u8be5\u4f7f\u7528\u54ea\u79cd\u6570\u636e\u7ed3\u6784\u8bb0\u5f55\u6ed1\u52a8\u7a97\u53e3<br>\u7531\u9898\u610f\u53ef\u5f97\uff0c\u6570\u7ec4\u957f\u5ea6\u53ef\u53d8\uff0c\u540c\u65f6\u662f\u5224\u65ad\u6ed1\u52a8\u7a97\u53e3\u5185\u662f\u5426\u6709\u91cd\u590d\u5b57\u7b26\uff0c\u6545\u53ef\u4ee5\u4f7f\u7528\u96c6\u5408set\u6765\u5224\u65ad\u662f\u5426\u91cd\u590d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nclass Solution(object):\n    def lengthOfLongestSubstring(self, s):\n        \"\"\"\n        \u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u91cd\u590d\u5b57\u7b26\u7684\u6700\u957f\u5b50\u4e32\u7684\u957f\u5ea6\n        \u6ce8\u610f\u662f\u5b57\u4e32\u800c\u4e0d\u662f\u5b50\u5e8f\u5217\n        :type s: str\n        :rtype: int\n        \"\"\"\n        temp=set()\n        left=0\n        right=0\n        max_len=0\n        while right&lt;len(s):\n            temp.add(s&#91;right])\n            right+=1\n            max_len=max(max_len,right-left)\n            while right&lt;len(s) and s&#91;right] in temp :\n                temp.remove(s&#91;left])\n                left+=1\n        return max_len\nif __name__=='__main__':\n    s='abcabcbb'\n    print(Solution().lengthOfLongestSubstring(s))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e00\u503c\u5f97\u6ce8\u610f\u7684\u5373\u4e3a\u5224\u65ad\u53f3\u4fa7\u5b57\u7b26\u662f\u5426\u5728temp\u4e2d\u65f6\uff0c\u8981\u9650\u5b9a\u53f3\u4fa7\u5b57\u7b26\u7684\u8303\u56f4\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u51fa\u73b0\u8d8a\u754c\u7684\u9519\u8bef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode\uff1a209<a href=\"https:\/\/leetcode.cn\/problems\/minimum-size-subarray-sum\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/minimum-size-subarray-sum\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\">\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u5b9a\u4e00\u4e2a\u542b\u6709&nbsp;<code>n<\/code><strong>&nbsp;<\/strong>\u4e2a\u6b63\u6574\u6570\u7684\u6570\u7ec4\u548c\u4e00\u4e2a\u6b63\u6574\u6570&nbsp;target<strong>&nbsp;\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u627e\u51fa\u8be5\u6570\u7ec4\u4e2d\u6ee1\u8db3\u5176\u603b\u548c\u5927\u4e8e\u7b49\u4e8e<strong>&nbsp;<\/strong><code>target<\/code><strong>&nbsp;<\/strong>\u7684\u957f\u5ea6\u6700\u5c0f\u7684&nbsp;<strong>\u5b50\u6570\u7ec4<\/strong>&nbsp;[nums<sub>l<\/sub>, nums<sub>l+1<\/sub>, &#8230;, nums<sub>r-1<\/sub>, nums<sub>r<\/sub>]&nbsp;\uff0c\u5e76\u8fd4\u56de\u5176\u957f\u5ea6<strong>\u3002<\/strong>\u5982\u679c\u4e0d\u5b58\u5728\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u6570\u7ec4\uff0c\u8fd4\u56de&nbsp;<code>0<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>target = 7, nums = [2,3,1,2,4,3]\n<strong>\u8f93\u51fa\uff1a<\/strong>2\n<strong>\u89e3\u91ca\uff1a<\/strong>\u5b50\u6570\u7ec4&nbsp;<code>[4,3]<\/code>&nbsp;\u662f\u8be5\u6761\u4ef6\u4e0b\u7684\u957f\u5ea6\u6700\u5c0f\u7684\u5b50\u6570\u7ec4\u3002\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>target = 4, nums = [1,4,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>1\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>target = 11, nums = [1,1,1,1,1,1,1,1]\n<strong>\u8f93\u51fa\uff1a<\/strong>0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u6837\uff0c\u5206\u6790\u9898\u76ee\uff0c\u663e\u7136\u4e0d\u662f\u5b9a\u957f\uff0c\u800c\u662f\u901a\u8fc7sum\u6765\u7ef4\u62a4\u6570\u7ec4\uff0c\u6545\u6ed1\u52a8\u7a97\u53e3\u76ee\u7684\u4e3a\u7ef4\u62a4\u4e00\u4e2a\u6570\u7ec4\u548c\uff0c\u5f53\u548c\u5c0f\u4e8etarget\u65f6\uff0c\u5411\u53f3\u6269\u5c55\u6570\u7ec4\uff0c\u5e76\u8bb0\u5f55\u5f53\u524d\u6570\u7ec4\u957f\u5ea6\uff1b\u5f53\u5927\u4e8e\u7b49\u4e8etarget\u65f6\uff0c\u5411\u5de6\u6536\u7d27\u6570\u7ec4\uff0c\u76f4\u5230sum\u5c0f\u4e8e\u7b49\u4e8etarget\u3002\u6700\u540e\u8fd4\u56de\u6700\u77ed\u6570\u7ec4\u957f\u5ea6\u3002<br>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>class <\/em>Solution:\n    <em>def <\/em>minSubArrayLen(<em>self<\/em>, target: <em>int<\/em>, nums: <em>list<\/em>&#91;<em>int<\/em>]) -&gt; <em>int<\/em>:\n        \"\"\"\n        \u627e\u51fa\u6570\u7ec4\u4e2d\u8fde\u7eed\u5b50\u6570\u7ec4\u7684\u6700\u5c0f\u957f\u5ea6\uff0c\u8be5\u5b50\u6570\u7ec4\u7684\u548c\u5927\u4e8e\u7b49target\n        <strong><em>:param<\/em><\/strong> target:\n        <strong><em>:param<\/em><\/strong> nums:\n        <strong><em>:return<\/em><\/strong>:\n        \"\"\"\n        sum=0\n        left=0\n        right=0\n        max_len=<em>len<\/em>(nums)\n        <em>for <\/em>i <em>in range<\/em>(<em>len<\/em>(nums)):\n            sum+=nums&#91;i]\n        <em>if <\/em>target&gt;sum:\n            <em>return <\/em>0\n        sum=0\n        <em>while <\/em>right&lt;<em>len<\/em>(nums):\n            sum+=nums&#91;right]\n            right+=1\n            <em>while <\/em>sum&gt;=target:\n                max_len=<em>min<\/em>(max_len,right-left)\n                sum-=nums&#91;left]\n                left+=1\n        <em>return <\/em>max_len\n<em>if <\/em>__name__ == '__main__':\n    <em>print<\/em>(Solution().minSubArrayLen(7,&#91;2,3,1,2,4,3]))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode\uff1a567<a href=\"https:\/\/leetcode.cn\/problems\/permutation-in-string\/?envType=problem-list-v2&amp;envId=UIeT7mzb\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/permutation-in-string\/?envType=problem-list-v2&amp;envId=UIeT7mzb\">\u5b57\u7b26\u4e32\u7684\u6392\u5217<\/a><br>\u7ed9\u4f60\u4e24\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s1<\/code>&nbsp;\u548c&nbsp;<code>s2<\/code>&nbsp;\uff0c\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5224\u65ad&nbsp;<code>s2<\/code>&nbsp;\u662f\u5426\u5305\u542b&nbsp;<code>s1<\/code><strong>&nbsp;<\/strong>\u7684&nbsp;\u6392\u5217\u3002\u5982\u679c\u662f\uff0c\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\uff1b\u5426\u5219\uff0c\u8fd4\u56de&nbsp;<code>false<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6362\u53e5\u8bdd\u8bf4\uff0c<code>s1<\/code>&nbsp;\u7684\u6392\u5217\u4e4b\u4e00\u662f&nbsp;<code>s2<\/code>&nbsp;\u7684&nbsp;<strong>\u5b50\u4e32<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s1 = &#8220;ab&#8221; s2 = &#8220;eidbaooo&#8221;\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n<strong>\u89e3\u91ca\uff1a<\/strong>s2 \u5305\u542b s1 \u7684\u6392\u5217\u4e4b\u4e00 (&#8220;ba&#8221;).\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s1= &#8220;ab&#8221; s2 = &#8220;eidboaoo&#8221;\n<strong>\u8f93\u51fa\uff1a<\/strong>false<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u9898\u610f\u53ef\u5f97\uff0c\u8fd9\u6b21\u662f\u7ef4\u62a4\u4e00\u4e2a\u5b9a\u957f\u7684\u7a97\u53e3\uff0c\u540c\u65f6\u4ec5\u4ec5\u53ea\u662f\u5224\u65ad\u8be5\u7a97\u53e3\u662f\u5426\u4e3a\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u6392\u5217\uff0c\u6545\u53ef\u4ee5\u4f7f\u7528python\u4e2d\u7684\u6570\u636e\u7ed3\u6784Counter\uff0c\u901a\u8fc7\u5224\u65adCounter\u76f8\u7b49\u6765\u5f97\u5230\u662f\u5426\u4e3a\u6392\u5217\uff0c\u4e0d\u8fc7\u8981\u6ce8\u610f\uff0c\u5f53\u5bf9\u5e94\u952e\u503c\u5bf9\u4e3a0\u65f6\u8981\u8bb0\u5f97\u5220\u9664\u8fd9\u4e2a\u952e\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u51fa\u6b21\u6570\u4e3a\u8d1f\u6570\u7684\u952e\u3002<br>\u540c\u65f6\uff0c\u6ce8\u610f\u5230\u662f\u7ef4\u62a4\u4e00\u4e2a\u5b9a\u957f\u7684\u7a97\u53e3\uff0c\u6545\u5728\u7f29\u77ed\u5de6\u8fb9\u754c\u65f6\uff0c\u4e0d\u9700\u8981\u4f7f\u7528while\uff0c\u4f7f\u7528if\u5373\u53ef<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>from <\/em>collections <em>import <\/em>Counter\n<em>class <\/em>Solution:\n    <em>def <\/em>checkInclusion(<em>self<\/em>, s1: <em>str<\/em>, s2: <em>str<\/em>) -&gt; bool:\n        <em>if len<\/em>(s1)&gt;<em>len<\/em>(s2):\n            <em>return False\n        <\/em>temp=Counter(s1)\n        windows=Counter()\n        left=0\n        right=0\n        word_len=<em>len<\/em>(s1)\n        <em>while <\/em>right&lt;<em>len<\/em>(s2):\n            windows&#91;s2&#91;right]]+=1\n            right+=1\n            <em>if <\/em>right-left==word_len:\n                <em>if <\/em>windows==temp:\n                    <em>return True\n                <\/em>left+=1\n                windows&#91;s2&#91;left-1]]-=1\n                <em>if <\/em>windows&#91;s2&#91;left-1]]==0:\n                    <em>del <\/em>windows&#91;s2&#91;left-1]]\n        <em>return False\n\nif <\/em>__name__==\"__main__\":\n    <em>print<\/em>(Solution().checkInclusion(s1 = \"ab\" ,s2 = \"eidbaooo\"))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u5c31\u5168\u662f\u7ea2\u9898\u4e86\uff08\u4e0d\u660e\u767d\u4e3a\u4ec0\u4e48\u6ed1\u52a8\u7a97\u53e3\u6709\u90a3\u4e48\u591a\u7ea2\u9898\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode\uff1a30<a href=\"https:\/\/leetcode.cn\/problems\/substring-with-concatenation-of-all-words\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/substring-with-concatenation-of-all-words\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\">\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b57\u4e32<\/a><br>\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code><strong>&nbsp;<\/strong>\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4&nbsp;words<strong>\u3002<\/strong>&nbsp;words&nbsp;\u4e2d\u6240\u6709\u5b57\u7b26\u4e32&nbsp;<strong>\u957f\u5ea6\u76f8\u540c<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;<code>s<\/code><strong>&nbsp;<\/strong>\u4e2d\u7684&nbsp;<strong>\u4e32\u8054\u5b50\u4e32<\/strong>&nbsp;\u662f\u6307\u4e00\u4e2a\u5305\u542b&nbsp;&nbsp;<code>words<\/code>&nbsp;\u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u4ee5\u4efb\u610f\u987a\u5e8f\u6392\u5217\u8fde\u63a5\u8d77\u6765\u7684\u5b50\u4e32\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982\uff0c\u5982\u679c&nbsp;words = [&#8220;ab&#8221;,&#8221;cd&#8221;,&#8221;ef&#8221;]\uff0c \u90a3\u4e48&nbsp;&#8220;abcdef&#8221;\uff0c&nbsp;&#8220;abefcd&#8221;\uff0c&#8221;cdabef&#8221;\uff0c&nbsp;&#8220;cdefab&#8221;\uff0c&#8221;efabcd&#8221;\uff0c \u548c&nbsp;&#8220;efcdab&#8221;&nbsp;\u90fd\u662f\u4e32\u8054\u5b50\u4e32\u3002&nbsp;&#8220;acdbef&#8221;&nbsp;\u4e0d\u662f\u4e32\u8054\u5b50\u4e32\uff0c\u56e0\u4e3a\u4ed6\u4e0d\u662f\u4efb\u4f55&nbsp;words&nbsp;\u6392\u5217\u7684\u8fde\u63a5\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd4\u56de\u6240\u6709\u4e32\u8054\u5b50\u4e32\u5728&nbsp;<code>s<\/code><strong>&nbsp;<\/strong>\u4e2d\u7684\u5f00\u59cb\u7d22\u5f15\u3002\u4f60\u53ef\u4ee5\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;barfoothefoobarman&#8221;, words = [&#8220;foo&#8221;,&#8221;bar&#8221;]<br><strong>\u8f93\u51fa\uff1a<\/strong>[0,9]<br><strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a words.length == 2 \u540c\u65f6 words[i].length == 3\uff0c\u8fde\u63a5\u7684\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 6\u3002<br>\u5b50\u4e32 &#8220;barfoo&#8221; \u5f00\u59cb\u4f4d\u7f6e\u662f 0\u3002\u5b83\u662f words \u4e2d\u4ee5 [&#8220;bar&#8221;,&#8221;foo&#8221;] \u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002<br>\u5b50\u4e32 &#8220;foobar&#8221; \u5f00\u59cb\u4f4d\u7f6e\u662f 9\u3002\u5b83\u662f words \u4e2d\u4ee5 [&#8220;foo&#8221;,&#8221;bar&#8221;] \u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002<br>\u8f93\u51fa\u987a\u5e8f\u65e0\u5173\u7d27\u8981\u3002\u8fd4\u56de [9,0] \u4e5f\u662f\u53ef\u4ee5\u7684\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;wordgoodgoodgoodbestword&#8221;, words = [&#8220;word&#8221;,&#8221;good&#8221;,&#8221;best&#8221;,&#8221;word&#8221;]<br><strong>\u8f93\u51fa\uff1a<\/strong>[]<br><strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a<strong> <\/strong>words.length == 4 \u5e76\u4e14 words[i].length == 4\uff0c\u6240\u4ee5\u4e32\u8054\u5b50\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 16\u3002<br>s \u4e2d\u6ca1\u6709\u5b50\u4e32\u957f\u5ea6\u4e3a 16 \u5e76\u4e14\u7b49\u4e8e words \u7684\u4efb\u4f55\u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002<br>\u6240\u4ee5\u6211\u4eec\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;barfoofoobarthefoobarman&#8221;, words = [&#8220;bar&#8221;,&#8221;foo&#8221;,&#8221;the&#8221;]\n<strong>\u8f93\u51fa\uff1a<\/strong>[6,9,12]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u56e0\u4e3a words.length == 3 \u5e76\u4e14 words[i].length == 3\uff0c\u6240\u4ee5\u4e32\u8054\u5b50\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a 9\u3002\n\u5b50\u4e32 &#8220;foobarthe&#8221; \u5f00\u59cb\u4f4d\u7f6e\u662f 6\u3002\u5b83\u662f words \u4e2d\u4ee5 [&#8220;foo&#8221;,&#8221;bar&#8221;,&#8221;the&#8221;] \u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002\n\u5b50\u4e32 &#8220;barthefoo&#8221; \u5f00\u59cb\u4f4d\u7f6e\u662f 9\u3002\u5b83\u662f words \u4e2d\u4ee5 [&#8220;bar&#8221;,&#8221;the&#8221;,&#8221;foo&#8221;] \u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002\n\u5b50\u4e32 &#8220;thefoobar&#8221; \u5f00\u59cb\u4f4d\u7f6e\u662f 12\u3002\u5b83\u662f words \u4e2d\u4ee5 [&#8220;the&#8221;,&#8221;foo&#8221;,&#8221;bar&#8221;] \u987a\u5e8f\u6392\u5217\u7684\u8fde\u63a5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u662f\u7528\u8001\u65b9\u6cd5\u5206\u6790\u9898\u76ee\uff0c\u9898\u76ee\u7ed9\u51fawords\u91cc\u9762\u7684\u6240\u6709\u5355\u8bcd\u90fd\u662f\u5b9a\u957f\u7684\uff0c\u90a3\u4e48\u53ef\u4ee5\u786e\u5b9a\u662f\u7ef4\u62a4\u4e00\u4e2a\u5b9a\u957f\u7684\u6570\u7ec4\uff0c\u540c\u65f6\u4e5f\u662f\u5224\u65ad\u662f\u5426\u4e3a\u7ed9\u5b9a\u5b57\u7b26\u4e32\u7684\u6392\u5217\uff0c\u6545\u4e5f\u53ef\u4ee5\u4f7f\u7528python\u91cc\u7684Couner\u3002<br>\u7136\u800c\uff0c\u672c\u9898\u8fd8\u6709\u51e0\u4e2a\u503c\u5f97\u6ce8\u610f\u7684\u70b9<br>\u5982\u679c\u6bcf\u6b21\u53ea\u662f\u79fb\u52a8\u4e00\u4e2a\u683c\u5b50\uff0c\u5c31\u5fc5\u7136\u9700\u8981\u5bf9\u6bcf\u4e00\u7a97\u53e3\u8fdb\u884clen_word\u7684\u5206\u5272\u6765\u5f97\u5230\u5bf9\u5e94\u7684Counter\uff0c\u8fd9\u6837\u4f1a\u9020\u6210\u8ba1\u7b97\u590d\u6742\u5ea6\u903c\u8fd1O\uff08n<sup>2<\/sup>\uff09\u6700\u7ec8\u5bfc\u81f4\u8d85\u65f6\uff08\u522b\u95ee\uff0c\u95ee\u5c31\u662f\u8d85\u65f6\u7206\u7ea2\uff09\u3002\u7136\u6b63\u6240\u8c13\u8f66\u5230\u5c71\u524d\u5fc5\u6709\u8def\uff0c\u53ef\u4ee5\u770b\u51fa\u6bcf\u4e00\u4e2aword\u90fd\u662f\u5b9a\u957f\u7684\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5bf9left\u4ece0-word_len-1\u6bcf\u4e00\u4e2a\u5355\u72ec\u8ba8\u8bba\uff0c\u968f\u540e\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u7a97\u53e3\uff0c\u6bcf\u6b21\u79fb\u52a8\u4e00\u4e2aword_len\uff0c\u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u907f\u514d\u91cd\u590d\u8ba1\u7b97Counter\u4e86\u3002<br>\u4ee5\u4e0b\u4e3a\u5bf9\u5e94\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>from <\/em>collections <em>import <\/em>Counter\n<em>class <\/em>Solution(<em>object<\/em>):\n    <em>def <\/em>findSubstring(<em>self<\/em>, s, words):\n        \"\"\"\n        \u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b57\u4e32\n        <strong><em>:type<\/em><\/strong> s: str\n        <strong><em>:type<\/em><\/strong> words: List&#91;str]\n        <strong><em>:rtype<\/em><\/strong>: List&#91;int]\n        \"\"\"\n        word_len=<em>len<\/em>(words&#91;0])\n        total_len=word_len*<em>len<\/em>(words)\n        word_count=Counter(words)\n        s_count=Counter()\n        left=0\n        right=0\n        res=&#91;]\n        <em>if <\/em>total_len&gt;<em>len<\/em>(s):\n            <em>return <\/em>res\n        <em>for <\/em>i <em>in range<\/em>(word_len):\n            left=i\n            right=i\n            <em>while <\/em>right&lt;<em>len<\/em>(s):\n                s_count&#91;s&#91;right:right+word_len]]+=1\n                right+=word_len\n                <em>if <\/em>right-left==total_len:\n                    <em>if <\/em>s_count==word_count:\n                        res.append(left)\n                    left+=word_len\n                    s_count&#91;s&#91;left-word_len:left]]-=1\n                    <em>if <\/em>s_count&#91;s&#91;left:left-word_len]]==0:\n                        <em>del <\/em>s_count&#91;s&#91;left:left-word_len]]\n            <em>if <\/em>s_count==word_count:\n                res.append(left)\n            s_count.clear()\n        <em>return <\/em>res\n<em>if <\/em>__name__ == '__main__':\n    s=\"barfoothefoobarman\"\n    words=&#91;\"foo\",\"bar\"]\n    <em>print<\/em>(Solution().findSubstring(s,words))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode76\uff1a\u6700\u5c0f\u8986\u76d6\u5b57\u4e32<br>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\u3001\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>t<\/code>&nbsp;\u3002\u8fd4\u56de&nbsp;<code>s<\/code>&nbsp;\u4e2d\u6db5\u76d6&nbsp;<code>t<\/code>&nbsp;\u6240\u6709\u5b57\u7b26\u7684\u6700\u5c0f\u5b50\u4e32\u3002\u5982\u679c&nbsp;<code>s<\/code>&nbsp;\u4e2d\u4e0d\u5b58\u5728\u6db5\u76d6&nbsp;<code>t<\/code>&nbsp;\u6240\u6709\u5b57\u7b26\u7684\u5b50\u4e32\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32&nbsp;<code>\"\"<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e&nbsp;<code>t<\/code>&nbsp;\u4e2d\u91cd\u590d\u5b57\u7b26\uff0c\u6211\u4eec\u5bfb\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u4e2d\u8be5\u5b57\u7b26\u6570\u91cf\u5fc5\u987b\u4e0d\u5c11\u4e8e&nbsp;<code>t<\/code>&nbsp;\u4e2d\u8be5\u5b57\u7b26\u6570\u91cf\u3002<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;<code>s<\/code>&nbsp;\u4e2d\u5b58\u5728\u8fd9\u6837\u7684\u5b50\u4e32\uff0c\u6211\u4eec\u4fdd\u8bc1\u5b83\u662f\u552f\u4e00\u7684\u7b54\u6848\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;ADOBECODEBANC&#8221;, t = &#8220;ABC&#8221;\n<strong>\u8f93\u51fa\uff1a<\/strong>&#8220;BANC&#8221;\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u5c0f\u8986\u76d6\u5b50\u4e32 &#8220;BANC&#8221; \u5305\u542b\u6765\u81ea\u5b57\u7b26\u4e32 t \u7684 &#8216;A&#8217;\u3001&#8217;B&#8217; \u548c &#8216;C&#8217;\u3002\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>s = &#8220;a&#8221;, t = &#8220;a&#8221;\n<strong>\u8f93\u51fa\uff1a<\/strong>&#8220;a&#8221;\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6574\u4e2a\u5b57\u7b26\u4e32 s \u662f\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u3002\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 3:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165:<\/strong> s = &#8220;a&#8221;, t = &#8220;aa&#8221;\n<strong>\u8f93\u51fa:<\/strong> &#8220;&#8221;\n<strong>\u89e3\u91ca:<\/strong> t \u4e2d\u4e24\u4e2a\u5b57\u7b26 &#8216;a&#8217; \u5747\u5e94\u5305\u542b\u5728 s \u7684\u5b50\u4e32\u4e2d\uff0c\n\u56e0\u6b64\u6ca1\u6709\u7b26\u5408\u6761\u4ef6\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u6837\u7528\u8001\u65b9\u6cd5\u5206\u6790\uff0c\u6709\u9898\u76ee\u53ef\u5f97\u4e3a\u975e\u5b9a\u957f\u6ed1\u52a8\u7a97\u53e3\uff0c\u540c\u65f6\u662f\u5224\u65ad\u662f\u5426\u8986\u76d6\u5bf9\u5e94\u5b57\u4e32\uff0c\u6545\u53ef\u4ee5\u7528python\u91cc\u7684Counter\u8fdb\u884c\u5224\u65ad\uff0c\u53ea\u8981t\u4e2d\u6240\u6709\u952e\u503c\u5bf9\u90fd\u5c0f\u4e8eCounter\u91cc\u7684\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from collections import Counter\nclass Solution(object):\n    def counters_contains(self,counter1:Counter,counter2:Counter)-&gt;bool:\n        \"\"\"\n        \u5224\u65adcounter1\u662f\u5426\u5305\u542bcounter2\n        :param counter1:\n        :param counter2:\n        :return:\n        \"\"\"\n        for item,count in counter2.items():\n            if counter1.get(item,0)&lt;count:\n                return False\n        return True\n    def minWindow(self, s, t):\n        \"\"\"\n        :type s: str\n        :type t: str\n        :rtype: str\n        \"\"\"\n        temp=Counter(t)\n        windows=Counter()\n        left=0\n        right=0\n        res=\"\"\n        len_t=len(t)\n        if len(s)&lt;len(t):\n            return \"\"\n        while right&lt;len(s):\n            windows&#91;s&#91;right]]+=1\n            right+=1\n            while self.counters_contains(windows,temp):\n                if res==\"\":\n                    res=s&#91;left:right]\n                else:\n                    if len(res)&gt;right-left:\n                        res=s&#91;left:right]\n                windows&#91;s&#91;left]]-=1\n                left+=1\n                if windows&#91;s&#91;left]]==0:\n                    del windows&#91;s&#91;left]]\n        return res\nif __name__==\"__main__\":\n    s='ADOBECODEBANC'\n    t='ABC'\n    print(Solution().minWindow(s,t))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">leetcode\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/smallest-range-covering-elements-from-k-lists\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\" data-type=\"link\" data-id=\"https:\/\/leetcode.cn\/problems\/smallest-range-covering-elements-from-k-lists\/description\/?envType=problem-list-v2&amp;envId=UIeT7mzb\">632\u6700\u5c0f\u533a\u95f4<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u6709&nbsp;<code>k<\/code>&nbsp;\u4e2a&nbsp;<strong>\u975e\u9012\u51cf\u6392\u5217<\/strong>&nbsp;\u7684\u6574\u6570\u5217\u8868\u3002\u627e\u5230\u4e00\u4e2a&nbsp;<strong>\u6700\u5c0f&nbsp;<\/strong>\u533a\u95f4\uff0c\u4f7f\u5f97&nbsp;<code>k<\/code>&nbsp;\u4e2a\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5217\u8868\u81f3\u5c11\u6709\u4e00\u4e2a\u6570\u5305\u542b\u5728\u5176\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5b9a\u4e49\u5982\u679c&nbsp;b-a &lt; d-c&nbsp;\u6216\u8005\u5728&nbsp;b-a == d-c&nbsp;\u65f6&nbsp;a &lt; c\uff0c\u5219\u533a\u95f4&nbsp;[a,b]&nbsp;\u6bd4&nbsp;[c,d]&nbsp;\u5c0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]\n<strong>\u8f93\u51fa\uff1a<\/strong>[20,24]\n<strong>\u89e3\u91ca\uff1a<\/strong> \n\u5217\u8868 1\uff1a[4, 10, 15, 24, 26]\uff0c24 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 2\uff1a[0, 9, 12, 20]\uff0c20 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n\u5217\u8868 3\uff1a[5, 18, 22, 30]\uff0c22 \u5728\u533a\u95f4 [20,24] \u4e2d\u3002\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [[1,2,3],[1,2,3],[1,2,3]]\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,1]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u9898\u9700\u8981\u5148\u5206\u6790\u4e00\u4e0b\uff0c\u518d\u8f6c\u5316\u4e3a\u6ed1\u52a8\u7a97\u53e3\u3002\u9996\u5148\u5148\u5c06nums\u5185\u7684\u5143\u7d20\u8f6c\u4e3a\u5143\u7ec4\uff0c\u5143\u7ec4\u5206\u522b\u7531\u6570\u7ec4\u503c\u4e0e\u6570\u7ec4\u5bf9\u5e94\u6240\u5728\u5217\u8868\u7684\u7d22\u5f15\uff0c\u968f\u540e\u518d\u5bf9\u6240\u6709\u7684\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u53ea\u770b\u5bf9\u5e94\u7684\u5217\u8868\u7d22\u5f15\uff0c\u5c31\u53ef\u4ee5\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6ed1\u52a8\u7a97\u53e3\u95ee\u9898\u3002<br>\u89e3\u6790\u5982\u4e0b\uff1a<br>\u9996\u5148\u5c06 k \u7ec4\u6570\u636e\u5347\u5e8f\u5408\u5e76\u6210\u4e00\u7ec4\uff0c\u5e76\u8bb0\u5f55\u6bcf\u4e2a\u6570\u5b57\u6240\u5c5e\u7684\u7ec4\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5408\u5e76\u5347\u5e8f\u540e\u5f97\u5230\uff1a<br>[(0,1),(4,0),(5,2),(9,1),(10,0),(12,1),(15,0),(18,2),(20,1),(22,2),(24,0),(26,0),(30,2)]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u53ea\u770b\u6240\u5c5e\u7ec4\u7684\u8bdd\uff0c\u90a3\u4e48<br>[1,0,2,1,0,1,0,2,1,2,0,0,2]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6309\u7ec4\u8fdb\u884c\u6ed1\u7a97\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u7a97\u53e3\u7684\u7ec4\u6ee1\u8db3k\u7ec4\u540e\u5728\u8bb0\u5f55\u7a97\u53e3\u7684\u6700\u5c0f\u533a\u95f4\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[1 0 2] 2 1 0 1 0 2 1 2 0 0 2 [0, 5]<br>1 [0 2 1] 1 0 1 0 2 1 2 0 0 2 [0, 5]<br>1 0 [2 1 0] 0 1 0 2 1 2 0 0 2 [0, 5]<br>1 0 [2 1 0 1] 1 0 2 1 2 0 0 2 [0, 5]<br>1 0 [2 1 0 1 0] 0 2 1 2 0 0 2 [0, 5]<br>1 0 2 1 0 [1 0 2] 2 1 2 0 0 2 [0, 5]<br>1 0 2 1 0 1 [0 2 1] 1 2 0 0 2 [0, 5]<br>1 0 2 1 0 1 [0 2 1 2] 2 0 0 2 [0, 5]<br>1 0 2 1 0 1 0 2 [1 2 0] 0 0 2 [20, 24]<br>1 0 2 1 0 1 0 2 [1 2 0 0] 0 2 [20, 24]<br>1 0 2 1 0 1 0 2 [1 2 0 0 2] 2 [20, 24]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f5c\u8005\uff1aNetcan<br>\u94fe\u63a5\uff1ahttps:\/\/leetcode.cn\/problems\/smallest-range-covering-elements-from-k-lists\/solutions\/240717\/pai-xu-hua-chuang-by-netcan\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81f3\u6b64\uff0c\u8f6c\u6362\u4e3a\u4e00\u4e2a\u4e0d\u5b9a\u957f\u5224\u65ad\u662f\u5426\u8986\u76d6\u7684\u6ed1\u52a8\u7a97\u53e3\u95ee\u9898\uff0c\u5224\u65ad\u662f\u5426\u8986\u76d6\uff0c\u5176\u5b9e\u53ea\u7528\u5224\u65adCounter\u7684\u957f\u5ea6\u662f\u5426\u76f8\u7b49\u5373\u53ef\uff0c\u56e0\u4e3a\u5143\u7d20\u662f\u56fa\u5b9a\uff0c\u5373[i for i in range(len(nums))]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from collections import Counter\nclass Solution:\n    def is_min_range(self,left,right,min_range):\n        \"\"\"\n        \u5224\u65adwindows\u533a\u95f4\u662f\u5426\u4e3a\u6700\u5c0f\n        :param left:\u533a\u95f4\u5de6\u8fb9\u754c\n        :param right:\u533a\u95f4\u6709\u8fb9\u754c\n        :param min_range:\u5f53\u524d\u6700\u5c0f\u533a\u95f4\n        :return:\n        \"\"\"\n        if right-left&lt;min_range&#91;1]-min_range&#91;0]:\n            return True\n        elif right-left==min_range and left&lt;min_range&#91;0]:\n            return True\n        else:\n            return False\n    def smallestRange(self, nums):\n        \"\"\"\n        \u6c42\u6700\u5c0f\u533a\u95f4\n        1\uff0c\u5c06nums\u5408\u5e76\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u5217\u8868\u5143\u7d20\u4e3a\u4e00\u4e2a\u5143\u7ec4\uff0c\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a\u6570\u7ec4\u503c\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u4e3a\u5143\u7d20\u5f52\u5c5e\u7684\u6570\u7ec4\u7f16\u53f7\n        2\uff0c\u5408\u5e76\u540e\u7684\u5217\u8868\u8fdb\u884c\u6392\u5e8f\n        3\uff0c\u4f7f\u7528\u6ed1\u52a8\u7a97\u53e3\uff0c\u5f97\u5230\u6700\u5c0f\u533a\u95f4\n        4\uff0c\u8fd4\u56de\u6700\u5c0f\u533a\u95f4\n        :param nums:\n        :return:\n        \"\"\"\n        nums_list=&#91;]\n        for i in range(len(nums)):\n            for j in range(len(nums&#91;i])):\n                nums_list.append((nums&#91;i]&#91;j],i))\n        nums_list=sorted(nums_list,key=lambda x:x&#91;0],reverse=False)\n        left=0\n        right=0\n        windows=Counter()\n        temp=Counter(&#91;i for i in range(len(nums))])\n        min_range=(float('-inf'),float('inf'))\n\n        while right&lt;len(nums_list):\n            windows&#91;nums_list&#91;right]&#91;1]]+=1\n            right+=1\n            while len(windows)==len(temp):\n                if self.is_min_range(nums_list&#91;left]&#91;0],nums_list&#91;right-1]&#91;0],min_range):\n                    min_range=(nums_list&#91;left]&#91;0],nums_list&#91;right-1]&#91;0])\n                windows&#91;nums_list&#91;left]&#91;1]]-=1\n                if windows&#91;nums_list&#91;left]&#91;1]]==0:\n                    del windows&#91;nums_list&#91;left]&#91;1]]\n                left+=1\n\n        return &#91;min_range&#91;0],min_range&#91;1]]\n\nif __name__==\"__main__\":\n    print(Solution().smallestRange(&#91;&#91;4,10,15,24,26],&#91;0,9,12,20],&#91;5,18,22,30]]))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\uff0c\u8fdb\u884c\u6a21\u677f\u603b\u7ed3\uff0c\u5bf9\u4e8e\u6ed1\u52a8\u7a97\u53e3\uff0c\u53ef\u4ee5\u6309\u7167\u89c4\u5219\u5206\u4e3a\u5b9a\u957f\u4e0e\u4e0d\u5b9a\u957f\u4e24\u79cd\u7c7b\u522b\uff0c\u540c\u65f6\uff0c\u82e5\u5224\u65ad\u6761\u4ef6\u4e3a\u662f\u5426\u91cd\u590d\uff0c\u5219\u53ef\u7528set\uff0c\u5176\u4f59\u4e00\u822c\u4e3a\u4f7f\u7528Counter\uff0c\u6a21\u677f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def move_windows(s:str,t:str):\n    \"\"\"\n    \u6ed1\u52a8\u7a97\u53e3\u6a21\u677f\n    :param s: \n    :param t: \n    :return: \n    \"\"\"\n    left=0\n    right=0\n    if \u7ec8\u6b62\u6761\u4ef6:\n        return \"\"\n    while right&lt;len(s):\n        \u7a97\u53e3\u6269\u5927\n        right+=1\n        while \u7a97\u53e3\u7f29\u5c0f\u6761\u4ef6:  #\u5982\u679c\u4e3a\u5b9a\u957f\uff0c\u5219\u7528if\n            if \u9898\u76ee\u6761\u4ef6:\n                \u8bb0\u5f55\u6240\u7ef4\u62a4\u53d8\u91cf\n            \u7a97\u53e3\u7f29\u5c0f\n            left+=1\n            \u82e5\u7528counter\u5219\u6d88\u53bb\u503c\u4e3a0\u7684\u952e\n    \n    return \u6240\u7ef4\u62a4\u53d8\u91cf\n            <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u8ff7\u4e0a\u4e86leetcode\u5237\u9898\uff0c\u6ed1\u52a8\u7a97\u53e3\u53ef\u4ee5\u8bf4\u662fleetcode\u5165\u95e8\u5fc5\u4f1a\u6280\u5de7\u4e86\uff0c\u8fd9\u91cc\u901a\u8fc7\u5199\u9898\u7684\u8fc7\u7a0b\u91cd\u65b0\u590d\u4e60\u4e00\u904d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":29,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning"],"_links":{"self":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":6,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/posts\/82\/revisions\/93"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media\/29"}],"wp:attachment":[{"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yxzhangcoco.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}