{"id":95089,"date":"2026-08-16T08:25:39","date_gmt":"2026-08-16T00:25:39","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/95089.html"},"modified":"2026-08-16T08:25:39","modified_gmt":"2026-08-16T00:25:39","slug":"leetcode-438%ef%bc%9a%e6%89%be%e5%88%b0%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e6%89%80%e6%9c%89%e5%ad%97%e6%af%8d%e5%bc%82%e4%bd%8d%e8%af%8d%ef%bc%88%e6%bb%91%e5%8a%a8%e7%aa%97%e5%8f%a3%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/95089.html","title":{"rendered":"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3"},"content":{"rendered":"<h2>\u00a0\u00a0&#x1f44b; \u6b22\u8fce\u9605\u8bfb<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"686\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002533-6a81037d4f4e4.jpg\" width=\"868\" \/><\/p>\n<h2>\u4e00.\u9898\u76ee<\/h2>\n<p>438. \u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd &#8211; \u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"645\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002533-6a81037d839d5.png\" width=\"844\" \/><\/p>\n<p>&#x1f3af; \u6b22\u8fce\u6765\u5230\u300c\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u300d\u9898\u89e3\u4e4b\u65c5&#xff01;\u00a0\u672c\u6587\u5c06\u5e26\u4f60\u4ece&#034;\u5728\u957f\u4e32\u4e2d\u6ed1\u52a8\u7a97\u53e3\u5bfb\u627e\u5f02\u4f4d\u8bcd&#034;\u8fd9\u4e00\u76f4\u89c2\u573a\u666f\u51fa\u53d1&#xff0c;\u6df1\u5165\u7406\u89e3\u6ed1\u52a8\u7a97\u53e3 &#043; \u8ba1\u6570\u6570\u7ec4\u7684\u5de7\u5999\u8fd0\u7528&#xff0c;\u5e76\u638c\u63e1\u5982\u4f55\u7528\u6709\u6548\u8ba1\u6570 count \u5224\u65ad\u547d\u4e2d\u6765\u5b9a\u4f4d\u5168\u90e8\u5f02\u4f4d\u8bcd\u8d77\u70b9\u3002<\/p>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u5efa\u8bae\u4f60\u5148&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e86\u89e3\u9898\u76ee\u80cc\u666f&#xff1a;\u8fd9\u662f LeetCode 438 \u9898&#xff0c;\u7ed9\u5b9a\u5b57\u7b26\u4e32\u00a0s\u00a0\u548c\u00a0p&#xff0c;\u627e\u51fa\u00a0s\u00a0\u4e2d\u6240\u6709\u00a0p\u00a0\u7684\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5b50\u4e32\u8d77\u59cb\u4e0b\u6807\u3002\u672c\u8d28\u4e0a&#xff0c;\u5f02\u4f4d\u8bcd\u5373\u5404\u5b57\u6bcd\u51fa\u73b0\u6b21\u6570\u76f8\u540c&#xff0c;\u95ee\u9898\u8f6c\u5316\u4e3a\u5b9a\u957f\u7a97\u53e3\u5185\u7684\u8ba1\u6570\u6bd4\u5bf9\u3002<\/p>\n<\/li>\n<li>\n<p>\u660e\u786e\u5b66\u4e60\u76ee\u6807&#xff1a;\u638c\u63e1\u6ed1\u52a8\u7a97\u53e3 &#043; \u53cc\u8ba1\u6570\u6570\u7ec4\u6280\u672f&#xff0c;\u7406\u89e3\u6709\u6548\u8ba1\u6570 count\u00a0\u7684\u7ef4\u62a4\u539f\u7406&#xff0c;\u5e76\u719f\u7ec3\u5904\u7406\u7a97\u53e3\u8d85\u957f\u65f6\u7684\u51fa\u7a97\u53e3\u903b\u8f91\u3002<\/p>\n<\/li>\n<li>\n<p>\u51c6\u5907\u597d\u73af\u5883&#xff1a;\u5efa\u8bae\u5728\u672c\u5730 IDE \u6216 LeetCode \u5728\u7ebf\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u4ee3\u7801&#xff0c;\u8fb9\u770b\u8fb9\u8fd0\u884c&#xff0c;\u4eb2\u624b\u9a8c\u8bc1\u793a\u4f8b&#xff08;\u5982\u00a0s &#061; &#034;cbaebabacd&#034;, p &#061; &#034;abc&#034;\u00a0\u8f93\u51fa\u00a0[0, 6]&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u672c\u6587\u5c06\u4ece\u95ee\u9898\u8f6c\u5316\u3001\u8fdb\u7a97\u53e3\u3001\u51fa\u7a97\u53e3\u3001\u66f4\u65b0\u7ed3\u679c\u5230\u4ee3\u7801\u5b9e\u73b0&#xff0c;\u5c42\u5c42\u9012\u8fdb\u3002\u5373\u4f7f\u4f60\u5bf9\u6ed1\u52a8\u7a97\u53e3\u8fd8\u4e0d\u719f\u6089&#xff0c;\u6211\u4eec\u4e5f\u4f1a\u4ece&#034;\u8ba9\u7a97\u53e3\u4e0e p \u7b49\u957f&#xff0c;\u8fb9\u8d70\u8fb9\u6838\u5bf9\u5b57\u6bcd\u8d26\u672c&#034;\u8fd9\u4e00\u76f4\u89c9\u51fa\u53d1&#xff0c;\u8ba9\u4f60\u8f7b\u677e\u6293\u4f4f\u6838\u5fc3\u601d\u60f3\u2014\u2014\u7a97\u53e3\u5b9a\u957f\u6ed1\u52a8&#xff0c;\u8ba1\u6570\u5bf9\u9f50\u5373\u547d\u4e2d\u3002\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u4e00\u8d77\u6ed1\u52a8\u7a97\u53e3&#xff0c;\u627e\u51fa\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u8d77\u70b9\u5427&#xff01; &#x1f4cd;&#x1f50d;<\/p>\n<h2>\u4e8c.\u505a\u9898\u601d\u8def<\/h2>\n<h3><span style=\"color:#1c7892\">\u4e00\u3001\u95ee\u9898\u5206\u6790&#xff08;\u524d\u7f6e\u5206\u6790&#xff09;<\/span><\/h3>\n<ul>\n<li>\u9898\u76ee\u8981\u6c42&#xff1a;\u5728\u00a0s\u00a0\u4e2d\u627e\u51fa\u6240\u6709\u4e0e\u00a0p\u00a0\u4e92\u4e3a\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u7684\u8fde\u7eed\u5b50\u4e32&#xff0c;\u8fd4\u56de\u5176\u8d77\u59cb\u4e0b\u6807\u3002<\/li>\n<li>\u5173\u952e\u7ea6\u675f&#xff1a;\u5b50\u4e32\u957f\u5ea6\u5fc5\u987b\u7b49\u4e8e\u00a0p\u00a0\u7684\u957f\u5ea6&#xff08;\u5b9a\u957f\u7a97\u53e3&#xff09;&#xff1b;\u4ec5\u542b\u5c0f\u5199\u5b57\u6bcd&#xff08;\u53ef\u7528 26 \u957f\u5ea6\u8ba1\u6570\u6570\u7ec4&#xff09;&#xff1b;\u5f02\u4f4d\u8bcd\u53ea\u770b\u5b57\u7b26\u9891\u6b21\u76f8\u7b49&#xff0c;\u4e0e\u987a\u5e8f\u65e0\u5173\u3002<\/li>\n<li>\u6838\u5fc3\u601d\u8def&#xff1a;\u7ef4\u62a4\u957f\u5ea6\u6052\u4e3a\u00a0n1\u00a0\u7684\u6ed1\u52a8\u7a97\u53e3&#xff0c;\u7528\u6709\u6548\u8ba1\u6570 count\u00a0\u628a O(26) \u7684\u9891\u6b21\u6bd4\u5bf9\u538b\u7f29\u4e3a O(1) \u7684\u6574\u6570\u5224\u65ad\u3002<\/li>\n<\/ul>\n<h3><span style=\"color:#1c7892\">\u4e8c\u3001\u7b97\u6cd5\u7b56\u7565&#xff08;\u6ed1\u52a8\u7a97\u53e3 &#043; \u8ba1\u6570\u6570\u7ec4&#xff09;<\/span><\/h3>\n<p>\u6838\u5fc3\u6b65\u9aa4&#xff1a;<\/p>\n<li><span style=\"color:#494949\">\u7edf\u8ba1\u00a0p\u00a0\u4e2d\u5404\u5b57\u7b26\u9891\u6b21\u5230\u00a0hash1[26]\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u521d\u59cb\u5316\u7a97\u53e3&#xff1a;left &#061; 0\u3001right &#061; 0\u3001count &#061; 0&#xff0c;hash2[26]\u00a0\u8bb0\u5f55\u7a97\u53e3\u5185\u9891\u6b21\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u8fdb\u7a97\u53e3&#xff1a;right\u00a0\u6307\u5411\u7684\u5b57\u7b26\u52a0\u5165\u00a0hash2&#xff1b;\u82e5\u52a0\u5165\u540e\u00a0hash2[ch] &lt;&#061; hash1[ch]&#xff0c;\u8bf4\u660e\u8be5\u5b57\u7b26\u4ecd\u5728\u914d\u989d\u5185&#xff0c;count&#043;&#043;\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u51fa\u7a97\u53e3&#xff1a;\u5f53\u7a97\u53e3\u957f\u5ea6\u00a0right &#8211; left &#043; 1 &gt; n1\u00a0\u65f6&#xff0c;\u79fb\u9664\u00a0left\u00a0\u6307\u5411\u7684\u5b57\u7b26&#xff1a;\u82e5\u79fb\u9664\u524d\u00a0hash2[ch] &lt;&#061; hash1[ch]&#xff0c;\u8bf4\u660e\u5b83\u66fe\u8ba1\u5165\u914d\u989d&#xff0c;count&#8211;&#xff0c;\u518d\u00a0hash2[ch]&#8211;\u3001left&#043;&#043;\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u66f4\u65b0\u7ed3\u679c&#xff1a;\u82e5\u00a0count &#061;&#061; n1&#xff0c;\u8bf4\u660e\u7a97\u53e3\u5185\u9891\u6b21\u4e0e\u00a0p\u00a0\u5b8c\u5168\u4e00\u81f4&#xff0c;\u8bb0\u5f55\u00a0left\u3002<\/span><\/li>\n<p>\u793a\u4f8b\u6267\u884c\u8fc7\u7a0b&#xff08;s &#061; &#034;cbaebabacd&#034;&#xff0c;p &#061; &#034;abc&#034;&#xff0c;n1 &#061; 3&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u6b65\u9aa4\u53d8\u91cf\u53d8\u5316\u64cd\u4f5c\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>\u9884\u5904\u7406<\/td>\n<td>hash1[a]&#061;1, b&#061;1, c&#061;1<\/td>\n<td>\u7edf\u8ba1 p \u7684\u9891\u6b21<\/td>\n<td>\u8ba1\u6570\u8868\u5c31\u7eea<\/td>\n<\/tr>\n<tr>\n<td>right&#061;0<\/td>\n<td>hash2[c]&#061;1, count&#061;1<\/td>\n<td>\u8fdb &#039;c&#039;&#xff0c;\u914d\u989d\u5185<\/td>\n<td>\u672a\u547d\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>right&#061;1<\/td>\n<td>hash2[b]&#061;1, count&#061;2<\/td>\n<td>\u8fdb &#039;b&#039;&#xff0c;\u914d\u989d\u5185<\/td>\n<td>\u672a\u547d\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>right&#061;2<\/td>\n<td>hash2[a]&#061;1, count&#061;3<\/td>\n<td>\u8fdb &#039;a&#039;&#xff0c;\u914d\u989d\u5185&#xff0c;\u7a97\u53e3&#061;3<\/td>\n<td>\u547d\u4e2d&#xff0c;\u8bb0\u5f55 left&#061;0<\/td>\n<\/tr>\n<tr>\n<td>right&#061;3<\/td>\n<td>count: 3\u21922, left&#061;1<\/td>\n<td>\u8fdb &#039;e&#039; \u4e0d\u8ba1&#xff1b;\u51fa &#039;c&#039; \u51cf count<\/td>\n<td>\u672a\u547d\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>\u2026<\/td>\n<td>\u2026<\/td>\n<td>\u2026<\/td>\n<td>\u2026<\/td>\n<\/tr>\n<tr>\n<td>right&#061;8<\/td>\n<td>count: 2\u21923, left&#061;6<\/td>\n<td>\u8fdb &#039;c&#039; \u8ba1 1&#xff1b;\u51fa &#039;a&#039; \u4e0d\u51cf<\/td>\n<td>\u547d\u4e2d&#xff0c;\u8bb0\u5f55 left&#061;6<\/td>\n<\/tr>\n<tr>\n<td>right&#061;9<\/td>\n<td>count: 3\u21922, left&#061;7<\/td>\n<td>\u8fdb &#039;d&#039; \u4e0d\u8ba1&#xff1b;\u51fa &#039;b&#039; \u51cf count<\/td>\n<td>\u672a\u547d\u4e2d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u7ec8\u8fd4\u56de\u00a0[0, 6]&#xff0c;\u4e0e\u9898\u76ee\u793a\u4f8b\u4e00\u81f4\u3002<\/p>\n<h3><span style=\"color:#1c7892\">\u4e09\u3001\u6b63\u786e\u6027\u8bf4\u660e&#xff08;\u7b80\u5355\u7248\u672c&#xff09;<\/span><\/h3>\n<ul>\n<li><span style=\"color:#494949\">\u7a97\u53e3\u957f\u5ea6\u6052\u4e3a n1&#xff1a;\u6bcf\u6b21\u53f3\u6307\u9488\u524d\u8fdb\u540e&#xff0c;\u53ea\u8981\u957f\u5ea6\u8d85\u8fc7 n1 \u5c31\u7acb\u523b\u6536\u7f29\u5de6\u7aef&#xff0c;\u4fdd\u8bc1\u88ab\u5224\u65ad\u7684\u7a97\u53e3\u59cb\u7ec8\u4e0e p \u7b49\u957f&#xff0c;\u4e0d\u6f0f\u68c0\u4e5f\u4e0d\u91cd\u68c0\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">count \u8bed\u4e49\u53ef\u9760&#xff1a;count \u8868\u793a\u7a97\u53e3\u4e2d&#034;\u6709\u6548\u5b57\u7b26&#034;\u603b\u6570\u2014\u2014\u5373\u6bcf\u4e2a\u5b57\u7b26\u5728\u4e0d\u8d85\u8fc7 p \u9700\u6c42\u914d\u989d\u5185\u7684\u7d2f\u8ba1\u6570\u91cf\u3002\u53ea\u6709\u5f53\u00a0count &#061;&#061; n1\u00a0\u65f6&#xff0c;\u7a97\u53e3\u5185\u9891\u6b21\u624d\u6070\u597d\u5168\u90e8\u7b49\u4e8e p \u7684\u9700\u6c42&#xff0c;\u6b64\u65f6\u7a97\u53e3\u5fc5\u7136\u662f\u5f02\u4f4d\u8bcd&#xff1b;\u53cd\u4e4b\u4ea6\u7136&#xff0c;\u4e0d\u4f1a\u9519\u89e3\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u6bcf\u4e2a\u8d77\u70b9\u90fd\u88ab\u8986\u76d6&#xff1a;left \u4ece 0 \u4e00\u8def\u53f3\u79fb\u5230\u00a0n2 &#8211; n1&#xff0c;\u6240\u6709\u53ef\u80fd\u7684\u5b9a\u957f\u5b50\u4e32\u6070\u597d\u88ab\u7a97\u53e3\u5b8c\u6574\u8986\u76d6\u4e00\u6b21&#xff0c;\u4e0d\u4f1a\u6f0f\u89e3\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u51fa\u7a97\u53e3\u5224\u5b9a\u5b89\u5168&#xff1a;\u5148\u4f9d\u636e\u79fb\u9664\u524d\u7684\u9891\u6b21\u5224\u65ad\u662f\u5426 count&#8211;&#xff0c;\u518d\u771f\u6b63\u51cf\u9891\u6b21&#xff0c;\u987a\u5e8f\u4fdd\u8bc1 count \u59cb\u7ec8\u51c6\u786e\u3002<\/span><\/li>\n<\/ul>\n<h3><span style=\"color:#1c7892\">\u56db\u3001\u5b9e\u73b0\u7ec6\u8282&#xff08;\u8fb9\u754c\u9632\u62a4&#xff09;<\/span><\/h3>\n<ul>\n<li><span style=\"color:#494949\">\u521d\u59cb\u5316&#xff1a;hash1[26] &#061; {0}\u3001hash2[26] &#061; {0}\u3001left &#061; 0\u3001right &#061; 0\u3001count &#061; 0\u3001n1 &#061; p.size()\u3001n2 &#061; s.size()\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u8fb9\u754c\u9632\u62a4&#xff1a;\u82e5\u00a0n1 &gt; n2&#xff0c;s \u4e2d\u4e0d\u53ef\u80fd\u5b58\u5728\u957f\u5ea6 n1 \u7684\u5f02\u4f4d\u8bcd\u5b50\u4e32&#xff0c;\u76f4\u63a5\u8fd4\u56de\u7a7a&#xff1b;right\u00a0\u904d\u5386\u5230\u00a0n2\u00a0\u5373\u505c&#xff1b;\u5b57\u7b26\u7edf\u4e00\u7528\u00a0ch &#8211; &#039;a&#039;\u00a0\u6620\u5c04\u5230 0~25\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u590d\u6742\u5ea6&#xff1a;\u65f6\u95f4 O(n2)&#xff08;\u6bcf\u4e2a\u5b57\u7b26\u8fdb\u3001\u51fa\u7a97\u53e3\u5404\u4e00\u6b21&#xff0c;count \u5224\u65ad O(1)&#xff09;&#xff0c;\u7a7a\u95f4 O(1)&#xff08;\u4e24\u4e2a\u56fa\u5b9a\u957f\u5ea6 26 \u7684\u6570\u7ec4&#xff09;\u3002<\/span><\/li>\n<li><span style=\"color:#494949\">\u5173\u952e\u5224\u65ad&#xff1a;if (hash2[in] &lt;&#061; hash1[in]) count&#043;&#043;&#xff08;\u8fdb\u7a97\u53e3\u914d\u989d\u5224\u65ad&#xff09;\u3001if (right &#8211; left &#043; 1 &gt; n1)&#xff08;\u7a97\u53e3\u6536\u7f29\u5224\u65ad&#xff09;\u3001if (count &#061;&#061; n1)&#xff08;\u547d\u4e2d\u5224\u65ad&#xff09;\u3002<\/span><\/li>\n<\/ul>\n<h3><span style=\"color:#1c7892\">\u4e94\u3001\u8fd4\u56de\u503c&#xff08;\u76ee\u6807\u6620\u5c04&#xff09;<\/span><\/h3>\n<ul>\n<li><span style=\"color:#1c7892\">\u8fd4\u56de\u00a0v&#xff1a;\u6240\u6709\u6ee1\u8db3\u6761\u4ef6\u7684\u5b50\u4e32\u8d77\u59cb\u4e0b\u6807\u3002\u7531\u4e8e left \u4ece\u5de6\u5411\u53f3\u79fb\u52a8&#xff0c;\u7ed3\u679c\u81ea\u7136\u5347\u5e8f\u6392\u5217&#xff0c;\u6b63\u597d\u5bf9\u5e94\u9898\u76ee\u8981\u6c42\u7684&#034;\u8fd4\u56de\u6240\u6709\u8d77\u59cb\u7d22\u5f15&#034;\u3002<\/span><\/li>\n<\/ul>\n<h2>\u4e09.\u4ee3\u7801<\/h2>\n<p>class Solution<br \/>\n{<br \/>\npublic:<br \/>\n    vector&lt;int&gt; findAnagrams(string s, string p)<br \/>\n    {<br \/>\n        vector&lt;int&gt; v;                 \/\/ \u7ed3\u679c\u6570\u7ec4&#xff1a;\u8bb0\u5f55\u6240\u6709\u5f02\u4f4d\u8bcd\u5b50\u4e32\u7684\u8d77\u59cb\u4e0b\u6807<br \/>\n        int n1 &#061; p.size();             \/\/ p \u7684\u957f\u5ea6&#xff0c;\u5373\u7a97\u53e3\u7684\u56fa\u5b9a\u957f\u5ea6<br \/>\n        int n2 &#061; s.size();<\/p>\n<p>        \/\/ \u8fb9\u754c\u9632\u62a4&#xff1a;s \u6bd4 p \u77ed&#xff0c;\u4e0d\u53ef\u80fd\u5b58\u5728\u5f02\u4f4d\u8bcd\u5b50\u4e32&#xff0c;\u76f4\u63a5\u8fd4\u56de\u7a7a<br \/>\n        if (n1 &gt; n2)<br \/>\n        {<br \/>\n            return v;<br \/>\n        }<\/p>\n<p>        int hash1[26] &#061; { 0 };         \/\/ p \u7684\u9891\u6b21\u8868&#xff1a;\u8bb0\u5f55 p \u4e2d\u6bcf\u4e2a\u5b57\u6bcd\u7684\u51fa\u73b0\u6b21\u6570<br \/>\n        \/\/ 1. \u9884\u5904\u7406&#xff1a;\u7edf\u8ba1 p \u4e2d\u5404\u5b57\u7b26\u9891\u6b21<br \/>\n        for (auto ch : p)<br \/>\n        {<br \/>\n            hash1[ch &#8211; &#039;a&#039;]&#043;&#043;;         \/\/ &#039;a&#039; \u7684 ASCII \u7801\u662f 97&#xff0c;\u7edf\u4e00\u6620\u5c04\u5230 0~25<br \/>\n        }<\/p>\n<p>        int hash2[26] &#061; { 0 };         \/\/ \u7a97\u53e3\u9891\u6b21\u8868&#xff1a;\u8bb0\u5f55\u5f53\u524d\u7a97\u53e3\u5185\u5404\u5b57\u7b26\u51fa\u73b0\u6b21\u6570<\/p>\n<p>        \/\/ 2. \u6ed1\u52a8\u7a97\u53e3&#xff1a;\u8fdb\u7a97\u53e3 -&gt; \u5224\u65ad\/\u51fa\u7a97\u53e3 -&gt; \u66f4\u65b0\u7ed3\u679c<br \/>\n        for (int left &#061; 0, right &#061; 0, count &#061; 0; right &lt; n2; right&#043;&#043;)<br \/>\n        {<br \/>\n            \/\/ &#8212;&#8212;&#8212;- \u8fdb\u7a97\u53e3 &#8212;&#8212;&#8212;-<br \/>\n            int in &#061; s[right] &#8211; &#039;a&#039;;   \/\/ \u8fdb\u5165\u7a97\u53e3\u7684\u5b57\u7b26<br \/>\n            hash2[in]&#043;&#043;;               \/\/ \u7a97\u53e3\u9891\u6b21 &#043;1<br \/>\n            if (hash2[in] &lt;&#061; hash1[in])<br \/>\n            {<br \/>\n                count&#043;&#043;;               \/\/ \u8be5\u5b57\u7b26\u4ecd\u5728 p \u7684\u201c\u914d\u989d\u201d\u5185&#xff0c;\u6709\u6548\u8ba1\u6570 &#043;1<br \/>\n            }<\/p>\n<p>            \/\/ &#8212;&#8212;&#8212;- \u5224\u65ad \/ \u51fa\u7a97\u53e3 &#8212;&#8212;&#8212;-<br \/>\n            if (right &#8211; left &#043; 1 &gt; n1) \/\/ \u7a97\u53e3\u957f\u5ea6\u8d85\u51fa p \u7684\u957f\u5ea6&#xff0c;\u5fc5\u987b\u6536\u7f29<br \/>\n            {<br \/>\n                int out &#061; s[left] &#8211; &#039;a&#039;; \/\/ \u5373\u5c06\u79bb\u5f00\u7a97\u53e3\u7684\u5b57\u7b26<br \/>\n                if (hash2[out] &lt;&#061; hash1[out])<br \/>\n                {<br \/>\n                    count&#8211;;           \/\/ \u79fb\u9664\u524d\u8be5\u5b57\u7b26\u66fe\u8ba1\u5165\u914d\u989d&#xff0c;\u6709\u6548\u8ba1\u6570 -1<br \/>\n                }<br \/>\n                hash2[out]&#8211;;          \/\/ \u7a97\u53e3\u9891\u6b21 -1<br \/>\n                left&#043;&#043;;                \/\/ \u5de6\u6307\u9488\u53f3\u79fb&#xff0c;\u7a97\u53e3\u6062\u590d\u4e3a n1 \u957f\u5ea6<br \/>\n            }<\/p>\n<p>            \/\/ &#8212;&#8212;&#8212;- \u66f4\u65b0\u7ed3\u679c &#8212;&#8212;&#8212;-<br \/>\n            if (count &#061;&#061; n1)           \/\/ \u6709\u6548\u8ba1\u6570\u7b49\u4e8e p \u957f\u5ea6&#xff0c;\u8bf4\u660e\u9891\u6b21\u5b8c\u5168\u5339\u914d<br \/>\n            {<br \/>\n                v.push_back(left);     \/\/ \u8bb0\u5f55\u5f53\u524d\u7a97\u53e3\u8d77\u70b9<br \/>\n            }<br \/>\n        }<br \/>\n        return v;                      \/\/ 3. \u8fd4\u56de\u6240\u6709\u5f02\u4f4d\u8bcd\u8d77\u59cb\u4e0b\u6807<br \/>\n    }<br \/>\n}; <\/p>\n<h2><\/h2>\n<h2>\u56db\u3001\u6613\u9519\u70b9\u5206\u6790<\/h2>\n<h4>\u96be\u70b91&#xff1a;\u8fdb\u7a97\u53e3\u65f6&#034;\u5148\u52a0\u9891\u6b21&#xff0c;\u518d\u5224\u65ad\u914d\u989d&#034;\u7684\u987a\u5e8f<\/h4>\n<p>hash2[in]&#043;&#043;;<br \/>\nif (hash2[in] &lt;&#061; hash1[in])<br \/>\n{<br \/>\n    count&#043;&#043;;<br \/>\n} <\/p>\n<p>count \u7edf\u8ba1\u7684\u662f\u7a97\u53e3\u4e2d\u672a\u8d85\u51fa p \u914d\u989d\u7684\u5b57\u7b26\u4e2a\u6570\u3002\u8fdb\u7a97\u53e3\u65f6\u5224\u65ad\u4f9d\u636e\u5fc5\u987b\u662f\u52a0\u5165\u540e\u7684\u6700\u65b0\u9891\u6b21&#xff0c;\u6240\u4ee5\u5fc5\u987b\u5148\u00a0hash2[in]&#043;&#043;\u00a0\u518d\u6bd4\u8f83&#xff1b;\u82e5\u987a\u5e8f\u98a0\u5012&#xff0c;\u5c31\u4f1a\u7528\u65e7\u9891\u6b21\u8bef\u5224&#xff0c;\u5bfc\u81f4 count \u504f\u5c0f\u3001\u6f0f\u89e3\u3002<\/p>\n<hr \/>\n<h4>\u96be\u70b92&#xff1a;\u51fa\u7a97\u53e3\u65f6 count&#8211; \u7684\u5224\u65ad\u57fa\u4e8e&#034;\u79fb\u9664\u524d&#034;\u7684\u9891\u6b21<\/h4>\n<p>int out &#061; s[left] &#8211; &#039;a&#039;;<br \/>\nif (hash2[out] &lt;&#061; hash1[out])<br \/>\n{<br \/>\n    count&#8211;;<br \/>\n}<br \/>\nhash2[out]&#8211;; <\/p>\n<p>\u8fd9\u91cc\u5224\u65ad\u7684\u662f&#034;\u8be5\u5b57\u7b26\u88ab\u79fb\u9664\u524d\u662f\u5426\u5904\u4e8e\u914d\u989d\u5185&#034;\u3002\u5982\u679c\u5148\u00a0hash2[out]&#8211;\u00a0\u518d\u5224\u65ad&#xff0c;\u9891\u6b21\u5df2\u51cf\u5c11&#xff0c;\u7ed3\u679c\u53ef\u80fd\u5931\u771f&#xff08;\u4f8b\u5982\u539f\u9891\u6b21\u6070\u597d\u8d85\u914d\u989d 1&#xff0c;\u5148\u51cf\u540e\u5224\u53d8\u6210&#034;\u5728\u914d\u989d\u5185&#034;&#xff0c;\u5bfc\u81f4 count \u6f0f\u51cf&#xff09;\u3002\u5224\u65ad\u4e0e\u4fee\u6539\u7684\u5148\u540e\u987a\u5e8f\u662f\u672c\u9898\u6700\u5bb9\u6613\u5199\u9519\u7684\u5730\u65b9\u3002<\/p>\n<hr \/>\n<h4>\u96be\u70b93&#xff1a;count \u4e0d\u662f&#034;\u7a97\u53e3\u5b57\u7b26\u603b\u6570&#034;&#xff0c;\u800c\u662f&#034;\u6709\u6548\u5b57\u7b26\u603b\u6570&#034;<\/h4>\n<p>if (count &#061;&#061; n1)<br \/>\n{<br \/>\n    v.push_back(left);<br \/>\n} <\/p>\n<p>\u7a97\u53e3\u91cc\u53ef\u80fd\u6df7\u5165 p \u4e2d\u6ca1\u6709\u7684\u5b57\u7b26&#xff08;\u5982 &#039;e&#039;\u3001&#039;d&#039;&#xff09;&#xff0c;\u5b83\u4eec\u4e0d\u8ba1\u5165 count&#xff1b;\u540c\u4e00\u5b57\u7b26\u8d85\u51fa\u914d\u989d\u7684\u91cd\u590d\u51fa\u73b0\u4e5f\u4e0d\u8ba1\u5165\u3002\u53ea\u6709\u00a0count &#061;&#061; n1\u00a0\u65f6&#xff0c;\u7a97\u53e3\u5185\u9891\u6b21\u624d\u4e0e p \u5b8c\u5168\u4e00\u81f4\u3002\u628a count \u8bef\u5f53\u6210\u7a97\u53e3\u957f\u5ea6\u662f\u5e38\u89c1\u7684\u7406\u89e3\u8bef\u533a\u3002<\/p>\n<h4>\u96be\u70b94&#xff1a;\u7a97\u53e3\u6536\u7f29\u6761\u4ef6\u00a0&gt;\u00a0\u4e0e\u00a0&gt;&#061;\u00a0\u7684\u4e00\u5b57\u4e4b\u5dee<\/h4>\n<p>if (right &#8211; left &#043; 1 &gt; n1)<br \/>\n{<br \/>\n    &#8230;<br \/>\n    left&#043;&#043;;<br \/>\n} <\/p>\n<p>\u7a97\u53e3\u957f\u5ea6\u5fc5\u987b\u6070\u597d\u7b49\u4e8e n1&#xff1a;\u77ed\u4e86\u4f1a\u6f0f\u68c0&#xff0c;\u957f\u4e86\u4f1a\u91cd\u590d\u3002\u7528\u00a0&gt;\u00a0\u4fdd\u8bc1\u6bcf\u8f6e\u81f3\u591a\u6536\u7f29\u4e00\u6b21&#xff0c;\u7a97\u53e3\u7a33\u5b9a\u5728 n1&#xff1b;\u82e5\u8bef\u5199\u6210\u00a0&gt;&#061;&#xff0c;\u7a97\u53e3\u4f1a\u88ab\u538b\u5230 n1-1&#xff0c;\u5bfc\u81f4\u6c38\u8fdc\u65e0\u6cd5\u547d\u4e2d&#xff0c;\u8fd4\u56de\u7a7a\u6570\u7ec4\u3002<\/p>\n<h2>\u4e94\u3001\u6d41\u7a0b\u56fe<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"6986\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002533-6a81037dbb134.png\" width=\"2027\" \/>\u200b<\/p>\n<h3>\u00a0&#x1f3af; \u95ed\u5e55<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1080\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002538-6a81038244f7c.jpg\" width=\"1920\" \/>\u200b<\/p>\n<p>&#x1f389; \u606d\u559c\u4f60\u5b8c\u6210\u4e86\u300c\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u300d\u95ee\u9898\u7684\u5b66\u4e60&#xff01;<\/p>\n<p>\u4e3a\u4e86\u5de9\u56fa\u77e5\u8bc6\u5e76\u8fdb\u4e00\u6b65\u62d3\u5c55&#xff0c;\u5efa\u8bae\u4f60&#xff1a;<\/p>\n<p>&#x1f680;\u00a0\u52a8\u624b\u5b9e\u8df5 \u5728 LeetCode \u4e0a\u63d0\u4ea4\u4ee3\u7801&#xff0c;\u5c1d\u8bd5\u4e0d\u540c\u7684\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<p>&#x1f4a1;\u00a0\u6df1\u5165\u601d\u8003<\/p>\n<ul>\n<li>\n<p>\u672c\u9898\u4f7f\u7528\u00a0\u56fa\u5b9a\u957f\u5ea6\u7684\u6ed1\u52a8\u7a97\u53e3&#xff08;\u7a97\u53e3\u5927\u5c0f\u56fa\u5b9a\u4e3a\u00a0p.length()&#xff09;&#xff0c;\u5e76\u901a\u8fc7\u00a0\u6570\u7ec4\u54c8\u5e0c\u8868\u00a0\u7edf\u8ba1\u7a97\u53e3\u5185\u5b57\u7b26\u9891\u6b21\u4e0e\u00a0p\u00a0\u7684\u9891\u6b21\u8fdb\u884c\u6bd4\u8f83\u3002\u8bf7\u95ee\u00a0\u4e3a\u4ec0\u4e48\u7a97\u53e3\u957f\u5ea6\u56fa\u5b9a\u4e3a\u00a0p\u00a0\u7684\u957f\u5ea6&#xff1f;\u5982\u679c\u7a97\u53e3\u957f\u5ea6\u4e0d\u56fa\u5b9a&#xff0c;\u8fd8\u80fd\u7528\u8fd9\u79cd\u65b9\u5f0f\u5417&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u4e2d\u901a\u8fc7\u00a0count\u00a0\u53d8\u91cf\u8bb0\u5f55\u00a0\u6709\u6548\u5b57\u7b26\u6570&#xff08;\u5373\u7a97\u53e3\u5185\u9891\u6b21\u4e0d\u8d85\u8fc7\u00a0p\u00a0\u5bf9\u5e94\u9891\u6b21\u7684\u5b57\u7b26\u4e2a\u6570&#xff09;&#xff0c;\u4ece\u800c\u907f\u514d\u6bcf\u6b21\u5b8c\u6574\u6bd4\u8f83\u4e24\u4e2a\u54c8\u5e0c\u8868\u3002\u4e3a\u4ec0\u4e48\u00a0count &#061;&#061; n1\u00a0\u5c31\u80fd\u8bf4\u660e\u7a97\u53e3\u662f\u5f02\u4f4d\u8bcd&#xff1f;\u00a0\u8fd9\u80cc\u540e\u7684\u7b49\u4ef7\u6761\u4ef6\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u5f53\u7a97\u53e3\u957f\u5ea6\u8d85\u8fc7\u00a0n1\u00a0\u65f6&#xff0c;\u4ee3\u7801\u5148\u5224\u65ad\u00a0hash2[out] &lt;&#061; hash1[out]\u00a0\u518d\u00a0count&#8211;&#xff0c;\u7136\u540e\u518d\u00a0hash2[out]&#8211;\u3002\u4e3a\u4ec0\u4e48\u5148\u5224\u65ad\u518d\u51cf&#xff0c;\u800c\u4e0d\u662f\u5148\u51cf\u518d\u5224\u65ad&#xff1f;\u00a0\u987a\u5e8f\u98a0\u5012\u4f1a\u6709\u4ec0\u4e48\u95ee\u9898&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u672c\u9898\u5b57\u7b26\u96c6\u9650\u5b9a\u4e3a\u00a0\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd&#xff0c;\u6240\u4ee5\u7528\u00a0int hash[26]\u00a0\u8db3\u591f\u3002\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u00a0Unicode \u5b57\u7b26&#xff08;\u5982\u4e2d\u6587&#xff09;&#xff0c;\u5e94\u5982\u4f55\u6539\u9020\u4ee3\u7801&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u6ed1\u52a8\u7a97\u53e3\u7684\u00a0\u201c\u8fdb\u7a97\u53e3 \u2192 \u5224\u65ad\/\u51fa\u7a97\u53e3 \u2192 \u66f4\u65b0\u7ed3\u679c\u201d\u00a0\u4e09\u6bb5\u5f0f\u7ed3\u6784\u662f\u672c\u9898\u6a21\u677f\u7684\u5178\u578b\u5199\u6cd5\u3002\u5982\u679c\u5c06\u51fa\u7a97\u53e3\u653e\u5728\u00a0\u66f4\u65b0\u7ed3\u679c\u4e4b\u540e&#xff08;\u5373\u5148\u5224\u65ad\u518d\u6536\u7f29&#xff09;&#xff0c;\u4f1a\u6709\u4ec0\u4e48\u5f71\u54cd&#xff1f;<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f4da;\u00a0\u5ef6\u4f38\u6311\u6218<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u9898\u76ee\u8981\u6c42\u8fd4\u56de\u00a0\u6240\u6709\u5f02\u4f4d\u8bcd\u5b50\u4e32\u672c\u8eab&#xff08;\u800c\u4e0d\u662f\u8d77\u59cb\u4e0b\u6807&#xff09;&#xff0c;\u4f60\u7684\u4ee3\u7801\u5e94\u505a\u54ea\u4e9b\u8c03\u6574&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u00a0p\u00a0\u4e2d\u53ef\u80fd\u5305\u542b\u00a0\u91cd\u590d\u5b57\u7b26&#xff08;\u4f8b\u5982\u00a0p &#061; &#034;aa&#034;&#xff09;&#xff0c;\u5f53\u524d\u7684\u00a0count\u00a0\u8ba1\u6570\u903b\u8f91\u662f\u5426\u4ecd\u7136\u6b63\u786e&#xff1f;\u8bf7\u7ed3\u5408\u793a\u4f8b\u00a0s &#061; &#034;baa&#034;\u00a0\u9a8c\u8bc1\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9&#xff0c;\u6b22\u8fce&#xff1a;<\/p>\n<p>&#x1f44d;\u00a0\u70b9\u8d5e \/ \u6536\u85cf &#x1f464;\u00a0\u5173\u6ce8\u4f5c\u8005&#xff0c;\u83b7\u53d6\u66f4\u591a\u9898\u89e3 &#x1f4ac;\u00a0\u7559\u8a00\u4ea4\u6d41\u4f60\u7684\u7591\u95ee\u6216\u4f18\u5316\u601d\u8def<\/p>\n<hr \/>\n<p>&#x1f4cc;\u00a0\u6df1\u5165\u601d\u8003\u7b54\u6848<\/p>\n<ul>\n<li>\n<p>\u7a97\u53e3\u957f\u5ea6\u56fa\u5b9a\u4e3a\u00a0n1&#xff0c;\u56e0\u4e3a\u5f02\u4f4d\u8bcd\u8981\u6c42\u00a0\u957f\u5ea6\u76f8\u540c\u4e14\u5b57\u7b26\u9891\u6b21\u76f8\u540c&#xff0c;\u957f\u5ea6\u4e0d\u540c\u5219\u4e0d\u53ef\u80fd\u5339\u914d&#xff0c;\u56e0\u6b64\u56fa\u5b9a\u7a97\u53e3\u957f\u5ea6\u662f\u81ea\u7136\u7684\u7ea6\u675f\u3002<\/p>\n<\/li>\n<li>\n<p>count &#061;&#061; n1\u00a0\u7b49\u4ef7\u4e8e\u5b8c\u5168\u5339\u914d&#xff0c;\u56e0\u4e3a\u00a0count\u00a0\u8bb0\u5f55\u7684\u662f\u7a97\u53e3\u5185\u6240\u6709\u5b57\u7b26\u7684\u9891\u6b21\u90fd\u4e0d\u8d85\u8fc7\u00a0p\u00a0\u4e2d\u5bf9\u5e94\u5b57\u7b26\u9891\u6b21\u7684\u6570\u91cf&#xff0c;\u4e14\u7a97\u53e3\u957f\u5ea6\u7b49\u4e8e\u00a0n1&#xff0c;\u8fd9\u610f\u5473\u7740\u7a97\u53e3\u5185\u6bcf\u4e2a\u5b57\u7b26\u7684\u9891\u6b21\u6070\u597d\u7b49\u4e8e\u00a0p\u00a0\u4e2d\u5bf9\u5e94\u5b57\u7b26\u7684\u9891\u6b21&#xff0c;\u5373\u5b8c\u5168\u5339\u914d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u5148\u5224\u65ad\u518d\u51cf&#xff0c;\u56e0\u4e3a\u5224\u65ad\u7684\u662f\u00a0\u79fb\u9664\u524d\u00a0\u8be5\u5b57\u7b26\u662f\u5426\u5728\u00a0p\u00a0\u7684\u914d\u989d\u5185&#xff0c;\u82e5\u5148\u51cf\u518d\u5224\u65ad&#xff0c;hash2[out]\u00a0\u5df2\u53d8\u5316&#xff0c;\u5224\u65ad\u7ed3\u679c\u4f1a\u9519\u8bef&#xff0c;\u5bfc\u81f4\u00a0count\u00a0\u8ba1\u6570\u4e0d\u51c6\u3002<\/p>\n<\/li>\n<li>\n<p>\u82e5\u5b57\u7b26\u96c6\u4e3a Unicode&#xff0c;\u6539\u7528\u00a0unordered_map&lt;char, int&gt;\u00a0\u66ff\u4ee3\u56fa\u5b9a\u6570\u7ec4&#xff0c;\u52a8\u6001\u7edf\u8ba1\u9891\u6b21&#xff0c;\u9002\u5e94\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<\/li>\n<li>\n<p>\u82e5\u5148\u66f4\u65b0\u7ed3\u679c\u518d\u6536\u7f29&#xff0c;\u4f1a\u5bfc\u81f4\u7a97\u53e3\u957f\u5ea6\u5927\u4e8e\u00a0n1\u00a0\u65f6\u4ecd\u53ef\u80fd\u88ab\u5224\u65ad\u4e3a\u6709\u6548&#xff0c;\u7834\u574f\u56fa\u5b9a\u7a97\u53e3\u7684\u8bed\u4e49&#xff0c;\u5fc5\u987b\u5148\u5728\u66f4\u65b0\u7ed3\u679c\u524d\u786e\u4fdd\u7a97\u53e3\u957f\u5ea6\u5408\u6cd5\u3002<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f50d;\u00a0\u5ef6\u4f38\u6311\u6218\u7b54\u6848<\/p>\n<ul>\n<li>\n<p>\u6311\u62181&#xff1a;\u53ea\u9700\u5728\u00a0v.push_back(left)\u00a0\u7684\u540c\u65f6&#xff0c;\u7528\u00a0s.substr(left, n1)\u00a0\u53d6\u51fa\u5b50\u4e32\u5e76\u5b58\u5165\u7ed3\u679c\u6570\u7ec4\u5373\u53ef\u3002<\/p>\n<\/li>\n<li>\n<p>\u6311\u62182&#xff1a;count\u00a0\u903b\u8f91\u4ecd\u7136\u6b63\u786e\u3002\u4ee5\u00a0s&#061;&#034;baa&#034;, p&#061;&#034;aa&#034;\u00a0\u4e3a\u4f8b&#xff1a;\u521d\u59cb\u7a97\u53e3\u00a0&#034;ba&#034;&#xff0c;count\u00a0\u4e2d\u00a0b\u00a0\u9891\u6b21 1 &gt;\u00a0hash1[&#039;b&#039;]&#061;0&#xff0c;\u4e0d\u8ba1\u5165&#xff1b;a\u00a0\u9891\u6b21 1 \u2264\u00a0hash1[&#039;a&#039;]&#061;2&#xff0c;\u8ba1\u5165&#xff0c;count&#061;1&#xff0c;\u4e0d\u6ee1\u8db3\u00a0count&#061;&#061;2\u3002\u53f3\u79fb\u540e\u7a97\u53e3\u00a0&#034;aa&#034;&#xff0c;\u4e24\u4e2a\u00a0a\u00a0\u5747\u8ba1\u5165&#xff0c;count&#061;2&#xff0c;\u5339\u914d&#xff0c;\u903b\u8f91\u65e0\u8bef\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u795d\u4f60\u5728\u00a0\u7b97\u6cd5\u4e4b\u8def\u00a0\u4e0a\u8d8a\u8d70\u8d8a\u7a33&#xff0c;\u65e9\u65e5\u653b\u514b\u6bcf\u4e00\u9053\u96be\u9898&#xff01;\u4e0b\u6b21\u89c1 &#x1f680;\u2728<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f44b; \u6b22\u8fce\u9605\u8bfb \u4e00.\u9898\u76ee<br \/>\n438. \u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd &#8211; \u529b\u6263&#xff08;LeetCode&#xff09; &#x1f3af; \u6b22\u8fce\u6765\u5230\u300c\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u300d\u9898\u89e3\u4e4b\u65c5&#xff01;\u00a0\u672c\u6587\u5c06\u5e26\u4f60\u4ece\\&#8221;\u5728\u957f\u4e32\u4e2d\u6ed1\u52a8\u7a97\u53e3\u5bfb\u627e\u5f02\u4f4d\u8bcd\\&#8221;\u8fd9\u4e00\u76f4\u89c2\u573a\u666f\u51fa\u53d1&#xff0c;\u6df1\u5165\u7406\u89e3\u6ed1\u52a8\u7a97\u53e3  \u8ba1\u6570\u6570\u7ec4\u7684\u5de7\u5999\u8fd0\u7528&#xff0c;\u5e76\u638c\u63e1\u5982\u4f55\u7528\u6709\u6548\u8ba1\u6570 count \u5224\u65ad\u547d\u4e2d\u6765\u5b9a\u4f4d\u5168\u90e8\u5f02\u4f4d\u8bcd\u8d77\u70b9\u3002<br \/>\n\u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u5efa\u8bae\u4f60\u5148&#xff1a; \u4e86\u89e3\u9898\u76ee\u80cc<\/p>\n","protected":false},"author":2,"featured_media":95085,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10187,55,2692,1813,5148,427],"topic":[],"class_list":["post-95089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-codingplan","tag-c","tag-leetcode","tag-1813","tag-5148","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/95089.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f44b; \u6b22\u8fce\u9605\u8bfb \u4e00.\u9898\u76ee 438. \u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd - \u529b\u6263&#xff08;LeetCode&#xff09; &#x1f3af; \u6b22\u8fce\u6765\u5230\u300c\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u300d\u9898\u89e3\u4e4b\u65c5&#xff01;\u00a0\u672c\u6587\u5c06\u5e26\u4f60\u4ece&quot;\u5728\u957f\u4e32\u4e2d\u6ed1\u52a8\u7a97\u53e3\u5bfb\u627e\u5f02\u4f4d\u8bcd&quot;\u8fd9\u4e00\u76f4\u89c2\u573a\u666f\u51fa\u53d1&#xff0c;\u6df1\u5165\u7406\u89e3\u6ed1\u52a8\u7a97\u53e3 \u8ba1\u6570\u6570\u7ec4\u7684\u5de7\u5999\u8fd0\u7528&#xff0c;\u5e76\u638c\u63e1\u5982\u4f55\u7528\u6709\u6548\u8ba1\u6570 count \u5224\u65ad\u547d\u4e2d\u6765\u5b9a\u4f4d\u5168\u90e8\u5f02\u4f4d\u8bcd\u8d77\u70b9\u3002 \u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u5efa\u8bae\u4f60\u5148&#xff1a; \u4e86\u89e3\u9898\u76ee\u80cc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/95089.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-16T00:25:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002533-6a81037d4f4e4.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95089.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/95089.html\",\"name\":\"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-16T00:25:39+00:00\",\"dateModified\":\"2026-08-16T00:25:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/95089.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/95089.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/95089.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/95089.html","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f44b; \u6b22\u8fce\u9605\u8bfb \u4e00.\u9898\u76ee 438. \u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd - \u529b\u6263&#xff08;LeetCode&#xff09; &#x1f3af; \u6b22\u8fce\u6765\u5230\u300c\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u300d\u9898\u89e3\u4e4b\u65c5&#xff01;\u00a0\u672c\u6587\u5c06\u5e26\u4f60\u4ece\"\u5728\u957f\u4e32\u4e2d\u6ed1\u52a8\u7a97\u53e3\u5bfb\u627e\u5f02\u4f4d\u8bcd\"\u8fd9\u4e00\u76f4\u89c2\u573a\u666f\u51fa\u53d1&#xff0c;\u6df1\u5165\u7406\u89e3\u6ed1\u52a8\u7a97\u53e3 \u8ba1\u6570\u6570\u7ec4\u7684\u5de7\u5999\u8fd0\u7528&#xff0c;\u5e76\u638c\u63e1\u5982\u4f55\u7528\u6709\u6548\u8ba1\u6570 count \u5224\u65ad\u547d\u4e2d\u6765\u5b9a\u4f4d\u5168\u90e8\u5f02\u4f4d\u8bcd\u8d77\u70b9\u3002 \u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u5efa\u8bae\u4f60\u5148&#xff1a; \u4e86\u89e3\u9898\u76ee\u80cc","og_url":"https:\/\/www.wsisp.com\/helps\/95089.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-16T00:25:39+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260816002533-6a81037d4f4e4.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/95089.html","url":"https:\/\/www.wsisp.com\/helps\/95089.html","name":"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-16T00:25:39+00:00","dateModified":"2026-08-16T00:25:39+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/95089.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/95089.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/95089.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LeetCode 438\uff1a\u627e\u5230\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u6bcd\u5f02\u4f4d\u8bcd\uff08\u6ed1\u52a8\u7a97\u53e3\uff09 \u2014\u2014 \u9898\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=95089"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/95089\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/95085"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=95089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=95089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=95089"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=95089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}