{"id":453,"date":"2026-02-25T00:59:46","date_gmt":"2026-02-24T16:59:46","guid":{"rendered":"https:\/\/jdoxk3.cn\/?p=453"},"modified":"2026-02-25T00:59:46","modified_gmt":"2026-02-24T16:59:46","slug":"%e4%bb%a3%e7%a0%81%e9%9a%8f%e6%83%b3%e5%bd%95%e7%ae%97%e6%b3%95%e8%ae%ad%e7%bb%83%e8%90%a5%e7%ac%ac%e4%ba%8c%e5%8d%81%e5%a4%a9235-%e4%ba%8c%e5%8f%89%e6%90%9c%e7%b4%a2%e6%a0%91%e7%9a%84%e6%9c%80","status":"publish","type":"post","link":"https:\/\/jdoxk3.cn\/index.php\/2026\/02\/25\/%e4%bb%a3%e7%a0%81%e9%9a%8f%e6%83%b3%e5%bd%95%e7%ae%97%e6%b3%95%e8%ae%ad%e7%bb%83%e8%90%a5%e7%ac%ac%e4%ba%8c%e5%8d%81%e5%a4%a9235-%e4%ba%8c%e5%8f%89%e6%90%9c%e7%b4%a2%e6%a0%91%e7%9a%84%e6%9c%80\/","title":{"rendered":"\u4ee3\u7801\u968f\u60f3\u5f55\u7b97\u6cd5\u8bad\u7ec3\u8425\u7b2c\u4e8c\u5341\u5929|235.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\uff0c701.\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c\uff0c450.\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u524d\u8a00<\/h1>\n\n\n\n<p>\u4eca\u5929\u4e0d\u662f\u7b97\u6cd5\u8bad\u7ec3\u8425\u7684\u7b2c\u4e8c\u5341\u5929\uff0c\u4f9d\u65e7\u662f\u731b\u8ffd\u5148\u524d\u843d\u4e0b\u7684\u8fdb\u5ea6\uff0c\u4e89\u53d6\u5728\u5f00\u5b66\u524d\u80fd\u591f\u628a\u4efb\u52a1\u5b8c\u6210\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">235.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148<\/h1>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/lowest-common-ancestor-of-a-binary-search-tree\/\">235. \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148<\/a><\/p>\n\n\n\n<p>\u9898\u76ee\u63cf\u8ff0\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811, \u627e\u5230\u8be5\u6811\u4e2d\u4e24\u4e2a\u6307\u5b9a\u8282\u70b9\u7684\u6700\u8fd1\u516c\u5171\u7956\u5148\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/baike.baidu.com\/item\/%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88\/8918834?fr=aladdin\">\u767e\u5ea6\u767e\u79d1<\/a>\u4e2d\u6700\u8fd1\u516c\u5171\u7956\u5148\u7684\u5b9a\u4e49\u4e3a\uff1a\u201c\u5bf9\u4e8e\u6709\u6839\u6811 T \u7684\u4e24\u4e2a\u7ed3\u70b9 p\u3001q\uff0c\u6700\u8fd1\u516c\u5171\u7956\u5148\u8868\u793a\u4e3a\u4e00\u4e2a\u7ed3\u70b9 x\uff0c\u6ee1\u8db3 x \u662f p\u3001q \u7684\u7956\u5148\u4e14 x \u7684\u6df1\u5ea6\u5c3d\u53ef\u80fd\u5927\uff08<strong>\u4e00\u4e2a\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u5b83\u81ea\u5df1\u7684\u7956\u5148<\/strong>\uff09\u3002\u201d<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u601d\u8def<\/h2>\n\n\n\n<p>\u8fd9\u9053\u9898\u4e0e\u5148\u524d\u7684\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u7956\u5148\u7c7b\u4f3c\uff0c\u76f8\u6bd4\u8d77\u6765\u96be\u5ea6\u751a\u81f3\u66f4\u4f4e\u4e00\u4e9b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u672c\u8eab\u5c31\u5df2\u7ecf\u6709\u4e00\u5b9a\u987a\u5e8f\u89c4\u5f8b\u53ef\u89c2\u5bdf\u5230\u3002\u5728\u4e4b\u524d\u89e3\u51b3\u4e8c\u53c9\u6811\u7684\u6700\u8fd1\u7956\u5148\u65f6\uff0c\u6211\u4eec\u7684\u60f3\u6cd5\u662f\u81ea\u5e95\u5411\u4e0a\u56de\u6eaf\u67e5\u627e\uff0c\u5982\u679c\u53d1\u73b0\u5de6\u5b50\u6811\u4e2d\u6709p\u3001\u53f3\u5b50\u6811\u4e2d\u6709q\uff0c\u90a3\u4e48\u8bf4\u660e\u5f53\u524d\u8282\u70b9\u662f\u516c\u5171\u7956\u5148\u3002<\/p>\n\n\n\n<p>\u56de\u5230\u8fd9\u9053\u9898\u76ee\uff0c\u7531\u4e8e\u8fd9\u91cc\u662f\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u4e0e\u5148\u524d\u4e0d\u540c\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5f53\u524d\u8282\u70b9\u7684\u503c\u662f\u5927\u4e8e\u5c0f\u4e8e\uff08\u4e00\u5927\u4e00\u5c0f\uff09p\u3001q\u7684\u503c\u5c31\u8bf4\u660e\u5f53\u524d\u8282\u70b9\u662f\u516c\u5171\u7956\u5148\uff0c\u5982\u679c\u540c\u65f6\u5c0f\u4e8e\u5c31\u5904\u7406\u53f3\u5b50\u6811\uff0c\u5982\u679c\u540c\u65f6\u5927\u4e8e\u5c31\u5904\u7406\u5de6\u5b50\u6811\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b8c\u6574\u4ee3\u7801\u5b9e\u73b0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, x):\n#         self.val = x\n#         self.left = None\n#         self.right = None\n\nclass Solution:\n    def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':\n        while root:\n            if root.val &lt; p.val and root.val &lt; q.val:\n                return self.lowestCommonAncestor(root.right, p, q)\n            elif root.val > p.val and root.val > q.val:\n                return self.lowestCommonAncestor(root.left, p, q)\n            else:\n                return root\n        return None<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">701.\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c<\/h1>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/insert-into-a-binary-search-tree\/\">701. \u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u63d2\u5165\u64cd\u4f5c<\/a><\/p>\n\n\n\n<p>\u9898\u76ee\u63cf\u8ff0\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7ed9\u5b9a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u7684\u6839\u8282\u70b9 <code>root<\/code> \u548c\u8981\u63d2\u5165\u6811\u4e2d\u7684\u503c <code>value<\/code> \uff0c\u5c06\u503c\u63d2\u5165\u4e8c\u53c9\u641c\u7d22\u6811\u3002 \u8fd4\u56de\u63d2\u5165\u540e\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9\u3002 \u8f93\u5165\u6570\u636e <strong>\u4fdd\u8bc1<\/strong> \uff0c\u65b0\u503c\u548c\u539f\u59cb\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u4efb\u610f\u8282\u70b9\u503c\u90fd\u4e0d\u540c\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff0c\u53ef\u80fd\u5b58\u5728\u591a\u79cd\u6709\u6548\u7684\u63d2\u5165\u65b9\u5f0f\uff0c\u53ea\u8981\u6811\u5728\u63d2\u5165\u540e\u4ecd\u4fdd\u6301\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811\u5373\u53ef\u3002 \u4f60\u53ef\u4ee5\u8fd4\u56de <strong>\u4efb\u610f\u6709\u6548\u7684\u7ed3\u679c<\/strong> \u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u601d\u8def<\/h2>\n\n\n\n<p>\u8fd9\u9053\u9898\u7684\u601d\u8def\u6bd4\u8f83\u7b80\u5355\u4e9b\uff0c\u5927\u81f4\u53ef\u4ee5\u7406\u89e3\u4e3a\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u641c\u7d22\u64cd\u4f5c\u7684\u57fa\u7840\u4e0a\u52a0\u4e00\u6b65\u63d2\u5165\uff0c\u603b\u4f53\u6765\u8bf4\u5c31\u662f\u5982\u679c\u5f53\u524d\u8282\u70b9\u6bd4\u76ee\u6807\u503c\u5927\u5c31\u5224\u65ad\u662f\u5426\u6709\u5de6\u5b69\u5b50\uff0c\u6ca1\u5de6\u5b69\u5b50\u5c31\u76f4\u63a5\u63d2\u5165\uff0c\u5982\u679c\u6709\u5c31\u9012\u5f52\u8fdb\u884c\u4e0b\u4e00\u8f6e\u67e5\u627e\uff0c\u53f3\u5b69\u5b50\u540c\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6574\u4f53\u4ee3\u7801\u5b9e\u73b0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def insertIntoBST(self, root: Optional&#91;TreeNode], val: int) -> Optional&#91;TreeNode]:\n        if not root or root.val == val:\n            return TreeNode(val)\n        \n        elif root.val > val:\n            if not root.left:\n                root.left = TreeNode(val)\n            else:\n                self.insertIntoBST(root.left, val)\n        elif root.val &lt; val:\n            if not root.right:\n                root.right = TreeNode(val)\n            else:\n                self.insertIntoBST(root.right, val)\n        return root<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">450.\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9<\/h1>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode.cn\/problems\/delete-node-in-a-bst\/\">450. \u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684\u8282\u70b9<\/a><\/p>\n\n\n\n<p>\u9898\u76ee\u63cf\u8ff0\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6839\u8282\u70b9 <strong>root<\/strong> \u548c\u4e00\u4e2a\u503c <strong>key<\/strong>\uff0c\u5220\u9664\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u7684 <strong>key<\/strong> \u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u5e76\u4fdd\u8bc1\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u4e0d\u53d8\u3002\u8fd4\u56de\u4e8c\u53c9\u641c\u7d22\u6811\uff08\u6709\u53ef\u80fd\u88ab\u66f4\u65b0\uff09\u7684\u6839\u8282\u70b9\u7684\u5f15\u7528\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u5220\u9664\u8282\u70b9\u53ef\u5206\u4e3a\u4e24\u4e2a\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u9996\u5148\u627e\u5230\u9700\u8981\u5220\u9664\u7684\u8282\u70b9\uff1b<\/li>\n\n\n\n<li>\u5982\u679c\u627e\u5230\u4e86\uff0c\u5220\u9664\u5b83\u3002<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u601d\u8def<\/h2>\n\n\n\n<p>\u8fd9\u9053\u9898\u76ee\u6d89\u53ca\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u7ed3\u6784\uff0c\u76f8\u6bd4\u524d\u9762\u7684\u9898\u76ee\u96be\u5ea6\u6709\u6240\u63d0\u5347\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u8981\u5bf9\u4e8c\u53c9\u641c\u7d22\u6811\u8fdb\u884c\u5220\u9664\u64cd\u4f5c\uff0c\u7531\u4e8e\u4e8c\u53c9\u641c\u7d22\u6811\u6027\u8d28\u7279\u6b8a\uff0c\u6211\u4eec\u9700\u8981\u5206\u6210\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u8fdb\u884c\u8ba8\u8bba\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u88ab\u5220\u8282\u70b9\u662f\u53f6\u5b50\u8282\u70b9<\/li>\n\n\n\n<li>\u88ab\u5220\u8282\u70b9\u6709\u5de6\u5b50\u6811\u6ca1\u53f3\u5b50\u6811\u6216\u88ab\u5220\u8282\u70b9\u6709\u53f3\u5b50\u6811\u6ca1\u5de6\u5b50\u6811<\/li>\n\n\n\n<li>\u88ab\u5220\u8282\u70b9\u540c\u65f6\u5177\u5907\u5de6\u53f3\u5b50\u6811<\/li>\n<\/ul>\n\n\n\n<p>\u9996\u5148\u8ba8\u8bba\u88ab\u5220\u8282\u70b9\u662f\u53f6\u5b50\u8282\u70b9\u7684\u60c5\u51b5\uff0c\u5982\u679c\u88ab\u5220\u8282\u70b9\u662f\u53f6\u5b50\u8282\u70b9\uff0c\u6211\u4eec\u76f4\u63a5\u8fd4\u56de\u7a7a\u5c31\u884c\uff0c\u4e0d\u9700\u8981\u989d\u5916\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u662f\u88ab\u5220\u8282\u70b9\u6709\u5de6\u5b50\u6811\u6ca1\u53f3\u5b50\u6811\u6216\u88ab\u5220\u8282\u70b9\u6709\u53f3\u5b50\u6811\u6ca1\u5de6\u5b50\u6811\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8fd4\u56de\u5176\u5269\u4e0b\u7684\u5b50\u6811\u63a5\u4e0a\u5c31\u884c\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u662f\u88ab\u5220\u8282\u70b9\u540c\u65f6\u5177\u5907\u5de6\u53f3\u5b50\u6811\uff0c\u8fd9\u79cd\u60c5\u51b5\u76f8\u8f83\u4e4b\u524d\u5c31\u590d\u6742\u4e00\u4e9b\u4e86\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u53f3\u5b50\u6811\u4e2d\u7684\u6700\u5de6\u8282\u70b9\uff0c\u5c06\u5220\u9664\u7684\u8282\u70b9\u503c\u4e0e\u6700\u5de6\u8282\u70b9\u503c\u4ea4\u6362\uff0c\u8fd9\u6837\u6784\u5efa\u51fa\u6765\u7684\u6811\u7b26\u5408\u4e8c\u53c9\u641c\u7d22\u6811\u6027\u8d28\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6574\u4f53\u4ee3\u7801\u5b9e\u73b0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def deleteNode(self, root: Optional&#91;TreeNode], key: int) -> Optional&#91;TreeNode]:\n        if not root:\n            return root\n        if root.val == key:\n            if not root.left and not root.right:\n                return None\n            elif not root.left:\n                return root.right\n            elif not root.right:\n                return root.left\n            else:\n                cur = root.right\n                while cur.left:\n                    cur = cur.left\n                cur.left = root.left\n                return root.right\n        if root.val > key:\n            root.left = self.deleteNode(root.left, key)\n        if root.val &lt; key:\n            root.right = self.deleteNode(root.right, key)\n        return root<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u603b\u7ed3<\/h1>\n\n\n\n<p>\u679c\u7136\uff0c\u9694\u4e86\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\u518d\u5199\u56de\u987e\u91cd\u65b0\u53d1\u73b0\u4e86\u5f88\u591a\u7b2c\u4e00\u904d\u8fc7\u65f6\u6ca1\u53d1\u73b0\u6ca1\u8003\u8651\u7684\u95ee\u9898\uff0c\u76ee\u524d\u770b\u6765\u4e4b\u524d\u5237\u9898\u7684\u65f6\u5019\u751a\u81f3\u6709\u70b9\u6c34\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\u7684\u9898\u76ee\u524d\u9762\u4e24\u9053\u8fd8\u662f\u6bd4\u8f83\u597d\u7406\u89e3\u7684\uff0c\u6700\u540e\u4e00\u9053\u9898\u76ee\u6d89\u53ca\u5230\u6539\u53d8\u4e8c\u53c9\u6811\u7ed3\u6784\uff0c\u8fd9\u79cd\u9898\u76ee\u96be\u5ea6\u76f8\u8f83\u4e8e\u5229\u7528\u4e8c\u53c9\u6811\u6027\u8d28\u66f4\u96be\u4e00\u4e9b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4eca\u5929\u4e0d\u662f\u7b97\u6cd5\u8bad\u7ec3\u8425\u7684\u7b2c\u4e8c\u5341\u5929\uff0c\u4f9d\u65e7\u662f\u731b\u8ffd\u5148\u524d\u843d\u4e0b\u7684\u8fdb\u5ea6\uff0c\u4e89\u53d6\u5728\u5f00\u5b66\u524d\u80fd\u591f\u628a\u4efb\u52a1\u5b8c\u6210\u3002 235.\u4e8c\u53c9\u641c\u7d22\u6811 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[13,15,14],"class_list":["post-453","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-15","tag-14"],"_links":{"self":[{"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/posts\/453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":1,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdoxk3.cn\/index.php\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}