{"id":997587,"date":"2024-12-27T09:25:28","date_gmt":"2024-12-27T01:25:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/997587.html"},"modified":"2024-12-27T09:25:32","modified_gmt":"2024-12-27T01:25:32","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e9%bb%91%e7%99%bd%e6%a0%91","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/997587.html","title":{"rendered":"python\u5982\u4f55\u5b9e\u73b0\u9ed1\u767d\u6811"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073345\/5f789691-ef08-4432-a7c2-b1a70d41f1e5.webp\" alt=\"python\u5982\u4f55\u5b9e\u73b0\u9ed1\u767d\u6811\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/><strong>Python\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u81ea\u5b9a\u4e49\u7c7b\u3001\u9012\u5f52\u7b97\u6cd5\u3001\u6570\u636e\u7ed3\u6784\u6a21\u5757\u7b49\u65b9\u5f0f\u5b9e\u73b0\u9ed1\u767d\u6811<\/strong>\u3002\u9ed1\u767d\u6811\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u4e8c\u53c9\u6811\u7ed3\u6784\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u88ab\u8d4b\u4e88\u4e00\u79cd\u989c\u8272\uff1a\u9ed1\u8272\u6216\u767d\u8272\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3001\u6570\u636e\u5206\u7c7b\u7b49\u9886\u57df\u3002\u8981\u5b9e\u73b0\u9ed1\u767d\u6811\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8282\u70b9\u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u8282\u70b9\u7684\u503c\u548c\u989c\u8272\u5c5e\u6027\uff0c\u7136\u540e\u4f7f\u7528\u9012\u5f52\u65b9\u6cd5\u6765\u63d2\u5165\u3001\u5220\u9664\u548c\u67e5\u627e\u8282\u70b9\u3002\u9ed1\u767d\u6811\u7684\u5b9e\u73b0\u8fd8\u53ef\u4ee5\u501f\u52a9Python\u7684\u6570\u636e\u7ed3\u6784\u6a21\u5757\uff0c\u4f8b\u5982\u4f7f\u7528<code>collections<\/code>\u5e93\u4e2d\u7684<code>deque<\/code>\u6765\u7ef4\u62a4\u8282\u70b9\u7684\u987a\u5e8f\u548c\u5c42\u6b21\u7ed3\u6784\u3002\u8fd9\u79cd\u5b9e\u73b0\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u5f97\u6811\u7ed3\u6784\u66f4\u52a0\u7075\u6d3b\u548c\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u9ed1\u767d\u6811\u7684\u57fa\u672c\u6982\u5ff5\u4e0e\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u9ed1\u767d\u6811\uff08Black and White Tree\uff09\u662f\u4e00\u79cd\u4e8c\u53c9\u6811\u7ed3\u6784\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u989c\u8272\u5c5e\u6027\uff08\u9ed1\u8272\u6216\u767d\u8272\uff09\u3002\u8fd9\u79cd\u6811\u7ed3\u6784\u5e7f\u6cdb\u5e94\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3001\u6570\u636e\u5206\u6790\u548c\u5206\u7c7b\u7b49\u9886\u57df\u3002\u901a\u8fc7\u4e3a\u8282\u70b9\u8d4b\u4e88\u989c\u8272\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5c06\u6570\u636e\u5206\u7c7b\uff0c\u4ece\u800c\u5728\u67d0\u4e9b\u7b97\u6cd5\u4e2d\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u9ed1\u767d\u6811\u4e0e\u7ea2\u9ed1\u6811\u6709\u4e00\u5b9a\u7684\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u4e24\u8005\u5728\u6027\u8d28\u548c\u5e94\u7528\u4e0a\u6709\u6240\u4e0d\u540c\u3002\u9ed1\u767d\u6811\u7684\u989c\u8272\u5c5e\u6027\u4e3b\u8981\u7528\u4e8e\u8868\u793a\u8282\u70b9\u7684\u67d0\u79cd\u72b6\u6001\u6216\u7279\u5f81\uff0c\u800c\u7ea2\u9ed1\u6811\u7684\u989c\u8272\u5219\u662f\u7528\u4e8e\u7ef4\u62a4\u6811\u7684\u5e73\u8861\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Python\u5b9e\u73b0\u9ed1\u767d\u6811\u7684\u57fa\u7840\u6b65\u9aa4<\/p>\n<\/p>\n<ol>\n<li>\u5b9a\u4e49\u8282\u70b9\u7c7b<\/li>\n<\/ol>\n<p><p>\u5728\u5b9e\u73b0\u9ed1\u767d\u6811\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9996\u5148\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u8282\u70b9\u7c7b\uff0c\u8be5\u7c7b\u5305\u542b\u8282\u70b9\u7684\u57fa\u672c\u5c5e\u6027\uff0c\u5982\u503c\u3001\u989c\u8272\u3001\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Node:<\/p>\n<p>    def __init__(self, value, color):<\/p>\n<p>        self.value = value<\/p>\n<p>        self.color = color  # &#39;black&#39; or &#39;white&#39;<\/p>\n<p>        self.left = None<\/p>\n<p>        self.right = None<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7c7b\u662f\u9ed1\u767d\u6811\u7684\u57fa\u672c\u6784\u5efa\u5355\u5143\uff0c\u989c\u8272\u5c5e\u6027\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u8868\u793a\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u63d2\u5165\u8282\u70b9<\/li>\n<\/ol>\n<p><p>\u63d2\u5165\u8282\u70b9\u662f\u9ed1\u767d\u6811\u7684\u4e00\u4e2a\u57fa\u672c\u64cd\u4f5c\u3002\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u7b97\u6cd5\u5728\u6811\u4e2d\u63d2\u5165\u65b0\u8282\u70b9\u3002\u6bcf\u6b21\u63d2\u5165\u65f6\uff0c\u6839\u636e\u8282\u70b9\u7684\u503c\u786e\u5b9a\u5176\u5728\u6811\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def insert(root, value, color):<\/p>\n<p>    if root is None:<\/p>\n<p>        return Node(value, color)<\/p>\n<p>    if value &lt; root.value:<\/p>\n<p>        root.left = insert(root.left, value, color)<\/p>\n<p>    else:<\/p>\n<p>        root.right = insert(root.right, value, color)<\/p>\n<p>    return root<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u63d2\u5165\u64cd\u4f5c\u4e2d\uff0c\u9700\u8981\u4e0d\u65ad\u6bd4\u8f83\u8282\u70b9\u7684\u503c\uff0c\u4ee5\u786e\u5b9a\u65b0\u8282\u70b9\u5e94\u653e\u7f6e\u5728\u5de6\u5b50\u6811\u8fd8\u662f\u53f3\u5b50\u6811\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u9ed1\u767d\u6811\u7684\u67e5\u627e\u4e0e\u904d\u5386<\/p>\n<\/p>\n<ol>\n<li>\u67e5\u627e\u8282\u70b9<\/li>\n<\/ol>\n<p><p>\u67e5\u627e\u64cd\u4f5c\u7528\u4e8e\u5728\u6811\u4e2d\u627e\u5230\u7279\u5b9a\u7684\u8282\u70b9\u3002\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def search(root, value):<\/p>\n<p>    if root is None or root.value == value:<\/p>\n<p>        return root<\/p>\n<p>    if value &lt; root.value:<\/p>\n<p>        return search(root.left, value)<\/p>\n<p>    return search(root.right, value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u67e5\u627e\u8fc7\u7a0b\u4e2d\uff0c\u82e5\u627e\u5230\u8282\u70b9\uff0c\u5219\u8fd4\u56de\u8be5\u8282\u70b9\uff1b\u82e5\u672a\u627e\u5230\uff0c\u5219\u8fd4\u56de<code>None<\/code>\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u904d\u5386\u6811<\/li>\n<\/ol>\n<p><p>\u904d\u5386\u6811\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5e38\u89c1\u7684\u6709\u4e2d\u5e8f\u904d\u5386\u3001\u524d\u5e8f\u904d\u5386\u548c\u540e\u5e8f\u904d\u5386\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def inorder_traversal(root):<\/p>\n<p>    if root:<\/p>\n<p>        inorder_traversal(root.left)<\/p>\n<p>        print(f&quot;Value: {root.value}, Color: {root.color}&quot;)<\/p>\n<p>        inorder_traversal(root.right)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e2d\u5e8f\u904d\u5386\u662f\u4e00\u79cd\u5e38\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u5b83\u6309\u7167\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u8f93\u51fa\u8282\u70b9\u7684\u503c\u548c\u989c\u8272\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u9ed1\u767d\u6811\u7684\u5220\u9664\u4e0e\u8c03\u6574<\/p>\n<\/p>\n<ol>\n<li>\u5220\u9664\u8282\u70b9<\/li>\n<\/ol>\n<p><p>\u5220\u9664\u8282\u70b9\u662f\u9ed1\u767d\u6811\u4e2d\u7684\u4e00\u4e2a\u590d\u6742\u64cd\u4f5c\u3002\u5220\u9664\u8282\u70b9\u540e\uff0c\u9700\u8981\u8c03\u6574\u6811\u7684\u7ed3\u6784\uff0c\u4ee5\u4fdd\u6301\u5176\u6027\u8d28\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def delete_node(root, value):<\/p>\n<p>    if root is None:<\/p>\n<p>        return root<\/p>\n<p>    if value &lt; root.value:<\/p>\n<p>        root.left = delete_node(root.left, value)<\/p>\n<p>    elif value &gt; root.value:<\/p>\n<p>        root.right = delete_node(root.right, value)<\/p>\n<p>    else:<\/p>\n<p>        # Node with only one child or no child<\/p>\n<p>        if root.left is None:<\/p>\n<p>            return root.right<\/p>\n<p>        elif root.right is None:<\/p>\n<p>            return root.left<\/p>\n<p>        # Node with two children: get the inorder successor<\/p>\n<p>        temp = min_value_node(root.right)<\/p>\n<p>        root.value = temp.value<\/p>\n<p>        root.color = temp.color<\/p>\n<p>        root.right = delete_node(root.right, temp.value)<\/p>\n<p>    return root<\/p>\n<p>def min_value_node(node):<\/p>\n<p>    current = node<\/p>\n<p>    while current.left is not None:<\/p>\n<p>        current = current.left<\/p>\n<p>    return current<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5220\u9664\u64cd\u4f5c\u4e2d\uff0c\u9700\u8981\u5904\u7406\u8282\u70b9\u6709\u65e0\u5b50\u8282\u70b9\u7684\u60c5\u51b5\uff0c\u5e76\u627e\u5230\u5408\u9002\u7684\u7ee7\u4efb\u8005\u6765\u66ff\u4ee3\u88ab\u5220\u9664\u7684\u8282\u70b9\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8c03\u6574\u6811<\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u8c03\u6574\u6811\u7684\u7ed3\u6784\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u5f53\u63d2\u5165\u6216\u5220\u9664\u8282\u70b9\u540e\uff0c\u6811\u7684\u9ad8\u5ea6\u53d8\u5f97\u8fc7\u9ad8\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u65cb\u8f6c\u7b49\u64cd\u4f5c\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u9ed1\u767d\u6811\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u9ed1\u767d\u6811\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u4f8b\u5982\u7528\u4e8e\u56fe\u50cf\u5206\u5272\u3001\u8fb9\u7f18\u68c0\u6d4b\u7b49\u3002\u901a\u8fc7\u5c06\u56fe\u50cf\u50cf\u7d20\u6620\u5c04\u4e3a\u6811\u8282\u70b9\uff0c\u5e76\u6839\u636e\u50cf\u7d20\u503c\u548c\u989c\u8272\u8fdb\u884c\u5206\u7c7b\uff0c\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u56fe\u50cf\u5904\u7406\u3002<\/p>\n<\/p>\n<ol>\n<li>\u56fe\u50cf\u5206\u5272<\/li>\n<\/ol>\n<p><p>\u5728\u56fe\u50cf\u5206\u5272\u4e2d\uff0c\u9ed1\u767d\u6811\u53ef\u4ee5\u7528\u4e8e\u5c06\u56fe\u50cf\u5206\u5272\u4e3a\u4e0d\u540c\u7684\u533a\u57df\u3002\u901a\u8fc7\u4e3a\u6bcf\u4e2a\u50cf\u7d20\u8d4b\u4e88\u989c\u8272\u5c5e\u6027\uff0c\u53ef\u4ee5\u5feb\u901f\u8bc6\u522b\u56fe\u50cf\u4e2d\u7684\u4e0d\u540c\u533a\u57df\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8fb9\u7f18\u68c0\u6d4b<\/li>\n<\/ol>\n<p><p>\u8fb9\u7f18\u68c0\u6d4b\u662f\u56fe\u50cf\u5904\u7406\u4e2d\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u901a\u8fc7\u9ed1\u767d\u6811\uff0c\u5c06\u56fe\u50cf\u4e2d\u989c\u8272\u53d8\u5316\u660e\u663e\u7684\u533a\u57df\u8bc6\u522b\u4e3a\u8fb9\u7f18\u3002\u6811\u7684\u7ed3\u6784\u6709\u52a9\u4e8e\u5feb\u901f\u5b9a\u4f4d\u8fd9\u4e9b\u533a\u57df\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u9ed1\u767d\u6811\u5728\u6570\u636e\u5206\u7c7b\u4e2d\u7684\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u9ed1\u767d\u6811\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u5206\u7c7b\uff0c\u4f8b\u5982\u5728<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b97\u6cd5\u4e2d\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\u3002\u901a\u8fc7\u4e3a\u6570\u636e\u70b9\u8d4b\u4e88\u989c\u8272\u5c5e\u6027\uff0c\u53ef\u4ee5\u5feb\u901f\u5c06\u6570\u636e\u5206\u4e3a\u4e0d\u540c\u7684\u7c7b\u522b\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5206\u7c7b\u7b97\u6cd5<\/li>\n<\/ol>\n<p><p>\u5728\u5206\u7c7b\u7b97\u6cd5\u4e2d\uff0c\u9ed1\u767d\u6811\u53ef\u4ee5\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\u3002\u901a\u8fc7\u4e0d\u65ad\u8c03\u6574\u6811\u7684\u7ed3\u6784\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5206\u7c7b\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u6570\u636e\u5206\u6790<\/li>\n<\/ol>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u9ed1\u767d\u6811\u53ef\u4ee5\u7528\u4e8e\u5feb\u901f\u68c0\u7d22\u548c\u5206\u7c7b\u5927\u89c4\u6a21\u6570\u636e\u96c6\u3002\u6811\u7684\u7ed3\u6784\u4f7f\u5f97\u67e5\u8be2\u64cd\u4f5c\u975e\u5e38\u9ad8\u6548\uff0c\u9002\u5408\u5904\u7406\u5927\u91cf\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/p>\n<\/p>\n<p><p>\u9ed1\u767d\u6811\u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u7ed3\u6784\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u5e94\u7528\u573a\u666f\u3002\u901a\u8fc7\u5728Python\u4e2d\u5b9e\u73b0\u9ed1\u767d\u6811\uff0c\u53ef\u4ee5\u6df1\u5165\u7406\u89e3\u5176\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u4e3a\u6570\u636e\u5904\u7406\u548c\u7b97\u6cd5\u4f18\u5316\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002\u672a\u6765\uff0c\u968f\u7740\u8ba1\u7b97\u673a\u89c6\u89c9\u548c\u6570\u636e\u79d1\u5b66\u7684\u53d1\u5c55\uff0c\u9ed1\u767d\u6811\u7684\u5e94\u7528\u5c06\u66f4\u52a0\u5e7f\u6cdb\u548c\u6df1\u5165\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u9ed1\u767d\u6811\u662f\u4ec0\u4e48\uff1f\u5b83\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u9ed1\u767d\u6811\u662f\u4e00\u79cd\u81ea\u5e73\u8861\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u901a\u8fc7\u989c\u8272\u6807\u8bb0\u8282\u70b9\uff08\u9ed1\u8272\u548c\u767d\u8272\uff09\u6765\u4fdd\u6301\u6811\u7684\u5e73\u8861\u6027\u3002\u9ed1\u767d\u6811\u7684\u5e94\u7528\u573a\u666f\u5305\u62ec\u6570\u636e\u5e93\u7d22\u5f15\u3001\u5185\u5b58\u7ba1\u7406\u548c\u9ad8\u6548\u7684\u6570\u636e\u68c0\u7d22\u7b49\u3002\u7531\u4e8e\u5176\u826f\u597d\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u9ed1\u767d\u6811\u5728\u9700\u8981\u9891\u7e41\u63d2\u5165\u3001\u5220\u9664\u548c\u67e5\u627e\u64cd\u4f5c\u7684\u573a\u5408\u975e\u5e38\u9002\u5408\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u9ed1\u767d\u6811\u7684\u57fa\u672c\u7ed3\u6784\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2a\u8282\u70b9\u7c7b\u6765\u5b9e\u73b0\u9ed1\u767d\u6811\u7684\u57fa\u672c\u7ed3\u6784\u3002\u6bcf\u4e2a\u8282\u70b9\u5e94\u8be5\u5305\u542b\u503c\u3001\u989c\u8272\u3001\u5de6\u5b50\u8282\u70b9\u3001\u53f3\u5b50\u8282\u70b9\u548c\u7236\u8282\u70b9\u7684\u5f15\u7528\u3002\u6784\u5efa\u6811\u65f6\u9700\u8981\u8003\u8651\u8282\u70b9\u7684\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\uff0c\u5e76\u5728\u8fd9\u4e9b\u64cd\u4f5c\u4e2d\u7ef4\u62a4\u6811\u7684\u6027\u8d28\uff0c\u786e\u4fdd\u9ed1\u767d\u6811\u7684\u5e73\u8861\u3002<\/p>\n<p><strong>\u5b9e\u73b0\u9ed1\u767d\u6811\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u6027\u80fd\u4f18\u5316\uff1f<\/strong><br \/>\u5728\u5b9e\u73b0\u9ed1\u767d\u6811\u65f6\uff0c\u4f18\u5316\u6027\u80fd\u7684\u5173\u952e\u5728\u4e8e\u786e\u4fdd\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(log n)\u3002\u4e3a\u4e86\u8fbe\u5230\u8fd9\u4e00\u76ee\u6807\uff0c\u5efa\u8bae\u5728\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u5bf9\u6811\u7684\u7ed3\u6784\u8fdb\u884c\u5fc5\u8981\u7684\u65cb\u8f6c\u548c\u91cd\u65b0\u7740\u8272\u3002\u540c\u65f6\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u91cd\u590d\u8ba1\u7b97\u548c\u5185\u5b58\u5206\u914d\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6574\u4f53\u6027\u80fd\u3002\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u4e5f\u662f\u63d0\u5347\u6548\u7387\u7684\u91cd\u8981\u56e0\u7d20\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1aPython\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u81ea\u5b9a\u4e49\u7c7b\u3001\u9012\u5f52\u7b97\u6cd5\u3001\u6570\u636e\u7ed3\u6784\u6a21\u5757\u7b49\u65b9\u5f0f\u5b9e\u73b0\u9ed1\u767d\u6811\u3002\u9ed1\u767d\u6811\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u4e8c\u53c9\u6811\u7ed3 [&hellip;]","protected":false},"author":3,"featured_media":997606,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997587"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=997587"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997587\/revisions"}],"predecessor-version":[{"id":997610,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/997587\/revisions\/997610"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/997606"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=997587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=997587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=997587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}