{"id":51596,"date":"2025-08-11T01:04:32","date_gmt":"2025-08-10T17:04:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/51596.html"},"modified":"2025-08-11T01:04:32","modified_gmt":"2025-08-10T17:04:32","slug":"%e3%80%8aleetcode%e3%80%8b-%e9%9d%a2%e8%af%95%e9%a2%98-hot100-%e5%9b%9e%e6%ba%af","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/51596.html","title":{"rendered":"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf"},"content":{"rendered":"<h2>\u9898\u76ee\u5217\u8868<\/h2>\n<li>\n<p>46. \u5168\u6392\u5217 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>78. \u5b50\u96c6 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>17. \u7535\u8bdd\u53f7\u7801\u7684\u6570\u5b57\u7ec4\u5408 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>39. \u7ec4\u5408\u603b\u548c \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>22. \u62ec\u53f7\u751f\u6210 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>79. \u5355\u8bcd\u641c\u7d22 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>131. \u5206\u5272\u56de\u6587\u4e32 \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<li>\n<p>51. N\u7687\u540e \u4e2d\u7b49\u96be\u5ea6 leetcode\u94fe\u63a5<\/p>\n<\/li>\n<h2>\u9898\u76ee<\/h2>\n<h3>&#xff08;1&#xff09;\u5168\u6392\u5217<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e0d\u542b\u91cd\u590d\u6570\u5b57\u7684\u6570\u7ec4 nums &#xff0c;\u8fd4\u56de\u5176 \u6240\u6709\u53ef\u80fd\u7684\u5168\u6392\u5217 \u3002\u4f60\u53ef\u4ee5 \u6309\u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u7b54\u6848\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [1,2,3] \u8f93\u51fa&#xff1a;[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [0,1] \u8f93\u51fa&#xff1a;[[0,1],[1,0]]<\/p>\n<p>\u793a\u4f8b 3&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [1] \u8f93\u51fa&#xff1a;[[1]]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; nums.length &lt;&#061; 6<\/p>\n<\/li>\n<li>\n<p>-10 &lt;&#061; nums[i] &lt;&#061; 10<\/p>\n<\/li>\n<li>\n<p>nums \u4e2d\u7684\u6240\u6709\u6574\u6570 \u4e92\u4e0d\u76f8\u540c<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def permute(self, nums: List[int]) -&gt; List[List[int]]:<br \/>\n        result &#061; []<br \/>\n        self.backtracking(nums, [], [False] * len(nums), result)<br \/>\n        return result<\/p>\n<p>    def backtracking(self, nums, path, used, result):<br \/>\n        if len(path) &#061;&#061; len(nums):<br \/>\n            result.append(path[:])<br \/>\n            return<br \/>\n        for i in range(len(nums)):<br \/>\n            if used[i]:<br \/>\n                continue<br \/>\n            used[i] &#061; True<br \/>\n            path.append(nums[i])<br \/>\n            self.backtracking(nums, path, used, result)<br \/>\n            path.pop()<br \/>\n            used[i] &#061; False <\/p>\n<h3>&#xff08;2&#xff09;\u5b50\u96c6<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\u6570\u7ec4nums&#xff0c;\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4e92\u4e0d\u76f8\u540c \u3002\u8fd4\u56de\u8be5\u6570\u7ec4\u6240\u6709\u53ef\u80fd\u5b50\u96c6&#xff08;\u5e42\u96c6&#xff09;\u3002<\/p>\n<p>\u89e3\u96c6 \u4e0d\u80fd \u5305\u542b\u91cd\u590d\u7684\u5b50\u96c6\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u89e3\u96c6\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [1,2,3] \u8f93\u51fa&#xff1a;[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;nums &#061; [0] \u8f93\u51fa&#xff1a;[[],[0]]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; nums.length &lt;&#061; 10<\/p>\n<\/li>\n<li>\n<p>-10 &lt;&#061; nums[i] &lt;&#061; 10<\/p>\n<\/li>\n<li>\n<p>nums \u4e2d\u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def subsets(self, nums: List[int]) -&gt; List[List[int]]:<br \/>\n        result &#061; []<br \/>\n        path &#061; []<br \/>\n        self.backtracking(nums, 0, path, result)<br \/>\n        return result<\/p>\n<p>    def backtracking(self, nums, startIndex, path, result):<br \/>\n        result.append(path[:])  # \u6536\u96c6\u5b50\u96c6&#xff0c;\u8981\u653e\u5728\u7ec8\u6b62\u6dfb\u52a0\u7684\u4e0a\u9762&#xff0c;\u5426\u5219\u4f1a\u6f0f\u6389\u81ea\u5df1<br \/>\n        # if startIndex &gt;&#061; len(nums):  # \u7ec8\u6b62\u6761\u4ef6\u53ef\u4ee5\u4e0d\u52a0<br \/>\n        #     return<br \/>\n        for i in range(startIndex, len(nums)):<br \/>\n            path.append(nums[i])<br \/>\n            self.backtracking(nums, i &#043; 1, path, result)<br \/>\n            path.pop() <\/p>\n<h3>&#xff08;3&#xff09;\u7535\u8bdd\u53f7\u7801\u7684\u6570\u5b57\u7ec4\u5408<\/h3>\n<h4 style=\"background-color:transparent\">\u9898\u76ee<\/h4>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u6570\u5b57 2-9 \u7684\u5b57\u7b26\u4e32&#xff0c;\u8fd4\u56de\u6240\u6709\u5b83\u80fd\u8868\u793a\u7684\u5b57\u6bcd\u7ec4\u5408\u3002\u7b54\u6848\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u3002<\/p>\n<p>\u7ed9\u51fa\u6570\u5b57\u5230\u5b57\u6bcd\u7684\u6620\u5c04\u5982\u4e0b&#xff08;\u4e0e\u7535\u8bdd\u6309\u952e\u76f8\u540c&#xff09;\u3002\u6ce8\u610f 1 \u4e0d\u5bf9\u5e94\u4efb\u4f55\u5b57\u6bcd\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"282\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810170430-6898d11e76b9d.png\" width=\"348\" \/><\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;digits &#061; &#034;23&#034; \u8f93\u51fa&#xff1a;[&#034;ad&#034;,&#034;ae&#034;,&#034;af&#034;,&#034;bd&#034;,&#034;be&#034;,&#034;bf&#034;,&#034;cd&#034;,&#034;ce&#034;,&#034;cf&#034;]<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;digits &#061; &#034;&#034; \u8f93\u51fa&#xff1a;[]<\/p>\n<p>\u793a\u4f8b 3&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;digits &#061; &#034;2&#034; \u8f93\u51fa&#xff1a;[&#034;a&#034;,&#034;b&#034;,&#034;c&#034;]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>0 &lt;&#061; digits.length &lt;&#061; 4<\/p>\n<\/li>\n<li>\n<p>digits[i] \u662f\u8303\u56f4 [&#039;2&#039;, &#039;9&#039;] \u7684\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def __init__(self):<br \/>\n        self.letterMap &#061; [<br \/>\n            &#034;&#034;,     # 0<br \/>\n            &#034;&#034;,     # 1<br \/>\n            &#034;abc&#034;,  # 2<br \/>\n            &#034;def&#034;,  # 3<br \/>\n            &#034;ghi&#034;,  # 4<br \/>\n            &#034;jkl&#034;,  # 5<br \/>\n            &#034;mno&#034;,  # 6<br \/>\n            &#034;pqrs&#034;, # 7<br \/>\n            &#034;tuv&#034;,  # 8<br \/>\n            &#034;wxyz&#034;  # 9<br \/>\n        ]<br \/>\n        self.result &#061; []<br \/>\n        self.s &#061; &#034;&#034;<\/p>\n<p>    def backtracking(self, digits, index):<br \/>\n        if index &#061;&#061; len(digits):<br \/>\n            self.result.append(self.s)<br \/>\n            return<br \/>\n        digit &#061; int(digits[index])    # \u5c06\u7d22\u5f15\u5904\u7684\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570<br \/>\n        letters &#061; self.letterMap[digit]    # \u83b7\u53d6\u5bf9\u5e94\u7684\u5b57\u7b26\u96c6<br \/>\n        for i in range(len(letters)):<br \/>\n            self.s &#043;&#061; letters[i]    # \u5904\u7406\u5b57\u7b26<br \/>\n            self.backtracking(digits, index &#043; 1)    # \u9012\u5f52\u8c03\u7528&#xff0c;\u6ce8\u610f\u7d22\u5f15\u52a01&#xff0c;\u5904\u7406\u4e0b\u4e00\u4e2a\u6570\u5b57<br \/>\n            self.s &#061; self.s[:-1]    # \u56de\u6eaf&#xff0c;\u5220\u9664\u6700\u540e\u6dfb\u52a0\u7684\u5b57\u7b26<\/p>\n<p>    def letterCombinations(self, digits: str) -&gt; List[str]:<br \/>\n        if len(digits) &#061;&#061; 0:<br \/>\n            return self.result<br \/>\n        self.backtracking(digits, 0)<br \/>\n        return self.result <\/p>\n<h3>&#xff08;4&#xff09;\u7ec4\u5408\u603b\u548c<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u7ed9\u4f60\u4e00\u4e2a \u65e0\u91cd\u590d\u5143\u7d20 \u7684\u6574\u6570\u6570\u7ec4 candidates \u548c\u4e00\u4e2a\u76ee\u6807\u6574\u6570 target &#xff0c;\u627e\u51fa candidates \u4e2d\u53ef\u4ee5\u4f7f\u6570\u5b57\u548c\u4e3a\u76ee\u6807\u6570 target \u7684 \u6240\u6709 \u4e0d\u540c\u7ec4\u5408 &#xff0c;\u5e76\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u3002\u4f60\u53ef\u4ee5\u6309 \u4efb\u610f\u987a\u5e8f \u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\u3002<\/p>\n<p>candidates \u4e2d\u7684 \u540c\u4e00\u4e2a \u6570\u5b57\u53ef\u4ee5 \u65e0\u9650\u5236\u91cd\u590d\u88ab\u9009\u53d6 \u3002\u5982\u679c\u81f3\u5c11\u4e00\u4e2a\u6570\u5b57\u7684\u88ab\u9009\u6570\u91cf\u4e0d\u540c&#xff0c;\u5219\u4e24\u79cd\u7ec4\u5408\u662f\u4e0d\u540c\u7684\u3002<\/p>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u8f93\u5165&#xff0c;\u4fdd\u8bc1\u548c\u4e3a target \u7684\u4e0d\u540c\u7ec4\u5408\u6570\u5c11\u4e8e 150 \u4e2a\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;candidates &#061; [2,3,6,7], target &#061; 7\u8f93\u51fa&#xff1a;[[2,2,3],[7]] \u89e3\u91ca&#xff1a; 2 \u548c 3 \u53ef\u4ee5\u5f62\u6210\u4e00\u7ec4\u5019\u9009&#xff0c;2 &#043; 2 &#043; 3 &#061; 7 \u3002\u6ce8\u610f 2 \u53ef\u4ee5\u4f7f\u7528\u591a\u6b21\u3002 7 \u4e5f\u662f\u4e00\u4e2a\u5019\u9009&#xff0c; 7 &#061; 7 \u3002 \u4ec5\u6709\u8fd9\u4e24\u79cd\u7ec4\u5408\u3002<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165: candidates &#061; [2,3,5], target &#061; 8 \u8f93\u51fa: [[2,2,2,2],[2,3,3],[3,5]]<\/p>\n<p>\u793a\u4f8b 3&#xff1a;<\/p>\n<p>\u8f93\u5165: candidates &#061; [2], target &#061; 1 \u8f93\u51fa: []<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; candidates.length &lt;&#061; 30<\/p>\n<\/li>\n<li>\n<p>2 &lt;&#061; candidates[i] &lt;&#061; 40<\/p>\n<\/li>\n<li>\n<p>candidates \u7684\u6240\u6709\u5143\u7d20 \u4e92\u4e0d\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>1 &lt;&#061; target &lt;&#061; 40<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def backtracking(self, candidates, target, total, startIndex, path, result):<br \/>\n        if total &#061;&#061; target:<br \/>\n            result.append(path[:])<br \/>\n            return<\/p>\n<p>        for i in range(startIndex, len(candidates)):<br \/>\n            if total &#043; candidates[i] &gt; target:<br \/>\n                break<br \/>\n            total &#043;&#061; candidates[i]<br \/>\n            path.append(candidates[i])<br \/>\n            self.backtracking(candidates, target, total, i, path, result)<br \/>\n            total -&#061; candidates[i]<br \/>\n            path.pop()<\/p>\n<p>    def combinationSum(self, candidates: List[int], target: int) -&gt; List[List[int]]:<br \/>\n        result &#061; []<br \/>\n        candidates.sort()  # \u9700\u8981\u6392\u5e8f<br \/>\n        self.backtracking(candidates, target, 0, 0, [], result)<br \/>\n        return result  <\/p>\n<h3>&#xff08;5&#xff09;\u62ec\u53f7\u751f\u6210<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u6570\u5b57 n \u4ee3\u8868\u751f\u6210\u62ec\u53f7\u7684\u5bf9\u6570&#xff0c;\u8bf7\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u51fd\u6570&#xff0c;\u7528\u4e8e\u80fd\u591f\u751f\u6210\u6240\u6709\u53ef\u80fd\u7684\u5e76\u4e14 \u6709\u6548\u7684 \u62ec\u53f7\u7ec4\u5408\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;n &#061; 3 \u8f93\u51fa&#xff1a;[&#034;((()))&#034;,&#034;(()())&#034;,&#034;(())()&#034;,&#034;()(())&#034;,&#034;()()()&#034;]<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;n &#061; 1 \u8f93\u51fa&#xff1a;[&#034;()&#034;]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; n &lt;&#061; 8<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def generateParenthesis(self, n: int) -&gt; List[str]:<br \/>\n        if n &#061;&#061; 0:<br \/>\n            return [&#039;&#039;]<br \/>\n        ans &#061; []<br \/>\n        for c in range(n):<br \/>\n            for left in self.generateParenthesis(c):<br \/>\n                for right in self.generateParenthesis(n-1-c):<br \/>\n                    ans.append(&#039;({}){}&#039;.format(left, right))<br \/>\n        return ans<\/p>\n<p>#\u9898\u89e3&#xff1a;https:\/\/leetcode.cn\/problems\/generate-parentheses\/solutions\/192912\/gua-hao-sheng-cheng-by-leetcode-solution\/<\/p>\n<h3>&#xff08;6&#xff09;\u5355\u8bcd\u641c\u7d22<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u7ed9\u5b9a\u4e00\u4e2a m x n \u4e8c\u7ef4\u5b57\u7b26\u7f51\u683c board \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5355\u8bcd word \u3002\u5982\u679c word \u5b58\u5728\u4e8e\u7f51\u683c\u4e2d&#xff0c;\u8fd4\u56de true &#xff1b;\u5426\u5219&#xff0c;\u8fd4\u56de false \u3002<\/p>\n<p>\u5355\u8bcd\u5fc5\u987b\u6309\u7167\u5b57\u6bcd\u987a\u5e8f&#xff0c;\u901a\u8fc7\u76f8\u90bb\u7684\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u6784\u6210&#xff0c;\u5176\u4e2d\u201c\u76f8\u90bb\u201d\u5355\u5143\u683c\u662f\u90a3\u4e9b\u6c34\u5e73\u76f8\u90bb\u6216\u5782\u76f4\u76f8\u90bb\u7684\u5355\u5143\u683c\u3002\u540c\u4e00\u4e2a\u5355\u5143\u683c\u5185\u7684\u5b57\u6bcd\u4e0d\u5141\u8bb8\u88ab\u91cd\u590d\u4f7f\u7528\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;board &#061; [[&#034;A&#034;,&#034;B&#034;,&#034;C&#034;,&#034;E&#034;],[&#034;S&#034;,&#034;F&#034;,&#034;C&#034;,&#034;S&#034;],[&#034;A&#034;,&#034;D&#034;,&#034;E&#034;,&#034;E&#034;]], word &#061; &#034;ABCCED&#034; \u8f93\u51fa&#xff1a;true<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;board &#061; [[&#034;A&#034;,&#034;B&#034;,&#034;C&#034;,&#034;E&#034;],[&#034;S&#034;,&#034;F&#034;,&#034;C&#034;,&#034;S&#034;],[&#034;A&#034;,&#034;D&#034;,&#034;E&#034;,&#034;E&#034;]], word &#061; &#034;SEE&#034; \u8f93\u51fa&#xff1a;true<\/p>\n<p>\u793a\u4f8b 3&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;board &#061; [[&#034;A&#034;,&#034;B&#034;,&#034;C&#034;,&#034;E&#034;],[&#034;S&#034;,&#034;F&#034;,&#034;C&#034;,&#034;S&#034;],[&#034;A&#034;,&#034;D&#034;,&#034;E&#034;,&#034;E&#034;]], word &#061; &#034;ABCB&#034; \u8f93\u51fa&#xff1a;false<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>m &#061;&#061; board.length<\/p>\n<\/li>\n<li>\n<p>n &#061; board[i].length<\/p>\n<\/li>\n<li>\n<p>1 &lt;&#061; m, n &lt;&#061; 6<\/p>\n<\/li>\n<li>\n<p>1 &lt;&#061; word.length &lt;&#061; 15<\/p>\n<\/li>\n<li>\n<p>board \u548c word \u4ec5\u7531\u5927\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def exist(self, board: List[List[str]], word: str) -&gt; bool:<br \/>\n        def dfs(i, j, k, row, col, list_set, board, path):<br \/>\n            if k &#061;&#061; len(word):<br \/>\n                return True<br \/>\n            for x, y in list_set:<br \/>\n                word_x &#061; i &#043; x<br \/>\n                word_y &#061; j &#043; y<br \/>\n                if 0&lt;&#061; word_x&lt;row and 0&lt;&#061;word_y&lt;col and board[word_x][word_y] &#061;&#061; word[k] and (word_x, word_y) not in path:<br \/>\n                    path.add((word_x, word_y))<br \/>\n                    if dfs(word_x, word_y, k&#043;1, row, col, list_set, board, path):<br \/>\n                        return True<br \/>\n                    path.remove((word_x, word_y))<\/p>\n<p>        row &#061; len(board)<br \/>\n        col &#061; len(board[0])<br \/>\n        list_set &#061; [(-1, 0), (1, 0), (0, -1), (0, 1)]<br \/>\n        k &#061; 1<br \/>\n        for i in range(row):<br \/>\n            for j in range(col):<br \/>\n                if board[i][j] &#061;&#061; word[0] and dfs(i, j, k, row, col, list_set, board, {(i, j)}):<br \/>\n                    return True<br \/>\n        return False <\/p>\n<h3>&#xff08;7&#xff09;\u5206\u5272\u56de\u6587\u4e32<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32 s&#xff0c;\u8bf7\u4f60\u5c06 s \u5206\u5272\u6210\u4e00\u4e9b \u5b50\u4e32&#xff0c;\u4f7f\u6bcf\u4e2a\u5b50\u4e32\u90fd\u662f \u56de\u6587\u4e32 \u3002\u8fd4\u56de s \u6240\u6709\u53ef\u80fd\u7684\u5206\u5272\u65b9\u6848\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;s &#061; &#034;aab&#034; \u8f93\u51fa&#xff1a;[[&#034;a&#034;,&#034;a&#034;,&#034;b&#034;],[&#034;aa&#034;,&#034;b&#034;]]<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;s &#061; &#034;a&#034; \u8f93\u51fa&#xff1a;[[&#034;a&#034;]]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; s.length &lt;&#061; 16<\/p>\n<\/li>\n<li>\n<p>s \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def partition(self, s: str) -&gt; List[List[str]]:<br \/>\n        &#039;&#039;&#039;<br \/>\n        \u9012\u5f52\u7528\u4e8e\u7eb5\u5411\u904d\u5386<br \/>\n        for\u5faa\u73af\u7528\u4e8e\u6a2a\u5411\u904d\u5386<br \/>\n        \u5f53\u5207\u5272\u7ebf\u8fed\u4ee3\u81f3\u5b57\u7b26\u4e32\u672b\u5c3e&#xff0c;\u8bf4\u660e\u627e\u5230\u4e00\u79cd\u65b9\u6cd5<br \/>\n        \u7c7b\u4f3c\u7ec4\u5408\u95ee\u9898&#xff0c;\u4e3a\u4e86\u4e0d\u91cd\u590d\u5207\u5272\u540c\u4e00\u4f4d\u7f6e&#xff0c;\u9700\u8981start_index\u6765\u505a\u6807\u8bb0\u4e0b\u4e00\u8f6e\u9012\u5f52\u7684\u8d77\u59cb\u4f4d\u7f6e(\u5207\u5272\u7ebf)<br \/>\n        &#039;&#039;&#039;<br \/>\n        result &#061; []<br \/>\n        self.backtracking(s, 0, [], result)<br \/>\n        return result<\/p>\n<p>    def backtracking(self, s, start_index, path, result ):<br \/>\n        # Base Case<br \/>\n        if start_index &#061;&#061; len(s):<br \/>\n            result.append(path[:])<br \/>\n            return<\/p>\n<p>        # \u5355\u5c42\u9012\u5f52\u903b\u8f91<br \/>\n        for i in range(start_index, len(s)):<br \/>\n            # \u6b64\u6b21\u6bd4\u5176\u4ed6\u7ec4\u5408\u9898\u76ee\u591a\u4e86\u4e00\u6b65\u5224\u65ad&#xff1a;<br \/>\n            # \u5224\u65ad\u88ab\u622a\u53d6\u7684\u8fd9\u4e00\u6bb5\u5b50\u4e32([start_index, i])\u662f\u5426\u4e3a\u56de\u6587\u4e32<br \/>\n            if self.is_palindrome(s, start_index, i):<br \/>\n                path.append(s[start_index:i&#043;1])<br \/>\n                self.backtracking(s, i&#043;1, path, result)   # \u9012\u5f52\u7eb5\u5411\u904d\u5386&#xff1a;\u4ece\u4e0b\u4e00\u5904\u8fdb\u884c\u5207\u5272&#xff0c;\u5224\u65ad\u5176\u4f59\u662f\u5426\u4ecd\u4e3a\u56de\u6587\u4e32<br \/>\n                path.pop()             # \u56de\u6eaf<\/p>\n<p>    def is_palindrome(self, s: str, start: int, end: int) -&gt; bool:<br \/>\n        i: int &#061; start<br \/>\n        j: int &#061; end<br \/>\n        while i &lt; j:<br \/>\n            if s[i] !&#061; s[j]:<br \/>\n                return False<br \/>\n            i &#043;&#061; 1<br \/>\n            j -&#061; 1<br \/>\n        return True  <\/p>\n<h3>&#xff08;8&#xff09;N\u7687\u540e<\/h3>\n<h4>\u9898\u76ee<\/h4>\n<p>\u6309\u7167\u56fd\u9645\u8c61\u68cb\u7684\u89c4\u5219&#xff0c;\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u4e0e\u4e4b\u5904\u5728\u540c\u4e00\u884c\u6216\u540c\u4e00\u5217\u6216\u540c\u4e00\u659c\u7ebf\u4e0a\u7684\u68cb\u5b50\u3002<\/p>\n<p>n \u7687\u540e\u95ee\u9898 \u7814\u7a76\u7684\u662f\u5982\u4f55\u5c06 n \u4e2a\u7687\u540e\u653e\u7f6e\u5728 n\u00d7n \u7684\u68cb\u76d8\u4e0a&#xff0c;\u5e76\u4e14\u4f7f\u7687\u540e\u5f7c\u6b64\u4e4b\u95f4\u4e0d\u80fd\u76f8\u4e92\u653b\u51fb\u3002<\/p>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570 n &#xff0c;\u8fd4\u56de\u6240\u6709\u4e0d\u540c\u7684 n \u7687\u540e\u95ee\u9898 \u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u6bcf\u4e00\u79cd\u89e3\u6cd5\u5305\u542b\u4e00\u4e2a\u4e0d\u540c\u7684 n \u7687\u540e\u95ee\u9898 \u7684\u68cb\u5b50\u653e\u7f6e\u65b9\u6848&#xff0c;\u8be5\u65b9\u6848\u4e2d &#039;Q&#039; \u548c &#039;.&#039; \u5206\u522b\u4ee3\u8868\u4e86\u7687\u540e\u548c\u7a7a\u4f4d\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;n &#061; 4 \u8f93\u51fa&#xff1a;[[&#034;.Q..&#034;,&#034;&#8230;Q&#034;,&#034;Q&#8230;&#034;,&#034;..Q.&#034;],[&#034;..Q.&#034;,&#034;Q&#8230;&#034;,&#034;&#8230;Q&#034;,&#034;.Q..&#034;]] \u89e3\u91ca&#xff1a;\u5982\u4e0a\u56fe\u6240\u793a&#xff0c;4 \u7687\u540e\u95ee\u9898\u5b58\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u89e3\u6cd5\u3002<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<\/p>\n<p>\u8f93\u5165&#xff1a;n &#061; 1 \u8f93\u51fa&#xff1a;[[&#034;Q&#034;]]<\/p>\n<p>\u63d0\u793a&#xff1a;<\/p>\n<ul>\n<li>\n<p>1 &lt;&#061; n &lt;&#061; 9<\/p>\n<\/li>\n<\/ul>\n<h4>\u601d\u8def<\/h4>\n<p>class Solution:<br \/>\n    def solveNQueens(self, n: int) -&gt; List[List[str]]:<br \/>\n        def generateBoard():<br \/>\n            board &#061; list()<br \/>\n            for i in range(n):<br \/>\n                row[queens[i]] &#061; &#034;Q&#034;<br \/>\n                board.append(&#034;&#034;.join(row))<br \/>\n                row[queens[i]] &#061; &#034;.&#034;<br \/>\n            return board<\/p>\n<p>        def backtrack(row: int):<br \/>\n            if row &#061;&#061; n:<br \/>\n                board &#061; generateBoard()<br \/>\n                solutions.append(board)<br \/>\n            else:<br \/>\n                for i in range(n):<br \/>\n                    if i in columns or row &#8211; i in diagonal1 or row &#043; i in diagonal2:<br \/>\n                        continue<br \/>\n                    queens[row] &#061; i<br \/>\n                    columns.add(i)<br \/>\n                    diagonal1.add(row &#8211; i)<br \/>\n                    diagonal2.add(row &#043; i)<br \/>\n                    backtrack(row &#043; 1)<br \/>\n                    columns.remove(i)<br \/>\n                    diagonal1.remove(row &#8211; i)<br \/>\n                    diagonal2.remove(row &#043; i)<\/p>\n<p>        solutions &#061; list()<br \/>\n        queens &#061; [-1] * n<br \/>\n        columns &#061; set()<br \/>\n        diagonal1 &#061; set()<br \/>\n        diagonal2 &#061; set()<br \/>\n        row &#061; [&#034;.&#034;] * n<br \/>\n        backtrack(0)<br \/>\n        return solutions<\/p>\n<p>#\u94fe\u63a5&#xff1a;https:\/\/leetcode.cn\/problems\/n-queens\/solutions\/398929\/nhuang-hou-by-leetcode-solution\/<br \/>\n# \u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(N!)&#xff0c;\u5176\u4e2d N \u662f\u7687\u540e\u6570\u91cf\u3002<br \/>\n# \u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(N)&#xff0c;\u5176\u4e2d N \u662f\u7687\u540e\u6570\u91cf\u3002\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3b\u8981\u53d6\u51b3\u4e8e\u9012\u5f52\u8c03\u7528\u5c42\u6570\u3001\u8bb0\u5f55\u6bcf\u884c\u653e\u7f6e\u7684\u7687\u540e\u7684\u5217\u4e0b\u6807\u7684\u6570\u7ec4\u4ee5\u53ca\u4e09\u4e2a\u96c6\u5408&#xff0c;\u9012\u5f52\u8c03\u7528\u5c42\u6570\u4e0d\u4f1a\u8d85\u8fc7 N&#xff0c;\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a N&#xff0c;\u6bcf\u4e2a\u96c6\u5408\u7684\u5143\u7d20\u4e2a\u6570\u90fd\u4e0d\u4f1a\u8d85\u8fc7 N\u3002 <\/p>\n<h2>\u7ed3\u5c3e<\/h2>\n<p>\u4eb2\u7231\u7684\u8bfb\u8005\u670b\u53cb&#xff1a;\u611f\u8c22\u60a8\u5728\u7e41\u5fd9\u4e2d\u9a7b\u8db3\u9605\u8bfb\u672c\u671f\u5185\u5bb9&#xff01;\u60a8\u7684\u5230\u6765\u662f\u5bf9\u6211\u4eec\u6700\u5927\u7684\u652f\u6301\u2764\ufe0f<\/p>\n<p>\u6b63\u5982\u53e4\u8bed\u6240\u8a00&#xff1a;&#034;\u5f53\u5c40\u8005\u8ff7&#xff0c;\u65c1\u89c2\u8005\u6e05&#034;\u3002\u60a8\u72ec\u5230\u7684\u89c1\u89e3\u4e0e\u5ba2\u89c2\u8bc4\u4ef7&#xff0c;\u6070\u4f3c\u4e00\u76cf\u660e\u706f&#x1f4a1;&#xff0c;\u80fd\u5e2e\u52a9\u6211\u4eec\u7167\u4eae\u5185\u5bb9\u76f2\u533a&#xff0c;\u8ba9\u672a\u6765\u7684\u521b\u4f5c\u66f4\u52a0\u8d34\u8fd1\u60a8\u7684\u9700\u6c42\u3002<\/p>\n<p>\u82e5\u6b64\u6587\u7ed9\u60a8\u5e26\u6765\u542f\u53d1\u6216\u6536\u83b7&#xff0c;\u4e0d\u59a8\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4e3a\u5f7c\u6b64\u642d\u5efa\u4e00\u5ea7\u6865\u6881&#xff1a; \u2728 \u70b9\u51fb\u53f3\u4e0a\u89d2<span style=\"color:#956fe7\">\u3010\u70b9\u8d5e\u3011<\/span>\u56fe\u6807&#xff0c;\u8ba9\u597d\u5185\u5bb9\u88ab\u66f4\u591a\u4eba\u770b\u89c1 \u2728 \u6ed1\u52a8\u5c4f\u5e55<span style=\"color:#956fe7\">\u3010\u6536\u85cf\u3011<\/span>\u672c\u7bc7&#xff0c;\u4fbf\u4e8e\u968f\u65f6\u67e5\u9605\u56de\u5473 \u2728 \u5728<span style=\"color:#956fe7\">\u8bc4\u8bba<\/span>\u533a\u7559\u4e0b\u60a8\u7684\u771f\u77e5\u707c\u89c1&#xff0c;\u8ba9\u6211\u4eec\u5171\u540c\u78b0\u649e\u601d\u7ef4\u7684\u706b\u82b1<\/p>\n<p>\u6211\u59cb\u7ec8\u79c9\u6301\u5320\u5fc3\u7cbe\u795e&#xff0c;\u4ee5\u952e\u76d8\u4e3a\u7281\u94e7\u6df1\u8015\u77e5\u8bc6\u6c83\u571f&#x1f4bb;&#xff0c;\u7528\u6bcf\u4e00\u6b21\u6572\u51fb\u4f20\u9012\u4e13\u4e1a\u4ef7\u503c&#xff0c;\u4e0d\u65ad\u4f18\u5316\u5185\u5bb9\u5448\u73b0\u5f62\u5f0f&#xff0c;\u529b\u6c42\u4e3a\u60a8\u6253\u9020\u6c89\u6d78\u5f0f\u7684\u9605\u8bfb\u76db\u5bb4&#x1f4da;\u3002<\/p>\n<p>\u6709\u4efb\u4f55\u7591\u95ee\u6216\u5efa\u8bae&#xff1f;\u8bc4\u8bba\u533a\u5c31\u662f\u6211\u4eec\u7684\u8fde\u5fc3\u6865&#xff01;\u60a8\u7684\u6bcf\u4e00\u6761\u7559\u8a00\u6211\u90fd\u5c06\u8ba4\u771f\u7814\u8bfb&#xff0c;\u5e76\u572824\u5c0f\u65f6\u5185\u56de\u590d\u89e3\u7b54&#x1f4dd;\u3002<\/p>\n<p>\u613f\u6211\u4eec\u643a\u624b\u540c\u884c&#xff0c;\u5728\u77e5\u8bc6\u7684\u96e8\u6797\u4e2d\u8301\u58ee\u6210\u957f&#x1f333;&#xff0c;\u5171\u4eab\u601d\u60f3\u7efd\u653e\u7684\u7518\u751c\u679c\u5b9e\u3002\u4e0b\u671f\u76f8\u9047\u65f6&#xff0c;\u671f\u5f85\u770b\u5230\u60a8\u667a\u6167\u7684\u8bc4\u8bba\u4e0e\u95ea\u4eae\u7684\u70b9\u8d5e\u8eab\u5f71\u2728&#xff01;<\/p>\n<hr \/>\n<p>\u81ea\u6211\u4ecb\u7ecd&#xff1a;\u4e00\u7ebf\u4e92\u8054\u7f51\u5927\u5382\u8d44\u6df1\u7b97\u6cd5\u7814\u53d1&#xff08;\u5de5\u4f5c6\u5e74&#043;&#xff09;&#xff0c;4\u5e74\u4ee5\u4e0a\u62db\u8058\u9762\u8bd5\u5b98\u7ecf\u9a8c&#xff08;\u4e00\u4e8c\u9762\u9762\u8bd5\u5b98&#xff0c;\u9762\u8bd5\u5019\u9009\u4eba400&#043;&#xff09;&#xff0c;\u6df1\u8c19\u5c97\u4f4d\u4e13\u4e1a\u77e5\u8bc6\u3001\u6280\u80fd\u96f7\u8fbe\u56fe&#xff0c;\u5df2\u7d2f\u8ba1\u8f85\u5bfc15&#043;\u6c42\u804c\u8005\u987a\u5229\u5165\u804c\u5927\u4e2d\u578b\u4e92\u8054\u7f51\u516c\u53f8\u3002\u719f\u7ec3\u638c\u63e1\u5927\u6a21\u578b\u3001NLP\u3001\u641c\u7d22\u3001\u63a8\u8350\u3001\u6570\u636e\u6316\u6398\u7b97\u6cd5\u548c\u4f18\u5316&#xff0c;\u63d0\u4f9b\u9762\u8bd5\u8f85\u5bfc\u3001\u4e13\u4e1a\u77e5\u8bc6\u5165\u95e8\u5230\u8fdb\u9636\u8f85\u5bfc\u7b49\u5b9a\u5236\u5316\u9700\u6c42\u7b49\u670d\u52a1&#xff0c;\u52a9\u529b\u60a8\u987a\u5229\u5b8c\u6210\u5b66\u4e60\u548c\u6c42\u804c\u4e4b\u65c5&#xff08;\u6709\u9700\u8981\u8005\u53ef\u79c1\u4fe1\u8054\u7cfb&#xff09;\u00a0<\/p>\n<p>\u53cb\u53cb\u4eec&#xff0c;\u81ea\u5df1\u7684\u77e5\u4e4e\u8d26\u53f7\u4e3a<span style=\"color:#956fe7\">\u201c\u5feb\u4e50\u661f\u7403\u201d<\/span>&#xff0c;\u5b9a\u671f\u66f4\u65b0\u6280\u672f\u6587\u7ae0&#xff0c;\u656c\u8bf7\u5173\u6ce8&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb288\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u6574\u7406\u4e868\u9053\u56de\u6eaf\u7b97\u6cd5\u76f8\u5173\u7684\u4e2d\u7b49\u96be\u5ea6LeetCode\u9898\u76ee\uff0c\u5305\u62ec\u5168\u6392\u5217\u3001\u5b50\u96c6\u3001\u7535\u8bdd\u53f7\u7801\u5b57\u6bcd\u7ec4\u5408\u3001\u7ec4\u5408\u603b\u548c\u3001\u62ec\u53f7\u751f\u6210\u3001\u5355\u8bcd\u641c\u7d22\u3001\u5206\u5272\u56de\u6587\u4e32\u548cN\u7687\u540e\u95ee\u9898\u3002\u6bcf\u9053\u9898\u76ee\u90fd\u63d0\u4f9b\u4e86\u793a\u4f8b\u3001\u89e3\u9898\u601d\u8def\u548cPython\u4ee3\u7801\u5b9e\u73b0\uff0c\u5176\u4e2d\u5168\u6392\u5217\u4f7f\u7528\u56de\u6eaf\u6cd5\u6807\u8bb0\u5df2\u7528\u5143\u7d20\uff0c\u5b50\u96c6\u95ee\u9898\u901a\u8fc7\u63a7\u5236\u8d77\u59cb\u7d22\u5f15\u907f\u514d\u91cd\u590d\uff0c\u7ec4\u5408\u603b\u548c\u5141\u8bb8\u5143\u7d20\u91cd\u590d\u4f7f\u7528\uff0cN\u7687\u540e\u91c7\u7528\u96c6\u5408\u8bb0\u5f55\u653b\u51fb\u8303\u56f4\u3002\u8fd9\u4e9b\u9898\u76ee\u5c55\u793a\u4e86\u56de\u6eaf\u7b97\u6cd5\u5728\u7ec4\u5408\u3001\u6392\u5217\u3001\u641c\u7d22\u7b49\u573a\u666f\u7684\u5178\u578b\u5e94\u7528\u6a21\u5f0f\uff1a\u9012\u5f52\u63a2\u7d22\u6240\u6709\u53ef\u80fd\u89e3\uff0c\u901a\u8fc7\u526a\u679d\u4f18\u5316\u6548\u7387\u3002<\/p>\n","protected":false},"author":2,"featured_media":51595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,81,3509,427,925],"topic":[],"class_list":["post-51596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-leetcode","tag-python","tag-3509","tag-427","tag-925"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \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\/51596.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb288\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u6574\u7406\u4e868\u9053\u56de\u6eaf\u7b97\u6cd5\u76f8\u5173\u7684\u4e2d\u7b49\u96be\u5ea6LeetCode\u9898\u76ee\uff0c\u5305\u62ec\u5168\u6392\u5217\u3001\u5b50\u96c6\u3001\u7535\u8bdd\u53f7\u7801\u5b57\u6bcd\u7ec4\u5408\u3001\u7ec4\u5408\u603b\u548c\u3001\u62ec\u53f7\u751f\u6210\u3001\u5355\u8bcd\u641c\u7d22\u3001\u5206\u5272\u56de\u6587\u4e32\u548cN\u7687\u540e\u95ee\u9898\u3002\u6bcf\u9053\u9898\u76ee\u90fd\u63d0\u4f9b\u4e86\u793a\u4f8b\u3001\u89e3\u9898\u601d\u8def\u548cPython\u4ee3\u7801\u5b9e\u73b0\uff0c\u5176\u4e2d\u5168\u6392\u5217\u4f7f\u7528\u56de\u6eaf\u6cd5\u6807\u8bb0\u5df2\u7528\u5143\u7d20\uff0c\u5b50\u96c6\u95ee\u9898\u901a\u8fc7\u63a7\u5236\u8d77\u59cb\u7d22\u5f15\u907f\u514d\u91cd\u590d\uff0c\u7ec4\u5408\u603b\u548c\u5141\u8bb8\u5143\u7d20\u91cd\u590d\u4f7f\u7528\uff0cN\u7687\u540e\u91c7\u7528\u96c6\u5408\u8bb0\u5f55\u653b\u51fb\u8303\u56f4\u3002\u8fd9\u4e9b\u9898\u76ee\u5c55\u793a\u4e86\u56de\u6eaf\u7b97\u6cd5\u5728\u7ec4\u5408\u3001\u6392\u5217\u3001\u641c\u7d22\u7b49\u573a\u666f\u7684\u5178\u578b\u5e94\u7528\u6a21\u5f0f\uff1a\u9012\u5f52\u63a2\u7d22\u6240\u6709\u53ef\u80fd\u89e3\uff0c\u901a\u8fc7\u526a\u679d\u4f18\u5316\u6548\u7387\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/51596.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T17:04:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810170430-6898d11e76b9d.png\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51596.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/51596.html\",\"name\":\"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T17:04:32+00:00\",\"dateModified\":\"2025-08-10T17:04:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/51596.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/51596.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51596.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf\"}]},{\"@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":"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \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\/51596.html","og_locale":"zh_CN","og_type":"article","og_title":"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb288\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u6574\u7406\u4e868\u9053\u56de\u6eaf\u7b97\u6cd5\u76f8\u5173\u7684\u4e2d\u7b49\u96be\u5ea6LeetCode\u9898\u76ee\uff0c\u5305\u62ec\u5168\u6392\u5217\u3001\u5b50\u96c6\u3001\u7535\u8bdd\u53f7\u7801\u5b57\u6bcd\u7ec4\u5408\u3001\u7ec4\u5408\u603b\u548c\u3001\u62ec\u53f7\u751f\u6210\u3001\u5355\u8bcd\u641c\u7d22\u3001\u5206\u5272\u56de\u6587\u4e32\u548cN\u7687\u540e\u95ee\u9898\u3002\u6bcf\u9053\u9898\u76ee\u90fd\u63d0\u4f9b\u4e86\u793a\u4f8b\u3001\u89e3\u9898\u601d\u8def\u548cPython\u4ee3\u7801\u5b9e\u73b0\uff0c\u5176\u4e2d\u5168\u6392\u5217\u4f7f\u7528\u56de\u6eaf\u6cd5\u6807\u8bb0\u5df2\u7528\u5143\u7d20\uff0c\u5b50\u96c6\u95ee\u9898\u901a\u8fc7\u63a7\u5236\u8d77\u59cb\u7d22\u5f15\u907f\u514d\u91cd\u590d\uff0c\u7ec4\u5408\u603b\u548c\u5141\u8bb8\u5143\u7d20\u91cd\u590d\u4f7f\u7528\uff0cN\u7687\u540e\u91c7\u7528\u96c6\u5408\u8bb0\u5f55\u653b\u51fb\u8303\u56f4\u3002\u8fd9\u4e9b\u9898\u76ee\u5c55\u793a\u4e86\u56de\u6eaf\u7b97\u6cd5\u5728\u7ec4\u5408\u3001\u6392\u5217\u3001\u641c\u7d22\u7b49\u573a\u666f\u7684\u5178\u578b\u5e94\u7528\u6a21\u5f0f\uff1a\u9012\u5f52\u63a2\u7d22\u6240\u6709\u53ef\u80fd\u89e3\uff0c\u901a\u8fc7\u526a\u679d\u4f18\u5316\u6548\u7387\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/51596.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T17:04:32+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810170430-6898d11e76b9d.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/51596.html","url":"https:\/\/www.wsisp.com\/helps\/51596.html","name":"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T17:04:32+00:00","dateModified":"2025-08-10T17:04:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/51596.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/51596.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/51596.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u300aLeetcode\u300b-\u9762\u8bd5\u9898-hot100-\u56de\u6eaf"}]},{"@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\/51596","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=51596"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/51595"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=51596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=51596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=51596"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=51596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}