{"id":55326,"date":"2025-08-13T20:44:31","date_gmt":"2025-08-13T12:44:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/55326.html"},"modified":"2025-08-13T20:44:31","modified_gmt":"2025-08-13T12:44:31","slug":"leetcode%e5%88%b7%e9%a2%98%e8%ae%b0%e5%bd%95-108-%e5%b0%86%e6%9c%89%e5%ba%8f%e6%95%b0%e7%bb%84%e8%bd%ac%e6%8d%a2%e4%b8%ba%e4%ba%8c%e5%8f%89%e6%90%9c%e7%b4%a2%e6%a0%91%ef%bc%88easy","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/55326.html","title":{"rendered":"LeetCode\u5237\u9898\u8bb0\u5f55----108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy)"},"content":{"rendered":"<p>2025\/8\/7<\/p>\n<h2>\u9898\u76ee&#xff08;easy)&#xff1a;<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"824\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813124429-689c88ad75f2a.png\" width=\"825\" \/><\/p>\n<hr \/>\n<h2>\u6211\u7684\u601d\u8def&#xff1a;<\/h2>\n<p>\u9996\u5148\u89c2\u5bdf\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u5efa\u7acb\u597d\u7684\u4e8c\u53c9\u6811\u5b83\u7684\u6839\u8282\u70b9\u5e94\u8be5\u662f\u8fd9\u4e2a\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u7684\u5143\u7d20\u503c\u3002\u800c\u5b83\u7684\u5de6\u53f3\u5b50\u6811\u53c8\u662f\u4ece\u4e2d\u95f4\u628a\u8fd9\u4e2a\u6570\u7ec4\u5288\u6210\u4e24\u534a\u4e4b\u540e&#xff0c;\u5de6\u53f3\u6570\u7ec4\u5bf9\u5e94\u7684\u4e2d\u95f4\u4f4d\u7f6e\u7684\u5143\u7d20\u503c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"208\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813124430-689c88ae7e87f.png\" width=\"263\" \/><br \/>\n\u5927\u6982\u662f\u8fd9\u4e48\u4e2a\u610f\u601d&#xff08;*\u53ef\u80fd\u7a0d\u5fae\u770b\u8d77\u6765\u62bd\u8c61&#xff0c;\u5176\u5b9e\u4e5f\u6ca1\u90a3\u4e48\u62bd\u8c61*&#xff09;<\/p>\n<p>\u5927\u6982\u6b65\u9aa4\u5c31\u662f&#xff1a;<\/p>\n<p>\u2460\u4ece\u6570\u7ec4\u4e2d\u95f4\u4f4d\u7f6e\u5efa\u7acb\u5f53\u524d\u6811\u7684\u6839\u8282\u70b9&#xff08;mid)&#xff0c;\u5e76\u628a\u6570\u7ec4\u7528<span style=\"color:#fe2c24\">\u7d22\u5f15\u503c\u5206\u4e3a\u5de6\u53f3\u4e24\u534a<\/span><\/p>\n<p>\u2461\u5728<span style=\"color:#fe2c24\">\u5de6\u534a\u6570\u7ec4<\/span>\u4e2d\u5efa\u7acb\u5f53\u524d\u6811\u7684<span style=\"color:#fe2c24\">\u5de6\u5b50\u6811<\/span>&#xff08;\u8303\u56f4:<span style=\"color:#fe2c24\">[left, mid-1]<\/span>&#xff09;\u3010\u6ce8\u610f\u8981\u7f29\u5c0f\u533a\u95f4\u54e6&#xff0c;mid\u7528\u8fc7\u4e86\u5df2\u7ecf\u3011<\/p>\n<p>\u2462\u5728<span style=\"color:#fe2c24\">\u53f3\u534a\u6570\u7ec4<\/span>\u4e2d\u5efa\u7acb\u5f53\u524d\u6811\u7684<span style=\"color:#fe2c24\">\u53f3\u5b50\u6811<\/span>&#xff08;\u8303\u56f4:[mid&#043;1, right]&#xff09;\u3010\u6ce8\u610f\u8981\u7f29\u5c0f\u533a\u95f4\u54e6&#xff0c;mid\u7528\u8fc7\u4e86\u5df2\u7ecf\u3011<\/p>\n<p>\u2463\u6b65\u9aa4\u4e09\u56db\u4e2d\u7684\u5de6\u53f3\u5b50\u6811\u7531\u4e8e\u4e5f\u76f8\u5f53\u4e8e<span style=\"color:#fe2c24\">\u5df2\u7ecf\u77e5\u9053\u6570\u7ec4<\/span>&#xff0c;<span style=\"color:#fe2c24\">\u8981\u5efa\u7acb\u5e73\u8861\u6811<\/span>&#xff0c;\u6240\u4ee5\u9012\u5f52\u8fdb\u884c\u64cd\u4f5c<\/p>\n<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p># Definition for a binary tree node.<br \/>\n# class TreeNode:<br \/>\n#     def __init__(self, val&#061;0, left&#061;None, right&#061;None):<br \/>\n#         self.val &#061; val<br \/>\n#         self.left &#061; left<br \/>\n#         self.right &#061; right<br \/>\nclass Solution:<br \/>\n    def sortedArrayToBST(self, nums: List[int]) -&gt; Optional[TreeNode]:<br \/>\n        #\u4e8c\u5206\u67e5\u627e<br \/>\n        #\u6570\u7ec4\u4e2d\u95f4\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9<br \/>\n        #\u5de6\u53f3\u5b50\u6811\u7684\u6839\u8282\u70b9\u4ee5\u5b83\u4eec\u5bf9\u5e94\u7684\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9 &#8212; \u9012\u5f52\u7684\u5473\u9053<\/p>\n<p>        #\u8fd4\u56de\u4e00\u4e2a\u5df2\u7ecf\u4f5c\u4e3a\u4e8c\u53c9\u5e73\u8861\u6811\u7684\u5b50\u6811<br \/>\n        def dfs(left:int, right:int) -&gt; Optional[TreeNode]:<br \/>\n            if left &gt; right:<br \/>\n                return None<br \/>\n            mid &#061; (left &#043; right)\/\/2<br \/>\n            #\u6bcf\u6b21\u7f29\u5c0f\u533a\u95f4<br \/>\n            newRoot &#061; TreeNode(nums[mid], dfs(left, mid-1), dfs(mid&#043;1, right))<\/p>\n<p>            return newRoot<\/p>\n<p>        #\u5148\u5efa\u7acb\u5934\u8282\u70b9<br \/>\n        left, right &#061; 0, len(nums)-1<br \/>\n        mid &#061; (left &#043; right)\/\/2<br \/>\n        #\u7136\u540e\u5934\u8282\u70b9\u7684\u5de6\u53f3\u8282\u70b9\u8fde\u63a5\u5de6\u53f3\u5b50\u6811<br \/>\n        head &#061; TreeNode(nums[mid], dfs(left, mid-1), dfs(mid&#043;1, right))<\/p>\n<p>        return head<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O&#xff08;log2n&#xff09;<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O&#xff08;n)<\/p>\n<hr \/>\n<h2>\u4f18\u5316\u601d\u8def&#xff1a;<\/h2>\n<p>\u5176\u5b9e\u4f60\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570\u90fd\u53ef\u4ee5\u6839\u636e\u4f20\u5165\u7684\u5de6\u53f3\u534a\u4e2a\u533a\u95f4\u5efa\u7acb\u6839\u8282\u70b9\u7684\u5de6\u53f3\u5b50\u6811\u4e8c\u53c9\u641c\u7d22\u5e73\u8861\u6811\u4e86&#xff0c;\u90a3\u672c\u8eab\u5b8c\u6574\u7684\u533a\u95f4\u6765\u5efa\u7acb\u4e8c\u53c9\u5e73\u8861\u6811\u7684\u5bf9\u4e0d\u5bf9\u5440&#xff0c;\u6240\u4ee5\u5b8c\u5168\u6ca1\u6709\u5fc5\u8981\u5728\u5916\u9762\u518d\u7279\u6b8a\u53bb\u521b\u5efa\u6839\u8282\u70b9\u7684&#xff0c;\u76f4\u63a5\u5168\u90e8\u5728\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570\u4e2d\u5b8c\u6210\u5373\u53ef<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p># Definition for a binary tree node.<br \/>\n# class TreeNode:<br \/>\n#     def __init__(self, val&#061;0, left&#061;None, right&#061;None):<br \/>\n#         self.val &#061; val<br \/>\n#         self.left &#061; left<br \/>\n#         self.right &#061; right<br \/>\nclass Solution:<br \/>\n    def sortedArrayToBST(self, nums: List[int]) -&gt; Optional[TreeNode]:<br \/>\n        #\u4e8c\u5206\u67e5\u627e<br \/>\n        #\u6570\u7ec4\u4e2d\u95f4\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9<br \/>\n        #\u5de6\u53f3\u5b50\u6811\u7684\u6839\u8282\u70b9\u4ee5\u5b83\u4eec\u5bf9\u5e94\u7684\u6570\u7ec4\u7684\u4e2d\u95f4\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9 &#8212; \u9012\u5f52\u7684\u5473\u9053<\/p>\n<p>        #\u8fd4\u56de\u4e00\u4e2a\u5df2\u7ecf\u4f5c\u4e3a\u4e8c\u53c9\u5e73\u8861\u6811\u7684\u5b50\u6811<br \/>\n        def dfs(left:int, right:int) -&gt; Optional[TreeNode]:<br \/>\n            if left &gt; right:<br \/>\n                return None<br \/>\n            mid &#061; (left &#043; right)\/\/2<br \/>\n            #\u6bcf\u6b21\u7f29\u5c0f\u533a\u95f4<br \/>\n            newRoot &#061; TreeNode(nums[mid], dfs(left, mid-1), dfs(mid&#043;1, right))<\/p>\n<p>            return newRoot<\/p>\n<p>        #\u76f4\u63a5\u5168\u90e8\u5728\u9012\u5f52\u51fd\u6570\u91cc\u5b8c\u6210\u5c31\u597d\u4e86<br \/>\n        return dfs(0, len(nums)-1)<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O&#xff08;log2n&#xff09;<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O&#xff08;n)<\/p>\n<\/p>\n<p>\u770b\u4e86\u9898\u89e3\u540e\u53d1\u73b0\u8fd9\u4e2a\u6570\u7ec4\u539f\u6765\u662f\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u7684\u8f93\u51fa\u7ed3\u679c\u6570\u7ec4\u3002\u4e0d\u8fc7\u7531\u8fd9\u4e2a\u6570\u7ec4\u6ca1\u529e\u6cd5\u5f80\u56de\u63a8\u5f97\u552f\u4e00\u7684\u4e8c\u53c9\u6811&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u5176\u5b9e\u5b83\u5bf9\u5e94\u7684\u4e0d\u6b62\u6709\u4e00\u79cd\u5e73\u8861\u4e8c\u53c9\u6811\u3002<\/p>\n<p>\u800c\u6211\u4eec\u5982\u679c\u5bf9\u6839\u8282\u70b9\u7684\u53d6\u503c\u505a\u4e00\u70b9\u5c0f\u5c0f\u7684\u6539\u53d8\u7684\u8bdd&#xff0c;\u5b83\u4e5f\u662f\u4f1a\u53d8\u6210\u4e0d\u540c\u7684\u5e73\u8861\u641c\u7d22\u4e8c\u53c9\u6811\u7684\u3002\u6211\u4eec\u76ee\u524d\u6839\u8282\u70b9\u9009\u7684\u503c\u7684\u7d22\u5f15\u90fd\u662f<span style=\"color:#fe2c24\">mid &#061; (left &#043; right) \/\/ 2<\/span>&#xff0c;\u4e5f\u5c31\u662f\u4e00\u76f4\u9009<span style=\"color:#fe2c24\">\u4e2d\u95f4\u504f\u5de6<\/span>\u7684\u4f4d\u7f6e\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\u7684\u503c\u3002<\/p>\n<p>\u90a3\u5f53\u7136&#xff0c;\u6211\u4eec\u4e5f\u53ef\u4ee5\u6709<\/p>\n<p><span style=\"color:#fe2c24\">mid &#061; (left &#043; right &#043; 1) \/\/ 2\u00a0 \u00a0<\/span> \u00a0 \u00a0 \u3010\u4e00\u76f4\u9009<span style=\"color:#fe2c24\">\u4e2d\u95f4\u504f\u53f3\u4f4d\u7f6e<\/span>\u7684\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\u7684\u503c\u3011<\/p>\n<p><span style=\"color:#fe2c24\">mid &#061; (left &#043; right &#043; randint(0,1))\/\/2\u00a0 \u00a0<\/span> \u00a0 \u00a0 \u3010<span style=\"color:#fe2c24\">\u968f\u673a\u9009\u4e2d\u95f4\u504f\u5de6\u6216\u504f\u53f3<\/span>\u7684\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\u7684\u503c\u3011<\/p>\n<\/p>\n<p>\u53ea\u6709\u8fd9\u91cc\u4e0d\u4e00\u6837&#xff0c;\u5176\u4ed6\u4ee3\u7801\u90fd\u4e00\u6837&#xff0c;\u6240\u4ee5\u5c31\u4e0d\u7279\u610f\u590d\u5236\u7c98\u8d34\u8fc7\u6765\u4e86\u3002<\/p>\n<hr \/>\n<h2>\u603b\u7ed3&#xff1a;<\/h2>\n<p>\u2460\u8fd8\u662f\u8001\u6bdb\u75c5&#xff0c;\u4e0d\u8981\u8fb9\u60f3\u8fb9\u505a&#xff0c;\u601d\u8003\u8981\u6162&#xff0c;\u89e3\u9898\u624d\u80fd\u5feb\u3002\u4e0d\u7136\u5176\u5b9e\u662f\u53d8\u76f8\u7684\u5077\u61d2<\/p>\n<p>\u2461\u5bf9\u4e8e\u8fdb\u884c\u9012\u5f52\u64cd\u4f5c&#xff0c;\u6211\u4eec\u8981\u9996\u5148\u660e\u786e\u60f3\u597d\u6211\u4eec\u5e0c\u671b<span style=\"color:#fe2c24\">\u8f93\u5165\u4ec0\u4e48<\/span>&#xff0c;\u5e76\u4ece\u9012\u5f52\u51fd\u6570\u4e2d<span style=\"color:#fe2c24\">\u5f97\u5230\u4ec0\u4e48<\/span>\u3002\u6bd4\u5982\u8fd9\u91cc\u7684\u9012\u5f52\u6211\u4eec\u9700\u8981\u5f97\u5230\u5efa\u7acb\u597d\u7684\u5e73\u8861\u6811\u7684\u6839\u8282\u70b9&#xff0c;\u800c\u8981\u5f97\u5230\u8fd9\u4e2a\u6839\u8282\u70b9\u9700\u8981\u7684\u503c\u6211\u4eec\u5c31\u9700\u8981\u77e5\u9053\u8fd9\u4e2a\u6570\u7ec4\u7684\u533a\u95f4\u8303\u56f4&#xff0c;\u624d\u80fd\u53bb\u53d6\u5f97\u4e2d\u95f4\u7684\u503c&#xff0c;\u6240\u4ee5\u6211\u4eec\u5c31\u77e5\u9053\u8f93\u5165\u662f\u8981\u5efa\u7acb\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6570\u7ec4\u7684\u533a\u95f4\u3002<\/p>\n<p>\u2462\u5bf9\u4e8e\u4e8c\u5206\u641c\u7d22&#xff0c;\u4e00\u5b9a\u8981\u8bb0\u5f97\u6bcf\u6b21\u641c\u7d22\u5b8c\u4e2d\u95f4\u7684\u503c\u4e4b\u540e&#xff0c;\u518d\u53bb\u641c\u7d22\u5de6\u53f3\u4e24\u534a\u533a\u95f4\u7684\u65f6\u5019\u8981\u628a\u4e4b\u524d\u7684\u4e2d\u95f4\u503c\u6392\u9664\u51fa\u53bb&#xff0c;\u4e0d\u7136\u4e00\u76f4\u4f1a\u6709\u91cd\u590d\u7684\u9690\u60a3\u7684\u3002\u8fd9\u5f88\u4e0d\u597d<\/p>\n<p>\u2463\u6bcf\u4e2a\u6811\u90fd\u6709\u552f\u4e00\u786e\u5b9a\u7684\u4e2d\u5e8f\u904d\u5386\u8f93\u51fa\u987a\u5e8f&#xff0c;\u4f46\u662f\u540c\u4e00\u4e2a\u4e2d\u5e8f\u904d\u5386\u8f93\u51fa\u987a\u5e8f\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2a\u6811<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb649\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65b9\u6cd5\u3002\u6838\u5fc3\u601d\u8def\u662f\u91c7\u7528\u5206\u6cbb\u7b56\u7565\uff0c\u6bcf\u6b21\u9009\u62e9\u6570\u7ec4\u4e2d\u95f4\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u9012\u5f52\u6784\u5efa\u5de6\u53f3\u5b50\u6811\u3002\u6587\u4e2d\u7ed9\u51fa\u4e86\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff1a\u4e00\u79cd\u662f\u5148\u5355\u72ec\u5904\u7406\u6839\u8282\u70b9\uff0c\u53e6\u4e00\u79cd\u662f\u5b8c\u5168\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f18\u5316\u540e\u7684\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(logn)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6O(n)\u3002\u6587\u7ae0\u8fd8\u6307\u51fa\uff0c\u7531\u4e8e\u4e2d\u5e8f\u904d\u5386\u7ed3\u679c\u4e0d\u552f\u4e00\uff0c\u53ef\u4ee5\u9009\u62e9\u4e2d\u95f4\u504f\u5de6\u3001\u504f\u53f3\u6216\u968f\u673a\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9\u6765\u6784\u5efa\u4e0d\u540c\u7684\u5e73\u8861\u6811\u3002\u6700\u540e\u603b\u7ed3\u4e86\u9012\u5f52\u8bbe\u8ba1\u548c\u4e8c\u5206\u641c\u7d22\u7684\u6ce8\u610f\u4e8b\u9879\uff0c\u5f3a\u8c03\u660e\u786e\u9012\u5f52\u8f93\u5165\u8f93\u51fa\u548c\u907f\u514d\u91cd\u590d\u5143\u7d20\u5904\u7406\u7684\u91cd\u8981\u6027\u3002<\/p>\n","protected":false},"author":2,"featured_media":55324,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,4617,1578,427,5689],"topic":[],"class_list":["post-55326","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-leetcode","tag-4617","tag-1578","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \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\/55326.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb649\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65b9\u6cd5\u3002\u6838\u5fc3\u601d\u8def\u662f\u91c7\u7528\u5206\u6cbb\u7b56\u7565\uff0c\u6bcf\u6b21\u9009\u62e9\u6570\u7ec4\u4e2d\u95f4\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u9012\u5f52\u6784\u5efa\u5de6\u53f3\u5b50\u6811\u3002\u6587\u4e2d\u7ed9\u51fa\u4e86\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff1a\u4e00\u79cd\u662f\u5148\u5355\u72ec\u5904\u7406\u6839\u8282\u70b9\uff0c\u53e6\u4e00\u79cd\u662f\u5b8c\u5168\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f18\u5316\u540e\u7684\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(logn)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6O(n)\u3002\u6587\u7ae0\u8fd8\u6307\u51fa\uff0c\u7531\u4e8e\u4e2d\u5e8f\u904d\u5386\u7ed3\u679c\u4e0d\u552f\u4e00\uff0c\u53ef\u4ee5\u9009\u62e9\u4e2d\u95f4\u504f\u5de6\u3001\u504f\u53f3\u6216\u968f\u673a\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9\u6765\u6784\u5efa\u4e0d\u540c\u7684\u5e73\u8861\u6811\u3002\u6700\u540e\u603b\u7ed3\u4e86\u9012\u5f52\u8bbe\u8ba1\u548c\u4e8c\u5206\u641c\u7d22\u7684\u6ce8\u610f\u4e8b\u9879\uff0c\u5f3a\u8c03\u660e\u786e\u9012\u5f52\u8f93\u5165\u8f93\u51fa\u548c\u907f\u514d\u91cd\u590d\u5143\u7d20\u5904\u7406\u7684\u91cd\u8981\u6027\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/55326.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-13T12:44:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813124429-689c88ad75f2a.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=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55326.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/55326.html\",\"name\":\"LeetCode\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-13T12:44:31+00:00\",\"dateModified\":\"2025-08-13T12:44:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/55326.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/55326.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55326.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode\u5237\u9898\u8bb0\u5f55----108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy)\"}]},{\"@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\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \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\/55326.html","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb649\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65b9\u6cd5\u3002\u6838\u5fc3\u601d\u8def\u662f\u91c7\u7528\u5206\u6cbb\u7b56\u7565\uff0c\u6bcf\u6b21\u9009\u62e9\u6570\u7ec4\u4e2d\u95f4\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u9012\u5f52\u6784\u5efa\u5de6\u53f3\u5b50\u6811\u3002\u6587\u4e2d\u7ed9\u51fa\u4e86\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff1a\u4e00\u79cd\u662f\u5148\u5355\u72ec\u5904\u7406\u6839\u8282\u70b9\uff0c\u53e6\u4e00\u79cd\u662f\u5b8c\u5168\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f18\u5316\u540e\u7684\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(logn)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6O(n)\u3002\u6587\u7ae0\u8fd8\u6307\u51fa\uff0c\u7531\u4e8e\u4e2d\u5e8f\u904d\u5386\u7ed3\u679c\u4e0d\u552f\u4e00\uff0c\u53ef\u4ee5\u9009\u62e9\u4e2d\u95f4\u504f\u5de6\u3001\u504f\u53f3\u6216\u968f\u673a\u4f4d\u7f6e\u4f5c\u4e3a\u6839\u8282\u70b9\u6765\u6784\u5efa\u4e0d\u540c\u7684\u5e73\u8861\u6811\u3002\u6700\u540e\u603b\u7ed3\u4e86\u9012\u5f52\u8bbe\u8ba1\u548c\u4e8c\u5206\u641c\u7d22\u7684\u6ce8\u610f\u4e8b\u9879\uff0c\u5f3a\u8c03\u660e\u786e\u9012\u5f52\u8f93\u5165\u8f93\u51fa\u548c\u907f\u514d\u91cd\u590d\u5143\u7d20\u5904\u7406\u7684\u91cd\u8981\u6027\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/55326.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-13T12:44:31+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813124429-689c88ad75f2a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/55326.html","url":"https:\/\/www.wsisp.com\/helps\/55326.html","name":"LeetCode\u5237\u9898\u8bb0\u5f55-108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-13T12:44:31+00:00","dateModified":"2025-08-13T12:44:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/55326.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/55326.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/55326.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LeetCode\u5237\u9898\u8bb0\u5f55----108.\u5c06\u6709\u5e8f\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\uff08easy)"}]},{"@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\/55326","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=55326"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/55326\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/55324"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=55326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=55326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=55326"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=55326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}