From 49b2d9462d78b478a278321ed4a95a2ab1b49258 Mon Sep 17 00:00:00 2001 From: krahets Date: Mon, 4 Dec 2023 05:10:12 +0800 Subject: [PATCH] deploy --- chapter_appendix/contribution/index.html | 4 +- .../vscode_extension_installation.png | Bin 0 -> 147985 bytes .../vscode_installation.png | Bin 0 -> 120491 bytes chapter_appendix/installation/index.html | 222 ++++++++++-------- search/search_index.json | 2 +- sitemap.xml.gz | Bin 998 -> 998 bytes 6 files changed, 131 insertions(+), 97 deletions(-) create mode 100644 chapter_appendix/installation.assets/vscode_extension_installation.png create mode 100644 chapter_appendix/installation.assets/vscode_installation.png diff --git a/chapter_appendix/contribution/index.html b/chapter_appendix/contribution/index.html index 92a4b4b74..c3ce110ba 100644 --- a/chapter_appendix/contribution/index.html +++ b/chapter_appendix/contribution/index.html @@ -3404,14 +3404,14 @@

而在本开源书中,内容更迭的时间被缩短至数日甚至几个小时。

1.   内容微调

-

如图 16-1 所示,每个页面的右上角都有“编辑图标”。您可以按照以下步骤修改文本或代码。

+

如图 16-3 所示,每个页面的右上角都有“编辑图标”。您可以按照以下步骤修改文本或代码。

  1. 点击“编辑图标”,如果遇到“需要 Fork 此仓库”的提示,请同意该操作。
  2. 修改 Markdown 源文件内容,检查内容的正确性,并尽量保持排版格式的统一。
  3. 在页面底部填写修改说明,然后点击“Propose file change”按钮。页面跳转后,点击“Create pull request”按钮即可发起拉取请求。

页面编辑按键

-

图 16-1   页面编辑按键

+

图 16-3   页面编辑按键

图片无法直接修改,需要通过新建 Issue 或评论留言来描述问题,我们会尽快重新绘制并替换图片。

2.   内容创作

diff --git a/chapter_appendix/installation.assets/vscode_extension_installation.png b/chapter_appendix/installation.assets/vscode_extension_installation.png new file mode 100644 index 0000000000000000000000000000000000000000..0efab8178d683347b21ad98444b8f192ebb0201b GIT binary patch literal 147985 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%0D86+T?;gnjlt<=UB-rtD)u>c8;ak(2JI|A~ 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%0DnZk3LW&ZnIb?_z2qGLc&J2M(RQZo0N{EE4oy zEI6-~)*`NK>B@Hip1eL57>?dIW$(r!uKfgnZVG~4ci0Rn@Dc%_2WYqp0^qOgon33w zP#lNVFVLhlNt@6u##UR}Mp;dT+GRtXjEacX7lb%*MntPK$|k70P_#k^HBv+?+N&WQ z-GxvpY?OWguM`x#(i?BYFW{~JbNUiBb!K*IGktW)$w^w+#U6e+uf380p(*b<`0q#S zz8I4~OtN#mE8seKE&j(=g8>C1$c}7*o{#(2q5pTAjamT7zn=itEptWawbu3oA$$oT zes01wcx{B+7@`~m-@o&gF&kuQ0ls+3Vj?2l3CaQTgMXb8;FZBdf)EM+`n|VqTs|s` zq2pIMNPx#9l5fv>=IG2FS&Bmf+&QyT=5JsAN`QMdNfBra9Gt4}`Y1CkV~O&z(%hWm(!ZIguQu+{C_nlL>}{TUG@4 z2<%s4OZx^~9og7SfMx++z8I5Y96>PR?E`!E_(U;sV9#y`jRm;(4BtQempU{Kr>>e%;$E zLfep@5Fqv$HsFfw3P;f=C&v^0UY~FGwc&nlVEERh0iJMJ7vRSSKjhVC3ZCka0Og5i z=Lrs#C^>Qbz&XLqF&C%U5q|GXLh@cd)-T;XI5TtkA}w8KM`Zs+_NWXW8ho}_*gQ40 zQA#}9%lPk1J$rVW9CAVg1W2bdfCQ+*;gkx;ZeD`Zi{SOebR*yShoZ46T&Kc8Ow(>{ z(s>r>uS0(|uYKI5m%0u(kK z8YFNPBf0iWf!-*=5kKT|?>o7f-!K~A!23h@AB_?s7dh$`+@Yfz!Is?miG2(`I=X@1 zJh6`!nbFfBddK$0IKWd*G!D>%4j`xPP;_=dy4)0?M@eV%^Q?-57!`F)5C=K~Daryx zDQpn*d@DdDScg)XM*%Q6k3zFkvrhsfU4i`-)C35ar+=6fSSWn@5Q?bp-&7vrNLYEB z3-s2maOD48;p`~Dw*LUji@{jf6^`p4pYX!wg^|JJpg{F+7SO#FOn{p^^a9g@6vG9M z8a^|1p5_TKpe*r}EOQRGEHg9{i^XJtqWzMerbJ1g;X|Ax6AavRKmo2~ImWc6fZ&q? zhgOBN8^UGet2DINX_-0;fV4{a#Tuf%Lvt$Ir^{`|@DsH$qh|V)W(Y8f1enFoq|zRb ze-@R-(l%-XBm=p(m5MR`c`5rfl=l!eLaG!R7ZwHq{*irwzxvI$26nA18^1}axjfJOrBh_KQH{Ss-<%KEy7Gn*BzAP}EWGThKKnTSY$AH2d@dH)gd}DyH5Kll`6;4S|J1 zvxN4{?D7w9g|POW-G4Wb�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�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%0A#aeXHcXQQJ3Jz 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ΠYTW57E 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�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 z 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 literal 0 HcmV?d00001 diff --git a/chapter_appendix/installation.assets/vscode_installation.png b/chapter_appendix/installation.assets/vscode_installation.png new file mode 100644 index 0000000000000000000000000000000000000000..87f28b8bb108dcae6d49ff9038de2eccd8f56190 GIT binary patch literal 120491 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

VEc{E+G?wMqT}M$6PuRZ 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

  • _{oBjGrPJr8oe1Yo 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

  • - - 1.   VSCode + + 16.1.1   安装 IDE
  • - - 2.   Java 环境 + + 16.1.2   安装语言环境 + + +
  • @@ -3369,72 +3382,85 @@
    • - - 1.   VSCode + + 16.1.1   安装 IDE
    • - - 2.   Java 环境 + + 16.1.2   安装语言环境 + + +
    • @@ -3494,24 +3520,38 @@

      16.1   编程环境安装

      -

      1.   VSCode

      -

      本书推荐使用开源、轻量的 VSCode 作为本地 IDE ,下载并安装 VSCode

      -

      2.   Java 环境

      +

      16.1.1   安装 IDE

      +

      推荐使用开源、轻量的 VSCode 作为本地集成开发环境(IDE)。访问 VSCode 官网,根据操作系统选择相应版本的 VSCode 进行下载和安装。

      +

      从官网下载 VSCode

      +

      图 16-1   从官网下载 VSCode

      + +

      VSCode 拥有强大的扩展包生态系统,支持大多数编程语言的运行和调试。以 Python 为例,安装“Python Extension Pack”扩展包之后,即可进行 Python 代码调试。安装步骤如图 16-2 所示。

      +

      安装 VSCode 扩展包

      +

      图 16-2   安装 VSCode 扩展包

      + +

      16.1.2   安装语言环境

      +

      1.   Python 环境

        -
      1. 下载并安装 OpenJDK(版本需满足 > JDK 9)。
      2. -
      3. 在 VSCode 的插件市场中搜索 java ,安装 Extension Pack for Java 。
      4. +
      5. 下载并安装 Miniconda3 ,需要 Python 3.10 或更新版本。
      6. +
      7. 在 VSCode 的插件市场中搜索 python ,安装 Python Extension Pack 。
      8. +
      9. (可选)在命令行输入 pip install black ,安装代码格式化工具。
      -

      3.   C/C++ 环境

      +

      2.   C/C++ 环境

      1. Windows 系统需要安装 MinGW配置教程);MacOS 自带 Clang ,无须安装。
      2. 在 VSCode 的插件市场中搜索 c++ ,安装 C/C++ Extension Pack 。
      3. (可选)打开 Settings 页面,搜索 Clang_format_fallback Style 代码格式化选项,设置为 { BasedOnStyle: Microsoft, BreakBeforeBraces: Attach }
      -

      4.   Python 环境

      +

      3.   Java 环境

        -
      1. 下载并安装 Miniconda3 ,需要 Python 3.10 或更新版本。
      2. -
      3. 在 VSCode 的插件市场中搜索 python ,安装 Python Extension Pack 。
      4. -
      5. (可选)在命令行输入 pip install black ,安装代码格式化工具。
      6. +
      7. 下载并安装 OpenJDK(版本需满足 > JDK 9)。
      8. +
      9. 在 VSCode 的插件市场中搜索 java ,安装 Extension Pack for Java 。
      10. +
      +

      4.   C# 环境

      +
        +
      1. 下载并安装 .Net 8.0
      2. +
      3. 在 VSCode 的插件市场中搜索 C# Dev Kit ,安装 C# Dev Kit (配置教程)。
      4. +
      5. 也可使用 Visual Studio(安装教程)。

      5.   Go 环境

        @@ -3519,29 +3559,23 @@
      1. 在 VSCode 的插件市场中搜索 go ,安装 Go 。
      2. 按快捷键 Ctrl + Shift + P 呼出命令栏,输入 go ,选择 Go: Install/Update Tools ,全部勾选并安装即可。
      -

      6.   JavaScript 环境

      +

      6.   Swift 环境

      +
        +
      1. 下载并安装 Swift
      2. +
      3. 在 VSCode 的插件市场中搜索 swift ,安装 Swift for Visual Studio Code
      4. +
      +

      7.   JavaScript 环境

      1. 下载并安装 node.js
      2. 在 VSCode 的插件市场中搜索 javascript ,安装 JavaScript (ES6) code snippets 。
      3. (可选)在 VSCode 的插件市场中搜索 Prettier ,安装代码格式化工具。
      -

      7.   C# 环境

      -
        -
      1. 下载并安装 .Net 8.0
      2. -
      3. 在 VSCode 的插件市场中搜索 C# Dev Kit ,安装 C# Dev Kit (配置教程)。
      4. -
      5. 也可使用 Visual Studio(安装教程)。
      6. -
      -

      8.   Swift 环境

      -
        -
      1. 下载并安装 Swift
      2. -
      3. 在 VSCode 的插件市场中搜索 swift ,安装 Swift for Visual Studio Code
      4. -
      -

      9.   Dart 环境

      +

      8.   Dart 环境

      1. 下载并安装 Dart
      2. 在 VSCode 的插件市场中搜索 dart ,安装 Dart
      -

      10.   Rust 环境

      +

      9.   Rust 环境

      1. 下载并安装 Rust
      2. 在 VSCode 的插件市场中搜索 rust ,安装 rust-analyzer
      3. diff --git a/search/search_index.json b/search/search_index.json index d2b42d36a..d8e8eeee5 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\u200b\\u3000\\-\u3001\u3002\uff0c\uff0e\uff1f\uff01\uff1b]+","pipeline":["stemmer"]},"docs":[{"location":"","title":"Home","text":"\u300a Hello \u7b97\u6cd5 \u300b

        \u52a8\u753b\u56fe\u89e3\u3001\u4e00\u952e\u8fd0\u884c\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6559\u7a0b

        \u63a8\u8350\u8bed

        Quote

        \u201c\u4e00\u672c\u901a\u4fd7\u6613\u61c2\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5165\u95e8\u4e66\uff0c\u5f15\u5bfc\u8bfb\u8005\u624b\u8111\u5e76\u7528\u5730\u5b66\u4e60\uff0c\u5f3a\u70c8\u63a8\u8350\u7b97\u6cd5\u521d\u5b66\u8005\u9605\u8bfb\u3002\u201d

        \u2014\u2014 \u9093\u4fca\u8f89\uff0c\u6e05\u534e\u5927\u5b66\u8ba1\u7b97\u673a\u7cfb\u6559\u6388

        Quote

        \u201c\u5982\u679c\u6211\u5f53\u5e74\u5b66\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u65f6\u5019\u6709\u300aHello \u7b97\u6cd5\u300b\uff0c\u5b66\u8d77\u6765\u5e94\u8be5\u4f1a\u7b80\u5355 10 \u500d\uff01\u201d

        \u2014\u2014 \u674e\u6c90\uff0c\u4e9a\u9a6c\u900a\u8d44\u6df1\u9996\u5e2d\u79d1\u5b66\u5bb6

        \u5168\u4e66\u52a8\u753b\u56fe\u89e3

        \u5185\u5bb9\u6e05\u6670\u6613\u61c2\u3001\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1\u7535\u8111\u3001\u5e73\u677f\u3001\u624b\u673a\u5168\u7ec8\u7aef\u9605\u8bfb

        \"A picture is worth a thousand words.\"

        \u201c\u4e00\u56fe\u80dc\u5343\u8a00\u201d

        \u4ee3\u7801\u4e00\u952e\u8fd0\u884c

        \u63d0\u4f9b\u5404\u4e2a\u7b97\u6cd5\u4e0e\u6570\u636e\u7ed3\u6784\u7684\u7b80\u6d01\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u6837\u4f8b\uff0c\u7686\u53ef\u76f4\u63a5\u8fd0\u884c\u652f\u6301 Python\u3001C++\u3001Java\u3001C#\u3001Go\u3001Swift\u3001JS\u3001TS\u3001Dart\u3001Rust\u3001C\u3001Zig \u7b49\u8bed\u8a00

        \"Talk is cheap. Show me the code.\"

        \u201c\u5c11\u5439\u725b\uff0c\u770b\u4ee3\u7801\u201d

        \u53ef\u8ba8\u8bba\u4e0e\u63d0\u95ee

        \u9f13\u52b1\u5c0f\u4f19\u4f34\u4eec\u4e92\u5e2e\u4e92\u52a9\u3001\u5171\u540c\u6210\u957f\u63d0\u95ee\u4e0e\u8bc4\u8bba\u4e00\u822c\u80fd\u5728\u4e24\u65e5\u5185\u5f97\u5230\u56de\u590d

        \u201c\u8ffd\u98ce\u8d76\u6708\u83ab\u505c\u7559\uff0c\u5e73\u829c\u5c3d\u5904\u662f\u6625\u5c71\u201d

        \u4e00\u8d77\u52a0\u6cb9\uff01

        \u5e8f

        \u4e24\u5e74\u524d\uff0c\u6211\u5728\u529b\u6263\u4e0a\u5206\u4eab\u4e86\u201c\u5251\u6307 Offer\u201d\u7cfb\u5217\u9898\u89e3\uff0c\u53d7\u5230\u4e86\u8bb8\u591a\u540c\u5b66\u7684\u559c\u7231\u548c\u652f\u6301\u3002\u5728\u4e0e\u8bfb\u8005\u4ea4\u6d41\u671f\u95f4\uff0c\u6211\u6700\u5e38\u6536\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u201c\u5982\u4f55\u5165\u95e8\u7b97\u6cd5\u201d\u3002\u9010\u6e10\u5730\uff0c\u6211\u5bf9\u8fd9\u4e2a\u95ee\u9898\u4ea7\u751f\u4e86\u6d53\u539a\u7684\u5174\u8da3\u3002

        \u4e24\u773c\u4e00\u62b9\u9ed1\u5730\u5237\u9898\u4f3c\u4e4e\u662f\u6700\u53d7\u6b22\u8fce\u7684\u65b9\u6cd5\uff0c\u7b80\u5355\u76f4\u63a5\u4e14\u6709\u6548\u3002\u7136\u800c\u5237\u9898\u5c31\u5982\u540c\u73a9\u201c\u626b\u96f7\u201d\u6e38\u620f\uff0c\u81ea\u5b66\u80fd\u529b\u5f3a\u7684\u540c\u5b66\u80fd\u591f\u987a\u5229\u5c06\u5730\u96f7\u9010\u4e2a\u6392\u6389\uff0c\u800c\u57fa\u7840\u4e0d\u8db3\u7684\u540c\u5b66\u5f88\u53ef\u80fd\u88ab\u70b8\u7684\u6ee1\u5934\u662f\u5305\uff0c\u5e76\u5728\u632b\u6298\u4e2d\u6b65\u6b65\u9000\u7f29\u3002\u901a\u8bfb\u6559\u6750\u4e5f\u662f\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\uff0c\u4f46\u5bf9\u4e8e\u9762\u5411\u6c42\u804c\u7684\u540c\u5b66\u6765\u8bf4\uff0c\u6bd5\u4e1a\u5b63\u3001\u6295\u9012\u7b80\u5386\u3001\u51c6\u5907\u7b14\u8bd5\u9762\u8bd5\u5df2\u7ecf\u6d88\u8017\u4e86\u5927\u90e8\u5206\u7cbe\u529b\uff0c\u5543\u539a\u91cd\u7684\u4e66\u5f80\u5f80\u53d8\u6210\u4e86\u4e00\u9879\u8270\u5de8\u7684\u6311\u6218\u3002

        \u5982\u679c\u4f60\u4e5f\u9762\u4e34\u7c7b\u4f3c\u7684\u56f0\u6270\uff0c\u90a3\u4e48\u5f88\u5e78\u8fd0\u8fd9\u672c\u4e66\u627e\u5230\u4e86\u4f60\u3002\u672c\u4e66\u662f\u6211\u5bf9\u8fd9\u4e2a\u95ee\u9898\u7ed9\u51fa\u7684\u7b54\u6848\uff0c\u5373\u4f7f\u4e0d\u662f\u6700\u4f18\u89e3\uff0c\u4e5f\u81f3\u5c11\u662f\u4e00\u6b21\u79ef\u6781\u7684\u5c1d\u8bd5\u3002\u672c\u4e66\u867d\u7136\u4e0d\u8db3\u4ee5\u8ba9\u4f60\u76f4\u63a5\u62ff\u5230 Offer \uff0c\u4f46\u4f1a\u5f15\u5bfc\u4f60\u63a2\u7d22\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u201c\u77e5\u8bc6\u5730\u56fe\u201d\uff0c\u5e26\u4f60\u4e86\u89e3\u4e0d\u540c\u201c\u5730\u96f7\u201d\u7684\u5f62\u72b6\u3001\u5927\u5c0f\u548c\u5206\u5e03\u4f4d\u7f6e\uff0c\u8ba9\u4f60\u638c\u63e1\u5404\u79cd\u201c\u6392\u96f7\u65b9\u6cd5\u201d\u3002\u6709\u4e86\u8fd9\u4e9b\u672c\u9886\uff0c\u76f8\u4fe1\u4f60\u53ef\u4ee5\u66f4\u52a0\u81ea\u5982\u5730\u5237\u9898\u548c\u9605\u8bfb\u6587\u732e\uff0c\u9010\u6b65\u6784\u5efa\u8d77\u5b8c\u6574\u7684\u77e5\u8bc6\u4f53\u7cfb\u3002

        \u6211\u6df1\u6df1\u8d5e\u540c\u8d39\u66fc\u6559\u6388\u6240\u8a00\uff1a\u201cKnowledge isn't free. You have to pay attention.\u201d\u4ece\u8fd9\u4e2a\u610f\u4e49\u4e0a\u770b\uff0c\u8fd9\u672c\u4e66\u5e76\u975e\u5b8c\u5168\u201c\u514d\u8d39\u201d\u3002\u4e3a\u4e86\u4e0d\u8f9c\u8d1f\u4f60\u4e3a\u672c\u4e66\u6240\u4ed8\u51fa\u7684\u5b9d\u8d35\u201c\u6ce8\u610f\u529b\u201d\uff0c\u6211\u4f1a\u5c3d\u6211\u6240\u80fd\uff0c\u6295\u5165\u6700\u5927\u7684\u201c\u6ce8\u610f\u529b\u201d\u6765\u5b8c\u6210\u8fd9\u672c\u4e66\u7684\u521b\u4f5c\u3002

        \u4f5c\u8005\u7b80\u4ecb

        \u9773\u5b87\u680b (Krahets)\uff0c\u5927\u5382\u9ad8\u7ea7\u7b97\u6cd5\u5de5\u7a0b\u5e08\uff0c\u4e0a\u6d77\u4ea4\u901a\u5927\u5b66\u7855\u58eb\u3002\u529b\u6263\uff08LeetCode\uff09\u5168\u7f51\u9605\u8bfb\u91cf\u6700\u9ad8\u535a\u4e3b\uff0c\u53d1\u8868\u7684\u300a\u56fe\u89e3\u7b97\u6cd5\u6570\u636e\u7ed3\u6784\u300b\u5df2\u88ab\u8ba2\u9605 27 \u4e07\u672c\u3002

        \u81f4\u8c22

        \u672c\u4e66\u5728\u5f00\u6e90\u793e\u533a\u4f17\u591a\u8d21\u732e\u8005\u7684\u5171\u540c\u52aa\u529b\u4e0b\u4e0d\u65ad\u5b8c\u5584\u3002\u611f\u8c22\u6bcf\u4e00\u4f4d\u6295\u5165\u65f6\u95f4\u4e0e\u7cbe\u529b\u7684\u64b0\u7a3f\u4eba\uff0c\u4ed6\u4eec\u662f\uff08\u6309\u7167 GitHub \u81ea\u52a8\u751f\u6210\u7684\u987a\u5e8f\u6392\u5217\uff09\uff1a

        \u672c\u4e66\u7684\u4ee3\u7801\u5ba1\u9605\u5de5\u4f5c\u7531 Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1\u3001Reanon \u548c sjinzh \u5b8c\u6210\uff08\u6309\u7167\u9996\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\uff09\u3002\u611f\u8c22\u4ed6\u4eec\u4ed8\u51fa\u7684\u65f6\u95f4\u4e0e\u7cbe\u529b\uff0c\u6b63\u662f\u4ed6\u4eec\u786e\u4fdd\u4e86\u5404\u8bed\u8a00\u4ee3\u7801\u7684\u89c4\u8303\u4e0e\u7edf\u4e00\u3002

        GongljaC, C++ gvenusleoDart hpstoryC# justin-tseJS, TS krahetsJava, Python night-cruiseRust nuomi1Swift ReanonGo, C sjinzhRust, Zig"},{"location":"chapter_appendix/","title":"\u7b2c 16 \u7ae0 \u00a0 \u9644\u5f55","text":""},{"location":"chapter_appendix/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 16.1 \u00a0 \u7f16\u7a0b\u73af\u5883\u5b89\u88c5
        • 16.2 \u00a0 \u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c
        • 16.3 \u00a0 \u672f\u8bed\u8868
        "},{"location":"chapter_appendix/contribution/","title":"16.2 \u00a0 \u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c","text":"

        \u7531\u4e8e\u7b14\u8005\u80fd\u529b\u6709\u9650\uff0c\u4e66\u4e2d\u96be\u514d\u5b58\u5728\u4e00\u4e9b\u9057\u6f0f\u548c\u9519\u8bef\uff0c\u8bf7\u60a8\u8c05\u89e3\u3002\u5982\u679c\u60a8\u53d1\u73b0\u4e86\u7b14\u8bef\u3001\u94fe\u63a5\u5931\u6548\u3001\u5185\u5bb9\u7f3a\u5931\u3001\u6587\u5b57\u6b67\u4e49\u3001\u89e3\u91ca\u4e0d\u6e05\u6670\u6216\u884c\u6587\u7ed3\u6784\u4e0d\u5408\u7406\u7b49\u95ee\u9898\uff0c\u8bf7\u534f\u52a9\u6211\u4eec\u8fdb\u884c\u4fee\u6b63\uff0c\u4ee5\u7ed9\u8bfb\u8005\u63d0\u4f9b\u66f4\u4f18\u8d28\u7684\u5b66\u4e60\u8d44\u6e90\u3002

        \u6240\u6709\u64b0\u7a3f\u4eba\u7684 GitHub ID \u5c06\u5728\u672c\u4e66\u4ed3\u5e93\u3001\u7f51\u9875\u7248\u548c PDF \u7248\u7684\u4e3b\u9875\u4e0a\u8fdb\u884c\u5c55\u793a\uff0c\u4ee5\u611f\u8c22\u4ed6\u4eec\u5bf9\u5f00\u6e90\u793e\u533a\u7684\u65e0\u79c1\u5949\u732e\u3002

        \u5f00\u6e90\u7684\u9b45\u529b

        \u7eb8\u8d28\u56fe\u4e66\u7684\u4e24\u6b21\u5370\u5237\u7684\u95f4\u9694\u65f6\u95f4\u5f80\u5f80\u8f83\u4e45\uff0c\u5185\u5bb9\u66f4\u65b0\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002

        \u800c\u5728\u672c\u5f00\u6e90\u4e66\u4e2d\uff0c\u5185\u5bb9\u66f4\u8fed\u7684\u65f6\u95f4\u88ab\u7f29\u77ed\u81f3\u6570\u65e5\u751a\u81f3\u51e0\u4e2a\u5c0f\u65f6\u3002

        "},{"location":"chapter_appendix/contribution/#1","title":"1. \u00a0 \u5185\u5bb9\u5fae\u8c03","text":"

        \u5982\u56fe 16-1 \u6240\u793a\uff0c\u6bcf\u4e2a\u9875\u9762\u7684\u53f3\u4e0a\u89d2\u90fd\u6709\u201c\u7f16\u8f91\u56fe\u6807\u201d\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u4fee\u6539\u6587\u672c\u6216\u4ee3\u7801\u3002

        1. \u70b9\u51fb\u201c\u7f16\u8f91\u56fe\u6807\u201d\uff0c\u5982\u679c\u9047\u5230\u201c\u9700\u8981 Fork \u6b64\u4ed3\u5e93\u201d\u7684\u63d0\u793a\uff0c\u8bf7\u540c\u610f\u8be5\u64cd\u4f5c\u3002
        2. \u4fee\u6539 Markdown \u6e90\u6587\u4ef6\u5185\u5bb9\uff0c\u68c0\u67e5\u5185\u5bb9\u7684\u6b63\u786e\u6027\uff0c\u5e76\u5c3d\u91cf\u4fdd\u6301\u6392\u7248\u683c\u5f0f\u7684\u7edf\u4e00\u3002
        3. \u5728\u9875\u9762\u5e95\u90e8\u586b\u5199\u4fee\u6539\u8bf4\u660e\uff0c\u7136\u540e\u70b9\u51fb\u201cPropose file change\u201d\u6309\u94ae\u3002\u9875\u9762\u8df3\u8f6c\u540e\uff0c\u70b9\u51fb\u201cCreate pull request\u201d\u6309\u94ae\u5373\u53ef\u53d1\u8d77\u62c9\u53d6\u8bf7\u6c42\u3002

        \u56fe 16-1 \u00a0 \u9875\u9762\u7f16\u8f91\u6309\u952e

        \u56fe\u7247\u65e0\u6cd5\u76f4\u63a5\u4fee\u6539\uff0c\u9700\u8981\u901a\u8fc7\u65b0\u5efa Issue \u6216\u8bc4\u8bba\u7559\u8a00\u6765\u63cf\u8ff0\u95ee\u9898\uff0c\u6211\u4eec\u4f1a\u5c3d\u5feb\u91cd\u65b0\u7ed8\u5236\u5e76\u66ff\u6362\u56fe\u7247\u3002

        "},{"location":"chapter_appendix/contribution/#2","title":"2. \u00a0 \u5185\u5bb9\u521b\u4f5c","text":"

        \u5982\u679c\u60a8\u6709\u5174\u8da3\u53c2\u4e0e\u6b64\u5f00\u6e90\u9879\u76ee\uff0c\u5305\u62ec\u5c06\u4ee3\u7801\u7ffb\u8bd1\u6210\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u3001\u6269\u5c55\u6587\u7ae0\u5185\u5bb9\u7b49\uff0c\u90a3\u4e48\u9700\u8981\u5b9e\u65bd\u4ee5\u4e0b Pull Request \u5de5\u4f5c\u6d41\u7a0b\u3002

        1. \u767b\u5f55 GitHub \uff0c\u5c06\u672c\u4e66\u7684\u4ee3\u7801\u4ed3\u5e93 Fork \u5230\u4e2a\u4eba\u8d26\u53f7\u4e0b\u3002
        2. \u8fdb\u5165\u60a8\u7684 Fork \u4ed3\u5e93\u7f51\u9875\uff0c\u4f7f\u7528 git clone \u547d\u4ee4\u5c06\u4ed3\u5e93\u514b\u9686\u81f3\u672c\u5730\u3002
        3. \u5728\u672c\u5730\u8fdb\u884c\u5185\u5bb9\u521b\u4f5c\uff0c\u5e76\u8fdb\u884c\u5b8c\u6574\u6d4b\u8bd5\uff0c\u9a8c\u8bc1\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002
        4. \u5c06\u672c\u5730\u6240\u505a\u66f4\u6539 Commit \uff0c\u7136\u540e Push \u81f3\u8fdc\u7a0b\u4ed3\u5e93\u3002
        5. \u5237\u65b0\u4ed3\u5e93\u7f51\u9875\uff0c\u70b9\u51fb\u201cCreate pull request\u201d\u6309\u94ae\u5373\u53ef\u53d1\u8d77\u62c9\u53d6\u8bf7\u6c42\u3002
        "},{"location":"chapter_appendix/contribution/#3-docker","title":"3. \u00a0 Docker \u90e8\u7f72","text":"

        \u5728 hello-algo \u6839\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b Docker \u811a\u672c\uff0c\u5373\u53ef\u5728 http://localhost:8000 \u8bbf\u95ee\u672c\u9879\u76ee\uff1a

        docker-compose up -d\n

        \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5220\u9664\u90e8\u7f72\uff1a

        docker-compose down\n
        "},{"location":"chapter_appendix/installation/","title":"16.1 \u00a0 \u7f16\u7a0b\u73af\u5883\u5b89\u88c5","text":""},{"location":"chapter_appendix/installation/#1-vscode","title":"1. \u00a0 VSCode","text":"

        \u672c\u4e66\u63a8\u8350\u4f7f\u7528\u5f00\u6e90\u3001\u8f7b\u91cf\u7684 VSCode \u4f5c\u4e3a\u672c\u5730 IDE \uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5 VSCode \u3002

        "},{"location":"chapter_appendix/installation/#2-java","title":"2. \u00a0 Java \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 OpenJDK\uff08\u7248\u672c\u9700\u6ee1\u8db3 > JDK 9\uff09\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 java \uff0c\u5b89\u88c5 Extension Pack for Java \u3002
        "},{"location":"chapter_appendix/installation/#3-cc","title":"3. \u00a0 C/C++ \u73af\u5883","text":"
        1. Windows \u7cfb\u7edf\u9700\u8981\u5b89\u88c5 MinGW\uff08\u914d\u7f6e\u6559\u7a0b\uff09\uff1bMacOS \u81ea\u5e26 Clang \uff0c\u65e0\u987b\u5b89\u88c5\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 c++ \uff0c\u5b89\u88c5 C/C++ Extension Pack \u3002
        3. \uff08\u53ef\u9009\uff09\u6253\u5f00 Settings \u9875\u9762\uff0c\u641c\u7d22 Clang_format_fallback Style \u4ee3\u7801\u683c\u5f0f\u5316\u9009\u9879\uff0c\u8bbe\u7f6e\u4e3a { BasedOnStyle: Microsoft, BreakBeforeBraces: Attach } \u3002
        "},{"location":"chapter_appendix/installation/#4-python","title":"4. \u00a0 Python \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Miniconda3 \uff0c\u9700\u8981 Python 3.10 \u6216\u66f4\u65b0\u7248\u672c\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 python \uff0c\u5b89\u88c5 Python Extension Pack \u3002
        3. \uff08\u53ef\u9009\uff09\u5728\u547d\u4ee4\u884c\u8f93\u5165 pip install black \uff0c\u5b89\u88c5\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u3002
        "},{"location":"chapter_appendix/installation/#5-go","title":"5. \u00a0 Go \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 go \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 go \uff0c\u5b89\u88c5 Go \u3002
        3. \u6309\u5feb\u6377\u952e Ctrl + Shift + P \u547c\u51fa\u547d\u4ee4\u680f\uff0c\u8f93\u5165 go \uff0c\u9009\u62e9 Go: Install/Update Tools \uff0c\u5168\u90e8\u52fe\u9009\u5e76\u5b89\u88c5\u5373\u53ef\u3002
        "},{"location":"chapter_appendix/installation/#6-javascript","title":"6. \u00a0 JavaScript \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 node.js \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 javascript \uff0c\u5b89\u88c5 JavaScript (ES6) code snippets \u3002
        3. \uff08\u53ef\u9009\uff09\u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 Prettier \uff0c\u5b89\u88c5\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u3002
        "},{"location":"chapter_appendix/installation/#7-c","title":"7. \u00a0 C# \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 .Net 8.0 \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 C# Dev Kit \uff0c\u5b89\u88c5 C# Dev Kit \uff08\u914d\u7f6e\u6559\u7a0b\uff09\u3002
        3. \u4e5f\u53ef\u4f7f\u7528 Visual Studio\uff08\u5b89\u88c5\u6559\u7a0b\uff09\u3002
        "},{"location":"chapter_appendix/installation/#8-swift","title":"8. \u00a0 Swift \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Swift \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 swift \uff0c\u5b89\u88c5 Swift for Visual Studio Code \u3002
        "},{"location":"chapter_appendix/installation/#9-dart","title":"9. \u00a0 Dart \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Dart \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 dart \uff0c\u5b89\u88c5 Dart \u3002
        "},{"location":"chapter_appendix/installation/#10-rust","title":"10. \u00a0 Rust \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Rust \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 rust \uff0c\u5b89\u88c5 rust-analyzer \u3002
        "},{"location":"chapter_appendix/terminology/","title":"16.3 \u00a0 \u672f\u8bed\u8868","text":"

        \u8868 16-1 \u5217\u51fa\u4e86\u4e66\u4e2d\u51fa\u73b0\u7684\u91cd\u8981\u672f\u8bed\u3002\u5efa\u8bae\u4f60\u540c\u65f6\u8bb0\u4f4f\u5b83\u4eec\u7684\u4e2d\u82f1\u6587\u53eb\u6cd5\uff0c\u4ee5\u4fbf\u9605\u8bfb\u82f1\u6587\u6587\u732e\u3002

        \u8868 16-1 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u91cd\u8981\u540d\u8bcd

        \u4e2d\u6587 English \u4e2d\u6587 English \u7b97\u6cd5 algorithm \u5c42\u5e8f\u904d\u5386 level-order traversal \u6570\u636e\u7ed3\u6784 data structure \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal \u6e10\u8fd1\u590d\u6742\u5ea6\u5206\u6790 asymptotic complexity analysis \u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal \u65f6\u95f4\u590d\u6742\u5ea6 time complexity \u4e8c\u53c9\u641c\u7d22\u6811 binary search tree \u7a7a\u95f4\u590d\u6742\u5ea6 space complexity \u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 balanced binary search tree \u8fed\u4ee3 iteration \u5e73\u8861\u56e0\u5b50 balance factor \u9012\u5f52 recursion \u5806 heap \u5c3e\u9012\u5f52 tail recursion \u5927\u9876\u5806 max heap \u9012\u5f52\u6811 recursion tree \u5c0f\u9876\u5806 min heap \u5927 big- \u4f18\u5148\u961f\u5217 priority queue \u8bb0\u53f7 notation \u6e10\u8fd1\u4e0a\u754c asymptotic upper bound \u5806\u5316 heapify \u539f\u7801 sign\u2013magnitude \u56fe graph \u53cd\u7801 1\u2019s complement \u9876\u70b9 vertex \u8865\u7801 2\u2019s complement \u65e0\u5411\u56fe undirected graph \u6570\u7ec4 array \u6709\u5411\u56fe directed graph \u7d22\u5f15 index \u8fde\u901a\u56fe connected graph \u94fe\u8868 linked list \u975e\u8fde\u901a\u56fe disconnected graph \u94fe\u8868\u8282\u70b9 linked list node, list node \u6709\u6743\u56fe weighted graph \u5217\u8868 list \u90bb\u63a5 adjacency \u52a8\u6001\u6570\u7ec4 dynamic array \u8def\u5f84 path \u786c\u76d8 hard disk \u5165\u5ea6 in-degree \u5185\u5b58 random-access memory (RAM) \u51fa\u5ea6 out-degree \u7f13\u5b58 cache memory \u90bb\u63a5\u77e9\u9635 adjacency matrix \u7f13\u5b58\u672a\u547d\u4e2d cache miss \u90bb\u63a5\u8868 adjacency list \u7f13\u5b58\u547d\u4e2d\u7387 cache hit rate \u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search \u6808 stack \u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search \u961f\u5217 queue \u4e8c\u5206\u67e5\u627e binary search \u53cc\u5411\u961f\u5217 double-ended queue \u641c\u7d22\u7b97\u6cd5 searching algorithm \u54c8\u5e0c\u8868 hash table \u6392\u5e8f\u7b97\u6cd5 sorting algorithm \u6876 bucket \u9009\u62e9\u6392\u5e8f selection sort \u54c8\u5e0c\u51fd\u6570 hash function \u5192\u6ce1\u6392\u5e8f bubble sort \u54c8\u5e0c\u51b2\u7a81 hash collision \u63d2\u5165\u6392\u5e8f insertion sort \u8d1f\u8f7d\u56e0\u5b50 load factor \u5feb\u901f\u6392\u5e8f quick sort \u94fe\u5f0f\u5730\u5740 separate chaining \u5f52\u5e76\u6392\u5e8f merge sort \u5f00\u653e\u5bfb\u5740 open addressing \u5806\u6392\u5e8f heap sort \u7ebf\u6027\u63a2\u6d4b linear probing \u6876\u6392\u5e8f bucket sort \u61d2\u5220\u9664 lazy deletion \u8ba1\u6570\u6392\u5e8f counting sort \u4e8c\u53c9\u6811 binary tree \u57fa\u6570\u6392\u5e8f radix sort \u6811\u8282\u70b9 tree node \u5206\u6cbb divide and conquer \u5de6\u5b50\u8282\u70b9 left-child node \u6c49\u8bfa\u5854\u95ee\u9898 hanota problem \u53f3\u5b50\u8282\u70b9 right-child node \u56de\u6eaf\u7b97\u6cd5 backtracking algorithm \u7236\u8282\u70b9 parent node \u7ea6\u675f constraint \u5de6\u5b50\u6811 left subtree \u89e3 solution \u53f3\u5b50\u6811 right subtree \u72b6\u6001 state \u6839\u8282\u70b9 root node \u526a\u679d pruning \u53f6\u8282\u70b9 leaf node \u5168\u6392\u5217\u95ee\u9898 permutations problem \u8fb9 edge \u5b50\u96c6\u548c\u95ee\u9898 subset-sum problem \u5c42 level N \u7687\u540e\u95ee\u9898 N-queens problem \u5ea6 degree \u52a8\u6001\u89c4\u5212 dynamic programming \u9ad8\u5ea6 height \u521d\u59cb\u72b6\u6001 initial state \u6df1\u5ea6 depth \u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b state-trasition equation \u5b8c\u7f8e\u4e8c\u53c9\u6811 perfect binary tree \u80cc\u5305\u95ee\u9898 knapsack problem \u5b8c\u5168\u4e8c\u53c9\u6811 complete binary tree \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898 edit distance problem \u5b8c\u6ee1\u4e8c\u53c9\u6811 full binary tree \u8d2a\u5fc3\u7b97\u6cd5 greedy algorithm \u5e73\u8861\u4e8c\u53c9\u6811 balanced binary tree AVL \u6811 AVL tree \u7ea2\u9ed1\u6811 red-black tree"},{"location":"chapter_array_and_linkedlist/","title":"\u7b2c 4 \u7ae0 \u00a0 \u6570\u7ec4\u4e0e\u94fe\u8868","text":"

        Abstract

        \u6570\u636e\u7ed3\u6784\u7684\u4e16\u754c\u5982\u540c\u4e00\u5835\u539a\u5b9e\u7684\u7816\u5899\u3002

        \u6570\u7ec4\u7684\u7816\u5757\u6574\u9f50\u6392\u5217\uff0c\u9010\u4e2a\u7d27\u8d34\u3002\u94fe\u8868\u7684\u7816\u5757\u5206\u6563\u5404\u5904\uff0c\u8fde\u63a5\u7684\u85e4\u8513\u81ea\u7531\u5730\u7a7f\u68ad\u4e8e\u7816\u7f1d\u4e4b\u95f4\u3002

        "},{"location":"chapter_array_and_linkedlist/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 4.1 \u00a0 \u6570\u7ec4
        • 4.2 \u00a0 \u94fe\u8868
        • 4.3 \u00a0 \u5217\u8868
        • 4.4 \u00a0 \u5185\u5b58\u4e0e\u7f13\u5b58 *
        • 4.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_array_and_linkedlist/array/","title":"4.1 \u00a0 \u6570\u7ec4","text":"

        \u300c\u6570\u7ec4 array\u300d\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u5c06\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\u3002\u6211\u4eec\u5c06\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u79f0\u4e3a\u8be5\u5143\u7d20\u7684\u300c\u7d22\u5f15 index\u300d\u3002\u56fe 4-1 \u5c55\u793a\u4e86\u6570\u7ec4\u7684\u4e3b\u8981\u672f\u8bed\u548c\u6982\u5ff5\u3002

        \u56fe 4-1 \u00a0 \u6570\u7ec4\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f

        "},{"location":"chapter_array_and_linkedlist/array/#411","title":"4.1.1 \u00a0 \u6570\u7ec4\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/array/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u6570\u7ec4","text":"

        \u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u7528\u6570\u7ec4\u7684\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u5f0f\uff1a\u65e0\u521d\u59cb\u503c\u3001\u7ed9\u5b9a\u521d\u59cb\u503c\u3002\u5728\u672a\u6307\u5b9a\u521d\u59cb\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4f1a\u5c06\u6570\u7ec4\u5143\u7d20\u521d\u59cb\u5316\u4e3a \\(0\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        # \u521d\u59cb\u5316\u6570\u7ec4\narr: list[int] = [0] * 5  # [ 0, 0, 0, 0, 0 ]\nnums: list[int] = [1, 3, 2, 5, 4]  \n
        array.cpp
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\n// \u5b58\u50a8\u5728\u6808\u4e0a\nint arr[5];\nint nums[5] = { 1, 3, 2, 5, 4 };\n// \u5b58\u50a8\u5728\u5806\u4e0a\uff08\u9700\u8981\u624b\u52a8\u91ca\u653e\u7a7a\u95f4\uff09\nint* arr1 = new int[5];\nint* nums1 = new int[5] { 1, 3, 2, 5, 4 };\n
        array.java
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint[] arr = new int[5]; // { 0, 0, 0, 0, 0 }\nint[] nums = { 1, 3, 2, 5, 4 };\n
        array.cs
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint[] arr = new int[5]; // { 0, 0, 0, 0, 0 }\nint[] nums = [1, 3, 2, 5, 4];\n
        array.go
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nvar arr [5]int\n// \u5728 Go \u4e2d\uff0c\u6307\u5b9a\u957f\u5ea6\u65f6\uff08[5]int\uff09\u4e3a\u6570\u7ec4\uff0c\u4e0d\u6307\u5b9a\u957f\u5ea6\u65f6\uff08[]int\uff09\u4e3a\u5207\u7247\n// \u7531\u4e8e Go \u7684\u6570\u7ec4\u88ab\u8bbe\u8ba1\u4e3a\u5728\u7f16\u8bd1\u671f\u786e\u5b9a\u957f\u5ea6\uff0c\u56e0\u6b64\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u6765\u6307\u5b9a\u957f\u5ea6\n// \u4e3a\u4e86\u65b9\u4fbf\u5b9e\u73b0\u6269\u5bb9 extend() \u65b9\u6cd5\uff0c\u4ee5\u4e0b\u5c06\u5207\u7247\uff08Slice\uff09\u770b\u4f5c\u6570\u7ec4\uff08Array\uff09\nnums := []int{1, 3, 2, 5, 4}\n
        array.swift
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr = Array(repeating: 0, count: 5) // [0, 0, 0, 0, 0]\nlet nums = [1, 3, 2, 5, 4]\n
        array.js
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nvar arr = new Array(5).fill(0);\nvar nums = [1, 3, 2, 5, 4];\n
        array.ts
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr: number[] = new Array(5).fill(0);\nlet nums: number[] = [1, 3, 2, 5, 4];\n
        array.dart
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nList<int> arr = List.filled(5, 0); // [0, 0, 0, 0, 0]\nList<int> nums = [1, 3, 2, 5, 4];\n
        array.rs
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr: Vec<i32> = vec![0; 5]; // [0, 0, 0, 0, 0]\nlet nums: Vec<i32> = vec![1, 3, 2, 5, 4];\n
        array.c
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint arr[5] = { 0 }; // { 0, 0, 0, 0, 0 }\nint nums[5] = { 1, 3, 2, 5, 4 };\n
        array.zig
        // \u521d\u59cb\u5316\u6570\u7ec4\nvar arr = [_]i32{0} ** 5; // { 0, 0, 0, 0, 0 }\nvar nums = [_]i32{ 1, 3, 2, 5, 4 };\n
        "},{"location":"chapter_array_and_linkedlist/array/#2","title":"2. \u00a0 \u8bbf\u95ee\u5143\u7d20","text":"

        \u6570\u7ec4\u5143\u7d20\u88ab\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u8ba1\u7b97\u6570\u7ec4\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\u975e\u5e38\u5bb9\u6613\u3002\u7ed9\u5b9a\u6570\u7ec4\u5185\u5b58\u5730\u5740\uff08\u9996\u5143\u7d20\u5185\u5b58\u5730\u5740\uff09\u548c\u67d0\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u56fe 4-2 \u6240\u793a\u7684\u516c\u5f0f\u8ba1\u7b97\u5f97\u5230\u8be5\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\uff0c\u4ece\u800c\u76f4\u63a5\u8bbf\u95ee\u8be5\u5143\u7d20\u3002

        \u56fe 4-2 \u00a0 \u6570\u7ec4\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\u8ba1\u7b97

        \u89c2\u5bdf\u56fe 4-2 \uff0c\u6211\u4eec\u53d1\u73b0\u6570\u7ec4\u9996\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4e3a \\(0\\) \uff0c\u8fd9\u4f3c\u4e4e\u6709\u4e9b\u53cd\u76f4\u89c9\uff0c\u56e0\u4e3a\u4ece \\(1\\) \u5f00\u59cb\u8ba1\u6570\u4f1a\u66f4\u81ea\u7136\u3002\u4f46\u4ece\u5730\u5740\u8ba1\u7b97\u516c\u5f0f\u7684\u89d2\u5ea6\u770b\uff0c\u7d22\u5f15\u672c\u8d28\u4e0a\u662f\u5185\u5b58\u5730\u5740\u7684\u504f\u79fb\u91cf\u3002\u9996\u4e2a\u5143\u7d20\u7684\u5730\u5740\u504f\u79fb\u91cf\u662f \\(0\\) \uff0c\u56e0\u6b64\u5b83\u7684\u7d22\u5f15\u4e3a \\(0\\) \u662f\u5408\u7406\u7684\u3002

        \u5728\u6570\u7ec4\u4e2d\u8bbf\u95ee\u5143\u7d20\u975e\u5e38\u9ad8\u6548\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u968f\u673a\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5143\u7d20\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def random_access(nums: list[int]) -> int:\n\"\"\"\u968f\u673a\u8bbf\u95ee\u5143\u7d20\"\"\"\n# \u5728\u533a\u95f4 [0, len(nums)-1] \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nrandom_index = random.randint(0, len(nums) - 1)\n# \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nrandom_num = nums[random_index]\nreturn random_num\n
        array.cpp
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int *nums, int size) {\n// \u5728\u533a\u95f4 [0, size) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = rand() % size;\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.java
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int[] nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = ThreadLocalRandom.current().nextInt(0, nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.cs
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint RandomAccess(int[] nums) {\nRandom random = new();\n// \u5728\u533a\u95f4 [0, nums.Length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = random.Next(nums.Length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.go
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunc randomAccess(nums []int) (randomNum int) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nrandomIndex := rand.Intn(len(nums))\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nrandomNum = nums[randomIndex]\nreturn\n}\n
        array.swift
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunc randomAccess(nums: [Int]) -> Int {\n// \u5728\u533a\u95f4 [0, nums.count) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nlet randomIndex = nums.indices.randomElement()!\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nlet randomNum = nums[randomIndex]\nreturn randomNum\n}\n
        array.js
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunction randomAccess(nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nconst random_index = Math.floor(Math.random() * nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nconst random_num = nums[random_index];\nreturn random_num;\n}\n
        array.ts
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunction randomAccess(nums: number[]): number {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nconst random_index = Math.floor(Math.random() * nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nconst random_num = nums[random_index];\nreturn random_num;\n}\n
        array.dart
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(List<int> nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = Random().nextInt(nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.rs
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfn random_access(nums: &[i32]) -> i32 {\n// \u5728\u533a\u95f4 [0, nums.len()) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nlet random_index = rand::thread_rng().gen_range(0..nums.len());\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nlet random_num = nums[random_index];\nrandom_num\n}\n
        array.c
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int *nums, int size) {\n// \u5728\u533a\u95f4 [0, size) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = rand() % size;\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.zig
        // \u968f\u673a\u8bbf\u95ee\u5143\u7d20\nfn randomAccess(nums: []i32) i32 {\n// \u5728\u533a\u95f4 [0, nums.len) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6574\u6570\nvar randomIndex = std.crypto.random.intRangeLessThan(usize, 0, nums.len);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nvar randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#3","title":"3. \u00a0 \u63d2\u5165\u5143\u7d20","text":"

        \u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u662f\u201c\u7d27\u6328\u7740\u7684\u201d\uff0c\u5b83\u4eec\u4e4b\u95f4\u6ca1\u6709\u7a7a\u95f4\u518d\u5b58\u653e\u4efb\u4f55\u6570\u636e\u3002\u5982\u56fe 4-3 \u6240\u793a\uff0c\u5982\u679c\u60f3\u5728\u6570\u7ec4\u4e2d\u95f4\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u5219\u9700\u8981\u5c06\u8be5\u5143\u7d20\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u4e4b\u540e\u518d\u628a\u5143\u7d20\u8d4b\u503c\u7ed9\u8be5\u7d22\u5f15\u3002

        \u56fe 4-3 \u00a0 \u6570\u7ec4\u63d2\u5165\u5143\u7d20\u793a\u4f8b

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u56e0\u6b64\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u4f1a\u5bfc\u81f4\u6570\u7ec4\u5c3e\u90e8\u5143\u7d20\u201c\u4e22\u5931\u201d\u3002\u6211\u4eec\u5c06\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u7559\u5728\u201c\u5217\u8868\u201d\u7ae0\u8282\u4e2d\u8ba8\u8bba\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def insert(nums: list[int], num: int, index: int):\n\"\"\"\u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num\"\"\"\n# \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in range(len(nums) - 1, index, -1):\nnums[i] = nums[i - 1]\n# \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n
        array.cpp
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int *nums, int size, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = size - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.java
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int[] nums, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.cs
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid Insert(int[] nums, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = nums.Length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.go
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunc insert(nums []int, num int, index int) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i := len(nums) - 1; i > index; i-- {\nnums[i] = nums[i-1]\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n}\n
        array.swift
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunc insert(nums: inout [Int], num: Int, index: Int) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in nums.indices.dropFirst(index).reversed() {\nnums[i] = nums[i - 1]\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n}\n
        array.js
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunction insert(nums, num, index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.ts
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunction insert(nums: number[], num: number, index: number): void {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.dart
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 _num */\nvoid insert(List<int> nums, int _num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (var i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 _num \u8d4b\u7ed9 index \u5904\u5143\u7d20\nnums[index] = _num;\n}\n
        array.rs
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfn insert(nums: &mut Vec<i32>, num: i32, index: usize) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in (index + 1..nums.len()).rev() {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.c
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int *nums, int size, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = size - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.zig
        // \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num\nfn insert(nums: []i32, num: i32, index: usize) void {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nvar i = nums.len - 1;\nwhile (i > index) : (i -= 1) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#4","title":"4. \u00a0 \u5220\u9664\u5143\u7d20","text":"

        \u540c\u7406\uff0c\u5982\u56fe 4-4 \u6240\u793a\uff0c\u82e5\u60f3\u5220\u9664\u7d22\u5f15 \\(i\\) \u5904\u7684\u5143\u7d20\uff0c\u5219\u9700\u8981\u628a\u7d22\u5f15 \\(i\\) \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\u3002

        \u56fe 4-4 \u00a0 \u6570\u7ec4\u5220\u9664\u5143\u7d20\u793a\u4f8b

        \u8bf7\u6ce8\u610f\uff0c\u5220\u9664\u5143\u7d20\u5b8c\u6210\u540e\uff0c\u539f\u5148\u672b\u5c3e\u7684\u5143\u7d20\u53d8\u5f97\u201c\u65e0\u610f\u4e49\u201d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u65e0\u987b\u7279\u610f\u53bb\u4fee\u6539\u5b83\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def remove(nums: list[int], index: int):\n\"\"\"\u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\"\"\"\n# \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in range(index, len(nums) - 1):\nnums[i] = nums[i + 1]\n
        array.cpp
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(int *nums, int size, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < size - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.java
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(int[] nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.cs
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid Remove(int[] nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < nums.Length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.go
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunc remove(nums []int, index int) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i := index; i < len(nums)-1; i++ {\nnums[i] = nums[i+1]\n}\n}\n
        array.swift
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunc remove(nums: inout [Int], index: Int) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in nums.indices.dropFirst(index).dropLast() {\nnums[i] = nums[i + 1]\n}\n}\n
        array.js
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunction remove(nums, index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.ts
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunction remove(nums: number[], index: number): void {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.dart
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(List<int> nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (var i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.rs
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfn remove(nums: &mut Vec<i32>, index: usize) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in index..nums.len() - 1 {\nnums[i] = nums[i + 1];\n}\n}\n
        array.c
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nvoid removeItem(int *nums, int size, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < size - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.zig
        // \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\nfn remove(nums: []i32, index: usize) void {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nvar i = index;\nwhile (i < nums.len - 1) : (i += 1) {\nnums[i] = nums[i + 1];\n}\n}\n

        \u603b\u7684\u6765\u770b\uff0c\u6570\u7ec4\u7684\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u6709\u4ee5\u4e0b\u7f3a\u70b9\u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6\u9ad8\uff1a\u6570\u7ec4\u7684\u63d2\u5165\u548c\u5220\u9664\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u6570\u7ec4\u957f\u5ea6\u3002
        • \u4e22\u5931\u5143\u7d20\uff1a\u7531\u4e8e\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u53ef\u53d8\uff0c\u56e0\u6b64\u5728\u63d2\u5165\u5143\u7d20\u540e\uff0c\u8d85\u51fa\u6570\u7ec4\u957f\u5ea6\u8303\u56f4\u7684\u5143\u7d20\u4f1a\u4e22\u5931\u3002
        • \u5185\u5b58\u6d6a\u8d39\uff1a\u6211\u4eec\u53ef\u4ee5\u521d\u59cb\u5316\u4e00\u4e2a\u6bd4\u8f83\u957f\u7684\u6570\u7ec4\uff0c\u53ea\u7528\u524d\u9762\u4e00\u90e8\u5206\uff0c\u8fd9\u6837\u5728\u63d2\u5165\u6570\u636e\u65f6\uff0c\u4e22\u5931\u7684\u672b\u5c3e\u5143\u7d20\u90fd\u662f\u201c\u65e0\u610f\u4e49\u201d\u7684\uff0c\u4f46\u8fd9\u6837\u505a\u4f1a\u9020\u6210\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u3002
        "},{"location":"chapter_array_and_linkedlist/array/#5","title":"5. \u00a0 \u904d\u5386\u6570\u7ec4","text":"

        \u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u65e2\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u904d\u5386\u83b7\u53d6\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def traverse(nums: list[int]):\n\"\"\"\u904d\u5386\u6570\u7ec4\"\"\"\ncount = 0\n# \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in range(len(nums)):\ncount += nums[i]\n# \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums:\ncount += num\n# \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\nfor i, num in enumerate(nums):\ncount += nums[i]\ncount += num\n
        array.cpp
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\ncount += nums[i];\n}\n}\n
        array.java
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int[] nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (int num : nums) {\ncount += num;\n}\n}\n
        array.cs
        /* \u904d\u5386\u6570\u7ec4 */\nvoid Traverse(int[] nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < nums.Length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nforeach (int num in nums) {\ncount += num;\n}\n}\n
        array.go
        /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums []int) {\ncount := 0\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i := 0; i < len(nums); i++ {\ncount += nums[i]\n}\ncount = 0\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor _, num := range nums {\ncount += num\n}\n// \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\nfor i, num := range nums {\ncount += nums[i]\ncount += num\n}\n}\n
        array.swift
        /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums: [Int]) {\nvar count = 0\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in nums.indices {\ncount += nums[i]\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums {\ncount += num\n}\n}\n
        array.js
        /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums) {\nlet count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (const num of nums) {\ncount += num;\n}\n}\n
        array.ts
        /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums: number[]): void {\nlet count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (const num of nums) {\ncount += num;\n}\n}\n
        array.dart
        /* \u904d\u5386\u6570\u7ec4\u5143\u7d20 */\nvoid traverse(List<int> nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (var i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (int _num in nums) {\ncount += _num;\n}\n// \u901a\u8fc7 forEach \u65b9\u6cd5\u904d\u5386\u6570\u7ec4\nnums.forEach((_num) {\ncount += _num;\n});\n}\n
        array.rs
        /* \u904d\u5386\u6570\u7ec4 */\nfn traverse(nums: &[i32]) {\nlet mut _count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in 0..nums.len() {\n_count += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums {\n_count += num;\n}\n}\n
        array.c
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\ncount += nums[i];\n}\n}\n
        array.zig
        // \u904d\u5386\u6570\u7ec4\nfn traverse(nums: []i32) void {\nvar count: i32 = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nvar i: i32 = 0;\nwhile (i < nums.len) : (i += 1) {\ncount += nums[i];\n}\ncount = 0;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (nums) |num| {\ncount += num;\n}\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#6","title":"6. \u00a0 \u67e5\u627e\u5143\u7d20","text":"

        \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\u9700\u8981\u904d\u5386\u6570\u7ec4\uff0c\u6bcf\u8f6e\u5224\u65ad\u5143\u7d20\u503c\u662f\u5426\u5339\u914d\uff0c\u82e5\u5339\u914d\u5219\u8f93\u51fa\u5bf9\u5e94\u7d22\u5f15\u3002

        \u56e0\u4e3a\u6570\u7ec4\u662f\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u6240\u4ee5\u4e0a\u8ff0\u67e5\u627e\u64cd\u4f5c\u88ab\u79f0\u4e3a\u201c\u7ebf\u6027\u67e5\u627e\u201d\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def find(nums: list[int], target: int) -> int:\n\"\"\"\u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\"\"\"\nfor i in range(len(nums)):\nif nums[i] == target:\nreturn i\nreturn -1\n
        array.cpp
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\nfor (int i = 0; i < size; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.java
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int[] nums, int target) {\nfor (int i = 0; i < nums.length; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.cs
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint Find(int[] nums, int target) {\nfor (int i = 0; i < nums.Length; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.go
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums []int, target int) (index int) {\nindex = -1\nfor i := 0; i < len(nums); i++ {\nif nums[i] == target {\nindex = i\nbreak\n}\n}\nreturn\n}\n
        array.swift
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums: [Int], target: Int) -> Int {\nfor i in nums.indices {\nif nums[i] == target {\nreturn i\n}\n}\nreturn -1\n}\n
        array.js
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums, target) {\nfor (let i = 0; i < nums.length; i++) {\nif (nums[i] === target) return i;\n}\nreturn -1;\n}\n
        array.ts
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums: number[], target: number): number {\nfor (let i = 0; i < nums.length; i++) {\nif (nums[i] === target) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        array.dart
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(List<int> nums, int target) {\nfor (var i = 0; i < nums.length; i++) {\nif (nums[i] == target) return i;\n}\nreturn -1;\n}\n
        array.rs
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfn find(nums: &[i32], target: i32) -> Option<usize> {\nfor i in 0..nums.len() {\nif nums[i] == target {\nreturn Some(i);\n}\n}\nNone\n}\n
        array.c
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\nfor (int i = 0; i < size; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.zig
        // \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\nfn find(nums: []i32, target: i32) i32 {\nfor (nums, 0..) |num, i| {\nif (num == target) return @intCast(i);\n}\nreturn -1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#7","title":"7. \u00a0 \u6269\u5bb9\u6570\u7ec4","text":"

        \u5728\u590d\u6742\u7684\u7cfb\u7edf\u73af\u5883\u4e2d\uff0c\u7a0b\u5e8f\u96be\u4ee5\u4fdd\u8bc1\u6570\u7ec4\u4e4b\u540e\u7684\u5185\u5b58\u7a7a\u95f4\u662f\u53ef\u7528\u7684\uff0c\u4ece\u800c\u65e0\u6cd5\u5b89\u5168\u5730\u6269\u5c55\u6570\u7ec4\u5bb9\u91cf\u3002\u56e0\u6b64\u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u4e0d\u53ef\u53d8\u7684\u3002

        \u5982\u679c\u6211\u4eec\u5e0c\u671b\u6269\u5bb9\u6570\u7ec4\uff0c\u5219\u9700\u91cd\u65b0\u5efa\u7acb\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u7136\u540e\u628a\u539f\u6570\u7ec4\u5143\u7d20\u4f9d\u6b21\u590d\u5236\u5230\u65b0\u6570\u7ec4\u3002\u8fd9\u662f\u4e00\u4e2a \\(O(n)\\) \u7684\u64cd\u4f5c\uff0c\u5728\u6570\u7ec4\u5f88\u5927\u7684\u60c5\u51b5\u4e0b\u975e\u5e38\u8017\u65f6\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def extend(nums: list[int], enlarge: int) -> list[int]:\n\"\"\"\u6269\u5c55\u6570\u7ec4\u957f\u5ea6\"\"\"\n# \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nres = [0] * (len(nums) + enlarge)\n# \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i in range(len(nums)):\nres[i] = nums[i]\n# \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n
        array.cpp
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint *extend(int *nums, int size, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint *res = new int[size + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\nres[i] = nums[i];\n}\n// \u91ca\u653e\u5185\u5b58\ndelete[] nums;\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.java
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint[] extend(int[] nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint[] res = new int[nums.length + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.cs
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint[] Extend(int[] nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint[] res = new int[nums.Length + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < nums.Length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.go
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfunc extend(nums []int, enlarge int) []int {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nres := make([]int, len(nums)+enlarge)\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i, num := range nums {\nres[i] = num\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n}\n
        array.swift
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfunc extend(nums: [Int], enlarge: Int) -> [Int] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nvar res = Array(repeating: 0, count: nums.count + enlarge)\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i in nums.indices {\nres[i] = nums[i]\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n}\n
        array.js
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\n// \u8bf7\u6ce8\u610f\uff0cJavaScript \u7684 Array \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u76f4\u63a5\u6269\u5c55\n// \u4e3a\u4e86\u65b9\u4fbf\u5b66\u4e60\uff0c\u672c\u51fd\u6570\u5c06 Array \u770b\u4f5c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6570\u7ec4\nfunction extend(nums, enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nconst res = new Array(nums.length + enlarge).fill(0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.ts
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\n// \u8bf7\u6ce8\u610f\uff0cTypeScript \u7684 Array \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u76f4\u63a5\u6269\u5c55\n// \u4e3a\u4e86\u65b9\u4fbf\u5b66\u4e60\uff0c\u672c\u51fd\u6570\u5c06 Array \u770b\u4f5c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6570\u7ec4\nfunction extend(nums: number[], enlarge: number): number[] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nconst res = new Array(nums.length + enlarge).fill(0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.dart
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nList<int> extend(List<int> nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nList<int> res = List.filled(nums.length + enlarge, 0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (var i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.rs
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfn extend(nums: Vec<i32>, enlarge: usize) -> Vec<i32> {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nlet mut res: Vec<i32> = vec![0; nums.len() + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\nfor i in 0..nums.len() {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nres\n}\n
        array.c
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint *extend(int *nums, int size, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint *res = (int *)malloc(sizeof(int) * (size + enlarge));\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\nres[i] = nums[i];\n}\n// \u521d\u59cb\u5316\u6269\u5c55\u540e\u7684\u7a7a\u95f4\nfor (int i = size; i < size + enlarge; i++) {\nres[i] = 0;\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.zig
        // \u6269\u5c55\u6570\u7ec4\u957f\u5ea6\nfn extend(mem_allocator: std.mem.Allocator, nums: []i32, enlarge: usize) ![]i32 {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nvar res = try mem_allocator.alloc(i32, nums.len + enlarge);\n@memset(res, 0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nstd.mem.copy(i32, res, nums);\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#412","title":"4.1.2 \u00a0 \u6570\u7ec4\u7684\u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u6570\u7ec4\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u5185\uff0c\u4e14\u5143\u7d20\u7c7b\u578b\u76f8\u540c\u3002\u8fd9\u79cd\u505a\u6cd5\u5305\u542b\u4e30\u5bcc\u7684\u5148\u9a8c\u4fe1\u606f\uff0c\u7cfb\u7edf\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u4fe1\u606f\u6765\u4f18\u5316\u6570\u636e\u7ed3\u6784\u7684\u64cd\u4f5c\u6548\u7387\u3002

        • \u7a7a\u95f4\u6548\u7387\u9ad8\uff1a\u6570\u7ec4\u4e3a\u6570\u636e\u5206\u914d\u4e86\u8fde\u7eed\u7684\u5185\u5b58\u5757\uff0c\u65e0\u987b\u989d\u5916\u7684\u7ed3\u6784\u5f00\u9500\u3002
        • \u652f\u6301\u968f\u673a\u8bbf\u95ee\uff1a\u6570\u7ec4\u5141\u8bb8\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u8bbf\u95ee\u4efb\u4f55\u5143\u7d20\u3002
        • \u7f13\u5b58\u5c40\u90e8\u6027\uff1a\u5f53\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0c\u8ba1\u7b97\u673a\u4e0d\u4ec5\u4f1a\u52a0\u8f7d\u5b83\uff0c\u8fd8\u4f1a\u7f13\u5b58\u5176\u5468\u56f4\u7684\u5176\u4ed6\u6570\u636e\uff0c\u4ece\u800c\u501f\u52a9\u9ad8\u901f\u7f13\u5b58\u6765\u63d0\u5347\u540e\u7eed\u64cd\u4f5c\u7684\u6267\u884c\u901f\u5ea6\u3002

        \u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u662f\u4e00\u628a\u53cc\u5203\u5251\uff0c\u5176\u5b58\u5728\u4ee5\u4e0b\u5c40\u9650\u6027\u3002

        • \u63d2\u5165\u4e0e\u5220\u9664\u6548\u7387\u4f4e\uff1a\u5f53\u6570\u7ec4\u4e2d\u5143\u7d20\u8f83\u591a\u65f6\uff0c\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u9700\u8981\u79fb\u52a8\u5927\u91cf\u7684\u5143\u7d20\u3002
        • \u957f\u5ea6\u4e0d\u53ef\u53d8\uff1a\u6570\u7ec4\u5728\u521d\u59cb\u5316\u540e\u957f\u5ea6\u5c31\u56fa\u5b9a\u4e86\uff0c\u6269\u5bb9\u6570\u7ec4\u9700\u8981\u5c06\u6240\u6709\u6570\u636e\u590d\u5236\u5230\u65b0\u6570\u7ec4\uff0c\u5f00\u9500\u5f88\u5927\u3002
        • \u7a7a\u95f4\u6d6a\u8d39\uff1a\u5982\u679c\u6570\u7ec4\u5206\u914d\u7684\u5927\u5c0f\u8d85\u8fc7\u5b9e\u9645\u6240\u9700\uff0c\u90a3\u4e48\u591a\u4f59\u7684\u7a7a\u95f4\u5c31\u88ab\u6d6a\u8d39\u4e86\u3002
        "},{"location":"chapter_array_and_linkedlist/array/#413","title":"4.1.3 \u00a0 \u6570\u7ec4\u5178\u578b\u5e94\u7528","text":"

        \u6570\u7ec4\u662f\u4e00\u79cd\u57fa\u7840\u4e14\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\uff0c\u65e2\u9891\u7e41\u5e94\u7528\u5728\u5404\u7c7b\u7b97\u6cd5\u4e4b\u4e2d\uff0c\u4e5f\u53ef\u7528\u4e8e\u5b9e\u73b0\u5404\u79cd\u590d\u6742\u6570\u636e\u7ed3\u6784\u3002

        • \u968f\u673a\u8bbf\u95ee\uff1a\u5982\u679c\u6211\u4eec\u60f3\u968f\u673a\u62bd\u53d6\u4e00\u4e9b\u6837\u672c\uff0c\u90a3\u4e48\u53ef\u4ee5\u7528\u6570\u7ec4\u5b58\u50a8\uff0c\u5e76\u751f\u6210\u4e00\u4e2a\u968f\u673a\u5e8f\u5217\uff0c\u6839\u636e\u7d22\u5f15\u5b9e\u73b0\u968f\u673a\u62bd\u6837\u3002
        • \u6392\u5e8f\u548c\u641c\u7d22\uff1a\u6570\u7ec4\u662f\u6392\u5e8f\u548c\u641c\u7d22\u7b97\u6cd5\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u4e8c\u5206\u67e5\u627e\u7b49\u90fd\u4e3b\u8981\u5728\u6570\u7ec4\u4e0a\u8fdb\u884c\u3002
        • \u67e5\u627e\u8868\uff1a\u5f53\u9700\u8981\u5feb\u901f\u67e5\u627e\u4e00\u4e2a\u5143\u7d20\u6216\u5176\u5bf9\u5e94\u5173\u7cfb\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a\u67e5\u627e\u8868\u3002\u5047\u5982\u6211\u4eec\u60f3\u5b9e\u73b0\u5b57\u7b26\u5230 ASCII \u7801\u7684\u6620\u5c04\uff0c\u5219\u53ef\u4ee5\u5c06\u5b57\u7b26\u7684 ASCII \u7801\u503c\u4f5c\u4e3a\u7d22\u5f15\uff0c\u5bf9\u5e94\u7684\u5143\u7d20\u5b58\u653e\u5728\u6570\u7ec4\u4e2d\u7684\u5bf9\u5e94\u4f4d\u7f6e\u3002
        • \u673a\u5668\u5b66\u4e60\uff1a\u795e\u7ecf\u7f51\u7edc\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86\u5411\u91cf\u3001\u77e9\u9635\u3001\u5f20\u91cf\u4e4b\u95f4\u7684\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97\uff0c\u8fd9\u4e9b\u6570\u636e\u90fd\u662f\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u6784\u5efa\u7684\u3002\u6570\u7ec4\u662f\u795e\u7ecf\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6700\u5e38\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff1a\u6570\u7ec4\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u5806\u3001\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u3002\u4f8b\u5982\uff0c\u56fe\u7684\u90bb\u63a5\u77e9\u9635\u8868\u793a\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002
        "},{"location":"chapter_array_and_linkedlist/linked_list/","title":"4.2 \u00a0 \u94fe\u8868","text":"

        \u5185\u5b58\u7a7a\u95f4\u662f\u6240\u6709\u7a0b\u5e8f\u7684\u516c\u5171\u8d44\u6e90\uff0c\u5728\u4e00\u4e2a\u590d\u6742\u7684\u7cfb\u7edf\u8fd0\u884c\u73af\u5883\u4e0b\uff0c\u7a7a\u95f2\u7684\u5185\u5b58\u7a7a\u95f4\u53ef\u80fd\u6563\u843d\u5728\u5185\u5b58\u5404\u5904\u3002\u6211\u4eec\u77e5\u9053\uff0c\u5b58\u50a8\u6570\u7ec4\u7684\u5185\u5b58\u7a7a\u95f4\u5fc5\u987b\u662f\u8fde\u7eed\u7684\uff0c\u800c\u5f53\u6570\u7ec4\u975e\u5e38\u5927\u65f6\uff0c\u5185\u5b58\u53ef\u80fd\u65e0\u6cd5\u63d0\u4f9b\u5982\u6b64\u5927\u7684\u8fde\u7eed\u7a7a\u95f4\u3002\u6b64\u65f6\u94fe\u8868\u7684\u7075\u6d3b\u6027\u4f18\u52bf\u5c31\u4f53\u73b0\u51fa\u6765\u4e86\u3002

        \u300c\u94fe\u8868 linked list\u300d\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u8282\u70b9\u5bf9\u8c61\uff0c\u5404\u4e2a\u8282\u70b9\u901a\u8fc7\u201c\u5f15\u7528\u201d\u76f8\u8fde\u63a5\u3002\u5f15\u7528\u8bb0\u5f55\u4e86\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u5185\u5b58\u5730\u5740\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u4ece\u5f53\u524d\u8282\u70b9\u8bbf\u95ee\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002

        \u94fe\u8868\u7684\u8bbe\u8ba1\u4f7f\u5f97\u5404\u4e2a\u8282\u70b9\u53ef\u4ee5\u5206\u6563\u5b58\u50a8\u5728\u5185\u5b58\u5404\u5904\uff0c\u5b83\u4eec\u7684\u5185\u5b58\u5730\u5740\u65e0\u987b\u8fde\u7eed\u3002

        \u56fe 4-5 \u00a0 \u94fe\u8868\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f

        \u89c2\u5bdf\u56fe 4-5 \uff0c\u94fe\u8868\u7684\u7ec4\u6210\u5355\u4f4d\u662f\u300c\u8282\u70b9 node\u300d\u5bf9\u8c61\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u4e24\u9879\u6570\u636e\uff1a\u8282\u70b9\u7684\u201c\u503c\u201d\u548c\u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u201c\u5f15\u7528\u201d\u3002

        • \u94fe\u8868\u7684\u9996\u4e2a\u8282\u70b9\u88ab\u79f0\u4e3a\u201c\u5934\u8282\u70b9\u201d\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u88ab\u79f0\u4e3a\u201c\u5c3e\u8282\u70b9\u201d\u3002
        • \u5c3e\u8282\u70b9\u6307\u5411\u7684\u662f\u201c\u7a7a\u201d\uff0c\u5b83\u5728 Java\u3001C++ \u548c Python \u4e2d\u5206\u522b\u88ab\u8bb0\u4e3a \\(\\text{null}\\)\u3001\\(\\text{nullptr}\\) \u548c \\(\\text{None}\\) \u3002
        • \u5728 C\u3001C++\u3001Go \u548c Rust \u7b49\u652f\u6301\u6307\u9488\u7684\u8bed\u8a00\u4e2d\uff0c\u4e0a\u8ff0\u7684\u201c\u5f15\u7528\u201d\u5e94\u88ab\u66ff\u6362\u4e3a\u201c\u6307\u9488\u201d\u3002

        \u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u94fe\u8868\u8282\u70b9 ListNode \u9664\u4e86\u5305\u542b\u503c\uff0c\u8fd8\u9700\u989d\u5916\u4fdd\u5b58\u4e00\u4e2a\u5f15\u7528\uff08\u6307\u9488\uff09\u3002\u56e0\u6b64\u5728\u76f8\u540c\u6570\u636e\u91cf\u4e0b\uff0c\u94fe\u8868\u6bd4\u6570\u7ec4\u5360\u7528\u66f4\u591a\u7684\u5185\u5b58\u7a7a\u95f4\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class ListNode:\n\"\"\"\u94fe\u8868\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val               # \u8282\u70b9\u503c\nself.next: ListNode | None = None # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\nint val;         // \u8282\u70b9\u503c\nListNode *next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\nListNode(int x) : val(x), next(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\nListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  //\u6784\u9020\u51fd\u6570\nint val = x;         // \u8282\u70b9\u503c\nListNode? next;      // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype ListNode struct {\nVal  int       // \u8282\u70b9\u503c\nNext *ListNode // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n// NewListNode \u6784\u9020\u51fd\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\nfunc NewListNode(val int) *ListNode {\nreturn &ListNode{\nVal:  val,\nNext: nil,\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\ninit(x: Int) { // \u6784\u9020\u51fd\u6570\nval = x\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nconstructor(val, next) {\nthis.val = (val === undefined ? 0 : val);       // \u8282\u70b9\u503c\nthis.next = (next === undefined ? null : next); // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nval: number;\nnext: ListNode | null;\nconstructor(val?: number, next?: ListNode | null) {\nthis.val = val === undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next === undefined ? null : next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode? next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\nListNode(this.val, [this.next]); // \u6784\u9020\u51fd\u6570\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u94fe\u8868\u8282\u70b9\u7c7b */\n#[derive(Debug)]\nstruct ListNode {\nval: i32, // \u8282\u70b9\u503c\nnext: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\nint val;               // \u8282\u70b9\u503c\nstruct ListNode *next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\nListNode *node;\nnode = (ListNode *) malloc(sizeof(ListNode));\nnode->val = val;\nnode->next = NULL;\nreturn node;\n}\n
        // \u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = 0, // \u8282\u70b9\u503c\nnext: ?*Self = null, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\n}\n};\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#421","title":"4.2.1 \u00a0 \u94fe\u8868\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/linked_list/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u94fe\u8868","text":"

        \u5efa\u7acb\u94fe\u8868\u5206\u4e3a\u4e24\u6b65\uff0c\u7b2c\u4e00\u6b65\u662f\u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\u5bf9\u8c61\uff0c\u7b2c\u4e8c\u6b65\u662f\u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\u5173\u7cfb\u3002\u521d\u59cb\u5316\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u94fe\u8868\u7684\u5934\u8282\u70b9\u51fa\u53d1\uff0c\u901a\u8fc7\u5f15\u7528\u6307\u5411 next \u4f9d\u6b21\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        # \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4\n# \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nn0 = ListNode(1)\nn1 = ListNode(3)\nn2 = ListNode(2)\nn3 = ListNode(5)\nn4 = ListNode(4)\n# \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1\nn1.next = n2\nn2.next = n3\nn3.next = n4\n
        linked_list.cpp
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode* n0 = new ListNode(1);\nListNode* n1 = new ListNode(3);\nListNode* n2 = new ListNode(2);\nListNode* n3 = new ListNode(5);\nListNode* n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0->next = n1;\nn1->next = n2;\nn2->next = n3;\nn3->next = n4;\n
        linked_list.java
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = new ListNode(1);\nListNode n1 = new ListNode(3);\nListNode n2 = new ListNode(2);\nListNode n3 = new ListNode(5);\nListNode n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.cs
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = new(1);\nListNode n1 = new(3);\nListNode n2 = new(2);\nListNode n3 = new(5);\nListNode n4 = new(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.go
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nn0 := NewListNode(1)\nn1 := NewListNode(3)\nn2 := NewListNode(2)\nn3 := NewListNode(5)\nn4 := NewListNode(4)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.Next = n1\nn1.Next = n2\nn2.Next = n3\nn3.Next = n4\n
        linked_list.swift
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nlet n0 = ListNode(x: 1)\nlet n1 = ListNode(x: 3)\nlet n2 = ListNode(x: 2)\nlet n3 = ListNode(x: 5)\nlet n4 = ListNode(x: 4)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1\nn1.next = n2\nn2.next = n3\nn3.next = n4\n
        linked_list.js
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nconst n0 = new ListNode(1);\nconst n1 = new ListNode(3);\nconst n2 = new ListNode(2);\nconst n3 = new ListNode(5);\nconst n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.ts
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nconst n0 = new ListNode(1);\nconst n1 = new ListNode(3);\nconst n2 = new ListNode(2);\nconst n3 = new ListNode(5);\nconst n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.dart
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\\\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = ListNode(1);\nListNode n1 = ListNode(3);\nListNode n2 = ListNode(2);\nListNode n3 = ListNode(5);\nListNode n4 = ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.rs
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nlet n0 = Rc::new(RefCell::new(ListNode { val: 1, next: None }));\nlet n1 = Rc::new(RefCell::new(ListNode { val: 3, next: None }));\nlet n2 = Rc::new(RefCell::new(ListNode { val: 2, next: None }));\nlet n3 = Rc::new(RefCell::new(ListNode { val: 5, next: None }));\nlet n4 = Rc::new(RefCell::new(ListNode { val: 4, next: None }));\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.borrow_mut().next = Some(n1.clone());\nn1.borrow_mut().next = Some(n2.clone());\nn2.borrow_mut().next = Some(n3.clone());\nn3.borrow_mut().next = Some(n4.clone());\n
        linked_list.c
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode* n0 = newListNode(1);\nListNode* n1 = newListNode(3);\nListNode* n2 = newListNode(2);\nListNode* n3 = newListNode(5);\nListNode* n4 = newListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0->next = n1;\nn1->next = n2;\nn2->next = n3;\nn3->next = n4;\n
        linked_list.zig
        // \u521d\u59cb\u5316\u94fe\u8868\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nvar n0 = inc.ListNode(i32){.val = 1};\nvar n1 = inc.ListNode(i32){.val = 3};\nvar n2 = inc.ListNode(i32){.val = 2};\nvar n3 = inc.ListNode(i32){.val = 5};\nvar n4 = inc.ListNode(i32){.val = 4};\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = &n1;\nn1.next = &n2;\nn2.next = &n3;\nn3.next = &n4;\n

        \u6570\u7ec4\u6574\u4f53\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u6bd4\u5982\u6570\u7ec4 nums \u5305\u542b\u5143\u7d20 nums[0] \u548c nums[1] \u7b49\uff0c\u800c\u94fe\u8868\u662f\u7531\u591a\u4e2a\u72ec\u7acb\u7684\u8282\u70b9\u5bf9\u8c61\u7ec4\u6210\u7684\u3002\u6211\u4eec\u901a\u5e38\u5c06\u5934\u8282\u70b9\u5f53\u4f5c\u94fe\u8868\u7684\u4ee3\u79f0\uff0c\u6bd4\u5982\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u7684\u94fe\u8868\u53ef\u8bb0\u4f5c\u94fe\u8868 n0 \u3002

        "},{"location":"chapter_array_and_linkedlist/linked_list/#2","title":"2. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        \u5728\u94fe\u8868\u4e2d\u63d2\u5165\u8282\u70b9\u975e\u5e38\u5bb9\u6613\u3002\u5982\u56fe 4-6 \u6240\u793a\uff0c\u5047\u8bbe\u6211\u4eec\u60f3\u5728\u76f8\u90bb\u7684\u4e24\u4e2a\u8282\u70b9 n0 \u548c n1 \u4e4b\u95f4\u63d2\u5165\u4e00\u4e2a\u65b0\u8282\u70b9 P \uff0c\u5219\u53ea\u9700\u6539\u53d8\u4e24\u4e2a\u8282\u70b9\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        \u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5728\u6570\u7ec4\u4e2d\u63d2\u5165\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5728\u5927\u6570\u636e\u91cf\u4e0b\u7684\u6548\u7387\u8f83\u4f4e\u3002

        \u56fe 4-6 \u00a0 \u94fe\u8868\u63d2\u5165\u8282\u70b9\u793a\u4f8b

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def insert(n0: ListNode, P: ListNode):\n\"\"\"\u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P\"\"\"\nn1 = n0.next\nP.next = n1\nn0.next = P\n
        linked_list.cpp
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode *n0, ListNode *P) {\nListNode *n1 = n0->next;\nP->next = n1;\nn0->next = P;\n}\n
        linked_list.java
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode n0, ListNode P) {\nListNode n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.cs
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid Insert(ListNode n0, ListNode P) {\nListNode? n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.go
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunc insertNode(n0 *ListNode, P *ListNode) {\nn1 := n0.Next\nP.Next = n1\nn0.Next = P\n}\n
        linked_list.swift
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunc insert(n0: ListNode, P: ListNode) {\nlet n1 = n0.next\nP.next = n1\nn0.next = P\n}\n
        linked_list.js
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunction insert(n0, P) {\nconst n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.ts
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunction insert(n0: ListNode, P: ListNode): void {\nconst n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.dart
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode n0, ListNode P) {\nListNode? n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.rs
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\n#[allow(non_snake_case)]\npub fn insert<T>(n0: &Rc<RefCell<ListNode<T>>>, P: Rc<RefCell<ListNode<T>>>) {\nlet n1 =  n0.borrow_mut().next.take();\nP.borrow_mut().next = n1;\nn0.borrow_mut().next = Some(P);\n}\n
        linked_list.c
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode *n0, ListNode *P) {\nListNode *n1 = n0->next;\nP->next = n1;\nn0->next = P;\n}\n
        linked_list.zig
        // \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P\nfn insert(n0: ?*inc.ListNode(i32), P: ?*inc.ListNode(i32)) void {\nvar n1 = n0.?.next;\nP.?.next = n1;\nn0.?.next = P;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#3","title":"3. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u5982\u56fe 4-7 \u6240\u793a\uff0c\u5728\u94fe\u8868\u4e2d\u5220\u9664\u8282\u70b9\u4e5f\u975e\u5e38\u65b9\u4fbf\uff0c\u53ea\u9700\u6539\u53d8\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\u3002

        \u8bf7\u6ce8\u610f\uff0c\u5c3d\u7ba1\u5728\u5220\u9664\u64cd\u4f5c\u5b8c\u6210\u540e\u8282\u70b9 P \u4ecd\u7136\u6307\u5411 n1 \uff0c\u4f46\u5b9e\u9645\u4e0a\u904d\u5386\u6b64\u94fe\u8868\u5df2\u7ecf\u65e0\u6cd5\u8bbf\u95ee\u5230 P \uff0c\u8fd9\u610f\u5473\u7740 P \u5df2\u7ecf\u4e0d\u518d\u5c5e\u4e8e\u8be5\u94fe\u8868\u4e86\u3002

        \u56fe 4-7 \u00a0 \u94fe\u8868\u5220\u9664\u8282\u70b9

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def remove(n0: ListNode):\n\"\"\"\u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9\"\"\"\nif not n0.next:\nreturn\n# n0 -> P -> n1\nP = n0.next\nn1 = P.next\nn0.next = n1\n
        linked_list.cpp
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode *n0) {\nif (n0->next == nullptr)\nreturn;\n// n0 -> P -> n1\nListNode *P = n0->next;\nListNode *n1 = P->next;\nn0->next = n1;\n// \u91ca\u653e\u5185\u5b58\ndelete P;\n}\n
        linked_list.java
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode n0) {\nif (n0.next == null)\nreturn;\n// n0 -> P -> n1\nListNode P = n0.next;\nListNode n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.cs
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid Remove(ListNode n0) {\nif (n0.next == null)\nreturn;\n// n0 -> P -> n1\nListNode P = n0.next;\nListNode? n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.go
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunc removeItem(n0 *ListNode) {\nif n0.Next == nil {\nreturn\n}\n// n0 -> P -> n1\nP := n0.Next\nn1 := P.Next\nn0.Next = n1\n}\n
        linked_list.swift
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunc remove(n0: ListNode) {\nif n0.next == nil {\nreturn\n}\n// n0 -> P -> n1\nlet P = n0.next\nlet n1 = P?.next\nn0.next = n1\nP?.next = nil\n}\n
        linked_list.js
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunction remove(n0) {\nif (!n0.next) return;\n// n0 -> P -> n1\nconst P = n0.next;\nconst n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.ts
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunction remove(n0: ListNode): void {\nif (!n0.next) {\nreturn;\n}\n// n0 -> P -> n1\nconst P = n0.next;\nconst n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.dart
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode n0) {\nif (n0.next == null) return;\n// n0 -> P -> n1\nListNode P = n0.next!;\nListNode? n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.rs
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\n#[allow(non_snake_case)]\npub fn remove<T>(n0: &Rc<RefCell<ListNode<T>>>) {\nif n0.borrow().next.is_none() {return};\n// n0 -> P -> n1\nlet P = n0.borrow_mut().next.take();\nif let Some(node) = P {\nlet n1 = node.borrow_mut().next.take();\nn0.borrow_mut().next = n1;\n}\n}\n
        linked_list.c
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nvoid removeItem(ListNode *n0) {\nif (!n0->next)\nreturn;\n// n0 -> P -> n1\nListNode *P = n0->next;\nListNode *n1 = P->next;\nn0->next = n1;\n// \u91ca\u653e\u5185\u5b58\nfree(P);\n}\n
        linked_list.zig
        // \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9\nfn remove(n0: ?*inc.ListNode(i32)) void {\nif (n0.?.next == null) return;\n// n0 -> P -> n1\nvar P = n0.?.next;\nvar n1 = P.?.next;\nn0.?.next = n1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#4","title":"4. \u00a0 \u8bbf\u95ee\u8282\u70b9","text":"

        \u5728\u94fe\u8868\u4e2d\u8bbf\u95ee\u8282\u70b9\u7684\u6548\u7387\u8f83\u4f4e\u3002\u5982\u4e0a\u4e00\u8282\u6240\u8ff0\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u4e0b\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u5143\u7d20\u3002\u94fe\u8868\u5219\u4e0d\u7136\uff0c\u7a0b\u5e8f\u9700\u8981\u4ece\u5934\u8282\u70b9\u51fa\u53d1\uff0c\u9010\u4e2a\u5411\u540e\u904d\u5386\uff0c\u76f4\u81f3\u627e\u5230\u76ee\u6807\u8282\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8bbf\u95ee\u94fe\u8868\u7684\u7b2c \\(i\\) \u4e2a\u8282\u70b9\u9700\u8981\u5faa\u73af \\(i - 1\\) \u8f6e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def access(head: ListNode, index: int) -> ListNode | None:\n\"\"\"\u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9\"\"\"\nfor _ in range(index):\nif not head:\nreturn None\nhead = head.next\nreturn head\n
        linked_list.cpp
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == nullptr)\nreturn nullptr;\nhead = head->next;\n}\nreturn head;\n}\n
        linked_list.java
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode access(ListNode head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == null)\nreturn null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.cs
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? Access(ListNode? head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == null)\nreturn null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.go
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunc access(head *ListNode, index int) *ListNode {\nfor i := 0; i < index; i++ {\nif head == nil {\nreturn nil\n}\nhead = head.Next\n}\nreturn head\n}\n
        linked_list.swift
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunc access(head: ListNode, index: Int) -> ListNode? {\nvar head: ListNode? = head\nfor _ in 0 ..< index {\nif head == nil {\nreturn nil\n}\nhead = head?.next\n}\nreturn head\n}\n
        linked_list.js
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head, index) {\nfor (let i = 0; i < index; i++) {\nif (!head) {\nreturn null;\n}\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.ts
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head: ListNode | null, index: number): ListNode | null {\nfor (let i = 0; i < index; i++) {\nif (!head) {\nreturn null;\n}\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.dart
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? access(ListNode? head, int index) {\nfor (var i = 0; i < index; i++) {\nif (head == null) return null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.rs
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\npub fn access<T>(head: Rc<RefCell<ListNode<T>>>, index: i32) -> Rc<RefCell<ListNode<T>>> {\nif index <= 0 {return head};\nif let Some(node) = &head.borrow_mut().next {\nreturn access(node.clone(), index - 1);\n}\nreturn head;\n}\n
        linked_list.c
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\nwhile (head && head->next && index) {\nhead = head->next;\nindex--;\n}\nreturn head;\n}\n
        linked_list.zig
        // \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9\nfn access(node: ?*inc.ListNode(i32), index: i32) ?*inc.ListNode(i32) {\nvar head = node;\nvar i: i32 = 0;\nwhile (i < index) : (i += 1) {\nhead = head.?.next;\nif (head == null) return null;\n}\nreturn head;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#5","title":"5. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        \u904d\u5386\u94fe\u8868\uff0c\u67e5\u627e\u5176\u4e2d\u503c\u4e3a target \u7684\u8282\u70b9\uff0c\u8f93\u51fa\u8be5\u8282\u70b9\u5728\u94fe\u8868\u4e2d\u7684\u7d22\u5f15\u3002\u6b64\u8fc7\u7a0b\u4e5f\u5c5e\u4e8e\u7ebf\u6027\u67e5\u627e\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def find(head: ListNode, target: int) -> int:\n\"\"\"\u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9\"\"\"\nindex = 0\nwhile head:\nif head.val == target:\nreturn index\nhead = head.next\nindex += 1\nreturn -1\n
        linked_list.cpp
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode *head, int target) {\nint index = 0;\nwhile (head != nullptr) {\nif (head->val == target)\nreturn index;\nhead = head->next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.java
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target)\nreturn index;\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.cs
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint Find(ListNode? head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target)\nreturn index;\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.go
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunc findNode(head *ListNode, target int) int {\nindex := 0\nfor head != nil {\nif head.Val == target {\nreturn index\n}\nhead = head.Next\nindex++\n}\nreturn -1\n}\n
        linked_list.swift
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunc find(head: ListNode, target: Int) -> Int {\nvar head: ListNode? = head\nvar index = 0\nwhile head != nil {\nif head?.val == target {\nreturn index\n}\nhead = head?.next\nindex += 1\n}\nreturn -1\n}\n
        linked_list.js
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head, target) {\nlet index = 0;\nwhile (head !== null) {\nif (head.val === target) {\nreturn index;\n}\nhead = head.next;\nindex += 1;\n}\nreturn -1;\n}\n
        linked_list.ts
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head: ListNode | null, target: number): number {\nlet index = 0;\nwhile (head !== null) {\nif (head.val === target) {\nreturn index;\n}\nhead = head.next;\nindex += 1;\n}\nreturn -1;\n}\n
        linked_list.dart
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode? head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target) {\nreturn index;\n}\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.rs
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\npub fn find<T: PartialEq>(head: Rc<RefCell<ListNode<T>>>, target: T, index: i32) -> i32 {\nif head.borrow().val == target {return index};\nif let Some(node) = &head.borrow_mut().next {\nreturn find(node.clone(), target, index + 1);\n}\nreturn -1;\n}\n
        linked_list.c
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode *head, int target) {\nint index = 0;\nwhile (head) {\nif (head->val == target)\nreturn index;\nhead = head->next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.zig
        // \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9\nfn find(node: ?*inc.ListNode(i32), target: i32) i32 {\nvar head = node;\nvar index: i32 = 0;\nwhile (head != null) {\nif (head.?.val == target) return index;\nhead = head.?.next;\nindex += 1;\n}\nreturn -1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#422-vs","title":"4.2.2 \u00a0 \u6570\u7ec4 vs. \u94fe\u8868","text":"

        \u8868 4-1 \u603b\u7ed3\u4e86\u6570\u7ec4\u548c\u94fe\u8868\u7684\u5404\u9879\u7279\u70b9\u5e76\u5bf9\u6bd4\u4e86\u64cd\u4f5c\u6548\u7387\u3002\u7531\u4e8e\u5b83\u4eec\u91c7\u7528\u4e24\u79cd\u76f8\u53cd\u7684\u5b58\u50a8\u7b56\u7565\uff0c\u56e0\u6b64\u5404\u79cd\u6027\u8d28\u548c\u64cd\u4f5c\u6548\u7387\u4e5f\u5448\u73b0\u5bf9\u7acb\u7684\u7279\u70b9\u3002

        \u8868 4-1 \u00a0 \u6570\u7ec4\u4e0e\u94fe\u8868\u7684\u6548\u7387\u5bf9\u6bd4

        \u6570\u7ec4 \u94fe\u8868 \u5b58\u50a8\u65b9\u5f0f \u8fde\u7eed\u5185\u5b58\u7a7a\u95f4 \u5206\u6563\u5185\u5b58\u7a7a\u95f4 \u5bb9\u91cf\u6269\u5c55 \u957f\u5ea6\u4e0d\u53ef\u53d8 \u53ef\u7075\u6d3b\u6269\u5c55 \u5185\u5b58\u6548\u7387 \u5143\u7d20\u5360\u7528\u5185\u5b58\u5c11\u3001\u4f46\u53ef\u80fd\u6d6a\u8d39\u7a7a\u95f4 \u5143\u7d20\u5360\u7528\u5185\u5b58\u591a \u8bbf\u95ee\u5143\u7d20 \\(O(1)\\) \\(O(n)\\) \u6dfb\u52a0\u5143\u7d20 \\(O(n)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(1)\\)"},{"location":"chapter_array_and_linkedlist/linked_list/#423","title":"4.2.3 \u00a0 \u5e38\u89c1\u94fe\u8868\u7c7b\u578b","text":"

        \u5982\u56fe 4-8 \u6240\u793a\uff0c\u5e38\u89c1\u7684\u94fe\u8868\u7c7b\u578b\u5305\u62ec\u4e09\u79cd\u3002

        • \u5355\u5411\u94fe\u8868\uff1a\u5373\u524d\u9762\u4ecb\u7ecd\u7684\u666e\u901a\u94fe\u8868\u3002\u5355\u5411\u94fe\u8868\u7684\u8282\u70b9\u5305\u542b\u503c\u548c\u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\u4e24\u9879\u6570\u636e\u3002\u6211\u4eec\u5c06\u9996\u4e2a\u8282\u70b9\u79f0\u4e3a\u5934\u8282\u70b9\uff0c\u5c06\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u79f0\u4e3a\u5c3e\u8282\u70b9\uff0c\u5c3e\u8282\u70b9\u6307\u5411\u7a7a \\(\\text{None}\\) \u3002
        • \u73af\u5f62\u94fe\u8868\uff1a\u5982\u679c\u6211\u4eec\u4ee4\u5355\u5411\u94fe\u8868\u7684\u5c3e\u8282\u70b9\u6307\u5411\u5934\u8282\u70b9\uff08\u9996\u5c3e\u76f8\u63a5\uff09\uff0c\u5219\u5f97\u5230\u4e00\u4e2a\u73af\u5f62\u94fe\u8868\u3002\u5728\u73af\u5f62\u94fe\u8868\u4e2d\uff0c\u4efb\u610f\u8282\u70b9\u90fd\u53ef\u4ee5\u89c6\u4f5c\u5934\u8282\u70b9\u3002
        • \u53cc\u5411\u94fe\u8868\uff1a\u4e0e\u5355\u5411\u94fe\u8868\u76f8\u6bd4\uff0c\u53cc\u5411\u94fe\u8868\u8bb0\u5f55\u4e86\u4e24\u4e2a\u65b9\u5411\u7684\u5f15\u7528\u3002\u53cc\u5411\u94fe\u8868\u7684\u8282\u70b9\u5b9a\u4e49\u540c\u65f6\u5305\u542b\u6307\u5411\u540e\u7ee7\u8282\u70b9\uff08\u4e0b\u4e00\u4e2a\u8282\u70b9\uff09\u548c\u524d\u9a71\u8282\u70b9\uff08\u4e0a\u4e00\u4e2a\u8282\u70b9\uff09\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u3002\u76f8\u8f83\u4e8e\u5355\u5411\u94fe\u8868\uff0c\u53cc\u5411\u94fe\u8868\u66f4\u5177\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u671d\u4e24\u4e2a\u65b9\u5411\u904d\u5386\u94fe\u8868\uff0c\u4f46\u76f8\u5e94\u5730\u4e5f\u9700\u8981\u5360\u7528\u66f4\u591a\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class ListNode:\n\"\"\"\u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                # \u8282\u70b9\u503c\nself.next: ListNode | None = None  # \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nself.prev: ListNode | None = None  # \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\nint val;         // \u8282\u70b9\u503c\nListNode *next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nListNode *prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\nListNode(int x) : val(x), next(nullptr), prev(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\nListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  // \u6784\u9020\u51fd\u6570\nint val = x;    // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype DoublyListNode struct {\nVal  int             // \u8282\u70b9\u503c\nNext *DoublyListNode // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nPrev *DoublyListNode // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n// NewDoublyListNode \u521d\u59cb\u5316\nfunc NewDoublyListNode(val int) *DoublyListNode {\nreturn &DoublyListNode{\nVal:  val,\nNext: nil,\nPrev: nil,\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nvar prev: ListNode? // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\ninit(x: Int) { // \u6784\u9020\u51fd\u6570\nval = x\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nconstructor(val, next, prev) {\nthis.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nthis.prev = prev  ===  undefined ? null : prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nval: number;\nnext: ListNode | null;\nprev: ListNode | null;\nconstructor(val?: number, next?: ListNode | null, prev?: ListNode | null) {\nthis.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nthis.prev = prev  ===  undefined ? null : prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\nListNode(this.val, [this.next, this.prev]);  // \u6784\u9020\u51fd\u6570\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\u578b */\n#[derive(Debug)]\nstruct ListNode {\nval: i32, // \u8282\u70b9\u503c\nnext: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nprev: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n/* \u6784\u9020\u51fd\u6570 */\nimpl ListNode {\nfn new(val: i32) -> Self {\nListNode {\nval,\nnext: None,\nprev: None,\n}\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\nint val;               // \u8282\u70b9\u503c\nstruct ListNode *next; // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nstruct ListNode *prev; // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\nListNode *node;\nnode = (ListNode *) malloc(sizeof(ListNode));\nnode->val = val;\nnode->next = NULL;\nnode->prev = NULL;\nreturn node;\n}\n
        // \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = 0, // \u8282\u70b9\u503c\nnext: ?*Self = null, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nprev: ?*Self = null, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\nself.prev = null;\n}\n};\n}\n

        \u56fe 4-8 \u00a0 \u5e38\u89c1\u94fe\u8868\u79cd\u7c7b

        "},{"location":"chapter_array_and_linkedlist/linked_list/#424","title":"4.2.4 \u00a0 \u94fe\u8868\u5178\u578b\u5e94\u7528","text":"

        \u5355\u5411\u94fe\u8868\u901a\u5e38\u7528\u4e8e\u5b9e\u73b0\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u548c\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u3002

        • \u6808\u4e0e\u961f\u5217\uff1a\u5f53\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u90fd\u5728\u94fe\u8868\u7684\u4e00\u7aef\u8fdb\u884c\u65f6\uff0c\u5b83\u8868\u73b0\u51fa\u5148\u8fdb\u540e\u51fa\u7684\u7279\u6027\uff0c\u5bf9\u5e94\u6808\uff1b\u5f53\u63d2\u5165\u64cd\u4f5c\u5728\u94fe\u8868\u7684\u4e00\u7aef\u8fdb\u884c\uff0c\u5220\u9664\u64cd\u4f5c\u5728\u94fe\u8868\u7684\u53e6\u4e00\u7aef\u8fdb\u884c\uff0c\u5b83\u8868\u73b0\u51fa\u5148\u8fdb\u5148\u51fa\u7684\u7279\u6027\uff0c\u5bf9\u5e94\u961f\u5217\u3002
        • \u54c8\u5e0c\u8868\uff1a\u94fe\u5f0f\u5730\u5740\u662f\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81\u7684\u4e3b\u6d41\u65b9\u6848\u4e4b\u4e00\uff0c\u5728\u8be5\u65b9\u6848\u4e2d\uff0c\u6240\u6709\u51b2\u7a81\u7684\u5143\u7d20\u90fd\u4f1a\u88ab\u653e\u5230\u4e00\u4e2a\u94fe\u8868\u4e2d\u3002
        • \u56fe\uff1a\u90bb\u63a5\u8868\u662f\u8868\u793a\u56fe\u7684\u4e00\u79cd\u5e38\u7528\u65b9\u5f0f\uff0c\u5176\u4e2d\u56fe\u7684\u6bcf\u4e2a\u9876\u70b9\u90fd\u4e0e\u4e00\u4e2a\u94fe\u8868\u76f8\u5173\u8054\uff0c\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u4ee3\u8868\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u5176\u4ed6\u9876\u70b9\u3002

        \u53cc\u5411\u94fe\u8868\u5e38\u7528\u4e8e\u9700\u8981\u5feb\u901f\u67e5\u627e\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u573a\u666f\u3002

        • \u9ad8\u7ea7\u6570\u636e\u7ed3\u6784\uff1a\u6bd4\u5982\u5728\u7ea2\u9ed1\u6811\u3001B \u6811\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u8bbf\u95ee\u8282\u70b9\u7684\u7236\u8282\u70b9\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728\u8282\u70b9\u4e2d\u4fdd\u5b58\u4e00\u4e2a\u6307\u5411\u7236\u8282\u70b9\u7684\u5f15\u7528\u6765\u5b9e\u73b0\uff0c\u7c7b\u4f3c\u4e8e\u53cc\u5411\u94fe\u8868\u3002
        • \u6d4f\u89c8\u5668\u5386\u53f2\uff1a\u5728\u7f51\u9875\u6d4f\u89c8\u5668\u4e2d\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u524d\u8fdb\u6216\u540e\u9000\u6309\u94ae\u65f6\uff0c\u6d4f\u89c8\u5668\u9700\u8981\u77e5\u9053\u7528\u6237\u8bbf\u95ee\u8fc7\u7684\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u7f51\u9875\u3002\u53cc\u5411\u94fe\u8868\u7684\u7279\u6027\u4f7f\u5f97\u8fd9\u79cd\u64cd\u4f5c\u53d8\u5f97\u7b80\u5355\u3002
        • LRU \u7b97\u6cd5\uff1a\u5728\u7f13\u5b58\u6dd8\u6c70\uff08LRU\uff09\u7b97\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5feb\u901f\u627e\u5230\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684\u6570\u636e\uff0c\u4ee5\u53ca\u652f\u6301\u5feb\u901f\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u3002\u8fd9\u65f6\u5019\u4f7f\u7528\u53cc\u5411\u94fe\u8868\u5c31\u975e\u5e38\u5408\u9002\u3002

        \u73af\u5f62\u94fe\u8868\u5e38\u7528\u4e8e\u9700\u8981\u5468\u671f\u6027\u64cd\u4f5c\u7684\u573a\u666f\uff0c\u6bd4\u5982\u64cd\u4f5c\u7cfb\u7edf\u7684\u8d44\u6e90\u8c03\u5ea6\u3002

        • \u65f6\u95f4\u7247\u8f6e\u8f6c\u8c03\u5ea6\u7b97\u6cd5\uff1a\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u65f6\u95f4\u7247\u8f6e\u8f6c\u8c03\u5ea6\u7b97\u6cd5\u662f\u4e00\u79cd\u5e38\u89c1\u7684 CPU \u8c03\u5ea6\u7b97\u6cd5\uff0c\u5b83\u9700\u8981\u5bf9\u4e00\u7ec4\u8fdb\u7a0b\u8fdb\u884c\u5faa\u73af\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u88ab\u8d4b\u4e88\u4e00\u4e2a\u65f6\u95f4\u7247\uff0c\u5f53\u65f6\u95f4\u7247\u7528\u5b8c\u65f6\uff0cCPU \u5c06\u5207\u6362\u5230\u4e0b\u4e00\u4e2a\u8fdb\u7a0b\u3002\u8fd9\u79cd\u5faa\u73af\u64cd\u4f5c\u53ef\u4ee5\u901a\u8fc7\u73af\u5f62\u94fe\u8868\u6765\u5b9e\u73b0\u3002
        • \u6570\u636e\u7f13\u51b2\u533a\uff1a\u5728\u67d0\u4e9b\u6570\u636e\u7f13\u51b2\u533a\u7684\u5b9e\u73b0\u4e2d\uff0c\u4e5f\u53ef\u80fd\u4f1a\u4f7f\u7528\u73af\u5f62\u94fe\u8868\u3002\u6bd4\u5982\u5728\u97f3\u9891\u3001\u89c6\u9891\u64ad\u653e\u5668\u4e2d\uff0c\u6570\u636e\u6d41\u53ef\u80fd\u4f1a\u88ab\u5206\u6210\u591a\u4e2a\u7f13\u51b2\u5757\u5e76\u653e\u5165\u4e00\u4e2a\u73af\u5f62\u94fe\u8868\uff0c\u4ee5\u4fbf\u5b9e\u73b0\u65e0\u7f1d\u64ad\u653e\u3002
        "},{"location":"chapter_array_and_linkedlist/list/","title":"4.3 \u00a0 \u5217\u8868","text":"

        \u300c\u5217\u8868 list\u300d\u662f\u4e00\u4e2a\u62bd\u8c61\u7684\u6570\u636e\u7ed3\u6784\u6982\u5ff5\uff0c\u5b83\u8868\u793a\u5143\u7d20\u7684\u6709\u5e8f\u96c6\u5408\uff0c\u652f\u6301\u5143\u7d20\u8bbf\u95ee\u3001\u4fee\u6539\u3001\u6dfb\u52a0\u3001\u5220\u9664\u548c\u904d\u5386\u7b49\u64cd\u4f5c\uff0c\u65e0\u987b\u4f7f\u7528\u8005\u8003\u8651\u5bb9\u91cf\u9650\u5236\u7684\u95ee\u9898\u3002\u5217\u8868\u53ef\u4ee5\u57fa\u4e8e\u94fe\u8868\u6216\u6570\u7ec4\u5b9e\u73b0\u3002

        • \u94fe\u8868\u5929\u7136\u53ef\u4ee5\u88ab\u770b\u4f5c\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u652f\u6301\u5143\u7d20\u589e\u5220\u67e5\u6539\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ef\u4ee5\u7075\u6d3b\u52a8\u6001\u6269\u5bb9\u3002
        • \u6570\u7ec4\u4e5f\u652f\u6301\u5143\u7d20\u589e\u5220\u67e5\u6539\uff0c\u4f46\u7531\u4e8e\u5176\u957f\u5ea6\u4e0d\u53ef\u53d8\uff0c\u56e0\u6b64\u53ea\u80fd\u88ab\u770b\u4f5c\u4e00\u4e2a\u5177\u6709\u957f\u5ea6\u9650\u5236\u7684\u5217\u8868\u3002

        \u5f53\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u5217\u8868\u65f6\uff0c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6027\u8d28\u4f1a\u5bfc\u81f4\u5217\u8868\u7684\u5b9e\u7528\u6027\u964d\u4f4e\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u901a\u5e38\u65e0\u6cd5\u4e8b\u5148\u786e\u5b9a\u9700\u8981\u5b58\u50a8\u591a\u5c11\u6570\u636e\uff0c\u4ece\u800c\u96be\u4ee5\u9009\u62e9\u5408\u9002\u7684\u5217\u8868\u957f\u5ea6\u3002\u82e5\u957f\u5ea6\u8fc7\u5c0f\uff0c\u5219\u5f88\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u4f7f\u7528\u9700\u6c42\uff1b\u82e5\u957f\u5ea6\u8fc7\u5927\uff0c\u5219\u4f1a\u9020\u6210\u5185\u5b58\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002

        \u4e3a\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u300c\u52a8\u6001\u6570\u7ec4 dynamic array\u300d\u6765\u5b9e\u73b0\u5217\u8868\u3002\u5b83\u7ee7\u627f\u4e86\u6570\u7ec4\u7684\u5404\u9879\u4f18\u70b9\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u52a8\u6001\u6269\u5bb9\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u6807\u51c6\u5e93\u63d0\u4f9b\u7684\u5217\u8868\u90fd\u662f\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\u5b9e\u73b0\u7684\uff0c\u4f8b\u5982 Python \u4e2d\u7684 list \u3001Java \u4e2d\u7684 ArrayList \u3001C++ \u4e2d\u7684 vector \u548c C# \u4e2d\u7684 List \u7b49\u3002\u5728\u63a5\u4e0b\u6765\u7684\u8ba8\u8bba\u4e2d\uff0c\u6211\u4eec\u5c06\u628a\u201c\u5217\u8868\u201d\u548c\u201c\u52a8\u6001\u6570\u7ec4\u201d\u89c6\u4e3a\u7b49\u540c\u7684\u6982\u5ff5\u3002

        "},{"location":"chapter_array_and_linkedlist/list/#431","title":"4.3.1 \u00a0 \u5217\u8868\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/list/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u5217\u8868","text":"

        \u6211\u4eec\u901a\u5e38\u4f7f\u7528\u201c\u65e0\u521d\u59cb\u503c\u201d\u548c\u201c\u6709\u521d\u59cb\u503c\u201d\u8fd9\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u521d\u59cb\u5316\u5217\u8868\n# \u65e0\u521d\u59cb\u503c\nnums1: list[int] = []\n# \u6709\u521d\u59cb\u503c\nnums: list[int] = [1, 3, 2, 5, 4]\n
        list.cpp
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u9700\u6ce8\u610f\uff0cC++ \u4e2d vector \u5373\u662f\u672c\u6587\u63cf\u8ff0\u7684 nums\n// \u65e0\u521d\u59cb\u503c\nvector<int> nums1;\n// \u6709\u521d\u59cb\u503c\nvector<int> nums = { 1, 3, 2, 5, 4 };\n
        list.java
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<Integer> nums1 = new ArrayList<>();\n// \u6709\u521d\u59cb\u503c\uff08\u6ce8\u610f\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u9700\u4e3a int[] \u7684\u5305\u88c5\u7c7b Integer[]\uff09\nInteger[] numbers = new Integer[] { 1, 3, 2, 5, 4 };\nList<Integer> nums = new ArrayList<>(Arrays.asList(numbers));\n
        list.cs
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<int> nums1 = [];\n// \u6709\u521d\u59cb\u503c\nint[] numbers = [1, 3, 2, 5, 4];\nList<int> nums = [.. numbers];\n
        list_test.go
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nnums1 := []int{}\n// \u6709\u521d\u59cb\u503c\nnums := []int{1, 3, 2, 5, 4}\n
        list.swift
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nlet nums1: [Int] = []\n// \u6709\u521d\u59cb\u503c\nvar nums = [1, 3, 2, 5, 4]\n
        list.js
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nconst nums1 = [];\n// \u6709\u521d\u59cb\u503c\nconst nums = [1, 3, 2, 5, 4];\n
        list.ts
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nconst nums1: number[] = [];\n// \u6709\u521d\u59cb\u503c\nconst nums: number[] = [1, 3, 2, 5, 4];\n
        list.dart
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<int> nums1 = [];\n// \u6709\u521d\u59cb\u503c\nList<int> nums = [1, 3, 2, 5, 4];\n
        list.rs
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nlet nums1: Vec<i32> = Vec::new();\n// \u6709\u521d\u59cb\u503c\nlet nums: Vec<i32> = vec![1, 3, 2, 5, 4];\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u521d\u59cb\u5316\u5217\u8868\nvar nums = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nums.deinit();\ntry nums.appendSlice(&[_]i32{ 1, 3, 2, 5, 4 });\n
        "},{"location":"chapter_array_and_linkedlist/list/#2","title":"2. \u00a0 \u8bbf\u95ee\u5143\u7d20","text":"

        \u5217\u8868\u672c\u8d28\u4e0a\u662f\u6570\u7ec4\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u8bbf\u95ee\u548c\u66f4\u65b0\u5143\u7d20\uff0c\u6548\u7387\u5f88\u9ad8\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u8bbf\u95ee\u5143\u7d20\nnum: int = nums[1]  # \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n# \u66f4\u65b0\u5143\u7d20\nnums[1] = 0    # \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.cpp
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.java
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums.get(1);  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums.set(1, 0);  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.cs
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list_test.go
        /* \u8bbf\u95ee\u5143\u7d20 */\nnum := nums[1]  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0     // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.swift
        /* \u8bbf\u95ee\u5143\u7d20 */\nlet num = nums[1] // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0 // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.js
        /* \u8bbf\u95ee\u5143\u7d20 */\nconst num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.ts
        /* \u8bbf\u95ee\u5143\u7d20 */\nconst num: number = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.dart
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.rs
        /* \u8bbf\u95ee\u5143\u7d20 */\nlet num: i32 = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;             // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u8bbf\u95ee\u5143\u7d20\nvar num = nums.items[1]; // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n// \u66f4\u65b0\u5143\u7d20\nnums.items[1] = 0; // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0  \n
        "},{"location":"chapter_array_and_linkedlist/list/#3","title":"3. \u00a0 \u63d2\u5165\u4e0e\u5220\u9664\u5143\u7d20","text":"

        \u76f8\u8f83\u4e8e\u6570\u7ec4\uff0c\u5217\u8868\u53ef\u4ee5\u81ea\u7531\u5730\u6dfb\u52a0\u4e0e\u5220\u9664\u5143\u7d20\u3002\u5728\u5217\u8868\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff0c\u4f46\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u7684\u6548\u7387\u4ecd\u4e0e\u6570\u7ec4\u76f8\u540c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u6e05\u7a7a\u5217\u8868\nnums.clear()\n# \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n# \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\nnums.insert(3, 6)  # \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n# \u5220\u9664\u5143\u7d20\nnums.pop(3)        # \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.cpp
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push_back(1);\nnums.push_back(3);\nnums.push_back(2);\nnums.push_back(5);\nnums.push_back(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(nums.begin() + 3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.erase(nums.begin() + 3);      // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.java
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.add(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(3);  // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.cs
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.Clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.Add(1);\nnums.Add(3);\nnums.Add(2);\nnums.Add(5);\nnums.Add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.Insert(3, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.RemoveAt(3);\n
        list_test.go
        /* \u6e05\u7a7a\u5217\u8868 */\nnums = nil\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums = append(nums, 1)\nnums = append(nums, 3)\nnums = append(nums, 2)\nnums = append(nums, 5)\nnums = append(nums, 4)\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums = append(nums[:3], append([]int{6}, nums[3:]...)...) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums = append(nums[:3], nums[4:]...) // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.swift
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.removeAll()\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(6, at: 3) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(at: 3) // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.js
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
        list.ts
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
        list.dart
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.removeAt(3); // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.rs
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(3);    // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u6e05\u7a7a\u5217\u8868\nnums.clearRetainingCapacity();\n// \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\ntry nums.append(1);\ntry nums.append(3);\ntry nums.append(2);\ntry nums.append(5);\ntry nums.append(4);\n// \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\ntry nums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n// \u5220\u9664\u5143\u7d20\n_ = nums.orderedRemove(3); // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        "},{"location":"chapter_array_and_linkedlist/list/#4","title":"4. \u00a0 \u904d\u5386\u5217\u8868","text":"

        \u4e0e\u6570\u7ec4\u4e00\u6837\uff0c\u5217\u8868\u53ef\u4ee5\u6839\u636e\u7d22\u5f15\u904d\u5386\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u904d\u5386\u5404\u5143\u7d20\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\ncount = 0\nfor i in range(len(nums)):\ncount += nums[i]\n# \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\nfor num in nums:\ncount += num\n
        list.cpp
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (int num : nums) {\ncount += num;\n}\n
        list.java
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\ncount += nums.get(i);\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\nfor (int num : nums) {\ncount += num;\n}\n
        list.cs
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.Count; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nforeach (int num in nums) {\ncount += num;\n}\n
        list_test.go
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\ncount := 0\nfor i := 0; i < len(nums); i++ {\ncount += nums[i]\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor _, num := range nums {\ncount += num\n}\n
        list.swift
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nvar count = 0\nfor i in nums.indices {\ncount += nums[i]\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor num in nums {\ncount += num\n}\n
        list.js
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\ncount += num;\n}\n
        list.ts
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\ncount += num;\n}\n
        list.dart
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (var i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (var num in nums) {\ncount += num;\n}\n
        list.rs
        // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\nlet mut _count = 0;\nfor i in 0..nums.len() {\n_count += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\n_count = 0;\nfor num in &nums {\n_count += num;\n}\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\nvar count: i32 = 0;\nvar i: i32 = 0;\nwhile (i < nums.items.len) : (i += 1) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\ncount = 0;\nfor (nums.items) |num| {\ncount += num;\n}\n
        "},{"location":"chapter_array_and_linkedlist/list/#5","title":"5. \u00a0 \u62fc\u63a5\u5217\u8868","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u65b0\u5217\u8868 nums1 \uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u62fc\u63a5\u5230\u539f\u5217\u8868\u7684\u5c3e\u90e8\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u62fc\u63a5\u4e24\u4e2a\u5217\u8868\nnums1: list[int] = [6, 8, 7, 10, 9]\nnums += nums1  # \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.cpp
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nvector<int> nums1 = { 6, 8, 7, 10, 9 };\n// \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\nnums.insert(nums.end(), nums1.begin(), nums1.end());\n
        list.java
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<Integer> nums1 = new ArrayList<>(Arrays.asList(new Integer[] { 6, 8, 7, 10, 9 }));\nnums.addAll(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.cs
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<int> nums1 = [6, 8, 7, 10, 9];\nnums.AddRange(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list_test.go
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nnums1 := []int{6, 8, 7, 10, 9}\nnums = append(nums, nums1...)  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.swift
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nlet nums1 = [6, 8, 7, 10, 9]\nnums.append(contentsOf: nums1) // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.js
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nconst nums1 = [6, 8, 7, 10, 9];\nnums.push(...nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.ts
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nconst nums1: number[] = [6, 8, 7, 10, 9];\nnums.push(...nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.dart
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<int> nums1 = [6, 8, 7, 10, 9];\nnums.addAll(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.rs
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nlet nums1: Vec<i32> = vec![6, 8, 7, 10, 9];\nnums.extend(nums1);\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u62fc\u63a5\u4e24\u4e2a\u5217\u8868\nvar nums1 = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nums1.deinit();\ntry nums1.appendSlice(&[_]i32{ 6, 8, 7, 10, 9 });\ntry nums.insertSlice(nums.items.len, nums1.items); // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        "},{"location":"chapter_array_and_linkedlist/list/#6","title":"6. \u00a0 \u6392\u5e8f\u5217\u8868","text":"

        \u5b8c\u6210\u5217\u8868\u6392\u5e8f\u540e\uff0c\u6211\u4eec\u4fbf\u53ef\u4ee5\u4f7f\u7528\u5728\u6570\u7ec4\u7c7b\u7b97\u6cd5\u9898\u4e2d\u7ecf\u5e38\u8003\u67e5\u7684\u201c\u4e8c\u5206\u67e5\u627e\u201d\u548c\u201c\u53cc\u6307\u9488\u201d\u7b97\u6cd5\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u6392\u5e8f\u5217\u8868\nnums.sort()  # \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.cpp
        /* \u6392\u5e8f\u5217\u8868 */\nsort(nums.begin(), nums.end());  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.java
        /* \u6392\u5e8f\u5217\u8868 */\nCollections.sort(nums);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.cs
        /* \u6392\u5e8f\u5217\u8868 */\nnums.Sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list_test.go
        /* \u6392\u5e8f\u5217\u8868 */\nsort.Ints(nums)  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.swift
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort() // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.js
        /* \u6392\u5e8f\u5217\u8868 */  nums.sort((a, b) => a - b);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.ts
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort((a, b) => a - b);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.dart
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.rs
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u6392\u5e8f\u5217\u8868\nstd.sort.sort(i32, nums.items, {}, comptime std.sort.asc(i32));\n
        "},{"location":"chapter_array_and_linkedlist/list/#432","title":"4.3.2 \u00a0 \u5217\u8868\u5b9e\u73b0","text":"

        \u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u4e86\u5217\u8868\uff0c\u4f8b\u5982 Java\u3001C++\u3001Python \u7b49\u3002\u5b83\u4eec\u7684\u5b9e\u73b0\u6bd4\u8f83\u590d\u6742\uff0c\u5404\u4e2a\u53c2\u6570\u7684\u8bbe\u5b9a\u4e5f\u975e\u5e38\u8003\u7a76\uff0c\u4f8b\u5982\u521d\u59cb\u5bb9\u91cf\u3001\u6269\u5bb9\u500d\u6570\u7b49\u3002\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u67e5\u9605\u6e90\u7801\u8fdb\u884c\u5b66\u4e60\u3002

        \u4e3a\u4e86\u52a0\u6df1\u5bf9\u5217\u8868\u5de5\u4f5c\u539f\u7406\u7684\u7406\u89e3\uff0c\u6211\u4eec\u5c1d\u8bd5\u5b9e\u73b0\u4e00\u4e2a\u7b80\u6613\u7248\u5217\u8868\uff0c\u5305\u62ec\u4ee5\u4e0b\u4e09\u4e2a\u91cd\u70b9\u8bbe\u8ba1\u3002

        • \u521d\u59cb\u5bb9\u91cf\uff1a\u9009\u53d6\u4e00\u4e2a\u5408\u7406\u7684\u6570\u7ec4\u521d\u59cb\u5bb9\u91cf\u3002\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9 10 \u4f5c\u4e3a\u521d\u59cb\u5bb9\u91cf\u3002
        • \u6570\u91cf\u8bb0\u5f55\uff1a\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf size \uff0c\u7528\u4e8e\u8bb0\u5f55\u5217\u8868\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff0c\u5e76\u968f\u7740\u5143\u7d20\u63d2\u5165\u548c\u5220\u9664\u5b9e\u65f6\u66f4\u65b0\u3002\u6839\u636e\u6b64\u53d8\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4f4d\u5217\u8868\u5c3e\u90e8\uff0c\u4ee5\u53ca\u5224\u65ad\u662f\u5426\u9700\u8981\u6269\u5bb9\u3002
        • \u6269\u5bb9\u673a\u5236\uff1a\u82e5\u63d2\u5165\u5143\u7d20\u65f6\u5217\u8868\u5bb9\u91cf\u5df2\u6ee1\uff0c\u5219\u9700\u8981\u8fdb\u884c\u6269\u5bb9\u3002\u5148\u6839\u636e\u6269\u5bb9\u500d\u6570\u521b\u5efa\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u518d\u5c06\u5f53\u524d\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u4f9d\u6b21\u79fb\u52a8\u81f3\u65b0\u6570\u7ec4\u3002\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u89c4\u5b9a\u6bcf\u6b21\u5c06\u6570\u7ec4\u6269\u5bb9\u81f3\u4e4b\u524d\u7684 2 \u500d\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_list.py
        class MyList:\n\"\"\"\u5217\u8868\u7c7b\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._capacity: int = 10  # \u5217\u8868\u5bb9\u91cf\nself._arr: list[int] = [0] * self._capacity  # \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nself._size: int = 0  # \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nself._extend_ratio: int = 2  # \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\"\"\"\nreturn self._size\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u5217\u8868\u5bb9\u91cf\"\"\"\nreturn self._capacity\ndef get(self, index: int) -> int:\n\"\"\"\u8bbf\u95ee\u5143\u7d20\"\"\"\n# \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nreturn self._arr[index]\ndef set(self, num: int, index: int):\n\"\"\"\u66f4\u65b0\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nself._arr[index] = num\ndef add(self, num: int):\n\"\"\"\u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\"\"\"\n# \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size() == self.capacity():\nself.extend_capacity()\nself._arr[self._size] = num\nself._size += 1\ndef insert(self, num: int, index: int):\n\"\"\"\u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n# \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self._size == self.capacity():\nself.extend_capacity()\n# \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in range(self._size - 1, index - 1, -1):\nself._arr[j + 1] = self._arr[j]\nself._arr[index] = num\n# \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself._size += 1\ndef remove(self, index: int) -> int:\n\"\"\"\u5220\u9664\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nnum = self._arr[index]\n# \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in range(index, self._size - 1):\nself._arr[j] = self._arr[j + 1]\n# \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself._size -= 1\n# \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\ndef extend_capacity(self):\n\"\"\"\u5217\u8868\u6269\u5bb9\"\"\"\n# \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 __extend_ratio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nself._arr = self._arr + [0] * self.capacity() * (self._extend_ratio - 1)\n# \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself._capacity = len(self._arr)\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868\"\"\"\nreturn self._arr[: self._size]\n
        my_list.cpp
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate:\nint *arr;             // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint arrCapacity = 10; // \u5217\u8868\u5bb9\u91cf\nint arrSize = 0;      // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nint extendRatio = 2;   // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nMyList() {\narr = new int[arrCapacity];\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~MyList() {\ndelete[] arr;\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nint size() {\nreturn arrSize;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity() {\nreturn arrCapacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(int index, int num) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size() == capacity())\nextendCapacity();\narr[size()] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(int index, int num) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size() == capacity())\nextendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = size() - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nint remove(int index) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < size() - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\nint newCapacity = capacity() * extendRatio;\nint *tmp = arr;\narr = new int[newCapacity];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\narr[i] = tmp[i];\n}\n// \u91ca\u653e\u5185\u5b58\ndelete[] tmp;\narrCapacity = newCapacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Vector \u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> vec(size());\nfor (int i = 0; i < size(); i++) {\nvec[i] = arr[i];\n}\nreturn vec;\n}\n};\n
        my_list.java
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate int[] arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate int capacity = 10; // \u5217\u8868\u5bb9\u91cf\nprivate int size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate int extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\npublic MyList() {\narr = new int[capacity];\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\npublic int size() {\nreturn size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic int capacity() {\nreturn capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic int get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic void set(int index, int num) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic void add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size == capacity())\nextendCapacity();\narr[size] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic void insert(int index, int num) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size == capacity())\nextendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = size - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic int remove(int index) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < size - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic void extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\narr = Arrays.copyOf(arr, capacity() * extendRatio);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\ncapacity = arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic int[] toArray() {\nint size = size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] arr = new int[size];\nfor (int i = 0; i < size; i++) {\narr[i] = get(i);\n}\nreturn arr;\n}\n}\n
        my_list.cs
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate int[] arr;           // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate int arrCapacity = 10;    // \u5217\u8868\u5bb9\u91cf\nprivate int arrSize = 0;         // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate readonly int extendRatio = 2;  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\npublic MyList() {\narr = new int[arrCapacity];\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npublic int Size() {\nreturn arrSize;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic int Capacity() {\nreturn arrCapacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic int Get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic void Set(int index, int num) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic void Add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (arrSize == arrCapacity)\nExtendCapacity();\narr[arrSize] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic void Insert(int index, int num) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (arrSize == arrCapacity)\nExtendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = arrSize - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic int Remove(int index) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < arrSize - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic void ExtendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a arrCapacity * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nArray.Resize(ref arr, arrCapacity * extendRatio);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\narrCapacity = arr.Length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] arr = new int[arrSize];\nfor (int i = 0; i < arrSize; i++) {\narr[i] = Get(i);\n}\nreturn arr;\n}\n}\n
        my_list.go
        /* \u5217\u8868\u7c7b */\ntype myList struct {\narrCapacity int\narr         []int\narrSize     int\nextendRatio int\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newMyList() *myList {\nreturn &myList{\narrCapacity: 10,              // \u5217\u8868\u5bb9\u91cf\narr:         make([]int, 10), // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\narrSize:     0,               // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextendRatio: 2,               // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\nfunc (l *myList) size() int {\nreturn l.arrSize\n}\n/*  \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc (l *myList) capacity() int {\nreturn l.arrCapacity\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc (l *myList) get(index int) int {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nreturn l.arr[index]\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc (l *myList) set(num, index int) {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nl.arr[index] = num\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nfunc (l *myList) add(num int) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif l.arrSize == l.arrCapacity {\nl.extendCapacity()\n}\nl.arr[l.arrSize] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize++\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc (l *myList) insert(num, index int) {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif l.arrSize == l.arrCapacity {\nl.extendCapacity()\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j := l.arrSize - 1; j >= index; j-- {\nl.arr[j+1] = l.arr[j]\n}\nl.arr[index] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize++\n}\n/* \u5220\u9664\u5143\u7d20 */\nfunc (l *myList) remove(index int) int {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nnum := l.arr[index]\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j := index; j < l.arrSize-1; j++ {\nl.arr[j] = l.arr[j+1]\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize--\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\n}\n/* \u5217\u8868\u6269\u5bb9 */\nfunc (l *myList) extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nl.arr = append(l.arr, make([]int, l.arrCapacity*(l.extendRatio-1))...)\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nl.arrCapacity = len(l.arr)\n}\n/* \u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868 */\nfunc (l *myList) toArray() []int {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nreturn l.arr[:l.arrSize]\n}\n
        my_list.swift
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate var arr: [Int] // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate var _capacity = 10 // \u5217\u8868\u5bb9\u91cf\nprivate var _size = 0 // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate let extendRatio = 2 // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\narr = Array(repeating: 0, count: _capacity)\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nfunc size() -> Int {\n_size\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc capacity() -> Int {\n_capacity\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc get(index: Int) -> Int {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u9519\u8bef\uff0c\u4e0b\u540c\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nreturn arr[index]\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc set(index: Int, num: Int) {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\narr[index] = num\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nfunc add(num: Int) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif _size == _capacity {\nextendCapacity()\n}\narr[_size] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size += 1\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc insert(index: Int, num: Int) {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif _size == _capacity {\nextendCapacity()\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in sequence(first: _size - 1, next: { $0 >= index + 1 ? $0 - 1 : nil }) {\narr[j + 1] = arr[j]\n}\narr[index] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size += 1\n}\n/* \u5220\u9664\u5143\u7d20 */\n@discardableResult\nfunc remove(index: Int) -> Int {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nlet num = arr[index]\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in index ..< (_size - 1) {\narr[j] = arr[j + 1]\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size -= 1\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\n}\n/* \u5217\u8868\u6269\u5bb9 */\nfunc extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\narr = arr + Array(repeating: 0, count: _capacity * (extendRatio - 1))\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n_capacity = arr.count\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\nfunc toArray() -> [Int] {\nvar arr = Array(repeating: 0, count: _size)\nfor i in 0 ..< _size {\narr[i] = get(index: i)\n}\nreturn arr\n}\n}\n
        my_list.js
        /* \u5217\u8868\u7c7b */\nclass MyList {\n#arr = new Array(); // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n#capacity = 10; // \u5217\u8868\u5bb9\u91cf\n#size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n#extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#arr = new Array(this.#capacity);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nsize() {\nreturn this.#size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\ncapacity() {\nreturn this.#capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nget(index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nreturn this.#arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nset(index, num) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nthis.#arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nadd(num) {\n// \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\nif (this.#size === this.#capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\nthis.#arr[this.#size] = num;\nthis.#size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\ninsert(index, num) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (this.#size === this.#capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let j = this.#size - 1; j >= index; j--) {\nthis.#arr[j + 1] = this.#arr[j];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.#arr[index] = num;\nthis.#size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nremove(index) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nlet num = this.#arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let j = index; j < this.#size - 1; j++) {\nthis.#arr[j] = this.#arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.#size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nextendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nthis.#arr = this.#arr.concat(\nnew Array(this.capacity() * (this.#extendRatio - 1))\n);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nthis.#capacity = this.#arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\ntoArray() {\nlet size = this.size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(size);\nfor (let i = 0; i < size; i++) {\narr[i] = this.get(i);\n}\nreturn arr;\n}\n}\n
        my_list.ts
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate arr: Array<number>; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate _capacity: number = 10; // \u5217\u8868\u5bb9\u91cf\nprivate _size: number = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate extendRatio: number = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.arr = new Array(this._capacity);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npublic size(): number {\nreturn this._size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic capacity(): number {\nreturn this._capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic get(index: number): number {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nreturn this.arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic set(index: number, num: number): void {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nthis.arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic add(num: number): void {\n// \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\nif (this._size === this._capacity) this.extendCapacity();\n// \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\nthis.arr[this._size] = num;\nthis._size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic insert(index: number, num: number): void {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (this._size === this._capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let j = this._size - 1; j >= index; j--) {\nthis.arr[j + 1] = this.arr[j];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.arr[index] = num;\nthis._size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic remove(index: number): number {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nlet num = this.arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let j = index; j < this._size - 1; j++) {\nthis.arr[j] = this.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis._size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic extendCapacity(): void {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nthis.arr = this.arr.concat(\nnew Array(this.capacity() * (this.extendRatio - 1))\n);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nthis._capacity = this.arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic toArray(): number[] {\nlet size = this.size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(size);\nfor (let i = 0; i < size; i++) {\narr[i] = this.get(i);\n}\nreturn arr;\n}\n}\n
        my_list.dart
        /* \u5217\u8868\u7c7b */\nclass MyList {\nlate List<int> _arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint _capacity = 10; // \u5217\u8868\u5bb9\u91cf\nint _size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nint _extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nMyList() {\n_arr = List.filled(_capacity, 0);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nint size() => _size;\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity() => _capacity;\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(int index) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\nreturn _arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(int index, int _num) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n_arr[index] = _num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(int _num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (_size == _capacity) extendCapacity();\n_arr[_size] = _num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(int index, int _num) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (_size == _capacity) extendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (var j = _size - 1; j >= index; j--) {\n_arr[j + 1] = _arr[j];\n}\n_arr[index] = _num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nint remove(int index) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\nint _num = _arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (var j = index; j < _size - 1; j++) {\n_arr[j] = _arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn _num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 _extendRatio \u500d\u7684\u65b0\u6570\u7ec4\nfinal _newNums = List.filled(_capacity * _extendRatio, 0);\n// \u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nList.copyRange(_newNums, 0, _arr);\n// \u66f4\u65b0 _arr \u7684\u5f15\u7528\n_arr = _newNums;\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n_capacity = _arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\nList<int> toArray() {\nList<int> arr = [];\nfor (var i = 0; i < _size; i++) {\narr.add(get(i));\n}\nreturn arr;\n}\n}\n
        my_list.rs
        /* \u5217\u8868\u7c7b */\n#[allow(dead_code)]\nstruct MyList {\narr: Vec<i32>,       // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\ncapacity: usize,      // \u5217\u8868\u5bb9\u91cf\nsize: usize,          // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextend_ratio: usize,  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n#[allow(unused,unused_comparisons)]\nimpl MyList {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(capacity: usize) -> Self {\nlet mut vec = Vec::new(); vec.resize(capacity, 0);\nSelf {\narr: vec,\ncapacity,\nsize: 0,\nextend_ratio: 2,\n}\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npub fn size(&self) -> usize {\nreturn self.size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npub fn capacity(&self) -> usize {\nreturn self.capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npub fn get(&self, index: usize) -> i32 {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nreturn self.arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npub fn set(&mut self, index: usize, num: i32) {\nif index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nself.arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npub fn add(&mut self, num: i32) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size == self.capacity() {\nself.extend_capacity();\n}\nself.arr[self.size] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size += 1;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npub fn insert(&mut self, index: usize, num: i32) {\nif index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size == self.capacity() {\nself.extend_capacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in (index..self.size).rev() {\nself.arr[j + 1] = self.arr[j];\n}\nself.arr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size += 1;\n}\n/* \u5220\u9664\u5143\u7d20 */\npub fn remove(&mut self, index: usize) -> i32 {\nif index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nlet num = self.arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in (index..self.size - 1) {\nself.arr[j] = self.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size -= 1;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npub fn extend_capacity(&mut self) {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extend_ratio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nlet new_capacity = self.capacity * self.extend_ratio;\nself.arr.resize(new_capacity, 0);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself.capacity = new_capacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npub fn to_array(&mut self) -> Vec<i32> {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nlet mut arr = Vec::new();\nfor i in 0..self.size {\narr.push(self.get(i));\n}\narr\n}\n}\n
        my_list.c
        /* \u5217\u8868\u7c7b */\ntypedef struct {\nint *arr;        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint capacity;    // \u5217\u8868\u5bb9\u91cf\nint size;        // \u5217\u8868\u5927\u5c0f\nint extendRatio; // \u5217\u8868\u6bcf\u6b21\u6269\u5bb9\u7684\u500d\u6570\n} MyList;\n/* \u6784\u9020\u51fd\u6570 */\nMyList *newMyList() {\nMyList *nums = malloc(sizeof(MyList));\nnums->capacity = 10;\nnums->arr = malloc(sizeof(int) * nums->capacity);\nnums->size = 0;\nnums->extendRatio = 2;\nreturn nums;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delMyList(MyList *nums) {\nfree(nums->arr);\nfree(nums);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6 */\nint size(MyList *nums) {\nreturn nums->size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity(MyList *nums) {\nreturn nums->capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(MyList *nums, int index) {\nassert(index >= 0 && index < nums->size);\nreturn nums->arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(MyList *nums, int index, int num) {\nassert(index >= 0 && index < nums->size);\nnums->arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(MyList *nums, int num) {\nif (size(nums) == capacity(nums)) {\nextendCapacity(nums); // \u6269\u5bb9\n}\nnums->arr[size(nums)] = num;\nnums->size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(MyList *nums, int index, int num) {\nassert(index >= 0 && index < size(nums));\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size(nums) == capacity(nums)) {\nextendCapacity(nums); // \u6269\u5bb9\n}\nfor (int i = size(nums); i > index; --i) {\nnums->arr[i] = nums->arr[i - 1];\n}\nnums->arr[index] = num;\nnums->size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nint removeItem(MyList *nums, int index) {\nassert(index >= 0 && index < size(nums));\nint num = nums->arr[index];\nfor (int i = index; i < size(nums) - 1; i++) {\nnums->arr[i] = nums->arr[i + 1];\n}\nnums->size--;\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity(MyList *nums) {\n// \u5148\u5206\u914d\u7a7a\u95f4\nint newCapacity = capacity(nums) * nums->extendRatio;\nint *extend = (int *)malloc(sizeof(int) * newCapacity);\nint *temp = nums->arr;\n// \u62f7\u8d1d\u65e7\u6570\u636e\u5230\u65b0\u6570\u636e\nfor (int i = 0; i < size(nums); i++)\nextend[i] = nums->arr[i];\n// \u91ca\u653e\u65e7\u6570\u636e\nfree(temp);\n// \u66f4\u65b0\u65b0\u6570\u636e\nnums->arr = extend;\nnums->capacity = newCapacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Array \u7528\u4e8e\u6253\u5370 */\nint *toArray(MyList *nums) {\nreturn nums->arr;\n}\n
        my_list.zig
        // \u5217\u8868\u7c7b\nfn MyList(comptime T: type) type {\nreturn struct {\nconst Self = @This();\narr: []T = undefined,                        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\narrCapacity: usize = 10,                     // \u5217\u8868\u5bb9\u91cf\nnumSize: usize = 0,                           // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextendRatio: usize = 2,                       // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined, // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u5217\u8868\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.arr = try self.mem_allocator.alloc(T, self.arrCapacity);\n@memset(self.arr, @as(T, 0));\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\npub fn size(self: *Self) usize {\nreturn self.numSize;\n}\n// \u83b7\u53d6\u5217\u8868\u5bb9\u91cf\npub fn capacity(self: *Self) usize {\nreturn self.arrCapacity;\n}\n// \u8bbf\u95ee\u5143\u7d20\npub fn get(self: *Self, index: usize) T {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn self.arr[index];\n}  // \u66f4\u65b0\u5143\u7d20\npub fn set(self: *Self, index: usize, num: T) void {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nself.arr[index] = num;\n}  // \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\npub fn add(self: *Self, num: T) !void {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (self.size() == self.capacity()) try self.extendCapacity();\nself.arr[self.size()] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize += 1;\n}  // \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\npub fn insert(self: *Self, index: usize, num: T) !void {\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (self.size() == self.capacity()) try self.extendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nvar j = self.size() - 1;\nwhile (j >= index) : (j -= 1) {\nself.arr[j + 1] = self.arr[j];\n}\nself.arr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize += 1;\n}\n// \u5220\u9664\u5143\u7d20\npub fn remove(self: *Self, index: usize) T {\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nvar num = self.arr[index];\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nvar j = index;\nwhile (j < self.size() - 1) : (j += 1) {\nself.arr[j] = self.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize -= 1;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n// \u5217\u8868\u6269\u5bb9\npub fn extendCapacity(self: *Self) !void {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nvar newCapacity = self.capacity() * self.extendRatio;\nvar extend = try self.mem_allocator.alloc(T, newCapacity);\n@memset(extend, @as(T, 0));\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nstd.mem.copy(T, extend, self.arr);\nself.arr = extend;\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself.arrCapacity = newCapacity;\n}\n// \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar arr = try self.mem_allocator.alloc(T, self.size());\n@memset(arr, @as(T, 0));\nfor (arr, 0..) |*num, i| {\nnum.* = self.get(i);\n}\nreturn arr;\n}\n};\n}\n
        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/","title":"4.4 \u00a0 \u5185\u5b58\u4e0e\u7f13\u5b58 *","text":"

        \u5728\u672c\u7ae0\u7684\u524d\u4e24\u8282\u4e2d\uff0c\u6211\u4eec\u63a2\u8ba8\u4e86\u6570\u7ec4\u548c\u94fe\u8868\u8fd9\u4e24\u79cd\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u4eec\u5206\u522b\u4ee3\u8868\u4e86\u201c\u8fde\u7eed\u5b58\u50a8\u201d\u548c\u201c\u5206\u6563\u5b58\u50a8\u201d\u8fd9\u4e24\u79cd\u4e0d\u540c\u7684\u7269\u7406\u7ed3\u6784\u3002

        \u5b9e\u9645\u4e0a\uff0c\u7269\u7406\u7ed3\u6784\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u51b3\u5b9a\u4e86\u7a0b\u5e8f\u5bf9\u5185\u5b58\u548c\u7f13\u5b58\u7684\u4f7f\u7528\u6548\u7387\uff0c\u8fdb\u800c\u5f71\u54cd\u7b97\u6cd5\u7a0b\u5e8f\u7684\u6574\u4f53\u6027\u80fd\u3002

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#441","title":"4.4.1 \u00a0 \u8ba1\u7b97\u673a\u5b58\u50a8\u8bbe\u5907","text":"

        \u8ba1\u7b97\u673a\u4e2d\u5305\u62ec\u4e09\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u5b58\u50a8\u8bbe\u5907\uff1a\u300c\u786c\u76d8 hard disk\u300d\u3001\u300c\u5185\u5b58 random-access memory, RAM\u300d\u3001\u300c\u7f13\u5b58 cache memory\u300d\u3002\u8868 4-2 \u5c55\u793a\u4e86\u5b83\u4eec\u5728\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u4e0d\u540c\u89d2\u8272\u548c\u6027\u80fd\u7279\u70b9\u3002

        \u8868 4-2 \u00a0 \u8ba1\u7b97\u673a\u7684\u5b58\u50a8\u8bbe\u5907

        \u786c\u76d8 \u5185\u5b58 \u7f13\u5b58 \u7528\u9014 \u957f\u671f\u5b58\u50a8\u6570\u636e\uff0c\u5305\u62ec\u64cd\u4f5c\u7cfb\u7edf\u3001\u7a0b\u5e8f\u3001\u6587\u4ef6\u7b49 \u4e34\u65f6\u5b58\u50a8\u5f53\u524d\u8fd0\u884c\u7684\u7a0b\u5e8f\u548c\u6b63\u5728\u5904\u7406\u7684\u6570\u636e \u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u548c\u6307\u4ee4\uff0c\u51cf\u5c11 CPU \u8bbf\u95ee\u5185\u5b58\u7684\u6b21\u6570 \u6613\u5931\u6027 \u65ad\u7535\u540e\u6570\u636e\u4e0d\u4f1a\u4e22\u5931 \u65ad\u7535\u540e\u6570\u636e\u4f1a\u4e22\u5931 \u65ad\u7535\u540e\u6570\u636e\u4f1a\u4e22\u5931 \u5bb9\u91cf \u8f83\u5927\uff0cTB \u7ea7\u522b \u8f83\u5c0f\uff0cGB \u7ea7\u522b \u975e\u5e38\u5c0f\uff0cMB \u7ea7\u522b \u901f\u5ea6 \u8f83\u6162\uff0c\u51e0\u767e\u5230\u51e0\u5343 MB/s \u8f83\u5feb\uff0c\u51e0\u5341 GB/s \u975e\u5e38\u5feb\uff0c\u51e0\u5341\u5230\u51e0\u767e GB/s \u4ef7\u683c \u8f83\u4fbf\u5b9c\uff0c\u51e0\u6bdb\u5230\u51e0\u5143 / GB \u8f83\u8d35\uff0c\u51e0\u5341\u5230\u51e0\u767e\u5143 / GB \u975e\u5e38\u8d35\uff0c\u968f CPU \u6253\u5305\u8ba1\u4ef7

        \u6211\u4eec\u53ef\u4ee5\u5c06\u8ba1\u7b97\u673a\u5b58\u50a8\u7cfb\u7edf\u60f3\u8c61\u4e3a\u56fe 4-9 \u6240\u793a\u7684\u91d1\u5b57\u5854\u7ed3\u6784\u3002\u8d8a\u9760\u8fd1\u91d1\u5b57\u5854\u9876\u7aef\u7684\u5b58\u50a8\u8bbe\u5907\u7684\u901f\u5ea6\u8d8a\u5feb\u3001\u5bb9\u91cf\u8d8a\u5c0f\u3001\u6210\u672c\u8d8a\u9ad8\u3002\u8fd9\u79cd\u591a\u5c42\u7ea7\u7684\u8bbe\u8ba1\u5e76\u975e\u5076\u7136\uff0c\u800c\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u5bb6\u548c\u5de5\u7a0b\u5e08\u4eec\u7ecf\u8fc7\u6df1\u601d\u719f\u8651\u7684\u7ed3\u679c\u3002

        • \u786c\u76d8\u96be\u4ee5\u88ab\u5185\u5b58\u53d6\u4ee3\u3002\u9996\u5148\uff0c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5728\u65ad\u7535\u540e\u4f1a\u4e22\u5931\uff0c\u56e0\u6b64\u5b83\u4e0d\u9002\u5408\u957f\u671f\u5b58\u50a8\u6570\u636e\uff1b\u5176\u6b21\uff0c\u5185\u5b58\u7684\u6210\u672c\u5927\u7ea6\u662f\u786c\u76d8\u7684\u51e0\u5341\u500d\uff0c\u8fd9\u4f7f\u5f97\u5b83\u96be\u4ee5\u5728\u6d88\u8d39\u8005\u5e02\u573a\u666e\u53ca\u3002
        • \u7f13\u5b58\u7684\u5927\u5bb9\u91cf\u548c\u9ad8\u901f\u5ea6\u96be\u4ee5\u517c\u5f97\u3002\u968f\u7740 L1\u3001L2\u3001L3 \u7f13\u5b58\u7684\u5bb9\u91cf\u9010\u6b65\u589e\u5927\uff0c\u5176\u7269\u7406\u5c3a\u5bf8\u4f1a\u53d8\u5927\uff0c\u4e0e CPU \u6838\u5fc3\u4e4b\u95f4\u7684\u7269\u7406\u8ddd\u79bb\u4f1a\u53d8\u8fdc\uff0c\u4ece\u800c\u5bfc\u81f4\u6570\u636e\u4f20\u8f93\u65f6\u95f4\u589e\u52a0\uff0c\u5143\u7d20\u8bbf\u95ee\u5ef6\u8fdf\u53d8\u9ad8\u3002\u5728\u5f53\u524d\u6280\u672f\u4e0b\uff0c\u591a\u5c42\u7ea7\u7684\u7f13\u5b58\u7ed3\u6784\u662f\u5bb9\u91cf\u3001\u901f\u5ea6\u548c\u6210\u672c\u4e4b\u95f4\u7684\u6700\u4f73\u5e73\u8861\u70b9\u3002

        \u56fe 4-9 \u00a0 \u8ba1\u7b97\u673a\u5b58\u50a8\u7cfb\u7edf

        Note

        \u8ba1\u7b97\u673a\u7684\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\u4f53\u73b0\u4e86\u901f\u5ea6\u3001\u5bb9\u91cf\u548c\u6210\u672c\u4e09\u8005\u4e4b\u95f4\u7684\u7cbe\u5999\u5e73\u8861\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u79cd\u6743\u8861\u666e\u904d\u5b58\u5728\u4e8e\u6240\u6709\u5de5\u4e1a\u9886\u57df\uff0c\u5b83\u8981\u6c42\u6211\u4eec\u5728\u4e0d\u540c\u7684\u4f18\u52bf\u548c\u9650\u5236\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u7684\u5e73\u8861\u70b9\u3002

        \u603b\u7684\u6765\u8bf4\uff0c\u786c\u76d8\u7528\u4e8e\u957f\u671f\u5b58\u50a8\u5927\u91cf\u6570\u636e\uff0c\u5185\u5b58\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u6b63\u5728\u5904\u7406\u7684\u6570\u636e\uff0c\u800c\u7f13\u5b58\u5219\u7528\u4e8e\u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u548c\u6307\u4ee4\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\u3002\u8fd9\u4e09\u8005\u5171\u540c\u534f\u4f5c\uff0c\u786e\u4fdd\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u9ad8\u6548\u8fd0\u884c\u3002

        \u5982\u56fe 4-10 \u6240\u793a\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u4f1a\u4ece\u786c\u76d8\u4e2d\u88ab\u8bfb\u53d6\u5230\u5185\u5b58\u4e2d\uff0c\u4f9b\u7ed9 CPU \u8ba1\u7b97\u4f7f\u7528\u3002\u7f13\u5b58\u53ef\u4ee5\u770b\u4f5c CPU \u7684\u4e00\u90e8\u5206\uff0c\u5b83\u901a\u8fc7\u667a\u80fd\u5730\u4ece\u5185\u5b58\u52a0\u8f7d\u6570\u636e\uff0c\u7ed9 CPU \u63d0\u4f9b\u9ad8\u901f\u7684\u6570\u636e\u8bfb\u53d6\uff0c\u4ece\u800c\u663e\u8457\u63d0\u5347\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u51cf\u5c11\u5bf9\u8f83\u6162\u7684\u5185\u5b58\u7684\u4f9d\u8d56\u3002

        \u56fe 4-10 \u00a0 \u786c\u76d8\u3001\u5185\u5b58\u548c\u7f13\u5b58\u4e4b\u95f4\u7684\u6570\u636e\u6d41\u901a

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#442","title":"4.4.2 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u5185\u5b58\u6548\u7387","text":"

        \u5728\u5185\u5b58\u7a7a\u95f4\u5229\u7528\u65b9\u9762\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u5177\u6709\u5404\u81ea\u7684\u4f18\u52bf\u548c\u5c40\u9650\u3002

        \u4e00\u65b9\u9762\uff0c\u5185\u5b58\u662f\u6709\u9650\u7684\uff0c\u4e14\u540c\u4e00\u5757\u5185\u5b58\u4e0d\u80fd\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u6570\u636e\u7ed3\u6784\u80fd\u591f\u5c3d\u53ef\u80fd\u9ad8\u6548\u5730\u5229\u7528\u7a7a\u95f4\u3002\u6570\u7ec4\u7684\u5143\u7d20\u7d27\u5bc6\u6392\u5217\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684\u7a7a\u95f4\u6765\u5b58\u50a8\u94fe\u8868\u8282\u70b9\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u56e0\u6b64\u7a7a\u95f4\u6548\u7387\u66f4\u9ad8\u3002\u7136\u800c\uff0c\u6570\u7ec4\u9700\u8981\u4e00\u6b21\u6027\u5206\u914d\u8db3\u591f\u7684\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u7684\u6d6a\u8d39\uff0c\u6570\u7ec4\u6269\u5bb9\u4e5f\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u6210\u672c\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u94fe\u8868\u4ee5\u201c\u8282\u70b9\u201d\u4e3a\u5355\u4f4d\u8fdb\u884c\u52a8\u6001\u5185\u5b58\u5206\u914d\u548c\u56de\u6536\uff0c\u8fd9\u79cd\u65b9\u5f0f\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u7075\u6d3b\u6027\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u968f\u7740\u53cd\u590d\u7533\u8bf7\u4e0e\u91ca\u653e\u5185\u5b58\uff0c\u7a7a\u95f2\u5185\u5b58\u7684\u788e\u7247\u5316\u7a0b\u5ea6\u4f1a\u8d8a\u6765\u8d8a\u9ad8\uff0c\u4ece\u800c\u5bfc\u81f4\u5185\u5b58\u7684\u5229\u7528\u6548\u7387\u964d\u4f4e\u3002\u6570\u7ec4\u7531\u4e8e\u5176\u8fde\u7eed\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u76f8\u5bf9\u4e0d\u5bb9\u6613\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u5316\u3002\u76f8\u53cd\uff0c\u94fe\u8868\u7684\u5143\u7d20\u662f\u5206\u6563\u5b58\u50a8\u7684\uff0c\u5728\u9891\u7e41\u7684\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u4e2d\uff0c\u66f4\u5bb9\u6613\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u5316\u3002

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#443","title":"4.4.3 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u7f13\u5b58\u6548\u7387","text":"

        \u7f13\u5b58\u867d\u7136\u5728\u7a7a\u95f4\u5bb9\u91cf\u4e0a\u8fdc\u5c0f\u4e8e\u5185\u5b58\uff0c\u4f46\u5b83\u6bd4\u5185\u5b58\u5feb\u5f97\u591a\uff0c\u5728\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u4e0a\u8d77\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u7531\u4e8e\u7f13\u5b58\u7684\u5bb9\u91cf\u6709\u9650\uff0c\u5b83\u53ea\u80fd\u5b58\u50a8\u4e00\u5c0f\u90e8\u5206\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u3002\u56e0\u6b64\uff0c\u5f53 CPU \u5c1d\u8bd5\u8bbf\u95ee\u7684\u6570\u636e\u4e0d\u5728\u7f13\u5b58\u4e2d\u65f6\uff0c\u5c31\u4f1a\u53d1\u751f\u300c\u7f13\u5b58\u672a\u547d\u4e2d cache miss\u300d\uff0c\u6b64\u65f6 CPU \u4e0d\u5f97\u4e0d\u4ece\u901f\u5ea6\u8f83\u6162\u7684\u5185\u5b58\u4e2d\u52a0\u8f7d\u6240\u9700\u6570\u636e\u3002

        \u663e\u7136\uff0c\u201c\u7f13\u5b58\u672a\u547d\u4e2d\u201d\u8d8a\u5c11\uff0cCPU \u8bfb\u5199\u6570\u636e\u7684\u6548\u7387\u5c31\u8d8a\u9ad8\uff0c\u7a0b\u5e8f\u6027\u80fd\u4e5f\u5c31\u8d8a\u597d\u3002\u6211\u4eec\u5c06 CPU \u4ece\u7f13\u5b58\u4e2d\u6210\u529f\u83b7\u53d6\u6570\u636e\u7684\u6bd4\u4f8b\u79f0\u4e3a\u300c\u7f13\u5b58\u547d\u4e2d\u7387 cache hit rate\u300d\uff0c\u8fd9\u4e2a\u6307\u6807\u901a\u5e38\u7528\u6765\u8861\u91cf\u7f13\u5b58\u6548\u7387\u3002

        \u4e3a\u4e86\u5c3d\u53ef\u80fd\u8fbe\u5230\u66f4\u9ad8\u6548\u7387\uff0c\u7f13\u5b58\u4f1a\u91c7\u53d6\u4ee5\u4e0b\u6570\u636e\u52a0\u8f7d\u673a\u5236\u3002

        • \u7f13\u5b58\u884c\uff1a\u7f13\u5b58\u4e0d\u662f\u5355\u4e2a\u5b57\u8282\u5730\u5b58\u50a8\u4e0e\u52a0\u8f7d\u6570\u636e\uff0c\u800c\u662f\u4ee5\u7f13\u5b58\u884c\u4e3a\u5355\u4f4d\u3002\u76f8\u6bd4\u4e8e\u5355\u4e2a\u5b57\u8282\u7684\u4f20\u8f93\uff0c\u7f13\u5b58\u884c\u7684\u4f20\u8f93\u5f62\u5f0f\u66f4\u52a0\u9ad8\u6548\u3002
        • \u9884\u53d6\u673a\u5236\uff1a\u5904\u7406\u5668\u4f1a\u5c1d\u8bd5\u9884\u6d4b\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\uff08\u4f8b\u5982\u987a\u5e8f\u8bbf\u95ee\u3001\u56fa\u5b9a\u6b65\u957f\u8df3\u8dc3\u8bbf\u95ee\u7b49\uff09\uff0c\u5e76\u6839\u636e\u7279\u5b9a\u6a21\u5f0f\u5c06\u6570\u636e\u52a0\u8f7d\u81f3\u7f13\u5b58\u4e4b\u4e2d\uff0c\u4ece\u800c\u63d0\u5347\u547d\u4e2d\u7387\u3002
        • \u7a7a\u95f4\u5c40\u90e8\u6027\uff1a\u5982\u679c\u4e00\u4e2a\u6570\u636e\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u5b83\u9644\u8fd1\u7684\u6570\u636e\u53ef\u80fd\u4e5f\u4f1a\u8fd1\u671f\u88ab\u8bbf\u95ee\u3002\u56e0\u6b64\uff0c\u7f13\u5b58\u5728\u52a0\u8f7d\u67d0\u4e00\u6570\u636e\u65f6\uff0c\u4e5f\u4f1a\u5c06\u5176\u9644\u8fd1\u7684\u6570\u636e\u52a0\u8f7d\u8fdb\u6765\uff0c\u4ee5\u63d0\u9ad8\u547d\u4e2d\u7387\u3002
        • \u65f6\u95f4\u5c40\u90e8\u6027\uff1a\u5982\u679c\u4e00\u4e2a\u6570\u636e\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u5b83\u5728\u4e0d\u4e45\u7684\u5c06\u6765\u5f88\u53ef\u80fd\u518d\u6b21\u88ab\u8bbf\u95ee\u3002\u7f13\u5b58\u5229\u7528\u8fd9\u4e00\u539f\u7406\uff0c\u901a\u8fc7\u4fdd\u7559\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684\u6570\u636e\u6765\u63d0\u9ad8\u547d\u4e2d\u7387\u3002

        \u5b9e\u9645\u4e0a\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u5bf9\u7f13\u5b58\u7684\u5229\u7528\u6548\u7387\u4e5f\u662f\u4e0d\u540c\u7684\uff0c\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u3002

        • \u5360\u7528\u7a7a\u95f4\uff1a\u94fe\u8868\u5143\u7d20\u6bd4\u6570\u7ec4\u5143\u7d20\u5360\u7528\u7a7a\u95f4\u66f4\u591a\uff0c\u5bfc\u81f4\u7f13\u5b58\u4e2d\u5bb9\u7eb3\u7684\u6709\u6548\u6570\u636e\u91cf\u66f4\u5c11\u3002
        • \u7f13\u5b58\u884c\uff1a\u94fe\u8868\u6570\u636e\u5206\u6563\u5728\u5185\u5b58\u5404\u5904\uff0c\u800c\u7f13\u5b58\u662f\u201c\u6309\u884c\u52a0\u8f7d\u201d\u7684\uff0c\u56e0\u6b64\u52a0\u8f7d\u5230\u7684\u65e0\u6548\u6570\u636e\u7684\u6bd4\u4f8b\u66f4\u9ad8\u3002
        • \u9884\u53d6\u673a\u5236\uff1a\u6570\u7ec4\u6bd4\u94fe\u8868\u7684\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u66f4\u5177\u201c\u53ef\u9884\u6d4b\u6027\u201d\uff0c\u5373\u7cfb\u7edf\u66f4\u5bb9\u6613\u731c\u51fa\u5373\u5c06\u88ab\u52a0\u8f7d\u7684\u6570\u636e\u3002
        • \u7a7a\u95f4\u5c40\u90e8\u6027\uff1a\u6570\u7ec4\u88ab\u5b58\u50a8\u5728\u96c6\u4e2d\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u56e0\u6b64\u88ab\u52a0\u8f7d\u6570\u636e\u7684\u9644\u8fd1\u6570\u636e\u66f4\u6709\u53ef\u80fd\u5373\u5c06\u88ab\u8bbf\u95ee\u3002

        \u603b\u4f53\u800c\u8a00\uff0c\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u7f13\u5b58\u547d\u4e2d\u7387\uff0c\u56e0\u6b64\u5b83\u5728\u64cd\u4f5c\u6548\u7387\u4e0a\u901a\u5e38\u4f18\u4e8e\u94fe\u8868\u3002\u8fd9\u4f7f\u5f97\u5728\u89e3\u51b3\u7b97\u6cd5\u95ee\u9898\u65f6\uff0c\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u5f80\u5f80\u66f4\u53d7\u6b22\u8fce\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9ad8\u7f13\u5b58\u6548\u7387\u5e76\u4e0d\u610f\u5473\u7740\u6570\u7ec4\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u4f18\u4e8e\u94fe\u8868\u3002\u5b9e\u9645\u5e94\u7528\u4e2d\u9009\u62e9\u54ea\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u6765\u51b3\u5b9a\u3002\u4f8b\u5982\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u201c\u6808\u201d\u6570\u636e\u7ed3\u6784\uff08\u4e0b\u4e00\u7ae0\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff09\uff0c\u4f46\u5b83\u4eec\u9002\u7528\u4e8e\u4e0d\u540c\u573a\u666f\u3002

        • \u5728\u505a\u7b97\u6cd5\u9898\u65f6\uff0c\u6211\u4eec\u4f1a\u503e\u5411\u4e8e\u9009\u62e9\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u64cd\u4f5c\u6548\u7387\u548c\u968f\u673a\u8bbf\u95ee\u7684\u80fd\u529b\uff0c\u4ee3\u4ef7\u4ec5\u662f\u9700\u8981\u9884\u5148\u4e3a\u6570\u7ec4\u5206\u914d\u4e00\u5b9a\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        • \u5982\u679c\u6570\u636e\u91cf\u975e\u5e38\u5927\u3001\u52a8\u6001\u6027\u5f88\u9ad8\u3001\u6808\u7684\u9884\u671f\u5927\u5c0f\u96be\u4ee5\u4f30\u8ba1\uff0c\u90a3\u4e48\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\u5c31\u66f4\u52a0\u5408\u9002\u3002\u94fe\u8868\u80fd\u591f\u5c06\u5927\u91cf\u6570\u636e\u5206\u6563\u5b58\u50a8\u4e8e\u5185\u5b58\u7684\u4e0d\u540c\u90e8\u5206\uff0c\u5e76\u4e14\u907f\u514d\u4e86\u6570\u7ec4\u6269\u5bb9\u4ea7\u751f\u7684\u989d\u5916\u5f00\u9500\u3002
        "},{"location":"chapter_array_and_linkedlist/summary/","title":"4.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_array_and_linkedlist/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6570\u7ec4\u548c\u94fe\u8868\u662f\u4e24\u79cd\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5206\u522b\u4ee3\u8868\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u4e24\u79cd\u5b58\u50a8\u65b9\u5f0f\uff1a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\u3002\u4e24\u8005\u7684\u7279\u70b9\u5448\u73b0\u51fa\u4e92\u8865\u7684\u7279\u6027\u3002
        • \u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3001\u5360\u7528\u5185\u5b58\u8f83\u5c11\uff1b\u4f46\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u6548\u7387\u4f4e\uff0c\u4e14\u521d\u59cb\u5316\u540e\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002
        • \u94fe\u8868\u901a\u8fc7\u66f4\u6539\u5f15\u7528\uff08\u6307\u9488\uff09\u5b9e\u73b0\u9ad8\u6548\u7684\u8282\u70b9\u63d2\u5165\u4e0e\u5220\u9664\uff0c\u4e14\u53ef\u4ee5\u7075\u6d3b\u8c03\u6574\u957f\u5ea6\uff1b\u4f46\u8282\u70b9\u8bbf\u95ee\u6548\u7387\u4f4e\u3001\u5360\u7528\u5185\u5b58\u8f83\u591a\u3002
        • \u5e38\u89c1\u7684\u94fe\u8868\u7c7b\u578b\u5305\u62ec\u5355\u5411\u94fe\u8868\u3001\u73af\u5f62\u94fe\u8868\u3001\u53cc\u5411\u94fe\u8868\uff0c\u5b83\u4eec\u5206\u522b\u5177\u6709\u5404\u81ea\u7684\u5e94\u7528\u573a\u666f\u3002
        • \u5217\u8868\u662f\u4e00\u79cd\u652f\u6301\u589e\u5220\u67e5\u6539\u7684\u5143\u7d20\u6709\u5e8f\u96c6\u5408\uff0c\u901a\u5e38\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\u5b9e\u73b0\uff0c\u5176\u4fdd\u7559\u4e86\u6570\u7ec4\u7684\u4f18\u52bf\uff0c\u540c\u65f6\u53ef\u4ee5\u7075\u6d3b\u8c03\u6574\u957f\u5ea6\u3002
        • \u5217\u8868\u7684\u51fa\u73b0\u5927\u5e45\u5730\u63d0\u9ad8\u4e86\u6570\u7ec4\u7684\u5b9e\u7528\u6027\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u3002
        • \u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u4e3b\u8981\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u6570\u7ec4\u63d0\u4f9b\u66f4\u9ad8\u7684\u5185\u5b58\u7a7a\u95f4\u6548\u7387\uff0c\u800c\u94fe\u8868\u5219\u5728\u5185\u5b58\u4f7f\u7528\u4e0a\u66f4\u52a0\u7075\u6d3b\u3002
        • \u7f13\u5b58\u901a\u8fc7\u7f13\u5b58\u884c\u3001\u9884\u53d6\u673a\u5236\u4ee5\u53ca\u7a7a\u95f4\u548c\u65f6\u95f4\u5c40\u90e8\u6027\u7b49\u6570\u636e\u52a0\u8f7d\u673a\u5236\uff0c\u4e3a CPU \u63d0\u4f9b\u5feb\u901f\u6570\u636e\u8bbf\u95ee\uff0c\u663e\u8457\u63d0\u5347\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\u3002
        • \u7531\u4e8e\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u7f13\u5b58\u547d\u4e2d\u7387\uff0c\u56e0\u6b64\u5b83\u901a\u5e38\u6bd4\u94fe\u8868\u66f4\u9ad8\u6548\u3002\u5728\u9009\u62e9\u6570\u636e\u7ed3\u6784\u65f6\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u573a\u666f\u505a\u51fa\u6070\u5f53\u9009\u62e9\u3002
        "},{"location":"chapter_array_and_linkedlist/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6570\u7ec4\u5b58\u50a8\u5728\u6808\u4e0a\u548c\u5b58\u50a8\u5728\u5806\u4e0a\uff0c\u5bf9\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u662f\u5426\u6709\u5f71\u54cd\uff1f

        \u5b58\u50a8\u5728\u6808\u4e0a\u548c\u5806\u4e0a\u7684\u6570\u7ec4\u90fd\u88ab\u5b58\u50a8\u5728\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\u5185\uff0c\u6570\u636e\u64cd\u4f5c\u6548\u7387\u662f\u57fa\u672c\u4e00\u81f4\u7684\u3002\u7136\u800c\uff0c\u6808\u548c\u5806\u5177\u6709\u5404\u81ea\u7684\u7279\u70b9\uff0c\u4ece\u800c\u5bfc\u81f4\u4ee5\u4e0b\u4e0d\u540c\u70b9\u3002

        1. \u5206\u914d\u548c\u91ca\u653e\u6548\u7387\uff1a\u6808\u662f\u4e00\u5757\u8f83\u5c0f\u7684\u5185\u5b58\uff0c\u5206\u914d\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5b8c\u6210\uff1b\u800c\u5806\u5185\u5b58\u76f8\u5bf9\u66f4\u5927\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u52a8\u6001\u5206\u914d\uff0c\u66f4\u5bb9\u6613\u788e\u7247\u5316\u3002\u56e0\u6b64\uff0c\u5806\u4e0a\u7684\u5206\u914d\u548c\u91ca\u653e\u64cd\u4f5c\u901a\u5e38\u6bd4\u6808\u4e0a\u7684\u6162\u3002
        2. \u5927\u5c0f\u9650\u5236\uff1a\u6808\u5185\u5b58\u76f8\u5bf9\u8f83\u5c0f\uff0c\u5806\u7684\u5927\u5c0f\u4e00\u822c\u53d7\u9650\u4e8e\u53ef\u7528\u5185\u5b58\u3002\u56e0\u6b64\u5806\u66f4\u52a0\u9002\u5408\u5b58\u50a8\u5927\u578b\u6570\u7ec4\u3002
        3. \u7075\u6d3b\u6027\uff1a\u6808\u4e0a\u7684\u6570\u7ec4\u7684\u5927\u5c0f\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u786e\u5b9a\uff0c\u800c\u5806\u4e0a\u7684\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u786e\u5b9a\u3002

        \u4e3a\u4ec0\u4e48\u6570\u7ec4\u8981\u6c42\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u800c\u5728\u94fe\u8868\u4e2d\u5374\u6ca1\u6709\u5f3a\u8c03\u540c\u7c7b\u578b\u5462\uff1f

        \u94fe\u8868\u7531\u8282\u70b9\u7ec4\u6210\uff0c\u8282\u70b9\u4e4b\u95f4\u901a\u8fc7\u5f15\u7528\uff08\u6307\u9488\uff09\u8fde\u63a5\uff0c\u5404\u4e2a\u8282\u70b9\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u4f8b\u5982 int\u3001double\u3001string\u3001object \u7b49\u3002

        \u76f8\u5bf9\u5730\uff0c\u6570\u7ec4\u5143\u7d20\u5219\u5fc5\u987b\u662f\u76f8\u540c\u7c7b\u578b\u7684\uff0c\u8fd9\u6837\u624d\u80fd\u901a\u8fc7\u8ba1\u7b97\u504f\u79fb\u91cf\u6765\u83b7\u53d6\u5bf9\u5e94\u5143\u7d20\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u6570\u7ec4\u540c\u65f6\u5305\u542b int \u548c long \u4e24\u79cd\u7c7b\u578b\uff0c\u5355\u4e2a\u5143\u7d20\u5206\u522b\u5360\u7528 4 bytes \u548c 8 bytes \uff0c\u6b64\u65f6\u5c31\u4e0d\u80fd\u7528\u4ee5\u4e0b\u516c\u5f0f\u8ba1\u7b97\u504f\u79fb\u91cf\u4e86\uff0c\u56e0\u4e3a\u6570\u7ec4\u4e2d\u5305\u542b\u4e86\u4e24\u79cd\u957f\u5ea6\u7684\u5143\u7d20\u3002

        # \u5143\u7d20\u5185\u5b58\u5730\u5740 = \u6570\u7ec4\u5185\u5b58\u5730\u5740 + \u5143\u7d20\u957f\u5ea6 * \u5143\u7d20\u7d22\u5f15\n

        \u5220\u9664\u8282\u70b9\u540e\uff0c\u662f\u5426\u9700\u8981\u628a P.next \u8bbe\u4e3a \\(\\text{None}\\) \u5462\uff1f

        \u4e0d\u4fee\u6539 P.next \u4e5f\u53ef\u4ee5\u3002\u4ece\u8be5\u94fe\u8868\u7684\u89d2\u5ea6\u770b\uff0c\u4ece\u5934\u8282\u70b9\u904d\u5386\u5230\u5c3e\u8282\u70b9\u5df2\u7ecf\u4e0d\u4f1a\u9047\u5230 P \u4e86\u3002\u8fd9\u610f\u5473\u7740\u8282\u70b9 P \u5df2\u7ecf\u4ece\u94fe\u8868\u4e2d\u5220\u9664\u4e86\uff0c\u6b64\u65f6\u8282\u70b9 P \u6307\u5411\u54ea\u91cc\u90fd\u4e0d\u4f1a\u5bf9\u8be5\u94fe\u8868\u4ea7\u751f\u5f71\u54cd\u3002

        \u4ece\u5783\u573e\u56de\u6536\u7684\u89d2\u5ea6\u770b\uff0c\u5bf9\u4e8e Java\u3001Python\u3001Go \u7b49\u62e5\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\u7684\u8bed\u8a00\u6765\u8bf4\uff0c\u8282\u70b9 P \u662f\u5426\u88ab\u56de\u6536\u53d6\u51b3\u4e8e\u662f\u5426\u4ecd\u5b58\u5728\u6307\u5411\u5b83\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f P.next \u7684\u503c\u3002\u5728 C \u548c C++ \u7b49\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u91ca\u653e\u8282\u70b9\u5185\u5b58\u3002

        \u5728\u94fe\u8868\u4e2d\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002\u4f46\u662f\u589e\u5220\u4e4b\u524d\u90fd\u9700\u8981 \\(O(n)\\) \u7684\u65f6\u95f4\u67e5\u627e\u5143\u7d20\uff0c\u90a3\u4e3a\u4ec0\u4e48\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u662f \\(O(n)\\) \u5462\uff1f

        \u5982\u679c\u662f\u5148\u67e5\u627e\u5143\u7d20\u3001\u518d\u5220\u9664\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u786e\u5b9e\u662f \\(O(n)\\) \u3002\u7136\u800c\uff0c\u94fe\u8868\u7684 \\(O(1)\\) \u589e\u5220\u7684\u4f18\u52bf\u53ef\u4ee5\u5728\u5176\u4ed6\u5e94\u7528\u4e0a\u5f97\u5230\u4f53\u73b0\u3002\u4f8b\u5982\uff0c\u53cc\u5411\u961f\u5217\u9002\u5408\u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\uff0c\u6211\u4eec\u7ef4\u62a4\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\u59cb\u7ec8\u6307\u5411\u5934\u8282\u70b9\u3001\u5c3e\u8282\u70b9\uff0c\u6bcf\u6b21\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u90fd\u662f \\(O(1)\\) \u3002

        \u56fe\u201c\u94fe\u8868\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f\u201d\u4e2d\uff0c\u6d45\u84dd\u8272\u7684\u5b58\u50a8\u8282\u70b9\u6307\u9488\u662f\u5360\u7528\u4e00\u5757\u5185\u5b58\u5730\u5740\u5417\uff1f\u8fd8\u662f\u548c\u8282\u70b9\u503c\u5404\u5360\u4e00\u534a\u5462\uff1f

        \u8be5\u793a\u610f\u56fe\u53ea\u662f\u5b9a\u6027\u8868\u793a\uff0c\u5b9a\u91cf\u8868\u793a\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u5206\u6790\u3002

        • \u4e0d\u540c\u7c7b\u578b\u7684\u8282\u70b9\u503c\u5360\u7528\u7684\u7a7a\u95f4\u662f\u4e0d\u540c\u7684\uff0c\u6bd4\u5982 int\u3001long\u3001double \u548c\u5b9e\u4f8b\u5bf9\u8c61\u7b49\u3002
        • \u6307\u9488\u53d8\u91cf\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u5927\u5c0f\u6839\u636e\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ca\u7f16\u8bd1\u73af\u5883\u800c\u5b9a\uff0c\u5927\u591a\u4e3a 8 \u5b57\u8282\u6216 4 \u5b57\u8282\u3002

        \u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20\u662f\u5426\u65f6\u65f6\u523b\u523b\u90fd\u4e3a \\(O(1)\\) \uff1f

        \u5982\u679c\u6dfb\u52a0\u5143\u7d20\u65f6\u8d85\u51fa\u5217\u8868\u957f\u5ea6\uff0c\u5219\u9700\u8981\u5148\u6269\u5bb9\u5217\u8868\u518d\u6dfb\u52a0\u3002\u7cfb\u7edf\u4f1a\u7533\u8bf7\u4e00\u5757\u65b0\u7684\u5185\u5b58\uff0c\u5e76\u5c06\u539f\u5217\u8868\u7684\u6240\u6709\u5143\u7d20\u642c\u8fd0\u8fc7\u53bb\uff0c\u8fd9\u65f6\u5019\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u4f1a\u662f \\(O(n)\\) \u3002

        \u201c\u5217\u8868\u7684\u51fa\u73b0\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u6570\u7ec4\u7684\u5b9e\u7528\u6027\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u201d\uff0c\u8fd9\u91cc\u7684\u7a7a\u95f4\u6d6a\u8d39\u662f\u6307\u989d\u5916\u589e\u52a0\u7684\u53d8\u91cf\u5982\u5bb9\u91cf\u3001\u957f\u5ea6\u3001\u6269\u5bb9\u500d\u6570\u6240\u5360\u7684\u5185\u5b58\u5417\uff1f

        \u8fd9\u91cc\u7684\u7a7a\u95f4\u6d6a\u8d39\u4e3b\u8981\u6709\u4e24\u65b9\u9762\u542b\u4e49\uff1a\u4e00\u65b9\u9762\uff0c\u5217\u8868\u90fd\u4f1a\u8bbe\u5b9a\u4e00\u4e2a\u521d\u59cb\u957f\u5ea6\uff0c\u6211\u4eec\u4e0d\u4e00\u5b9a\u9700\u8981\u7528\u8fd9\u4e48\u591a\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u4e3a\u4e86\u9632\u6b62\u9891\u7e41\u6269\u5bb9\uff0c\u6269\u5bb9\u4e00\u822c\u4f1a\u4e58\u4ee5\u4e00\u4e2a\u7cfb\u6570\uff0c\u6bd4\u5982 \\(\\times 1.5\\) \u3002\u8fd9\u6837\u4e00\u6765\uff0c\u4e5f\u4f1a\u51fa\u73b0\u5f88\u591a\u7a7a\u4f4d\uff0c\u6211\u4eec\u901a\u5e38\u4e0d\u80fd\u5b8c\u5168\u586b\u6ee1\u5b83\u4eec\u3002

        \u5728 Python \u4e2d\u521d\u59cb\u5316 n = [1, 2, 3] \u540e\uff0c\u8fd9 3 \u4e2a\u5143\u7d20\u7684\u5730\u5740\u662f\u76f8\u8fde\u7684\uff0c\u4f46\u662f\u521d\u59cb\u5316 m = [2, 1, 3] \u4f1a\u53d1\u73b0\u5b83\u4eec\u6bcf\u4e2a\u5143\u7d20\u7684 id \u5e76\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u800c\u662f\u5206\u522b\u8ddf n \u4e2d\u7684\u76f8\u540c\u3002\u8fd9\u4e9b\u5143\u7d20\u7684\u5730\u5740\u4e0d\u8fde\u7eed\uff0c\u90a3\u4e48 m \u8fd8\u662f\u6570\u7ec4\u5417\uff1f

        \u5047\u5982\u628a\u5217\u8868\u5143\u7d20\u6362\u6210\u94fe\u8868\u8282\u70b9 n = [n1, n2, n3, n4, n5] \uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u8fd9 5 \u4e2a\u8282\u70b9\u5bf9\u8c61\u4e5f\u5206\u6563\u5b58\u50a8\u5728\u5185\u5b58\u5404\u5904\u3002\u7136\u800c\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868\u7d22\u5f15\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u83b7\u53d6\u8282\u70b9\u5185\u5b58\u5730\u5740\uff0c\u4ece\u800c\u8bbf\u95ee\u5230\u5bf9\u5e94\u7684\u8282\u70b9\u3002\u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u662f\u8282\u70b9\u7684\u5f15\u7528\uff0c\u800c\u975e\u8282\u70b9\u672c\u8eab\u3002

        \u4e0e\u8bb8\u591a\u8bed\u8a00\u4e0d\u540c\uff0cPython \u4e2d\u7684\u6570\u5b57\u4e5f\u88ab\u5305\u88c5\u4e3a\u5bf9\u8c61\uff0c\u5217\u8868\u4e2d\u5b58\u50a8\u7684\u4e0d\u662f\u6570\u5b57\u672c\u8eab\uff0c\u800c\u662f\u5bf9\u6570\u5b57\u7684\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0\u4e24\u4e2a\u6570\u7ec4\u4e2d\u7684\u76f8\u540c\u6570\u5b57\u62e5\u6709\u540c\u4e00\u4e2a id \uff0c\u5e76\u4e14\u8fd9\u4e9b\u6570\u5b57\u7684\u5185\u5b58\u5730\u5740\u65e0\u987b\u8fde\u7eed\u3002

        C++ STL \u91cc\u9762\u7684 std::list \u5df2\u7ecf\u5b9e\u73b0\u4e86\u53cc\u5411\u94fe\u8868\uff0c\u4f46\u597d\u50cf\u4e00\u4e9b\u7b97\u6cd5\u4e66\u4e0a\u4e0d\u600e\u4e48\u76f4\u63a5\u4f7f\u7528\u5b83\uff0c\u662f\u4e0d\u662f\u56e0\u4e3a\u6709\u4ec0\u4e48\u5c40\u9650\u6027\u5462\uff1f

        \u4e00\u65b9\u9762\uff0c\u6211\u4eec\u5f80\u5f80\u66f4\u9752\u7750\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u7b97\u6cd5\uff0c\u800c\u53ea\u5728\u5fc5\u8981\u65f6\u624d\u4f7f\u7528\u94fe\u8868\uff0c\u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0\u3002

        • \u7a7a\u95f4\u5f00\u9500\uff1a\u7531\u4e8e\u6bcf\u4e2a\u5143\u7d20\u9700\u8981\u4e24\u4e2a\u989d\u5916\u7684\u6307\u9488\uff08\u4e00\u4e2a\u7528\u4e8e\u524d\u4e00\u4e2a\u5143\u7d20\uff0c\u4e00\u4e2a\u7528\u4e8e\u540e\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u6240\u4ee5 std::list \u901a\u5e38\u6bd4 std::vector \u66f4\u5360\u7528\u7a7a\u95f4\u3002
        • \u7f13\u5b58\u4e0d\u53cb\u597d\uff1a\u7531\u4e8e\u6570\u636e\u4e0d\u662f\u8fde\u7eed\u5b58\u653e\u7684\uff0c\u56e0\u6b64 std::list \u5bf9\u7f13\u5b58\u7684\u5229\u7528\u7387\u8f83\u4f4e\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cstd::vector \u7684\u6027\u80fd\u4f1a\u66f4\u597d\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5fc5\u8981\u4f7f\u7528\u94fe\u8868\u7684\u60c5\u51b5\u4e3b\u8981\u662f\u4e8c\u53c9\u6811\u548c\u56fe\u3002\u6808\u548c\u961f\u5217\u5f80\u5f80\u4f1a\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684 stack \u548c queue \uff0c\u800c\u975e\u94fe\u8868\u3002

        \u521d\u59cb\u5316\u5217\u8868 res = [0] * self.size() \u64cd\u4f5c\uff0c\u4f1a\u5bfc\u81f4 res \u7684\u6bcf\u4e2a\u5143\u7d20\u5f15\u7528\u76f8\u540c\u7684\u5730\u5740\u5417\uff1f

        \u4e0d\u4f1a\u3002\u4f46\u4e8c\u7ef4\u6570\u7ec4\u4f1a\u6709\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f8b\u5982\u521d\u59cb\u5316\u4e8c\u7ef4\u5217\u8868 res = [[0] * self.size()] \uff0c\u5219\u591a\u6b21\u5f15\u7528\u4e86\u540c\u4e00\u4e2a\u5217\u8868 [0] \u3002

        \u5728\u5220\u9664\u8282\u70b9\u4e2d\uff0c\u9700\u8981\u65ad\u5f00\u8be5\u8282\u70b9\u4e0e\u5176\u540e\u7ee7\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\u6307\u5411\u5417\uff1f

        \u4ece\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\uff08\u505a\u9898\uff09\u7684\u89d2\u5ea6\u770b\uff0c\u4e0d\u65ad\u5f00\u6ca1\u6709\u5173\u7cfb\uff0c\u53ea\u8981\u4fdd\u8bc1\u7a0b\u5e8f\u7684\u903b\u8f91\u662f\u6b63\u786e\u7684\u5c31\u884c\u3002\u4ece\u6807\u51c6\u5e93\u7684\u89d2\u5ea6\u770b\uff0c\u65ad\u5f00\u66f4\u52a0\u5b89\u5168\u3001\u903b\u8f91\u66f4\u52a0\u6e05\u6670\u3002\u5982\u679c\u4e0d\u65ad\u5f00\uff0c\u5047\u8bbe\u88ab\u5220\u9664\u8282\u70b9\u672a\u88ab\u6b63\u5e38\u56de\u6536\uff0c\u90a3\u4e48\u5b83\u4e5f\u4f1a\u5f71\u54cd\u540e\u7ee7\u8282\u70b9\u7684\u5185\u5b58\u56de\u6536\u3002

        "},{"location":"chapter_backtracking/","title":"\u7b2c 13 \u7ae0 \u00a0 \u56de\u6eaf","text":"

        Abstract

        \u6211\u4eec\u5982\u540c\u8ff7\u5bab\u4e2d\u7684\u63a2\u7d22\u8005\uff0c\u5728\u524d\u8fdb\u7684\u9053\u8def\u4e0a\u53ef\u80fd\u4f1a\u9047\u5230\u56f0\u96be\u3002

        \u56de\u6eaf\u7684\u529b\u91cf\u8ba9\u6211\u4eec\u80fd\u591f\u91cd\u65b0\u5f00\u59cb\uff0c\u4e0d\u65ad\u5c1d\u8bd5\uff0c\u6700\u7ec8\u627e\u5230\u901a\u5f80\u5149\u660e\u7684\u51fa\u53e3\u3002

        "},{"location":"chapter_backtracking/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 13.1 \u00a0 \u56de\u6eaf\u7b97\u6cd5
        • 13.2 \u00a0 \u5168\u6392\u5217\u95ee\u9898
        • 13.3 \u00a0 \u5b50\u96c6\u548c\u95ee\u9898
        • 13.4 \u00a0 N \u7687\u540e\u95ee\u9898
        • 13.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_backtracking/backtracking_algorithm/","title":"13.1 \u00a0 \u56de\u6eaf\u7b97\u6cd5","text":"

        \u300c\u56de\u6eaf\u7b97\u6cd5 backtracking algorithm\u300d\u662f\u4e00\u79cd\u901a\u8fc7\u7a77\u4e3e\u6765\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5\uff0c\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f\u4ece\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\u51fa\u53d1\uff0c\u66b4\u529b\u641c\u7d22\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5f53\u9047\u5230\u6b63\u786e\u7684\u89e3\u5219\u5c06\u5176\u8bb0\u5f55\uff0c\u76f4\u5230\u627e\u5230\u89e3\u6216\u8005\u5c1d\u8bd5\u4e86\u6240\u6709\u53ef\u80fd\u7684\u9009\u62e9\u90fd\u65e0\u6cd5\u627e\u5230\u89e3\u4e3a\u6b62\u3002

        \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u91c7\u7528\u201c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u6765\u904d\u5386\u89e3\u7a7a\u95f4\u3002\u5728\u201c\u4e8c\u53c9\u6811\u201d\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u63d0\u5230\u524d\u5e8f\u3001\u4e2d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5229\u7528\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e00\u4e2a\u56de\u6eaf\u95ee\u9898\uff0c\u9010\u6b65\u4e86\u89e3\u56de\u6eaf\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u3002

        \u4f8b\u9898\u4e00

        \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u641c\u7d22\u5e76\u8bb0\u5f55\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u8282\u70b9\u5217\u8868\u3002

        \u5bf9\u4e8e\u6b64\u9898\uff0c\u6211\u4eec\u524d\u5e8f\u904d\u5386\u8fd9\u68f5\u6811\uff0c\u5e76\u5224\u65ad\u5f53\u524d\u8282\u70b9\u7684\u503c\u662f\u5426\u4e3a \\(7\\) \uff0c\u82e5\u662f\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u7684\u503c\u52a0\u5165\u7ed3\u679c\u5217\u8868 res \u4e4b\u4e2d\u3002\u76f8\u5173\u8fc7\u7a0b\u5b9e\u73b0\u5982\u56fe 13-1 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_i_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00\"\"\"\nif root is None:\nreturn\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(root)\npre_order(root.left)\npre_order(root.right)\n
        preorder_traversal_i_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr) {\nreturn;\n}\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(root);\n}\npreOrder(root->left);\npreOrder(root->right);\n}\n
        preorder_traversal_i_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode root) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(root);\n}\npreOrder(root.left);\npreOrder(root.right);\n}\n
        preorder_traversal_i_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid PreOrder(TreeNode? root) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(root);\n}\nPreOrder(root.left);\nPreOrder(root.right);\n}\n
        preorder_traversal_i_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrderI(root *TreeNode, res *[]*TreeNode) {\nif root == nil {\nreturn\n}\nif (root.Val).(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, root)\n}\npreOrderI(root.Left, res)\npreOrderI(root.Right, res)\n}\n
        preorder_traversal_i_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(root)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n}\n
        preorder_traversal_i_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root, res) {\nif (root === null) {\nreturn;\n}\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root: TreeNode | null, res: TreeNode[]): void {\nif (root === null) {\nreturn;\n}\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode? root, List<TreeNode> res) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfn pre_order(res: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\nif root.is_none() {\nreturn;\n}\nif let Some(node) = root {\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(node.clone());\n}\npre_order(res, node.borrow().left.clone());\npre_order(res, node.borrow().right.clone());\n}\n}\n
        preorder_traversal_i_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\nif (root == NULL) {\nreturn;\n}\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres[resSize++] = root;\n}\npreOrder(root->left);\npreOrder(root->right);\n}\n
        preorder_traversal_i_compact.zig
        [class]{}-[func]{preOrder}\n

        \u56fe 13-1 \u00a0 \u5728\u524d\u5e8f\u904d\u5386\u4e2d\u641c\u7d22\u8282\u70b9

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1311","title":"13.1.1 \u00a0 \u5c1d\u8bd5\u4e0e\u56de\u9000","text":"

        \u4e4b\u6240\u4ee5\u79f0\u4e4b\u4e3a\u56de\u6eaf\u7b97\u6cd5\uff0c\u662f\u56e0\u4e3a\u8be5\u7b97\u6cd5\u5728\u641c\u7d22\u89e3\u7a7a\u95f4\u65f6\u4f1a\u91c7\u7528\u201c\u5c1d\u8bd5\u201d\u4e0e\u201c\u56de\u9000\u201d\u7684\u7b56\u7565\u3002\u5f53\u7b97\u6cd5\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u9047\u5230\u67d0\u4e2a\u72b6\u6001\u65e0\u6cd5\u7ee7\u7eed\u524d\u8fdb\u6216\u65e0\u6cd5\u5f97\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u65f6\uff0c\u5b83\u4f1a\u64a4\u9500\u4e0a\u4e00\u6b65\u7684\u9009\u62e9\uff0c\u9000\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5e76\u5c1d\u8bd5\u5176\u4ed6\u53ef\u80fd\u7684\u9009\u62e9\u3002

        \u5bf9\u4e8e\u4f8b\u9898\u4e00\uff0c\u8bbf\u95ee\u6bcf\u4e2a\u8282\u70b9\u90fd\u4ee3\u8868\u4e00\u6b21\u201c\u5c1d\u8bd5\u201d\uff0c\u800c\u8d8a\u8fc7\u53f6\u8282\u70b9\u6216\u8fd4\u56de\u7236\u8282\u70b9\u7684 return \u5219\u8868\u793a\u201c\u56de\u9000\u201d\u3002

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u56de\u9000\u5e76\u4e0d\u4ec5\u4ec5\u5305\u62ec\u51fd\u6570\u8fd4\u56de\u3002\u4e3a\u89e3\u91ca\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u5bf9\u4f8b\u9898\u4e00\u7a0d\u4f5c\u62d3\u5c55\u3002

        \u4f8b\u9898\u4e8c

        \u5728\u4e8c\u53c9\u6811\u4e2d\u641c\u7d22\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u6839\u8282\u70b9\u5230\u8fd9\u4e9b\u8282\u70b9\u7684\u8def\u5f84\u3002

        \u5728\u4f8b\u9898\u4e00\u4ee3\u7801\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u5217\u8868 path \u8bb0\u5f55\u8bbf\u95ee\u8fc7\u7684\u8282\u70b9\u8def\u5f84\u3002\u5f53\u8bbf\u95ee\u5230\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\u65f6\uff0c\u5219\u590d\u5236 path \u5e76\u6dfb\u52a0\u8fdb\u7ed3\u679c\u5217\u8868 res \u3002\u904d\u5386\u5b8c\u6210\u540e\uff0cres \u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u6240\u6709\u7684\u89e3\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_ii_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c\"\"\"\nif root is None:\nreturn\n# \u5c1d\u8bd5\npath.append(root)\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(list(path))\npre_order(root.left)\npre_order(root.right)\n# \u56de\u9000\npath.pop()\n
        preorder_traversal_ii_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push_back(root);\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(path);\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npath.pop_back();\n}\n
        preorder_traversal_ii_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode root) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(new ArrayList<>(path));\n}\npreOrder(root.left);\npreOrder(root.right);\n// \u56de\u9000\npath.remove(path.size() - 1);\n}\n
        preorder_traversal_ii_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid PreOrder(TreeNode? root) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.Add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(new List<TreeNode>(path));\n}\nPreOrder(root.left);\nPreOrder(root.right);\n// \u56de\u9000\npath.RemoveAt(path.Count - 1);\n}\n
        preorder_traversal_ii_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunc preOrderII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {\nif root == nil {\nreturn\n}\n// \u5c1d\u8bd5\n*path = append(*path, root)\nif root.Val.(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, *path)\n}\npreOrderII(root.Left, res, path)\npreOrderII(root.Right, res, path)\n// \u56de\u9000\n*path = (*path)[:len(*path)-1]\n}\n
        preorder_traversal_ii_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u5c1d\u8bd5\npath.append(root)\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(path)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n// \u56de\u9000\npath.removeLast()\n}\n
        preorder_traversal_ii_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(root, path, res) {\nif (root === null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_ii_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(\nroot: TreeNode | null,\npath: TreeNode[],\nres: TreeNode[][]\n): void {\nif (root === null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_ii_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(\nTreeNode? root,\nList<TreeNode> path,\nList<List<TreeNode>> res,\n) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(List.from(path));\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.removeLast();\n}\n
        preorder_traversal_ii_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfn pre_order(res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>, path: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\nif root.is_none() {\nreturn;\n}\nif let Some(node) = root {\n// \u5c1d\u8bd5\npath.push(node.clone());\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(path.clone());\n}\npre_order(res, path, node.borrow().left.clone());\npre_order(res, path, node.borrow().right.clone());\n// \u56de\u9000\npath.remove(path.len() -  1);\n}\n}\n
        preorder_traversal_ii_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\nif (root == NULL) {\nreturn;\n}\n// \u5c1d\u8bd5\npath[pathSize++] = root;\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nfor (int i = 0; i < pathSize; ++i) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npathSize--;\n}\n
        preorder_traversal_ii_compact.zig
        [class]{}-[func]{preOrder}\n

        \u5728\u6bcf\u6b21\u201c\u5c1d\u8bd5\u201d\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u5c06\u5f53\u524d\u8282\u70b9\u6dfb\u52a0\u8fdb path \u6765\u8bb0\u5f55\u8def\u5f84\uff1b\u800c\u5728\u201c\u56de\u9000\u201d\u524d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8be5\u8282\u70b9\u4ece path \u4e2d\u5f39\u51fa\uff0c\u4ee5\u6062\u590d\u672c\u6b21\u5c1d\u8bd5\u4e4b\u524d\u7684\u72b6\u6001\u3002

        \u89c2\u5bdf\u56fe 13-2 \u6240\u793a\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5c1d\u8bd5\u548c\u56de\u9000\u7406\u89e3\u4e3a\u201c\u524d\u8fdb\u201d\u4e0e\u201c\u64a4\u9500\u201d\uff0c\u4e24\u4e2a\u64cd\u4f5c\u4e92\u4e3a\u9006\u5411\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 13-2 \u00a0 \u5c1d\u8bd5\u4e0e\u56de\u9000

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1312","title":"13.1.2 \u00a0 \u526a\u679d","text":"

        \u590d\u6742\u7684\u56de\u6eaf\u95ee\u9898\u901a\u5e38\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u7ea6\u675f\u6761\u4ef6\uff0c\u7ea6\u675f\u6761\u4ef6\u901a\u5e38\u53ef\u7528\u4e8e\u201c\u526a\u679d\u201d\u3002

        \u4f8b\u9898\u4e09

        \u5728\u4e8c\u53c9\u6811\u4e2d\u641c\u7d22\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u6839\u8282\u70b9\u5230\u8fd9\u4e9b\u8282\u70b9\u7684\u8def\u5f84\uff0c\u5e76\u8981\u6c42\u8def\u5f84\u4e2d\u4e0d\u5305\u542b\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u3002

        \u4e3a\u4e86\u6ee1\u8db3\u4ee5\u4e0a\u7ea6\u675f\u6761\u4ef6\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u526a\u679d\u64cd\u4f5c\uff1a\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u82e5\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\uff0c\u5219\u63d0\u524d\u8fd4\u56de\uff0c\u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_iii_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09\"\"\"\n# \u526a\u679d\nif root is None or root.val == 3:\nreturn\n# \u5c1d\u8bd5\npath.append(root)\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(list(path))\npre_order(root.left)\npre_order(root.right)\n# \u56de\u9000\npath.pop()\n
        preorder_traversal_iii_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n// \u526a\u679d\nif (root == nullptr || root->val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push_back(root);\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(path);\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npath.pop_back();\n}\n
        preorder_traversal_iii_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode root) {\n// \u526a\u679d\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(new ArrayList<>(path));\n}\npreOrder(root.left);\npreOrder(root.right);\n// \u56de\u9000\npath.remove(path.size() - 1);\n}\n
        preorder_traversal_iii_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid PreOrder(TreeNode? root) {\n// \u526a\u679d\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.Add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(new List<TreeNode>(path));\n}\nPreOrder(root.left);\nPreOrder(root.right);\n// \u56de\u9000\npath.RemoveAt(path.Count - 1);\n}\n
        preorder_traversal_iii_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunc preOrderIII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {\n// \u526a\u679d\nif root == nil || root.Val == 3 {\nreturn\n}\n// \u5c1d\u8bd5\n*path = append(*path, root)\nif root.Val.(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, *path)\n}\npreOrderIII(root.Left, res, path)\npreOrderIII(root.Right, res, path)\n// \u56de\u9000\n*path = (*path)[:len(*path)-1]\n}\n
        preorder_traversal_iii_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunc preOrder(root: TreeNode?) {\n// \u526a\u679d\nguard let root = root, root.val != 3 else {\nreturn\n}\n// \u5c1d\u8bd5\npath.append(root)\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(path)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n// \u56de\u9000\npath.removeLast()\n}\n
        preorder_traversal_iii_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(root, path, res) {\n// \u526a\u679d\nif (root === null || root.val === 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_iii_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(\nroot: TreeNode | null,\npath: TreeNode[],\nres: TreeNode[][]\n): void {\n// \u526a\u679d\nif (root === null || root.val === 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_iii_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(\nTreeNode? root,\nList<TreeNode> path,\nList<List<TreeNode>> res,\n) {\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(List.from(path));\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.removeLast();\n}\n
        preorder_traversal_iii_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfn pre_order(res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>, path: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\n// \u526a\u679d\nif root.is_none() || root.as_ref().unwrap().borrow().val == 3 {\nreturn;\n}\nif let Some(node) = root {\n// \u5c1d\u8bd5\npath.push(node.clone());\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(path.clone());\n}\npre_order(res, path, node.borrow().left.clone());\npre_order(res, path, node.borrow().right.clone());\n// \u56de\u9000\npath.remove(path.len() -  1);\n}\n}\n
        preorder_traversal_iii_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n// \u526a\u679d\nif (root == NULL || root->val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath[pathSize++] = root;\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nfor (int i = 0; i < pathSize; i++) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npathSize--;\n}\n
        preorder_traversal_iii_compact.zig
        [class]{}-[func]{preOrder}\n

        \u201c\u526a\u679d\u201d\u662f\u4e00\u4e2a\u975e\u5e38\u5f62\u8c61\u7684\u540d\u8bcd\u3002\u5982\u56fe 13-3 \u6240\u793a\uff0c\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u201c\u526a\u6389\u201d\u4e86\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u641c\u7d22\u5206\u652f\uff0c\u907f\u514d\u8bb8\u591a\u65e0\u610f\u4e49\u7684\u5c1d\u8bd5\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u641c\u7d22\u6548\u7387\u3002

        \u56fe 13-3 \u00a0 \u6839\u636e\u7ea6\u675f\u6761\u4ef6\u526a\u679d

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1313","title":"13.1.3 \u00a0 \u6846\u67b6\u4ee3\u7801","text":"

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c1d\u8bd5\u5c06\u56de\u6eaf\u7684\u201c\u5c1d\u8bd5\u3001\u56de\u9000\u3001\u526a\u679d\u201d\u7684\u4e3b\u4f53\u6846\u67b6\u63d0\u70bc\u51fa\u6765\uff0c\u63d0\u5347\u4ee3\u7801\u7684\u901a\u7528\u6027\u3002

        \u5728\u4ee5\u4e0b\u6846\u67b6\u4ee3\u7801\u4e2d\uff0cstate \u8868\u793a\u95ee\u9898\u7684\u5f53\u524d\u72b6\u6001\uff0cchoices \u8868\u793a\u5f53\u524d\u72b6\u6001\u4e0b\u53ef\u4ee5\u505a\u51fa\u7684\u9009\u62e9\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def backtrack(state: State, choices: list[choice], res: list[state]):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\u6846\u67b6\"\"\"\n# \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif is_solution(state):\n# \u8bb0\u5f55\u89e3\nrecord_solution(state, res)\n# \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice):\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice)\nbacktrack(state, choices, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice)\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice : choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State state, List<Choice> choices, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice : choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid Backtrack(State state, List<Choice> choices, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (IsSolution(state)) {\n// \u8bb0\u5f55\u89e3\nRecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (Choice choice in choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (IsValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nMakeChoice(state, choice);\nBacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nUndoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunc backtrack(state *State, choices []Choice, res *[]State) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif isSolution(state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res)\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice)\nbacktrack(state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice)\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunc backtrack(state: inout State, choices: [Choice], res: inout [State]) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif isSolution(state: state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state: state, res: &res)\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state: state, choice: choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state: &state, choice: choice)\nbacktrack(state: &state, choices: choices, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state: &state, choice: choice)\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunction backtrack(state, choices, res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let choice of choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunction backtrack(state: State, choices: Choice[], res: State[]): void {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let choice of choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State state, List<Choice>, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice in choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfn backtrack(state: &mut State, choices: &Vec<Choice>, res: &mut Vec<State>) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif is_solution(state) {\n// \u8bb0\u5f55\u89e3\nrecord_solution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State *state, Choice *choices, int numChoices, State *res, int numRes) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res, numRes);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < numChoices; i++) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, &choices[i])) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, &choices[i]);\nbacktrack(state, choices, numChoices, res, numRes);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, &choices[i]);\n}\n}\n}\n
        \n

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u57fa\u4e8e\u6846\u67b6\u4ee3\u7801\u6765\u89e3\u51b3\u4f8b\u9898\u4e09\u3002\u72b6\u6001 state \u4e3a\u8282\u70b9\u904d\u5386\u8def\u5f84\uff0c\u9009\u62e9 choices \u4e3a\u5f53\u524d\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\uff0c\u7ed3\u679c res \u662f\u8def\u5f84\u5217\u8868\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_iii_template.py
        def is_solution(state: list[TreeNode]) -> bool:\n\"\"\"\u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3\"\"\"\nreturn state and state[-1].val == 7\ndef record_solution(state: list[TreeNode], res: list[list[TreeNode]]):\n\"\"\"\u8bb0\u5f55\u89e3\"\"\"\nres.append(list(state))\ndef is_valid(state: list[TreeNode], choice: TreeNode) -> bool:\n\"\"\"\u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5\"\"\"\nreturn choice is not None and choice.val != 3\ndef make_choice(state: list[TreeNode], choice: TreeNode):\n\"\"\"\u66f4\u65b0\u72b6\u6001\"\"\"\nstate.append(choice)\ndef undo_choice(state: list[TreeNode], choice: TreeNode):\n\"\"\"\u6062\u590d\u72b6\u6001\"\"\"\nstate.pop()\ndef backtrack(\nstate: list[TreeNode], choices: list[TreeNode], res: list[list[TreeNode]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09\"\"\"\n# \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif is_solution(state):\n# \u8bb0\u5f55\u89e3\nrecord_solution(state, res)\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice):\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice)\n
        preorder_traversal_iii_template.cpp
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(vector<TreeNode *> &state) {\nreturn !state.empty() && state.back()->val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(vector<TreeNode *> &state, vector<vector<TreeNode *>> &res) {\nres.push_back(state);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(vector<TreeNode *> &state, TreeNode *choice) {\nreturn choice != nullptr && choice->val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(vector<TreeNode *> &state, TreeNode *choice) {\nstate.push_back(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(vector<TreeNode *> &state, TreeNode *choice) {\nstate.pop_back();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode *choice : choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nvector<TreeNode *> nextChoices{choice->left, choice->right};\nbacktrack(state, nextChoices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.java
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nboolean isSolution(List<TreeNode> state) {\nreturn !state.isEmpty() && state.get(state.size() - 1).val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.add(new ArrayList<>(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nboolean isValid(List<TreeNode> state, TreeNode choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode choice) {\nstate.add(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode choice) {\nstate.remove(state.size() - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode choice : choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, Arrays.asList(choice.left, choice.right), res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.cs
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool IsSolution(List<TreeNode> state) {\nreturn state.Count != 0 && state[^1].val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid RecordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.Add(new List<TreeNode>(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool IsValid(List<TreeNode> state, TreeNode choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid MakeChoice(List<TreeNode> state, TreeNode choice) {\nstate.Add(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid UndoChoice(List<TreeNode> state, TreeNode choice) {\nstate.RemoveAt(state.Count - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid Backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (IsSolution(state)) {\n// \u8bb0\u5f55\u89e3\nRecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (TreeNode choice in choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (IsValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nMakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, [choice.left!, choice.right!], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nUndoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.go
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunc isSolution(state *[]*TreeNode) bool {\nreturn len(*state) != 0 && (*state)[len(*state)-1].Val == 7\n}\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state *[]*TreeNode, res *[][]*TreeNode) {\n*res = append(*res, *state)\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunc isValid(state *[]*TreeNode, choice *TreeNode) bool {\nreturn choice != nil && choice.Val != 3\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state *[]*TreeNode, choice *TreeNode) {\n*state = append(*state, choice)\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state *[]*TreeNode, choice *TreeNode) {\n*state = (*state)[:len(*state)-1]\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunc backtrackIII(state *[]*TreeNode, choices *[]*TreeNode, res *[][]*TreeNode) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif isSolution(state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range *choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\ntemp := make([]*TreeNode, 0)\ntemp = append(temp, choice.Left, choice.Right)\nbacktrackIII(state, &temp, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice)\n}\n}\n}\n
        preorder_traversal_iii_template.swift
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunc isSolution(state: [TreeNode]) -> Bool {\n!state.isEmpty && state.last!.val == 7\n}\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state: [TreeNode], res: inout [[TreeNode]]) {\nres.append(state)\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunc isValid(state: [TreeNode], choice: TreeNode?) -> Bool {\nchoice != nil && choice!.val != 3\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state: inout [TreeNode], choice: TreeNode) {\nstate.append(choice)\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state: inout [TreeNode], choice: TreeNode) {\nstate.removeLast()\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunc backtrack(state: inout [TreeNode], choices: [TreeNode], res: inout [[TreeNode]]) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif isSolution(state: state) {\nrecordSolution(state: state, res: &res)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state: state, choice: choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state: &state, choice: choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: [choice.left, choice.right].compactMap { $0 }, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state: &state, choice: choice)\n}\n}\n}\n
        preorder_traversal_iii_template.js
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunction isSolution(state) {\nreturn state && state[state.length - 1]?.val === 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state, res) {\nres.push([...state]);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state, choice) {\nreturn choice !== null && choice.val !== 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state, choice) {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state) {\nstate.pop();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(state, choices, res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state);\n}\n}\n}\n
        preorder_traversal_iii_template.ts
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunction isSolution(state: TreeNode[]): boolean {\nreturn state && state[state.length - 1]?.val === 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state: TreeNode[], res: TreeNode[][]): void {\nres.push([...state]);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state: TreeNode[], choice: TreeNode): boolean {\nreturn choice !== null && choice.val !== 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state: TreeNode[], choice: TreeNode): void {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state: TreeNode[]): void {\nstate.pop();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(\nstate: TreeNode[],\nchoices: TreeNode[],\nres: TreeNode[][]\n): void {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state);\n}\n}\n}\n
        preorder_traversal_iii_template.dart
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(List<TreeNode> state) {\nreturn state.isNotEmpty && state.last.val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.add(List.from(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(List<TreeNode> state, TreeNode? choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode? choice) {\nstate.add(choice!);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode? choice) {\nstate.removeLast();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(\nList<TreeNode> state,\nList<TreeNode?> choices,\nList<List<TreeNode>> res,\n) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode? choice in choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice!.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.rs
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfn is_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>) -> bool {\nreturn !state.is_empty() && state.get(state.len() - 1).unwrap().borrow().val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfn record_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\nres.push(state.clone());\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfn is_valid(_: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) -> bool {\nreturn choice.borrow().val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfn make_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfn undo_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, _: Rc<RefCell<TreeNode>>) {\nstate.remove(state.len() - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfn backtrack(state: &mut Vec<Rc<RefCell<TreeNode>>>, choices: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif is_solution(state) {\n// \u8bb0\u5f55\u89e3\nrecord_solution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice.clone()) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice.clone());\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, &mut vec![choice.borrow().left.clone().unwrap(), choice.borrow().right.clone().unwrap()], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice.clone());\n}\n}\n}\n
        preorder_traversal_iii_template.c
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(void) {\nreturn pathSize > 0 && path[pathSize - 1]->val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(void) {\nfor (int i = 0; i < pathSize; i++) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(TreeNode *choice) {\nreturn choice != NULL && choice->val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(TreeNode *choice) {\npath[pathSize++] = choice;\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(void) {\npathSize--;\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(TreeNode *choices[2]) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution()) {\n// \u8bb0\u5f55\u89e3\nrecordSolution();\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < 2; i++) {\nTreeNode *choice = choices[i];\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nTreeNode *nextChoices[2] = {choice->left, choice->right};\nbacktrack(nextChoices);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice();\n}\n}\n}\n
        preorder_traversal_iii_template.zig
        [class]{}-[func]{isSolution}\n[class]{}-[func]{recordSolution}\n[class]{}-[func]{isValid}\n[class]{}-[func]{makeChoice}\n[class]{}-[func]{undoChoice}\n[class]{}-[func]{backtrack}\n

        \u6839\u636e\u9898\u610f\uff0c\u6211\u4eec\u5728\u627e\u5230\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\u540e\u5e94\u8be5\u7ee7\u7eed\u641c\u7d22\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u8bb0\u5f55\u89e3\u4e4b\u540e\u7684 return \u8bed\u53e5\u5220\u9664\u3002\u56fe 13-4 \u5bf9\u6bd4\u4e86\u4fdd\u7559\u6216\u5220\u9664 return \u8bed\u53e5\u7684\u641c\u7d22\u8fc7\u7a0b\u3002

        \u56fe 13-4 \u00a0 \u4fdd\u7559\u4e0e\u5220\u9664 return \u7684\u641c\u7d22\u8fc7\u7a0b\u5bf9\u6bd4

        \u76f8\u6bd4\u57fa\u4e8e\u524d\u5e8f\u904d\u5386\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u57fa\u4e8e\u56de\u6eaf\u7b97\u6cd5\u6846\u67b6\u7684\u4ee3\u7801\u5b9e\u73b0\u867d\u7136\u663e\u5f97\u5570\u5506\uff0c\u4f46\u901a\u7528\u6027\u66f4\u597d\u3002\u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u56de\u6eaf\u95ee\u9898\u53ef\u4ee5\u5728\u8be5\u6846\u67b6\u4e0b\u89e3\u51b3\u3002\u6211\u4eec\u53ea\u9700\u6839\u636e\u5177\u4f53\u95ee\u9898\u6765\u5b9a\u4e49 state \u548c choices \uff0c\u5e76\u5b9e\u73b0\u6846\u67b6\u4e2d\u7684\u5404\u4e2a\u65b9\u6cd5\u5373\u53ef\u3002

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1314","title":"13.1.4 \u00a0 \u5e38\u7528\u672f\u8bed","text":"

        \u4e3a\u4e86\u66f4\u6e05\u6670\u5730\u5206\u6790\u7b97\u6cd5\u95ee\u9898\uff0c\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\u56de\u6eaf\u7b97\u6cd5\u4e2d\u5e38\u7528\u672f\u8bed\u7684\u542b\u4e49\uff0c\u5e76\u5bf9\u7167\u4f8b\u9898\u4e09\u7ed9\u51fa\u5bf9\u5e94\u793a\u4f8b\uff0c\u5982\u8868 13-1 \u6240\u793a\u3002

        \u8868 13-1 \u00a0 \u5e38\u89c1\u7684\u56de\u6eaf\u7b97\u6cd5\u672f\u8bed

        \u540d\u8bcd \u5b9a\u4e49 \u4f8b\u9898\u4e09 \u89e3\uff08solution\uff09 \u89e3\u662f\u6ee1\u8db3\u95ee\u9898\u7279\u5b9a\u6761\u4ef6\u7684\u7b54\u6848\uff0c\u53ef\u80fd\u6709\u4e00\u4e2a\u6216\u591a\u4e2a \u6839\u8282\u70b9\u5230\u8282\u70b9 \\(7\\) \u7684\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u6240\u6709\u8def\u5f84 \u7ea6\u675f\u6761\u4ef6\uff08constraint\uff09 \u7ea6\u675f\u6761\u4ef6\u662f\u95ee\u9898\u4e2d\u9650\u5236\u89e3\u7684\u53ef\u884c\u6027\u7684\u6761\u4ef6\uff0c\u901a\u5e38\u7528\u4e8e\u526a\u679d \u8def\u5f84\u4e2d\u4e0d\u5305\u542b\u8282\u70b9 \\(3\\) \u72b6\u6001\uff08state\uff09 \u72b6\u6001\u8868\u793a\u95ee\u9898\u5728\u67d0\u4e00\u65f6\u523b\u7684\u60c5\u51b5\uff0c\u5305\u62ec\u5df2\u7ecf\u505a\u51fa\u7684\u9009\u62e9 \u5f53\u524d\u5df2\u8bbf\u95ee\u7684\u8282\u70b9\u8def\u5f84\uff0c\u5373 path \u8282\u70b9\u5217\u8868 \u5c1d\u8bd5\uff08attempt\uff09 \u5c1d\u8bd5\u662f\u6839\u636e\u53ef\u7528\u9009\u62e9\u6765\u63a2\u7d22\u89e3\u7a7a\u95f4\u7684\u8fc7\u7a0b\uff0c\u5305\u62ec\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\uff0c\u68c0\u67e5\u662f\u5426\u4e3a\u89e3 \u9012\u5f52\u8bbf\u95ee\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\uff0c\u5c06\u8282\u70b9\u6dfb\u52a0\u8fdb path \uff0c\u5224\u65ad\u8282\u70b9\u7684\u503c\u662f\u5426\u4e3a \\(7\\) \u56de\u9000\uff08backtracking\uff09 \u56de\u9000\u6307\u9047\u5230\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u72b6\u6001\u65f6\uff0c\u64a4\u9500\u524d\u9762\u505a\u51fa\u7684\u9009\u62e9\uff0c\u56de\u5230\u4e0a\u4e00\u4e2a\u72b6\u6001 \u5f53\u8d8a\u8fc7\u53f6\u8282\u70b9\u3001\u7ed3\u675f\u8282\u70b9\u8bbf\u95ee\u3001\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u65f6\u7ec8\u6b62\u641c\u7d22\uff0c\u51fd\u6570\u8fd4\u56de \u526a\u679d\uff08pruning\uff09 \u526a\u679d\u662f\u6839\u636e\u95ee\u9898\u7279\u6027\u548c\u7ea6\u675f\u6761\u4ef6\u907f\u514d\u65e0\u610f\u4e49\u7684\u641c\u7d22\u8def\u5f84\u7684\u65b9\u6cd5\uff0c\u53ef\u63d0\u9ad8\u641c\u7d22\u6548\u7387 \u5f53\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u65f6\uff0c\u5219\u4e0d\u518d\u7ee7\u7eed\u641c\u7d22

        Tip

        \u95ee\u9898\u3001\u89e3\u3001\u72b6\u6001\u7b49\u6982\u5ff5\u662f\u901a\u7528\u7684\uff0c\u5728\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u3001\u8d2a\u5fc3\u7b49\u7b97\u6cd5\u4e2d\u90fd\u6709\u6d89\u53ca\u3002

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1315","title":"13.1.5 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u56de\u6eaf\u7b97\u6cd5\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u7b97\u6cd5\uff0c\u5b83\u5c1d\u8bd5\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u76f4\u5230\u627e\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u80fd\u591f\u627e\u5230\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u800c\u4e14\u5728\u5408\u7406\u7684\u526a\u679d\u64cd\u4f5c\u4e0b\uff0c\u5177\u6709\u5f88\u9ad8\u7684\u6548\u7387\u3002

        \u7136\u800c\uff0c\u5728\u5904\u7406\u5927\u89c4\u6a21\u6216\u8005\u590d\u6742\u95ee\u9898\u65f6\uff0c\u56de\u6eaf\u7b97\u6cd5\u7684\u8fd0\u884c\u6548\u7387\u53ef\u80fd\u96be\u4ee5\u63a5\u53d7\u3002

        • \u65f6\u95f4\uff1a\u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u9700\u8981\u904d\u5386\u72b6\u6001\u7a7a\u95f4\u7684\u6240\u6709\u53ef\u80fd\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230\u6307\u6570\u9636\u6216\u9636\u4e58\u9636\u3002
        • \u7a7a\u95f4\uff1a\u5728\u9012\u5f52\u8c03\u7528\u4e2d\u9700\u8981\u4fdd\u5b58\u5f53\u524d\u7684\u72b6\u6001\uff08\u4f8b\u5982\u8def\u5f84\u3001\u7528\u4e8e\u526a\u679d\u7684\u8f85\u52a9\u53d8\u91cf\u7b49\uff09\uff0c\u5f53\u6df1\u5ea6\u5f88\u5927\u65f6\uff0c\u7a7a\u95f4\u9700\u6c42\u53ef\u80fd\u4f1a\u53d8\u5f97\u5f88\u5927\u3002

        \u5373\u4fbf\u5982\u6b64\uff0c\u56de\u6eaf\u7b97\u6cd5\u4ecd\u7136\u662f\u67d0\u4e9b\u641c\u7d22\u95ee\u9898\u548c\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u7684\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u95ee\u9898\uff0c\u7531\u4e8e\u65e0\u6cd5\u9884\u6d4b\u54ea\u4e9b\u9009\u62e9\u53ef\u751f\u6210\u6709\u6548\u7684\u89e3\uff0c\u56e0\u6b64\u6211\u4eec\u5fc5\u987b\u5bf9\u6240\u6709\u53ef\u80fd\u7684\u9009\u62e9\u8fdb\u884c\u904d\u5386\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5173\u952e\u662f\u5982\u4f55\u4f18\u5316\u6548\u7387\uff0c\u5e38\u89c1\u7684\u6548\u7387\u4f18\u5316\u65b9\u6cd5\u6709\u4e24\u79cd\u3002

        • \u526a\u679d\uff1a\u907f\u514d\u641c\u7d22\u90a3\u4e9b\u80af\u5b9a\u4e0d\u4f1a\u4ea7\u751f\u89e3\u7684\u8def\u5f84\uff0c\u4ece\u800c\u8282\u7701\u65f6\u95f4\u548c\u7a7a\u95f4\u3002
        • \u542f\u53d1\u5f0f\u641c\u7d22\uff1a\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u5f15\u5165\u4e00\u4e9b\u7b56\u7565\u6216\u8005\u4f30\u8ba1\u503c\uff0c\u4ece\u800c\u4f18\u5148\u641c\u7d22\u6700\u6709\u53ef\u80fd\u4ea7\u751f\u6709\u6548\u89e3\u7684\u8def\u5f84\u3002
        "},{"location":"chapter_backtracking/backtracking_algorithm/#1316","title":"13.1.6 \u00a0 \u56de\u6eaf\u5178\u578b\u4f8b\u9898","text":"

        \u56de\u6eaf\u7b97\u6cd5\u53ef\u7528\u4e8e\u89e3\u51b3\u8bb8\u591a\u641c\u7d22\u95ee\u9898\u3001\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u548c\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u3002

        \u641c\u7d22\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u5230\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u3002

        • \u5168\u6392\u5217\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\uff0c\u6c42\u51fa\u5176\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u7ec4\u5408\u3002
        • \u5b50\u96c6\u548c\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\u548c\u4e00\u4e2a\u76ee\u6807\u548c\uff0c\u627e\u5230\u96c6\u5408\u4e2d\u6240\u6709\u548c\u4e3a\u76ee\u6807\u548c\u7684\u5b50\u96c6\u3002
        • \u6c49\u8bfa\u5854\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e09\u6839\u67f1\u5b50\u548c\u4e00\u7cfb\u5217\u5927\u5c0f\u4e0d\u540c\u7684\u5706\u76d8\uff0c\u8981\u6c42\u5c06\u6240\u6709\u5706\u76d8\u4ece\u4e00\u6839\u67f1\u5b50\u79fb\u52a8\u5230\u53e6\u4e00\u6839\u67f1\u5b50\uff0c\u6bcf\u6b21\u53ea\u80fd\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\uff0c\u4e14\u4e0d\u80fd\u5c06\u5927\u5706\u76d8\u653e\u5728\u5c0f\u5706\u76d8\u4e0a\u3002

        \u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u5230\u6ee1\u8db3\u6240\u6709\u7ea6\u675f\u6761\u4ef6\u7684\u89e3\u3002

        • \\(n\\) \u7687\u540e\uff1a\u5728 \\(n \\times n\\) \u7684\u68cb\u76d8\u4e0a\u653e\u7f6e \\(n\\) \u4e2a\u7687\u540e\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e92\u4e0d\u653b\u51fb\u3002
        • \u6570\u72ec\uff1a\u5728 \\(9 \\times 9\\) \u7684\u7f51\u683c\u4e2d\u586b\u5165\u6570\u5b57 \\(1\\) ~ \\(9\\) \uff0c\u4f7f\u5f97\u6bcf\u884c\u3001\u6bcf\u5217\u548c\u6bcf\u4e2a \\(3 \\times 3\\) \u5b50\u7f51\u683c\u4e2d\u7684\u6570\u5b57\u4e0d\u91cd\u590d\u3002
        • \u56fe\u7740\u8272\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u7528\u6700\u5c11\u7684\u989c\u8272\u7ed9\u56fe\u7684\u6bcf\u4e2a\u9876\u70b9\u7740\u8272\uff0c\u4f7f\u5f97\u76f8\u90bb\u9876\u70b9\u989c\u8272\u4e0d\u540c\u3002

        \u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u5728\u4e00\u4e2a\u7ec4\u5408\u7a7a\u95f4\u4e2d\u627e\u5230\u6ee1\u8db3\u67d0\u4e9b\u6761\u4ef6\u7684\u6700\u4f18\u89e3\u3002

        • 0-1 \u80cc\u5305\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u7269\u54c1\u548c\u4e00\u4e2a\u80cc\u5305\uff0c\u6bcf\u4e2a\u7269\u54c1\u6709\u4e00\u5b9a\u7684\u4ef7\u503c\u548c\u91cd\u91cf\uff0c\u8981\u6c42\u5728\u80cc\u5305\u5bb9\u91cf\u9650\u5236\u5185\uff0c\u9009\u62e9\u7269\u54c1\u4f7f\u5f97\u603b\u4ef7\u503c\u6700\u5927\u3002
        • \u65c5\u884c\u5546\u95ee\u9898\uff1a\u5728\u4e00\u4e2a\u56fe\u4e2d\uff0c\u4ece\u4e00\u4e2a\u70b9\u51fa\u53d1\uff0c\u8bbf\u95ee\u6240\u6709\u5176\u4ed6\u70b9\u6070\u597d\u4e00\u6b21\u540e\u8fd4\u56de\u8d77\u70b9\uff0c\u6c42\u6700\u77ed\u8def\u5f84\u3002
        • \u6700\u5927\u56e2\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u627e\u5230\u6700\u5927\u7684\u5b8c\u5168\u5b50\u56fe\uff0c\u5373\u5b50\u56fe\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u90fd\u6709\u8fb9\u76f8\u8fde\u3002

        \u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e\u8bb8\u591a\u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff0c\u56de\u6eaf\u4e0d\u662f\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u3002

        • 0-1 \u80cc\u5305\u95ee\u9898\u901a\u5e38\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u89e3\u51b3\uff0c\u4ee5\u8fbe\u5230\u66f4\u9ad8\u7684\u65f6\u95f4\u6548\u7387\u3002
        • \u65c5\u884c\u5546\u662f\u4e00\u4e2a\u8457\u540d\u7684 NP-Hard \u95ee\u9898\uff0c\u5e38\u7528\u89e3\u6cd5\u6709\u9057\u4f20\u7b97\u6cd5\u548c\u8681\u7fa4\u7b97\u6cd5\u7b49\u3002
        • \u6700\u5927\u56e2\u95ee\u9898\u662f\u56fe\u8bba\u4e2d\u7684\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\uff0c\u53ef\u7528\u8d2a\u5fc3\u7b97\u6cd5\u7b49\u542f\u53d1\u5f0f\u7b97\u6cd5\u6765\u89e3\u51b3\u3002
        "},{"location":"chapter_backtracking/n_queens_problem/","title":"13.4 \u00a0 N \u7687\u540e\u95ee\u9898","text":"

        Question

        \u6839\u636e\u56fd\u9645\u8c61\u68cb\u7684\u89c4\u5219\uff0c\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u4e0e\u540c\u5904\u4e00\u884c\u3001\u4e00\u5217\u6216\u4e00\u6761\u659c\u7ebf\u4e0a\u7684\u68cb\u5b50\u3002\u7ed9\u5b9a \\(n\\) \u4e2a\u7687\u540e\u548c\u4e00\u4e2a \\(n \\times n\\) \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5bfb\u627e\u4f7f\u5f97\u6240\u6709\u7687\u540e\u4e4b\u95f4\u65e0\u6cd5\u76f8\u4e92\u653b\u51fb\u7684\u6446\u653e\u65b9\u6848\u3002

        \u5982\u56fe 13-15 \u6240\u793a\uff0c\u5f53 \\(n = 4\\) \u65f6\uff0c\u5171\u53ef\u4ee5\u627e\u5230\u4e24\u4e2a\u89e3\u3002\u4ece\u56de\u6eaf\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\\(n \\times n\\) \u5927\u5c0f\u7684\u68cb\u76d8\u5171\u6709 \\(n^2\\) \u4e2a\u683c\u5b50\uff0c\u7ed9\u51fa\u4e86\u6240\u6709\u7684\u9009\u62e9 choices \u3002\u5728\u9010\u4e2a\u653e\u7f6e\u7687\u540e\u7684\u8fc7\u7a0b\u4e2d\uff0c\u68cb\u76d8\u72b6\u6001\u5728\u4e0d\u65ad\u5730\u53d8\u5316\uff0c\u6bcf\u4e2a\u65f6\u523b\u7684\u68cb\u76d8\u5c31\u662f\u72b6\u6001 state \u3002

        \u56fe 13-15 \u00a0 4 \u7687\u540e\u95ee\u9898\u7684\u89e3

        \u56fe 13-16 \u5c55\u793a\u4e86\u672c\u9898\u7684\u4e09\u4e2a\u7ea6\u675f\u6761\u4ef6\uff1a\u591a\u4e2a\u7687\u540e\u4e0d\u80fd\u5728\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u3001\u540c\u4e00\u5bf9\u89d2\u7ebf\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u89d2\u7ebf\u5206\u4e3a\u4e3b\u5bf9\u89d2\u7ebf \\ \u548c\u6b21\u5bf9\u89d2\u7ebf / \u4e24\u79cd\u3002

        \u56fe 13-16 \u00a0 n \u7687\u540e\u95ee\u9898\u7684\u7ea6\u675f\u6761\u4ef6

        "},{"location":"chapter_backtracking/n_queens_problem/#1","title":"1. \u00a0 \u9010\u884c\u653e\u7f6e\u7b56\u7565","text":"

        \u7687\u540e\u7684\u6570\u91cf\u548c\u68cb\u76d8\u7684\u884c\u6570\u90fd\u4e3a \\(n\\) \uff0c\u56e0\u6b64\u6211\u4eec\u5bb9\u6613\u5f97\u5230\u4e00\u4e2a\u63a8\u8bba\uff1a\u68cb\u76d8\u6bcf\u884c\u90fd\u5141\u8bb8\u4e14\u53ea\u5141\u8bb8\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u53d6\u9010\u884c\u653e\u7f6e\u7b56\u7565\uff1a\u4ece\u7b2c\u4e00\u884c\u5f00\u59cb\uff0c\u5728\u6bcf\u884c\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\uff0c\u76f4\u81f3\u6700\u540e\u4e00\u884c\u7ed3\u675f\u3002

        \u56fe 13-17 \u6240\u793a\u4e3a \\(4\\) \u7687\u540e\u95ee\u9898\u7684\u9010\u884c\u653e\u7f6e\u8fc7\u7a0b\u3002\u53d7\u753b\u5e45\u9650\u5236\uff0c\u56fe 13-17 \u4ec5\u5c55\u5f00\u4e86\u7b2c\u4e00\u884c\u7684\u5176\u4e2d\u4e00\u4e2a\u641c\u7d22\u5206\u652f\uff0c\u5e76\u4e14\u5c06\u4e0d\u6ee1\u8db3\u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u65b9\u6848\u90fd\u8fdb\u884c\u4e86\u526a\u679d\u3002

        \u56fe 13-17 \u00a0 \u9010\u884c\u653e\u7f6e\u7b56\u7565

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9010\u884c\u653e\u7f6e\u7b56\u7565\u8d77\u5230\u4e86\u526a\u679d\u7684\u4f5c\u7528\uff0c\u5b83\u907f\u514d\u4e86\u540c\u4e00\u884c\u51fa\u73b0\u591a\u4e2a\u7687\u540e\u7684\u6240\u6709\u641c\u7d22\u5206\u652f\u3002

        "},{"location":"chapter_backtracking/n_queens_problem/#2","title":"2. \u00a0 \u5217\u4e0e\u5bf9\u89d2\u7ebf\u526a\u679d","text":"

        \u4e3a\u4e86\u6ee1\u8db3\u5217\u7ea6\u675f\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u5e03\u5c14\u578b\u6570\u7ec4 cols \u8bb0\u5f55\u6bcf\u4e00\u5217\u662f\u5426\u6709\u7687\u540e\u3002\u5728\u6bcf\u6b21\u51b3\u5b9a\u653e\u7f6e\u524d\uff0c\u6211\u4eec\u901a\u8fc7 cols \u5c06\u5df2\u6709\u7687\u540e\u7684\u5217\u8fdb\u884c\u526a\u679d\uff0c\u5e76\u5728\u56de\u6eaf\u4e2d\u52a8\u6001\u66f4\u65b0 cols \u7684\u72b6\u6001\u3002

        \u90a3\u4e48\uff0c\u5982\u4f55\u5904\u7406\u5bf9\u89d2\u7ebf\u7ea6\u675f\u5462\uff1f\u8bbe\u68cb\u76d8\u4e2d\u67d0\u4e2a\u683c\u5b50\u7684\u884c\u5217\u7d22\u5f15\u4e3a \\((row, col)\\) \uff0c\u9009\u5b9a\u77e9\u9635\u4e2d\u7684\u67d0\u6761\u4e3b\u5bf9\u89d2\u7ebf\uff0c\u6211\u4eec\u53d1\u73b0\u8be5\u5bf9\u89d2\u7ebf\u4e0a\u6240\u6709\u683c\u5b50\u7684\u884c\u7d22\u5f15\u51cf\u5217\u7d22\u5f15\u90fd\u76f8\u7b49\uff0c\u5373\u5bf9\u89d2\u7ebf\u4e0a\u6240\u6709\u683c\u5b50\u7684 \\(row - col\\) \u4e3a\u6052\u5b9a\u503c\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e24\u4e2a\u683c\u5b50\u6ee1\u8db3 \\(row_1 - col_1 = row_2 - col_2\\) \uff0c\u5219\u5b83\u4eec\u4e00\u5b9a\u5904\u5728\u540c\u4e00\u6761\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u3002\u5229\u7528\u8be5\u89c4\u5f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u56fe 13-18 \u6240\u793a\u7684\u6570\u7ec4 diags1 \u8bb0\u5f55\u6bcf\u6761\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\u3002

        \u540c\u7406\uff0c\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u683c\u5b50\u7684 \\(row + col\\) \u662f\u6052\u5b9a\u503c\u3002\u6211\u4eec\u540c\u6837\u4e5f\u53ef\u4ee5\u501f\u52a9\u6570\u7ec4 diags2 \u6765\u5904\u7406\u6b21\u5bf9\u89d2\u7ebf\u7ea6\u675f\u3002

        \u56fe 13-18 \u00a0 \u5904\u7406\u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f

        "},{"location":"chapter_backtracking/n_queens_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u8bf7\u6ce8\u610f\uff0c\\(n\\) \u7ef4\u65b9\u9635\u4e2d \\(row - col\\) \u7684\u8303\u56f4\u662f \\([-n + 1, n - 1]\\) \uff0c\\(row + col\\) \u7684\u8303\u56f4\u662f \\([0, 2n - 2]\\) \uff0c\u6240\u4ee5\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\u7684\u6570\u91cf\u90fd\u4e3a \\(2n - 1\\) \uff0c\u5373\u6570\u7ec4 diags1 \u548c diags2 \u7684\u957f\u5ea6\u90fd\u4e3a \\(2n - 1\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig n_queens.py
        def backtrack(\nrow: int,\nn: int,\nstate: list[list[str]],\nres: list[list[list[str]]],\ncols: list[bool],\ndiags1: list[bool],\ndiags2: list[bool],\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e\"\"\"\n# \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n:\nres.append([list(row) for row in state])\nreturn\n# \u904d\u5386\u6240\u6709\u5217\nfor col in range(n):\n# \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 = row - col + n - 1\ndiag2 = row + col\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif not cols[col] and not diags1[diag1] and not diags2[diag2]:\n# \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\"\ncols[col] = diags1[diag1] = diags2[diag2] = True\n# \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2)\n# \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\"\ncols[col] = diags1[diag1] = diags2[diag2] = False\ndef n_queens(n: int) -> list[list[list[str]]]:\n\"\"\"\u6c42\u89e3 N \u7687\u540e\"\"\"\n# \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nstate = [[\"#\" for _ in range(n)] for _ in range(n)]\ncols = [False] * n  # \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\ndiags1 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\ndiags2 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nres = []\nbacktrack(0, n, state, res, cols, diags1, diags2)\nreturn res\n
        n_queens.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, vector<vector<string>> &state, vector<vector<vector<string>>> &res, vector<bool> &cols,\nvector<bool> &diags1, vector<bool> &diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nvector<vector<vector<string>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nvector<vector<string>> state(n, vector<string>(n, \"#\"));\nvector<bool> cols(n, false);           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nvector<bool> diags1(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvector<bool> diags2(2 * n - 1, false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvector<vector<vector<string>>> res;\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, List<List<String>> state, List<List<List<String>>> res,\nboolean[] cols, boolean[] diags1, boolean[] diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<String>> copyState = new ArrayList<>();\nfor (List<String> sRow : state) {\ncopyState.add(new ArrayList<>(sRow));\n}\nres.add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate.get(row).set(col, \"Q\");\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate.get(row).set(col, \"#\");\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<String>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<String>> state = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nList<String> row = new ArrayList<>();\nfor (int j = 0; j < n; j++) {\nrow.add(\"#\");\n}\nstate.add(row);\n}\nboolean[] cols = new boolean[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nboolean[] diags1 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nboolean[] diags2 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<String>>> res = new ArrayList<>();\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid Backtrack(int row, int n, List<List<string>> state, List<List<List<string>>> res,\nbool[] cols, bool[] diags1, bool[] diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<string>> copyState = [];\nforeach (List<string> sRow in state) {\ncopyState.Add(new List<string>(sRow));\n}\nres.Add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nBacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<string>>> NQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<string>> state = [];\nfor (int i = 0; i < n; i++) {\nList<string> row = [];\nfor (int j = 0; j < n; j++) {\nrow.Add(\"#\");\n}\nstate.Add(row);\n}\nbool[] cols = new bool[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nbool[] diags1 = new bool[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nbool[] diags2 = new bool[2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<string>>> res = [];\nBacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row, n int, state *[][]string, res *[][][]string, cols, diags1, diags2 *[]bool) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nnewState := make([][]string, len(*state))\nfor i, _ := range newState {\nnewState[i] = make([]string, len((*state)[0]))\ncopy(newState[i], (*state)[i])\n}\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col := 0; col < n; col++ {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 := row - col + n - 1\ndiag2 := row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !(*cols)[col] && !(*diags1)[diag1] && !(*diags2)[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n(*state)[row][col] = \"Q\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = true, true, true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row+1, n, state, res, cols, diags1, diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n(*state)[row][col] = \"#\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = false, false, false\n}\n}\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row, n int, state *[][]string, res *[][][]string, cols, diags1, diags2 *[]bool) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nnewState := make([][]string, len(*state))\nfor i, _ := range newState {\nnewState[i] = make([]string, len((*state)[0]))\ncopy(newState[i], (*state)[i])\n}\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col := 0; col < n; col++ {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 := row - col + n - 1\ndiag2 := row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !(*cols)[col] && !(*diags1)[diag1] && !(*diags2)[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n(*state)[row][col] = \"Q\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = true, true, true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row+1, n, state, res, cols, diags1, diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n(*state)[row][col] = \"#\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = false, false, false\n}\n}\n}\nfunc nQueens(n int) [][][]string {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nstate := make([][]string, n)\nfor i := 0; i < n; i++ {\nrow := make([]string, n)\nfor i := 0; i < n; i++ {\nrow[i] = \"#\"\n}\nstate[i] = row\n}\n// \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\ncols := make([]bool, n)\ndiags1 := make([]bool, 2*n-1)\ndiags2 := make([]bool, 2*n-1)\nres := make([][][]string, 0)\nbacktrack(0, n, &state, &res, &cols, &diags1, &diags2)\nreturn res\n}\n
        n_queens.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row: Int, n: Int, state: inout [[String]], res: inout [[[String]]], cols: inout [Bool], diags1: inout [Bool], diags2: inout [Bool]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col in 0 ..< n {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nlet diag1 = row - col + n - 1\nlet diag2 = row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !cols[col] && !diags1[diag1] && !diags2[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\"\ncols[col] = true\ndiags1[diag1] = true\ndiags2[diag2] = true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row: row + 1, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\"\ncols[col] = false\ndiags1[diag1] = false\ndiags2[diag2] = false\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunc nQueens(n: Int) -> [[[String]]] {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nvar state = Array(repeating: Array(repeating: \"#\", count: n), count: n)\nvar cols = Array(repeating: false, count: n) // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nvar diags1 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvar diags2 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvar res: [[[String]]] = []\nbacktrack(row: 0, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\nreturn res\n}\n
        n_queens.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(row, n, state, res, cols, diags1, diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row === n) {\nres.push(state.map((row) => row.slice()));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (let col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nconst diag1 = row - col + n - 1;\nconst diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunction nQueens(n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nconst state = Array.from({ length: n }, () => Array(n).fill('#'));\nconst cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nconst diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst res = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(\nrow: number,\nn: number,\nstate: string[][],\nres: string[][][],\ncols: boolean[],\ndiags1: boolean[],\ndiags2: boolean[]\n): void {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row === n) {\nres.push(state.map((row) => row.slice()));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (let col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nconst diag1 = row - col + n - 1;\nconst diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunction nQueens(n: number): string[][][] {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nconst state = Array.from({ length: n }, () => Array(n).fill('#'));\nconst cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nconst diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst res: string[][][] = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(\nint row,\nint n,\nList<List<String>> state,\nList<List<List<String>>> res,\nList<bool> cols,\nList<bool> diags1,\nList<bool> diags2,\n) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<String>> copyState = [];\nfor (List<String> sRow in state) {\ncopyState.add(List.from(sRow));\n}\nres.add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = true;\ndiags1[diag1] = true;\ndiags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = false;\ndiags1[diag1] = false;\ndiags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<String>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<String>> state = List.generate(n, (index) => List.filled(n, \"#\"));\nList<bool> cols = List.filled(n, false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nList<bool> diags1 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<bool> diags2 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<String>>> res = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfn backtrack(row: usize, n: usize, state: &mut Vec<Vec<String>>, res: &mut Vec<Vec<Vec<String>>>,\ncols: &mut [bool], diags1: &mut [bool], diags2: &mut [bool]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nlet mut copy_state: Vec<Vec<String>> = Vec::new();\nfor s_row in state.clone() {\ncopy_state.push(s_row);\n}\nres.push(copy_state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col in 0..n {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nlet diag1 = row + n - 1 - col;\nlet diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !cols[col] && !diags1[diag1] && !diags2[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate.get_mut(row).unwrap()[col] = \"Q\".into();\n(cols[col], diags1[diag1], diags2[diag2]) = (true, true, true);\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate.get_mut(row).unwrap()[col] = \"#\".into();\n(cols[col], diags1[diag1], diags2[diag2]) = (false, false, false);\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfn n_queens(n: usize) -> Vec<Vec<Vec<String>>> {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nlet mut state: Vec<Vec<String>> = Vec::new();\nfor _ in 0..n {\nlet mut row: Vec<String> = Vec::new();\nfor _ in 0..n {\nrow.push(\"#\".into());\n}\nstate.push(row);\n}\nlet mut cols = vec![false; n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nlet mut diags1 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nlet mut diags2 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nlet mut res: Vec<Vec<Vec<String>>> = Vec::new();\nbacktrack(0, n, &mut state, &mut res, &mut cols, &mut diags1, &mut diags2);\nres\n}\n
        n_queens.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, char state[MAX_SIZE][MAX_SIZE], char ***res, int *resSize, bool cols[MAX_SIZE],\nbool diags1[2 * MAX_SIZE - 1], bool diags2[2 * MAX_SIZE - 1]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nres[*resSize] = (char **)malloc(sizeof(char *) * n);\nfor (int i = 0; i < n; ++i) {\nres[*resSize][i] = (char *)malloc(sizeof(char) * (n + 1));\nstrcpy(res[*resSize][i], state[i]);\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, resSize, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nchar ***nQueens(int n, int *returnSize) {\nchar state[MAX_SIZE][MAX_SIZE];\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nfor (int i = 0; i < n; ++i) {\nfor (int j = 0; j < n; ++j) {\nstate[i][j] = '#';\n}\nstate[i][n] = '\\0';\n}\nbool cols[MAX_SIZE] = {false};           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nbool diags1[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nbool diags2[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nchar ***res = (char ***)malloc(sizeof(char **) * MAX_SIZE);\n*returnSize = 0;\nbacktrack(0, n, state, res, returnSize, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{nQueens}\n

        \u9010\u884c\u653e\u7f6e \\(n\\) \u6b21\uff0c\u8003\u8651\u5217\u7ea6\u675f\uff0c\u5219\u4ece\u7b2c\u4e00\u884c\u5230\u6700\u540e\u4e00\u884c\u5206\u522b\u6709 \\(n\\)\u3001\\(n-1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u4e2a\u9009\u62e9\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n!)\\) \u3002\u5b9e\u9645\u4e0a\uff0c\u6839\u636e\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u526a\u679d\u4e5f\u80fd\u591f\u5927\u5e45\u7f29\u5c0f\u641c\u7d22\u7a7a\u95f4\uff0c\u56e0\u800c\u641c\u7d22\u6548\u7387\u5f80\u5f80\u4f18\u4e8e\u4ee5\u4e0a\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \u6570\u7ec4 state \u4f7f\u7528 \\(O(n^2)\\) \u7a7a\u95f4\uff0c\u6570\u7ec4 cols\u3001diags1 \u548c diags2 \u7686\u4f7f\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002\u6700\u5927\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/","title":"13.2 \u00a0 \u5168\u6392\u5217\u95ee\u9898","text":"

        \u5168\u6392\u5217\u95ee\u9898\u662f\u56de\u6eaf\u7b97\u6cd5\u7684\u4e00\u4e2a\u5178\u578b\u5e94\u7528\u3002\u5b83\u7684\u5b9a\u4e49\u662f\u5728\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\uff08\u5982\u4e00\u4e2a\u6570\u7ec4\u6216\u5b57\u7b26\u4e32\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u627e\u51fa\u5176\u4e2d\u5143\u7d20\u7684\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002

        \u8868 13-2 \u5217\u4e3e\u4e86\u51e0\u4e2a\u793a\u4f8b\u6570\u636e\uff0c\u5305\u62ec\u8f93\u5165\u6570\u7ec4\u548c\u5bf9\u5e94\u7684\u6240\u6709\u6392\u5217\u3002

        \u8868 13-2 \u00a0 \u5168\u6392\u5217\u793a\u4f8b

        \u8f93\u5165\u6570\u7ec4 \u6240\u6709\u6392\u5217 \\([1]\\) \\([1]\\) \\([1, 2]\\) \\([1, 2], [2, 1]\\) \\([1, 2, 3]\\) \\([1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]\\)"},{"location":"chapter_backtracking/permutations_problem/#1321","title":"13.2.1 \u00a0 \u65e0\u76f8\u7b49\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u4e0d\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002

        \u4ece\u56de\u6eaf\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u751f\u6210\u6392\u5217\u7684\u8fc7\u7a0b\u60f3\u8c61\u6210\u4e00\u7cfb\u5217\u9009\u62e9\u7684\u7ed3\u679c\u3002\u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u4e3a \\([1, 2, 3]\\) \uff0c\u5982\u679c\u6211\u4eec\u5148\u9009\u62e9 \\(1\\) \uff0c\u518d\u9009\u62e9 \\(3\\) \uff0c\u6700\u540e\u9009\u62e9 \\(2\\) \uff0c\u5219\u83b7\u5f97\u6392\u5217 \\([1, 3, 2]\\) \u3002\u56de\u9000\u8868\u793a\u64a4\u9500\u4e00\u4e2a\u9009\u62e9\uff0c\u4e4b\u540e\u7ee7\u7eed\u5c1d\u8bd5\u5176\u4ed6\u9009\u62e9\u3002

        \u4ece\u56de\u6eaf\u4ee3\u7801\u7684\u89d2\u5ea6\u770b\uff0c\u5019\u9009\u96c6\u5408 choices \u662f\u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u72b6\u6001 state \u662f\u76f4\u81f3\u76ee\u524d\u5df2\u88ab\u9009\u62e9\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u5141\u8bb8\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u56e0\u6b64 state \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5e94\u8be5\u662f\u552f\u4e00\u7684\u3002

        \u5982\u56fe 13-5 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u641c\u7d22\u8fc7\u7a0b\u5c55\u5f00\u6210\u4e00\u68f5\u9012\u5f52\u6811\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u5f53\u524d\u72b6\u6001 state \u3002\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u7ecf\u8fc7\u4e09\u8f6e\u9009\u62e9\u540e\u5230\u8fbe\u53f6\u8282\u70b9\uff0c\u6bcf\u4e2a\u53f6\u8282\u70b9\u90fd\u5bf9\u5e94\u4e00\u4e2a\u6392\u5217\u3002

        \u56fe 13-5 \u00a0 \u5168\u6392\u5217\u7684\u9012\u5f52\u6811

        "},{"location":"chapter_backtracking/permutations_problem/#1","title":"1. \u00a0 \u91cd\u590d\u9009\u62e9\u526a\u679d","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u6bcf\u4e2a\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u6211\u4eec\u8003\u8651\u5f15\u5165\u4e00\u4e2a\u5e03\u5c14\u578b\u6570\u7ec4 selected \uff0c\u5176\u4e2d selected[i] \u8868\u793a choices[i] \u662f\u5426\u5df2\u88ab\u9009\u62e9\uff0c\u5e76\u57fa\u4e8e\u5b83\u5b9e\u73b0\u4ee5\u4e0b\u526a\u679d\u64cd\u4f5c\u3002

        • \u5728\u505a\u51fa\u9009\u62e9 choice[i] \u540e\uff0c\u6211\u4eec\u5c31\u5c06 selected[i] \u8d4b\u503c\u4e3a \\(\\text{True}\\) \uff0c\u4ee3\u8868\u5b83\u5df2\u88ab\u9009\u62e9\u3002
        • \u904d\u5386\u9009\u62e9\u5217\u8868 choices \u65f6\uff0c\u8df3\u8fc7\u6240\u6709\u5df2\u88ab\u9009\u62e9\u7684\u8282\u70b9\uff0c\u5373\u526a\u679d\u3002

        \u5982\u56fe 13-6 \u6240\u793a\uff0c\u5047\u8bbe\u6211\u4eec\u7b2c\u4e00\u8f6e\u9009\u62e9 1 \uff0c\u7b2c\u4e8c\u8f6e\u9009\u62e9 3 \uff0c\u7b2c\u4e09\u8f6e\u9009\u62e9 2 \uff0c\u5219\u9700\u8981\u5728\u7b2c\u4e8c\u8f6e\u526a\u6389\u5143\u7d20 1 \u7684\u5206\u652f\uff0c\u5728\u7b2c\u4e09\u8f6e\u526a\u6389\u5143\u7d20 1 \u548c\u5143\u7d20 3 \u7684\u5206\u652f\u3002

        \u56fe 13-6 \u00a0 \u5168\u6392\u5217\u526a\u679d\u793a\u4f8b

        \u89c2\u5bdf\u56fe 13-6 \u53d1\u73b0\uff0c\u8be5\u526a\u679d\u64cd\u4f5c\u5c06\u641c\u7d22\u7a7a\u95f4\u5927\u5c0f\u4ece \\(O(n^n)\\) \u51cf\u5c0f\u81f3 \\(O(n!)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u60f3\u6e05\u695a\u4ee5\u4e0a\u4fe1\u606f\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u6846\u67b6\u4ee3\u7801\u4e2d\u505a\u201c\u5b8c\u5f62\u586b\u7a7a\u201d\u4e86\u3002\u4e3a\u4e86\u7f29\u77ed\u6574\u4f53\u4ee3\u7801\uff0c\u6211\u4eec\u4e0d\u5355\u72ec\u5b9e\u73b0\u6846\u67b6\u4ee3\u7801\u4e2d\u7684\u5404\u4e2a\u51fd\u6570\uff0c\u800c\u662f\u5c06\u5b83\u4eec\u5c55\u5f00\u5728 backtrack() \u51fd\u6570\u4e2d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig permutations_i.py
        def backtrack(\nstate: list[int], choices: list[int], selected: list[bool], res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I\"\"\"\n# \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(state) == len(choices):\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i, choice in enumerate(choices):\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif not selected[i]:\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = True\nstate.append(choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = False\nstate.pop()\ndef permutations_i(nums: list[int]) -> list[list[int]]:\n\"\"\"\u5168\u6392\u5217 I\"\"\"\nres = []\nbacktrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\nreturn res\n
        permutations_i.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.size()) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.size(); i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push_back(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop_back();\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nvector<vector<int>> permutationsI(vector<int> nums) {\nvector<int> state;\nvector<bool> selected(nums.size(), false);\nvector<vector<int>> res;\nbacktrack(state, nums, selected, res);\nreturn res;\n}\n
        permutations_i.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.length) {\nres.add(new ArrayList<Integer>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.size() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<Integer>> permutationsI(int[] nums) {\nList<List<Integer>> res = new ArrayList<List<Integer>>();\nbacktrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\nreturn res;\n}\n
        permutations_i.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid Backtrack(List<int> state, int[] choices, bool[] selected, List<List<int>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.Count == choices.Length) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.Length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.Add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.RemoveAt(state.Count - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<int>> PermutationsI(int[] nums) {\nList<List<int>> res = [];\nBacktrack([], nums, new bool[nums.Length], res);\nreturn res;\n}\n
        permutations_i.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunc backtrackI(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(*state) == len(*choices) {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i := 0; i < len(*choices); i++ {\nchoice := (*choices)[i]\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !(*selected)[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n(*selected)[i] = true\n*state = append(*state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackI(state, choices, selected, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n(*selected)[i] = false\n*state = (*state)[:len(*state)-1]\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums []int) [][]int {\nres := make([][]int, 0)\nstate := make([]int, 0)\nselected := make([]bool, len(nums))\nbacktrackI(&state, &nums, &selected, &res)\nreturn res\n}\n
        permutations_i.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunc backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res: inout [[Int]]) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.count == choices.count {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (i, choice) in choices.enumerated() {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !selected[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true\nstate.append(choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: choices, selected: &selected, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false\nstate.removeLast()\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums: [Int]) -> [[Int]] {\nvar state: [Int] = []\nvar selected = Array(repeating: false, count: nums.count)\nvar res: [[Int]] = []\nbacktrack(state: &state, choices: nums, selected: &selected, res: &res)\nreturn res\n}\n
        permutations_i.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(state, choices, selected, res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums) {\nconst res = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_i.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(\nstate: number[],\nchoices: number[],\nselected: boolean[],\nres: number[][]\n): void {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums: number[]): number[][] {\nconst res: number[][] = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_i.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(\nList<int> state,\nList<int> choices,\nList<bool> selected,\nList<List<int>> res,\n) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length == choices.length) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.removeLast();\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<int>> permutationsI(List<int> nums) {\nList<List<int>> res = [];\nbacktrack([], nums, List.filled(nums.length, false), res);\nreturn res;\n}\n
        permutations_i.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &mut Vec<Vec<i32>>) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.len() == choices.len() {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in 0..choices.len() {\nlet choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !selected[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.len() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfn permutations_i(nums: &mut [i32]) -> Vec<Vec<i32>> {\nlet mut res = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nbacktrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\nres\n}\n
        permutations_i.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(int *state, int stateSize, int *choices, int choicesSize, bool *selected, int **res, int *resSize) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (stateSize == choicesSize) {\nres[*resSize] = (int *)malloc(choicesSize * sizeof(int));\nfor (int i = 0; i < choicesSize; i++) {\nres[*resSize][i] = state[i];\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choicesSize; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate[stateSize] = choice;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, stateSize + 1, choices, choicesSize, selected, res, resSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nint **permutationsI(int *nums, int numsSize, int *returnSize) {\nint *state = (int *)malloc(numsSize * sizeof(int));\nbool *selected = (bool *)malloc(numsSize * sizeof(bool));\nfor (int i = 0; i < numsSize; i++) {\nselected[i] = false;\n}\nint **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n*returnSize = 0;\nbacktrack(state, 0, nums, numsSize, selected, res, returnSize);\nfree(state);\nfree(selected);\nreturn res;\n}\n
        permutations_i.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{permutationsI}\n
        "},{"location":"chapter_backtracking/permutations_problem/#1322","title":"13.2.2 \u00a0 \u8003\u8651\u76f8\u7b49\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd4\u56de\u6240\u6709\u4e0d\u91cd\u590d\u7684\u6392\u5217\u3002

        \u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u4e3a \\([1, 1, 2]\\) \u3002\u4e3a\u4e86\u65b9\u4fbf\u533a\u5206\u4e24\u4e2a\u91cd\u590d\u5143\u7d20 \\(1\\) \uff0c\u6211\u4eec\u5c06\u7b2c\u4e8c\u4e2a \\(1\\) \u8bb0\u4e3a \\(\\hat{1}\\) \u3002

        \u5982\u56fe 13-7 \u6240\u793a\uff0c\u4e0a\u8ff0\u65b9\u6cd5\u751f\u6210\u7684\u6392\u5217\u6709\u4e00\u534a\u662f\u91cd\u590d\u7684\u3002

        \u56fe 13-7 \u00a0 \u91cd\u590d\u6392\u5217

        \u90a3\u4e48\u5982\u4f55\u53bb\u9664\u91cd\u590d\u7684\u6392\u5217\u5462\uff1f\u6700\u76f4\u63a5\u5730\uff0c\u8003\u8651\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\uff0c\u76f4\u63a5\u5bf9\u6392\u5217\u7ed3\u679c\u8fdb\u884c\u53bb\u91cd\u3002\u7136\u800c\u8fd9\u6837\u505a\u4e0d\u591f\u4f18\u96c5\uff0c\u56e0\u4e3a\u751f\u6210\u91cd\u590d\u6392\u5217\u7684\u641c\u7d22\u5206\u652f\u6ca1\u6709\u5fc5\u8981\uff0c\u5e94\u5f53\u63d0\u524d\u8bc6\u522b\u5e76\u526a\u679d\uff0c\u8fd9\u6837\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002

        "},{"location":"chapter_backtracking/permutations_problem/#1_1","title":"1. \u00a0 \u76f8\u7b49\u5143\u7d20\u526a\u679d","text":"

        \u89c2\u5bdf\u56fe 13-8 \uff0c\u5728\u7b2c\u4e00\u8f6e\u4e2d\uff0c\u9009\u62e9 \\(1\\) \u6216\u9009\u62e9 \\(\\hat{1}\\) \u662f\u7b49\u4ef7\u7684\uff0c\u5728\u8fd9\u4e24\u4e2a\u9009\u62e9\u4e4b\u4e0b\u751f\u6210\u7684\u6240\u6709\u6392\u5217\u90fd\u662f\u91cd\u590d\u7684\u3002\u56e0\u6b64\u5e94\u8be5\u628a \\(\\hat{1}\\) \u526a\u679d\u3002

        \u540c\u7406\uff0c\u5728\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(2\\) \u4e4b\u540e\uff0c\u7b2c\u4e8c\u8f6e\u9009\u62e9\u4e2d\u7684 \\(1\\) \u548c \\(\\hat{1}\\) \u4e5f\u4f1a\u4ea7\u751f\u91cd\u590d\u5206\u652f\uff0c\u56e0\u6b64\u4e5f\u5e94\u5c06\u7b2c\u4e8c\u8f6e\u7684 \\(\\hat{1}\\) \u526a\u679d\u3002

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u5728\u67d0\u4e00\u8f6e\u9009\u62e9\u4e2d\uff0c\u4fdd\u8bc1\u591a\u4e2a\u76f8\u7b49\u7684\u5143\u7d20\u4ec5\u88ab\u9009\u62e9\u4e00\u6b21\u3002

        \u56fe 13-8 \u00a0 \u91cd\u590d\u6392\u5217\u526a\u679d

        "},{"location":"chapter_backtracking/permutations_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5728\u4e0a\u4e00\u9898\u7684\u4ee3\u7801\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u8003\u8651\u5728\u6bcf\u4e00\u8f6e\u9009\u62e9\u4e2d\u5f00\u542f\u4e00\u4e2a\u54c8\u5e0c\u8868 duplicated \uff0c\u7528\u4e8e\u8bb0\u5f55\u8be5\u8f6e\u4e2d\u5df2\u7ecf\u5c1d\u8bd5\u8fc7\u7684\u5143\u7d20\uff0c\u5e76\u5c06\u91cd\u590d\u5143\u7d20\u526a\u679d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig permutations_ii.py
        def backtrack(\nstate: list[int], choices: list[int], selected: list[bool], res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II\"\"\"\n# \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(state) == len(choices):\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nduplicated = set[int]()\nfor i, choice in enumerate(choices):\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif not selected[i] and choice not in duplicated:\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice)  # \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = True\nstate.append(choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = False\nstate.pop()\ndef permutations_ii(nums: list[int]) -> list[list[int]]:\n\"\"\"\u5168\u6392\u5217 II\"\"\"\nres = []\nbacktrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\nreturn res\n
        permutations_ii.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.size()) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nunordered_set<int> duplicated;\nfor (int i = 0; i < choices.size(); i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && duplicated.find(choice) == duplicated.end()) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.emplace(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push_back(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop_back();\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nvector<vector<int>> permutationsII(vector<int> nums) {\nvector<int> state;\nvector<bool> selected(nums.size(), false);\nvector<vector<int>> res;\nbacktrack(state, nums, selected, res);\nreturn res;\n}\n
        permutations_ii.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.length) {\nres.add(new ArrayList<Integer>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nSet<Integer> duplicated = new HashSet<Integer>();\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.size() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<Integer>> permutationsII(int[] nums) {\nList<List<Integer>> res = new ArrayList<List<Integer>>();\nbacktrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\nreturn res;\n}\n
        permutations_ii.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid Backtrack(List<int> state, int[] choices, bool[] selected, List<List<int>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.Count == choices.Length) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nHashSet<int> duplicated = [];\nfor (int i = 0; i < choices.Length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.Contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.Add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.Add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.RemoveAt(state.Count - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<int>> PermutationsII(int[] nums) {\nList<List<int>> res = [];\nBacktrack([], nums, new bool[nums.Length], res);\nreturn res;\n}\n
        permutations_ii.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunc backtrackII(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(*state) == len(*choices) {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nduplicated := make(map[int]struct{}, 0)\nfor i := 0; i < len(*choices); i++ {\nchoice := (*choices)[i]\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif _, ok := duplicated[choice]; !ok && !(*selected)[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n// \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nduplicated[choice] = struct{}{}\n(*selected)[i] = true\n*state = append(*state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackI(state, choices, selected, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n(*selected)[i] = false\n*state = (*state)[:len(*state)-1]\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums []int) [][]int {\nres := make([][]int, 0)\nstate := make([]int, 0)\nselected := make([]bool, len(nums))\nbacktrackII(&state, &nums, &selected, &res)\nreturn res\n}\n
        permutations_ii.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunc backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res: inout [[Int]]) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.count == choices.count {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nvar duplicated: Set<Int> = []\nfor (i, choice) in choices.enumerated() {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif !selected[i], !duplicated.contains(choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.insert(choice) // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true\nstate.append(choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: choices, selected: &selected, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false\nstate.removeLast()\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums: [Int]) -> [[Int]] {\nvar state: [Int] = []\nvar selected = Array(repeating: false, count: nums.count)\nvar res: [[Int]] = []\nbacktrack(state: &state, choices: nums, selected: &selected, res: &res)\nreturn res\n}\n
        permutations_ii.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(state, choices, selected, res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nconst duplicated = new Set();\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.has(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums) {\nconst res = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_ii.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(\nstate: number[],\nchoices: number[],\nselected: boolean[],\nres: number[][]\n): void {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nconst duplicated = new Set();\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.has(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums: number[]): number[][] {\nconst res: number[][] = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_ii.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(\nList<int> state,\nList<int> choices,\nList<bool> selected,\nList<List<int>> res,\n) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length == choices.length) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nSet<int> duplicated = {};\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.removeLast();\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<int>> permutationsII(List<int> nums) {\nList<List<int>> res = [];\nbacktrack([], nums, List.filled(nums.length, false), res);\nreturn res;\n}\n
        permutations_ii.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &mut Vec<Vec<i32>>) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.len() == choices.len() {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nlet mut duplicated = HashSet::<i32>::new();\nfor i in 0..choices.len() {\nlet choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif !selected[i] && !duplicated.contains(&choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.insert(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.len() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfn permutations_ii(nums: &mut [i32]) -> Vec<Vec<i32>> {\nlet mut res = Vec::new();\nbacktrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\nres\n}\n
        permutations_ii.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(int *state, int stateSize, int *choices, int choicesSize, bool *selected, int **res, int *resSize) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (stateSize == choicesSize) {\nres[*resSize] = (int *)malloc(choicesSize * sizeof(int));\nfor (int i = 0; i < choicesSize; i++) {\nres[*resSize][i] = state[i];\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nbool duplicated[MAX_SIZE] = {false};\nfor (int i = 0; i < choicesSize; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated[choice]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated[choice] = true; // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate[stateSize] = choice;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, stateSize + 1, choices, choicesSize, selected, res, resSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nint **permutationsII(int *nums, int numsSize, int *returnSize) {\nint *state = (int *)malloc(numsSize * sizeof(int));\nbool *selected = (bool *)malloc(numsSize * sizeof(bool));\nfor (int i = 0; i < numsSize; i++) {\nselected[i] = false;\n}\nint **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n*returnSize = 0;\nbacktrack(state, 0, nums, numsSize, selected, res, returnSize);\nfree(state);\nfree(selected);\nreturn res;\n}\n
        permutations_ii.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{permutationsII}\n

        \u5047\u8bbe\u5143\u7d20\u4e24\u4e24\u4e4b\u95f4\u4e92\u4e0d\u76f8\u540c\uff0c\u5219 \\(n\\) \u4e2a\u5143\u7d20\u5171\u6709 \\(n!\\) \u79cd\u6392\u5217\uff08\u9636\u4e58\uff09\uff1b\u5728\u8bb0\u5f55\u7ed3\u679c\u65f6\uff0c\u9700\u8981\u590d\u5236\u957f\u5ea6\u4e3a \\(n\\) \u7684\u5217\u8868\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n!n)\\) \u3002

        \u6700\u5927\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002selected \u4f7f\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002\u540c\u4e00\u65f6\u523b\u6700\u591a\u5171\u6709 \\(n\\) \u4e2a duplicated \uff0c\u4f7f\u7528 \\(O(n^2)\\) \u7a7a\u95f4\u3002\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/#3","title":"3. \u00a0 \u4e24\u79cd\u526a\u679d\u5bf9\u6bd4","text":"

        \u8bf7\u6ce8\u610f\uff0c\u867d\u7136 selected \u548c duplicated \u90fd\u7528\u4e8e\u526a\u679d\uff0c\u4f46\u4e24\u8005\u7684\u76ee\u6807\u4e0d\u540c\u3002

        • \u91cd\u590d\u9009\u62e9\u526a\u679d\uff1a\u6574\u4e2a\u641c\u7d22\u8fc7\u7a0b\u4e2d\u53ea\u6709\u4e00\u4e2a selected \u3002\u5b83\u8bb0\u5f55\u7684\u662f\u5f53\u524d\u72b6\u6001\u4e2d\u5305\u542b\u54ea\u4e9b\u5143\u7d20\uff0c\u5176\u4f5c\u7528\u662f\u9632\u6b62 choices \u4e2d\u7684\u4efb\u4e00\u5143\u7d20\u5728 state \u4e2d\u91cd\u590d\u51fa\u73b0\u3002
        • \u76f8\u7b49\u5143\u7d20\u526a\u679d\uff1a\u6bcf\u8f6e\u9009\u62e9\uff08\u6bcf\u4e2a\u8c03\u7528\u7684 backtrack \u51fd\u6570\uff09\u90fd\u5305\u542b\u4e00\u4e2a duplicated \u3002\u5b83\u8bb0\u5f55\u7684\u662f\u5728\u672c\u8f6e\u904d\u5386\uff08for \u5faa\u73af\uff09\u4e2d\u54ea\u4e9b\u5143\u7d20\u5df2\u88ab\u9009\u62e9\u8fc7\uff0c\u5176\u4f5c\u7528\u662f\u4fdd\u8bc1\u76f8\u7b49\u7684\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\u3002

        \u56fe 13-9 \u5c55\u793a\u4e86\u4e24\u4e2a\u526a\u679d\u6761\u4ef6\u7684\u751f\u6548\u8303\u56f4\u3002\u6ce8\u610f\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u9009\u62e9\uff0c\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u7684\u5404\u4e2a\u8282\u70b9\u6784\u6210\u4e00\u4e2a\u6392\u5217\u3002

        \u56fe 13-9 \u00a0 \u4e24\u79cd\u526a\u679d\u6761\u4ef6\u7684\u4f5c\u7528\u8303\u56f4

        "},{"location":"chapter_backtracking/subset_sum_problem/","title":"13.3 \u00a0 \u5b50\u96c6\u548c\u95ee\u9898","text":""},{"location":"chapter_backtracking/subset_sum_problem/#1331","title":"13.3.1 \u00a0 \u65e0\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u6b63\u6574\u6570 target \uff0c\u8bf7\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\uff0c\u4f7f\u5f97\u7ec4\u5408\u4e2d\u7684\u5143\u7d20\u548c\u7b49\u4e8e target \u3002\u7ed9\u5b9a\u6570\u7ec4\u65e0\u91cd\u590d\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u88ab\u9009\u53d6\u591a\u6b21\u3002\u8bf7\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\uff0c\u5217\u8868\u4e2d\u4e0d\u5e94\u5305\u542b\u91cd\u590d\u7ec4\u5408\u3002

        \u4f8b\u5982\uff0c\u8f93\u5165\u96c6\u5408 \\(\\{3, 4, 5\\}\\) \u548c\u76ee\u6807\u6574\u6570 \\(9\\) \uff0c\u89e3\u4e3a \\(\\{3, 3, 3\\}, \\{4, 5\\}\\) \u3002\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e24\u70b9\u3002

        • \u8f93\u5165\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u91cd\u590d\u9009\u53d6\u3002
        • \u5b50\u96c6\u4e0d\u533a\u5206\u5143\u7d20\u987a\u5e8f\uff0c\u6bd4\u5982 \\(\\{4, 5\\}\\) \u548c \\(\\{5, 4\\}\\) \u662f\u540c\u4e00\u4e2a\u5b50\u96c6\u3002
        "},{"location":"chapter_backtracking/subset_sum_problem/#1","title":"1. \u00a0 \u53c2\u8003\u5168\u6392\u5217\u89e3\u6cd5","text":"

        \u7c7b\u4f3c\u4e8e\u5168\u6392\u5217\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b50\u96c6\u7684\u751f\u6210\u8fc7\u7a0b\u60f3\u8c61\u6210\u4e00\u7cfb\u5217\u9009\u62e9\u7684\u7ed3\u679c\uff0c\u5e76\u5728\u9009\u62e9\u8fc7\u7a0b\u4e2d\u5b9e\u65f6\u66f4\u65b0\u201c\u5143\u7d20\u548c\u201d\uff0c\u5f53\u5143\u7d20\u548c\u7b49\u4e8e target \u65f6\uff0c\u5c31\u5c06\u5b50\u96c6\u8bb0\u5f55\u81f3\u7ed3\u679c\u5217\u8868\u3002

        \u800c\u4e0e\u5168\u6392\u5217\u95ee\u9898\u4e0d\u540c\u7684\u662f\uff0c\u672c\u9898\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u9009\u53d6\uff0c\u56e0\u6b64\u65e0\u987b\u501f\u52a9 selected \u5e03\u5c14\u5217\u8868\u6765\u8bb0\u5f55\u5143\u7d20\u662f\u5426\u5df2\u88ab\u9009\u62e9\u3002\u6211\u4eec\u53ef\u4ee5\u5bf9\u5168\u6392\u5217\u4ee3\u7801\u8fdb\u884c\u5c0f\u5e45\u4fee\u6539\uff0c\u521d\u6b65\u5f97\u5230\u89e3\u9898\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_i_naive.py
        def backtrack(\nstate: list[int],\ntarget: int,\ntotal: int,\nchoices: list[int],\nres: list[list[int]],\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in range(len(choices)):\n# \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_i_naive(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\ntotal = 0  # \u5b50\u96c6\u548c\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res)\nreturn res\n
        subset_sum_i_naive.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(vector<int> &state, int target, int total, vector<int> &choices, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (size_t i = 0; i < choices.size(); i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nvector<vector<int>> subsetSumINaive(vector<int> &nums, int target) {\nvector<int> state;       // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0;           // \u5b50\u96c6\u548c\nvector<vector<int>> res; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(List<Integer> state, int target, int total, int[] choices, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<Integer>> subsetSumINaive(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5b50\u96c6\u548c\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid Backtrack(List<int> state, int target, int total, int[] choices, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.Length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<int>> SubsetSumINaive(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5b50\u96c6\u548c\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrackSubsetSumINaive(total, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == total {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i := 0; i < len(*choices); i++ {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total+(*choices)[i] > target {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumINaive(total+(*choices)[i], target, state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\ntotal := 0              // \u5b50\u96c6\u548c\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumINaive(total, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_i_naive.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrack(state: inout [Int], target: Int, total: Int, choices: [Int], res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in stride(from: 0, to: choices.count, by: 1) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target, total: total + choices[i], choices: choices, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet total = 0 // \u5b50\u96c6\u548c\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, total: total, choices: nums, res: &res)\nreturn res\n}\n
        subset_sum_i_naive.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(state, target, total, choices, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total === target) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nconst total = 0; // \u5b50\u96c6\u548c\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\nstate: number[],\ntarget: number,\ntotal: number,\nchoices: number[],\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total === target) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nconst total = 0; // \u5b50\u96c6\u548c\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\nList<int> state,\nint target,\nint total,\nList<int> choices,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<int>> subsetSumINaive(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5143\u7d20\u548c\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfn backtrack(mut state: Vec<i32>, target: i32, total: i32, choices: &[i32], res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in 0..choices.len() {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfn subset_sum_i_naive(nums: &[i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet total = 0; // \u5b50\u96c6\u548c\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, &mut res);\nres\n}\n
        subset_sum_i_naive.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(int target, int total, int *choices, int choicesSize) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nfor (int i = 0; i < stateSize; i++) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choicesSize; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate[stateSize++] = choices[i];\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target, total + choices[i], choices, choicesSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nvoid subsetSumINaive(int *nums, int numsSize, int target) {\nresSize = 0; // \u521d\u59cb\u5316\u89e3\u7684\u6570\u91cf\u4e3a0\nbacktrack(target, 0, nums, numsSize);\n}\n
        subset_sum_i_naive.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumINaive}\n

        \u5411\u4ee5\u4e0a\u4ee3\u7801\u8f93\u5165\u6570\u7ec4 \\([3, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a \\([3, 3, 3], [4, 5], [5, 4]\\) \u3002\u867d\u7136\u6210\u529f\u627e\u51fa\u4e86\u6240\u6709\u548c\u4e3a \\(9\\) \u7684\u5b50\u96c6\uff0c\u4f46\u5176\u4e2d\u5b58\u5728\u91cd\u590d\u7684\u5b50\u96c6 \\([4, 5]\\) \u548c \\([5, 4]\\) \u3002

        \u8fd9\u662f\u56e0\u4e3a\u641c\u7d22\u8fc7\u7a0b\u662f\u533a\u5206\u9009\u62e9\u987a\u5e8f\u7684\uff0c\u7136\u800c\u5b50\u96c6\u4e0d\u533a\u5206\u9009\u62e9\u987a\u5e8f\u3002\u5982\u56fe 13-10 \u6240\u793a\uff0c\u5148\u9009 \\(4\\) \u540e\u9009 \\(5\\) \u4e0e\u5148\u9009 \\(5\\) \u540e\u9009 \\(4\\) \u662f\u4e0d\u540c\u7684\u5206\u652f\uff0c\u4f46\u5bf9\u5e94\u540c\u4e00\u4e2a\u5b50\u96c6\u3002

        \u56fe 13-10 \u00a0 \u5b50\u96c6\u641c\u7d22\u4e0e\u8d8a\u754c\u526a\u679d

        \u4e3a\u4e86\u53bb\u9664\u91cd\u590d\u5b50\u96c6\uff0c\u4e00\u79cd\u76f4\u63a5\u7684\u601d\u8def\u662f\u5bf9\u7ed3\u679c\u5217\u8868\u8fdb\u884c\u53bb\u91cd\u3002\u4f46\u8fd9\u4e2a\u65b9\u6cd5\u6548\u7387\u5f88\u4f4e\uff0c\u6709\u4e24\u65b9\u9762\u539f\u56e0\u3002

        • \u5f53\u6570\u7ec4\u5143\u7d20\u8f83\u591a\uff0c\u5c24\u5176\u662f\u5f53 target \u8f83\u5927\u65f6\uff0c\u641c\u7d22\u8fc7\u7a0b\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u91cd\u590d\u5b50\u96c6\u3002
        • \u6bd4\u8f83\u5b50\u96c6\uff08\u6570\u7ec4\uff09\u7684\u5f02\u540c\u975e\u5e38\u8017\u65f6\uff0c\u9700\u8981\u5148\u6392\u5e8f\u6570\u7ec4\uff0c\u518d\u6bd4\u8f83\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5f02\u540c\u3002
        "},{"location":"chapter_backtracking/subset_sum_problem/#2","title":"2. \u00a0 \u91cd\u590d\u5b50\u96c6\u526a\u679d","text":"

        \u6211\u4eec\u8003\u8651\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u901a\u8fc7\u526a\u679d\u8fdb\u884c\u53bb\u91cd\u3002\u89c2\u5bdf\u56fe 13-11 \uff0c\u91cd\u590d\u5b50\u96c6\u662f\u5728\u4ee5\u4e0d\u540c\u987a\u5e8f\u9009\u62e9\u6570\u7ec4\u5143\u7d20\u65f6\u4ea7\u751f\u7684\uff0c\u4f8b\u5982\u4ee5\u4e0b\u60c5\u51b5\u3002

        1. \u5f53\u7b2c\u4e00\u8f6e\u548c\u7b2c\u4e8c\u8f6e\u5206\u522b\u9009\u62e9 \\(3\\) \u548c \\(4\\) \u65f6\uff0c\u4f1a\u751f\u6210\u5305\u542b\u8fd9\u4e24\u4e2a\u5143\u7d20\u7684\u6240\u6709\u5b50\u96c6\uff0c\u8bb0\u4e3a \\([3, 4, \\dots]\\) \u3002
        2. \u4e4b\u540e\uff0c\u5f53\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(4\\) \u65f6\uff0c\u5219\u7b2c\u4e8c\u8f6e\u5e94\u8be5\u8df3\u8fc7 \\(3\\) \uff0c\u56e0\u4e3a\u8be5\u9009\u62e9\u4ea7\u751f\u7684\u5b50\u96c6 \\([4, 3, \\dots]\\) \u548c\u7b2c 1. \u6b65\u4e2d\u751f\u6210\u7684\u5b50\u96c6\u5b8c\u5168\u91cd\u590d\u3002

        \u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e00\u5c42\u7684\u9009\u62e9\u90fd\u662f\u4ece\u5de6\u5230\u53f3\u88ab\u9010\u4e2a\u5c1d\u8bd5\u7684\uff0c\u56e0\u6b64\u8d8a\u9760\u53f3\u7684\u5206\u652f\u88ab\u526a\u6389\u7684\u8d8a\u591a\u3002

        1. \u524d\u4e24\u8f6e\u9009\u62e9 \\(3\\) \u548c \\(5\\) \uff0c\u751f\u6210\u5b50\u96c6 \\([3, 5, \\dots]\\) \u3002
        2. \u524d\u4e24\u8f6e\u9009\u62e9 \\(4\\) \u548c \\(5\\) \uff0c\u751f\u6210\u5b50\u96c6 \\([4, 5, \\dots]\\) \u3002
        3. \u82e5\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(5\\) \uff0c\u5219\u7b2c\u4e8c\u8f6e\u5e94\u8be5\u8df3\u8fc7 \\(3\\) \u548c \\(4\\) \uff0c\u56e0\u4e3a\u5b50\u96c6 \\([5, 3, \\dots]\\) \u548c \\([5, 4, \\dots]\\) \u4e0e\u7b2c 1. \u6b65\u548c\u7b2c 2. \u6b65\u4e2d\u63cf\u8ff0\u7684\u5b50\u96c6\u5b8c\u5168\u91cd\u590d\u3002

        \u56fe 13-11 \u00a0 \u4e0d\u540c\u9009\u62e9\u987a\u5e8f\u5bfc\u81f4\u7684\u91cd\u590d\u5b50\u96c6

        \u603b\u7ed3\u6765\u770b\uff0c\u7ed9\u5b9a\u8f93\u5165\u6570\u7ec4 \\([x_1, x_2, \\dots, x_n]\\) \uff0c\u8bbe\u641c\u7d22\u8fc7\u7a0b\u4e2d\u7684\u9009\u62e9\u5e8f\u5217\u4e3a \\([x_{i_1}, x_{i_2}, \\dots, x_{i_m}]\\) \uff0c\u5219\u8be5\u9009\u62e9\u5e8f\u5217\u9700\u8981\u6ee1\u8db3 \\(i_1 \\leq i_2 \\leq \\dots \\leq i_m\\) \uff0c\u4e0d\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u9009\u62e9\u5e8f\u5217\u90fd\u4f1a\u9020\u6210\u91cd\u590d\uff0c\u5e94\u5f53\u526a\u679d\u3002

        "},{"location":"chapter_backtracking/subset_sum_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4e3a\u5b9e\u73b0\u8be5\u526a\u679d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u53d8\u91cf start \uff0c\u7528\u4e8e\u6307\u793a\u904d\u5386\u8d77\u59cb\u70b9\u3002\u5f53\u505a\u51fa\u9009\u62e9 \\(x_{i}\\) \u540e\uff0c\u8bbe\u5b9a\u4e0b\u4e00\u8f6e\u4ece\u7d22\u5f15 \\(i\\) \u5f00\u59cb\u904d\u5386\u3002\u8fd9\u6837\u505a\u5c31\u53ef\u4ee5\u8ba9\u9009\u62e9\u5e8f\u5217\u6ee1\u8db3 \\(i_1 \\leq i_2 \\leq \\dots \\leq i_m\\) \uff0c\u4ece\u800c\u4fdd\u8bc1\u5b50\u96c6\u552f\u4e00\u3002

        \u9664\u6b64\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u5bf9\u4ee3\u7801\u8fdb\u884c\u4e86\u4ee5\u4e0b\u4e24\u9879\u4f18\u5316\u3002

        • \u5728\u5f00\u542f\u641c\u7d22\u524d\uff0c\u5148\u5c06\u6570\u7ec4 nums \u6392\u5e8f\u3002\u5728\u904d\u5386\u6240\u6709\u9009\u62e9\u65f6\uff0c\u5f53\u5b50\u96c6\u548c\u8d85\u8fc7 target \u65f6\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\uff0c\u56e0\u4e3a\u540e\u8fb9\u7684\u5143\u7d20\u66f4\u5927\uff0c\u5176\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target \u3002
        • \u7701\u53bb\u5143\u7d20\u548c\u53d8\u91cf total \uff0c\u901a\u8fc7\u5728 target \u4e0a\u6267\u884c\u51cf\u6cd5\u6765\u7edf\u8ba1\u5143\u7d20\u548c\uff0c\u5f53 target \u7b49\u4e8e \\(0\\) \u65f6\u8bb0\u5f55\u89e3\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_i.py
        def backtrack(\nstate: list[int], target: int, choices: list[int], start: int, res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\n# \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in range(start, len(choices)):\n# \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n# \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0:\nbreak\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_i(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart = 0  # \u904d\u5386\u8d77\u59cb\u70b9\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res)\nreturn res\n
        subset_sum_i.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(vector<int> &state, int target, vector<int> &choices, int start, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.size(); i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvector<vector<int>> subsetSumI(vector<int> &nums, int target) {\nvector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\nvector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<Integer>> subsetSumI(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid Backtrack(List<int> state, int target, int[] choices, int start, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.Length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> SubsetSumI(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArray.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrackSubsetSumI(start, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i := start; i < len(*choices); i++ {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target-(*choices)[i] < 0 {\nbreak\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumI(i, target-(*choices)[i], state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart := 0              // \u904d\u5386\u8d77\u59cb\u70b9\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumI(start, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_i.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrack(state: inout [Int], target: Int, choices: [Int], start: Int, res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in stride(from: start, to: choices.count, by: 1) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target - choices[i], choices: choices, start: i, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, choices: nums, start: start, res: &res)\nreturn res\n}\n
        subset_sum_i.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(state, target, choices, start, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\nstate: number[],\ntarget: number,\nchoices: number[],\nstart: number,\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\nList<int> state,\nint target,\nList<int> choices,\nint start,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> subsetSumI(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfn backtrack(mut state: Vec<i32>, target: i32, choices: &[i32], start: usize, res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in start..choices.len() {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfn subset_sum_i(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, &mut res);\nres\n}\n
        subset_sum_i.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(int target, int *choices, int choicesSize, int start) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nfor (int i = 0; i < stateSize; ++i) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choicesSize; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate[stateSize] = choices[i];\nstateSize++;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target - choices[i], choices, choicesSize, i);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvoid subsetSumI(int *nums, int numsSize, int target) {\nqsort(nums, numsSize, sizeof(int), cmp); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                           // \u904d\u5386\u8d77\u59cb\u70b9\nbacktrack(target, nums, numsSize, start);\n}\n
        subset_sum_i.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumI}\n

        \u56fe 13-12 \u6240\u793a\u4e3a\u5c06\u6570\u7ec4 \\([3, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \u8f93\u5165\u4ee5\u4e0a\u4ee3\u7801\u540e\u7684\u6574\u4f53\u56de\u6eaf\u8fc7\u7a0b\u3002

        \u56fe 13-12 \u00a0 \u5b50\u96c6\u548c I \u56de\u6eaf\u8fc7\u7a0b

        "},{"location":"chapter_backtracking/subset_sum_problem/#1332","title":"13.3.2 \u00a0 \u8003\u8651\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u6b63\u6574\u6570 target \uff0c\u8bf7\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\uff0c\u4f7f\u5f97\u7ec4\u5408\u4e2d\u7684\u5143\u7d20\u548c\u7b49\u4e8e target \u3002\u7ed9\u5b9a\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u53ef\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u8bf7\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\uff0c\u5217\u8868\u4e2d\u4e0d\u5e94\u5305\u542b\u91cd\u590d\u7ec4\u5408\u3002

        \u76f8\u6bd4\u4e8e\u4e0a\u9898\uff0c\u672c\u9898\u7684\u8f93\u5165\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd9\u5f15\u5165\u4e86\u65b0\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u7ed9\u5b9a\u6570\u7ec4 \\([4, \\hat{4}, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \uff0c\u5219\u73b0\u6709\u4ee3\u7801\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a \\([4, 5], [\\hat{4}, 5]\\) \uff0c\u51fa\u73b0\u4e86\u91cd\u590d\u5b50\u96c6\u3002

        \u9020\u6210\u8fd9\u79cd\u91cd\u590d\u7684\u539f\u56e0\u662f\u76f8\u7b49\u5143\u7d20\u5728\u67d0\u8f6e\u4e2d\u88ab\u591a\u6b21\u9009\u62e9\u3002\u5728\u56fe 13-13 \u4e2d\uff0c\u7b2c\u4e00\u8f6e\u5171\u6709\u4e09\u4e2a\u9009\u62e9\uff0c\u5176\u4e2d\u4e24\u4e2a\u90fd\u4e3a \\(4\\) \uff0c\u4f1a\u4ea7\u751f\u4e24\u4e2a\u91cd\u590d\u7684\u641c\u7d22\u5206\u652f\uff0c\u4ece\u800c\u8f93\u51fa\u91cd\u590d\u5b50\u96c6\uff1b\u540c\u7406\uff0c\u7b2c\u4e8c\u8f6e\u7684\u4e24\u4e2a \\(4\\) \u4e5f\u4f1a\u4ea7\u751f\u91cd\u590d\u5b50\u96c6\u3002

        \u56fe 13-13 \u00a0 \u76f8\u7b49\u5143\u7d20\u5bfc\u81f4\u7684\u91cd\u590d\u5b50\u96c6

        "},{"location":"chapter_backtracking/subset_sum_problem/#1_1","title":"1. \u00a0 \u76f8\u7b49\u5143\u7d20\u526a\u679d","text":"

        \u4e3a\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u9650\u5236\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u4e00\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u5b9e\u73b0\u65b9\u5f0f\u6bd4\u8f83\u5de7\u5999\uff1a\u7531\u4e8e\u6570\u7ec4\u662f\u5df2\u6392\u5e8f\u7684\uff0c\u56e0\u6b64\u76f8\u7b49\u5143\u7d20\u90fd\u662f\u76f8\u90bb\u7684\u3002\u8fd9\u610f\u5473\u7740\u5728\u67d0\u8f6e\u9009\u62e9\u4e2d\uff0c\u82e5\u5f53\u524d\u5143\u7d20\u4e0e\u5176\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u8bf4\u660e\u5b83\u5df2\u7ecf\u88ab\u9009\u62e9\u8fc7\uff0c\u56e0\u6b64\u76f4\u63a5\u8df3\u8fc7\u5f53\u524d\u5143\u7d20\u3002

        \u4e0e\u6b64\u540c\u65f6\uff0c\u672c\u9898\u89c4\u5b9a\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5229\u7528\u53d8\u91cf start \u6765\u6ee1\u8db3\u8be5\u7ea6\u675f\uff1a\u5f53\u505a\u51fa\u9009\u62e9 \\(x_{i}\\) \u540e\uff0c\u8bbe\u5b9a\u4e0b\u4e00\u8f6e\u4ece\u7d22\u5f15 \\(i + 1\\) \u5f00\u59cb\u5411\u540e\u904d\u5386\u3002\u8fd9\u6837\u65e2\u80fd\u53bb\u9664\u91cd\u590d\u5b50\u96c6\uff0c\u4e5f\u80fd\u907f\u514d\u91cd\u590d\u9009\u62e9\u5143\u7d20\u3002

        "},{"location":"chapter_backtracking/subset_sum_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_ii.py
        def backtrack(\nstate: list[int], target: int, choices: list[int], start: int, res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\n# \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n# \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in range(start, len(choices)):\n# \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n# \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0:\nbreak\n# \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start and choices[i] == choices[i - 1]:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_ii(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c II\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart = 0  # \u904d\u5386\u8d77\u59cb\u70b9\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res)\nreturn res\n
        subset_sum_ii.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(vector<int> &state, int target, vector<int> &choices, int start, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.size(); i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvector<vector<int>> subsetSumII(vector<int> &nums, int target) {\nvector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\nvector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<Integer>> subsetSumII(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid Backtrack(List<int> state, int target, int[] choices, int start, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.Length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> SubsetSumII(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArray.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunc backtrackSubsetSumII(start, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i := start; i < len(*choices); i++ {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target-(*choices)[i] < 0 {\nbreak\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start && (*choices)[i] == (*choices)[i-1] {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumII(i+1, target-(*choices)[i], state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart := 0              // \u904d\u5386\u8d77\u59cb\u70b9\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumII(start, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_ii.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunc backtrack(state: inout [Int], target: Int, choices: [Int], start: Int, res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in stride(from: start, to: choices.count, by: 1) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start, choices[i] == choices[i - 1] {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target - choices[i], choices: choices, start: i + 1, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, choices: nums, start: start, res: &res)\nreturn res\n}\n
        subset_sum_ii.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(state, target, choices, start, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] === choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(\nstate: number[],\ntarget: number,\nchoices: number[],\nstart: number,\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] === choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(\nList<int> state,\nint target,\nList<int> choices,\nint start,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> subsetSumII(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfn backtrack(mut state: Vec<i32>, target: i32, choices: &[i32], start: usize, res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in start..choices.len() {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start && choices[i] == choices[i - 1] {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfn subset_sum_ii(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, &mut res);\nres\n}\n
        subset_sum_ii.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(int target, int *choices, int choicesSize, int start) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nfor (int i = 0; i < stateSize; i++) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choicesSize; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\nif (target - choices[i] < 0) {\ncontinue;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate[stateSize] = choices[i];\nstateSize++;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target - choices[i], choices, choicesSize, i + 1);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvoid subsetSumII(int *nums, int numsSize, int target) {\n// \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nqsort(nums, numsSize, sizeof(int), cmp);\n// \u5f00\u59cb\u56de\u6eaf\nbacktrack(target, nums, numsSize, 0);\n}\n
        subset_sum_ii.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumII}\n

        \u56fe 13-14 \u5c55\u793a\u4e86\u6570\u7ec4 \\([4, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \u7684\u56de\u6eaf\u8fc7\u7a0b\uff0c\u5171\u5305\u542b\u56db\u79cd\u526a\u679d\u64cd\u4f5c\u3002\u8bf7\u4f60\u5c06\u56fe\u793a\u4e0e\u4ee3\u7801\u6ce8\u91ca\u76f8\u7ed3\u5408\uff0c\u7406\u89e3\u6574\u4e2a\u641c\u7d22\u8fc7\u7a0b\uff0c\u4ee5\u53ca\u6bcf\u79cd\u526a\u679d\u64cd\u4f5c\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002

        \u56fe 13-14 \u00a0 \u5b50\u96c6\u548c II \u56de\u6eaf\u8fc7\u7a0b

        "},{"location":"chapter_backtracking/summary/","title":"13.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_backtracking/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u56de\u6eaf\u7b97\u6cd5\u672c\u8d28\u662f\u7a77\u4e3e\u6cd5\uff0c\u901a\u8fc7\u5bf9\u89e3\u7a7a\u95f4\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u6765\u5bfb\u627e\u7b26\u5408\u6761\u4ef6\u7684\u89e3\u3002\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u9047\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u5219\u8bb0\u5f55\uff0c\u76f4\u81f3\u627e\u5230\u6240\u6709\u89e3\u6216\u904d\u5386\u5b8c\u6210\u540e\u7ed3\u675f\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u7684\u641c\u7d22\u8fc7\u7a0b\u5305\u62ec\u5c1d\u8bd5\u4e0e\u56de\u9000\u4e24\u4e2a\u90e8\u5206\u3002\u5b83\u901a\u8fc7\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u6765\u5c1d\u8bd5\u5404\u79cd\u9009\u62e9\uff0c\u5f53\u9047\u5230\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u60c5\u51b5\u65f6\uff0c\u5219\u64a4\u9500\u4e0a\u4e00\u6b65\u7684\u9009\u62e9\uff0c\u9000\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5e76\u7ee7\u7eed\u5c1d\u8bd5\u5176\u4ed6\u9009\u62e9\u3002\u5c1d\u8bd5\u4e0e\u56de\u9000\u662f\u4e24\u4e2a\u65b9\u5411\u76f8\u53cd\u7684\u64cd\u4f5c\u3002
        • \u56de\u6eaf\u95ee\u9898\u901a\u5e38\u5305\u542b\u591a\u4e2a\u7ea6\u675f\u6761\u4ef6\uff0c\u5b83\u4eec\u53ef\u7528\u4e8e\u5b9e\u73b0\u526a\u679d\u64cd\u4f5c\u3002\u526a\u679d\u53ef\u4ee5\u63d0\u524d\u7ed3\u675f\u4e0d\u5fc5\u8981\u7684\u641c\u7d22\u5206\u652f\uff0c\u5927\u5e45\u63d0\u5347\u641c\u7d22\u6548\u7387\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u4e3b\u8981\u53ef\u7528\u4e8e\u89e3\u51b3\u641c\u7d22\u95ee\u9898\u548c\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u3002\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u867d\u7136\u53ef\u4ee5\u7528\u56de\u6eaf\u7b97\u6cd5\u89e3\u51b3\uff0c\u4f46\u5f80\u5f80\u5b58\u5728\u6548\u7387\u66f4\u9ad8\u6216\u6548\u679c\u66f4\u597d\u7684\u89e3\u6cd5\u3002
        • \u5168\u6392\u5217\u95ee\u9898\u65e8\u5728\u641c\u7d22\u7ed9\u5b9a\u96c6\u5408\u5143\u7d20\u7684\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u6570\u7ec4\u6765\u8bb0\u5f55\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u88ab\u9009\u62e9\uff0c\u526a\u6389\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\u7684\u641c\u7d22\u5206\u652f\uff0c\u786e\u4fdd\u6bcf\u4e2a\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\u3002
        • \u5728\u5168\u6392\u5217\u95ee\u9898\u4e2d\uff0c\u5982\u679c\u96c6\u5408\u4e2d\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff0c\u5219\u6700\u7ec8\u7ed3\u679c\u4f1a\u51fa\u73b0\u91cd\u590d\u6392\u5217\u3002\u6211\u4eec\u9700\u8981\u7ea6\u675f\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u8fd9\u901a\u5e38\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\u6765\u5b9e\u73b0\u3002
        • \u5b50\u96c6\u548c\u95ee\u9898\u7684\u76ee\u6807\u662f\u5728\u7ed9\u5b9a\u96c6\u5408\u4e2d\u627e\u5230\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6240\u6709\u5b50\u96c6\u3002\u96c6\u5408\u4e0d\u533a\u5206\u5143\u7d20\u987a\u5e8f\uff0c\u800c\u641c\u7d22\u8fc7\u7a0b\u4f1a\u8f93\u51fa\u6240\u6709\u987a\u5e8f\u7684\u7ed3\u679c\uff0c\u4ea7\u751f\u91cd\u590d\u5b50\u96c6\u3002\u6211\u4eec\u5728\u56de\u6eaf\u524d\u5c06\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e2a\u53d8\u91cf\u6765\u6307\u793a\u6bcf\u4e00\u8f6e\u7684\u904d\u5386\u8d77\u59cb\u70b9\uff0c\u4ece\u800c\u5c06\u751f\u6210\u91cd\u590d\u5b50\u96c6\u7684\u641c\u7d22\u5206\u652f\u8fdb\u884c\u526a\u679d\u3002
        • \u5bf9\u4e8e\u5b50\u96c6\u548c\u95ee\u9898\uff0c\u6570\u7ec4\u4e2d\u7684\u76f8\u7b49\u5143\u7d20\u4f1a\u4ea7\u751f\u91cd\u590d\u96c6\u5408\u3002\u6211\u4eec\u5229\u7528\u6570\u7ec4\u5df2\u6392\u5e8f\u7684\u524d\u7f6e\u6761\u4ef6\uff0c\u901a\u8fc7\u5224\u65ad\u76f8\u90bb\u5143\u7d20\u662f\u5426\u76f8\u7b49\u5b9e\u73b0\u526a\u679d\uff0c\u4ece\u800c\u786e\u4fdd\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u4e2d\u4e00\u6b21\u3002
        • \\(n\\) \u7687\u540e\u95ee\u9898\u65e8\u5728\u5bfb\u627e\u5c06 \\(n\\) \u4e2a\u7687\u540e\u653e\u7f6e\u5230 \\(n \\times n\\) \u5c3a\u5bf8\u68cb\u76d8\u4e0a\u7684\u65b9\u6848\uff0c\u8981\u6c42\u6240\u6709\u7687\u540e\u4e24\u4e24\u4e4b\u95f4\u65e0\u6cd5\u653b\u51fb\u5bf9\u65b9\u3002\u8be5\u95ee\u9898\u7684\u7ea6\u675f\u6761\u4ef6\u6709\u884c\u7ea6\u675f\u3001\u5217\u7ea6\u675f\u3001\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\u7ea6\u675f\u3002\u4e3a\u6ee1\u8db3\u884c\u7ea6\u675f\uff0c\u6211\u4eec\u91c7\u7528\u6309\u884c\u653e\u7f6e\u7684\u7b56\u7565\uff0c\u4fdd\u8bc1\u6bcf\u4e00\u884c\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\u3002
        • \u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\u3002\u5bf9\u4e8e\u5217\u7ea6\u675f\uff0c\u6211\u4eec\u5229\u7528\u4e00\u4e2a\u6570\u7ec4\u6765\u8bb0\u5f55\u6bcf\u4e00\u5217\u662f\u5426\u6709\u7687\u540e\uff0c\u4ece\u800c\u6307\u793a\u9009\u4e2d\u7684\u683c\u5b50\u662f\u5426\u5408\u6cd5\u3002\u5bf9\u4e8e\u5bf9\u89d2\u7ebf\u7ea6\u675f\uff0c\u6211\u4eec\u501f\u52a9\u4e24\u4e2a\u6570\u7ec4\u6765\u5206\u522b\u8bb0\u5f55\u8be5\u4e3b\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u5b58\u5728\u7687\u540e\uff1b\u96be\u70b9\u5728\u4e8e\u627e\u5904\u5728\u5230\u540c\u4e00\u4e3b\uff08\u526f\uff09\u5bf9\u89d2\u7ebf\u4e0a\u683c\u5b50\u6ee1\u8db3\u7684\u884c\u5217\u7d22\u5f15\u89c4\u5f8b\u3002
        "},{"location":"chapter_backtracking/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u600e\u4e48\u7406\u89e3\u56de\u6eaf\u548c\u9012\u5f52\u7684\u5173\u7cfb\uff1f

        \u603b\u7684\u6765\u770b\uff0c\u56de\u6eaf\u662f\u4e00\u79cd\u201c\u7b97\u6cd5\u7b56\u7565\u201d\uff0c\u800c\u9012\u5f52\u66f4\u50cf\u662f\u4e00\u4e2a\u201c\u5de5\u5177\u201d\u3002

        • \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\u3002\u7136\u800c\uff0c\u56de\u6eaf\u662f\u9012\u5f52\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\uff0c\u662f\u9012\u5f52\u5728\u641c\u7d22\u95ee\u9898\u4e2d\u7684\u5e94\u7528\u3002
        • \u9012\u5f52\u7684\u7ed3\u6784\u4f53\u73b0\u4e86\u201c\u5b50\u95ee\u9898\u5206\u89e3\u201d\u7684\u89e3\u9898\u8303\u5f0f\uff0c\u5e38\u7528\u4e8e\u89e3\u51b3\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\uff08\u8bb0\u5fc6\u5316\u9012\u5f52\uff09\u7b49\u95ee\u9898\u3002
        "},{"location":"chapter_computational_complexity/","title":"\u7b2c 2 \u7ae0 \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        Abstract

        \u590d\u6742\u5ea6\u5206\u6790\u72b9\u5982\u6d69\u701a\u7684\u7b97\u6cd5\u5b87\u5b99\u4e2d\u7684\u65f6\u7a7a\u5411\u5bfc\u3002

        \u5b83\u5e26\u9886\u6211\u4eec\u5728\u65f6\u95f4\u4e0e\u7a7a\u95f4\u8fd9\u4e24\u4e2a\u7ef4\u5ea6\u4e0a\u6df1\u5165\u63a2\u7d22\uff0c\u5bfb\u627e\u66f4\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\u3002

        "},{"location":"chapter_computational_complexity/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 2.1 \u00a0 \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30
        • 2.2 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52
        • 2.3 \u00a0 \u65f6\u95f4\u590d\u6742\u5ea6
        • 2.4 \u00a0 \u7a7a\u95f4\u590d\u6742\u5ea6
        • 2.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/","title":"2.2 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52","text":"

        \u5728\u7b97\u6cd5\u4e2d\uff0c\u91cd\u590d\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u662f\u5f88\u5e38\u89c1\u7684\uff0c\u5176\u4e0e\u590d\u6742\u5ea6\u5206\u6790\u606f\u606f\u76f8\u5173\u3002\u56e0\u6b64\uff0c\u5728\u5c55\u5f00\u4ecb\u7ecd\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u4e86\u89e3\u5982\u4f55\u5728\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u91cd\u590d\u6267\u884c\u4efb\u52a1\uff0c\u5373\u4e24\u79cd\u57fa\u672c\u7684\u7a0b\u5e8f\u63a7\u5236\u7ed3\u6784\uff1a\u8fed\u4ee3\u3001\u9012\u5f52\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#221","title":"2.2.1 \u00a0 \u8fed\u4ee3","text":"

        \u300c\u8fed\u4ee3 iteration\u300d\u662f\u4e00\u79cd\u91cd\u590d\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u7684\u63a7\u5236\u7ed3\u6784\u3002\u5728\u8fed\u4ee3\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u5728\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\u4e0b\u91cd\u590d\u6267\u884c\u67d0\u6bb5\u4ee3\u7801\uff0c\u76f4\u5230\u8fd9\u4e2a\u6761\u4ef6\u4e0d\u518d\u6ee1\u8db3\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#1-for","title":"1. \u00a0 for \u5faa\u73af","text":"

        for \u5faa\u73af\u662f\u6700\u5e38\u89c1\u7684\u8fed\u4ee3\u5f62\u5f0f\u4e4b\u4e00\uff0c\u9002\u5408\u5728\u9884\u5148\u77e5\u9053\u8fed\u4ee3\u6b21\u6570\u65f6\u4f7f\u7528\u3002

        \u4ee5\u4e0b\u51fd\u6570\u57fa\u4e8e for \u5faa\u73af\u5b9e\u73b0\u4e86\u6c42\u548c \\(1 + 2 + \\dots + n\\) \uff0c\u6c42\u548c\u7ed3\u679c\u4f7f\u7528\u53d8\u91cf res \u8bb0\u5f55\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPython \u4e2d range(a, b) \u5bf9\u5e94\u7684\u533a\u95f4\u662f\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u7684\uff0c\u5bf9\u5e94\u7684\u904d\u5386\u8303\u56f4\u4e3a \\(a, a + 1, \\dots, b-1\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def for_loop(n: int) -> int:\n\"\"\"for \u5faa\u73af\"\"\"\nres = 0\n# \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in range(1, n + 1):\nres += i\nreturn res\n
        iteration.cpp
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; ++i) {\nres += i;\n}\nreturn res;\n}\n
        iteration.java
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.cs
        /* for \u5faa\u73af */\nint ForLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.go
        /* for \u5faa\u73af */\nfunc forLoop(n int) int {\nres := 0\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i := 1; i <= n; i++ {\nres += i\n}\nreturn res\n}\n
        iteration.swift
        /* for \u5faa\u73af */\nfunc forLoop(n: Int) -> Int {\nvar res = 0\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in 1 ... n {\nres += i\n}\nreturn res\n}\n
        iteration.js
        /* for \u5faa\u73af */\nfunction forLoop(n) {\nlet res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.ts
        /* for \u5faa\u73af */\nfunction forLoop(n: number): number {\nlet res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.dart
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.rs
        /* for \u5faa\u73af */\nfn for_loop(n: i32) -> i32 {\nlet mut res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in 1..=n {\nres += i;\n}\nres\n} 
        iteration.c
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.zig
        // for \u5faa\u73af\nfn forLoop(n: usize) i32 {\nvar res: i32 = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (1..n+1) |i| {\nres = res + @as(i32, @intCast(i));\n}\nreturn res;\n} 

        \u56fe 2-1 \u662f\u8be5\u6c42\u548c\u51fd\u6570\u7684\u6d41\u7a0b\u6846\u56fe\u3002

        \u56fe 2-1 \u00a0 \u6c42\u548c\u51fd\u6570\u7684\u6d41\u7a0b\u6846\u56fe

        \u6b64\u6c42\u548c\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u6210\u6b63\u6bd4\uff0c\u6216\u8005\u8bf4\u6210\u201c\u7ebf\u6027\u5173\u7cfb\u201d\u3002\u5b9e\u9645\u4e0a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u63cf\u8ff0\u7684\u5c31\u662f\u8fd9\u4e2a\u201c\u7ebf\u6027\u5173\u7cfb\u201d\u3002\u76f8\u5173\u5185\u5bb9\u5c06\u4f1a\u5728\u4e0b\u4e00\u8282\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#2-while","title":"2. \u00a0 while \u5faa\u73af","text":"

        \u4e0e for \u5faa\u73af\u7c7b\u4f3c\uff0cwhile \u5faa\u73af\u4e5f\u662f\u4e00\u79cd\u5b9e\u73b0\u8fed\u4ee3\u7684\u65b9\u6cd5\u3002\u5728 while \u5faa\u73af\u4e2d\uff0c\u7a0b\u5e8f\u6bcf\u8f6e\u90fd\u4f1a\u5148\u68c0\u67e5\u6761\u4ef6\uff0c\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u7ee7\u7eed\u6267\u884c\uff0c\u5426\u5219\u5c31\u7ed3\u675f\u5faa\u73af\u3002

        \u4e0b\u9762\u6211\u4eec\u7528 while \u5faa\u73af\u6765\u5b9e\u73b0\u6c42\u548c \\(1 + 2 + \\dots + n\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def while_loop(n: int) -> int:\n\"\"\"while \u5faa\u73af\"\"\"\nres = 0\ni = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n# \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n:\nres += i\ni += 1  # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\nreturn res\n
        iteration.cpp
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.java
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.cs
        /* while \u5faa\u73af */\nint WhileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.go
        /* while \u5faa\u73af */\nfunc whileLoop(n int) int {\nres := 0\n// \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\ni := 1\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++\n}\nreturn res\n}\n
        iteration.swift
        /* while \u5faa\u73af */\nfunc whileLoop(n: Int) -> Int {\nvar res = 0\nvar i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n {\nres += i\ni += 1 // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res\n}\n
        iteration.js
        /* while \u5faa\u73af */\nfunction whileLoop(n) {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.ts
        /* while \u5faa\u73af */\nfunction whileLoop(n: number): number {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.dart
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.rs
        /* while \u5faa\u73af */\nfn while_loop(n: i32) -> i32 {\nlet mut res = 0;\nlet mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n {\nres += i;\ni += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nres\n}\n
        iteration.c
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.zig
        // while \u5faa\u73af\nfn whileLoop(n: i32) i32 {\nvar res: i32 = 0;\nvar i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += @intCast(i);\ni += 1;\n}\nreturn res;\n}\n

        while \u5faa\u73af\u6bd4 for \u5faa\u73af\u7684\u81ea\u7531\u5ea6\u66f4\u9ad8\u3002\u5728 while \u5faa\u73af\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u7531\u5730\u8bbe\u8ba1\u6761\u4ef6\u53d8\u91cf\u7684\u521d\u59cb\u5316\u548c\u66f4\u65b0\u6b65\u9aa4\u3002

        \u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u6761\u4ef6\u53d8\u91cf \\(i\\) \u6bcf\u8f6e\u8fdb\u884c\u4e24\u6b21\u66f4\u65b0\uff0c\u8fd9\u79cd\u60c5\u51b5\u5c31\u4e0d\u592a\u65b9\u4fbf\u7528 for \u5faa\u73af\u5b9e\u73b0\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def while_loop_ii(n: int) -> int:\n\"\"\"while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\"\"\"\nres = 0\ni = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n# \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n:\nres += i\n# \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1\ni *= 2\nreturn res\n
        iteration.cpp
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.java
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.cs
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint WhileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, 4, 5...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1; i *= 2;\n}\nreturn res;\n}\n
        iteration.go
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n int) int {\nres := 0\n// \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\ni := 1\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nfor i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++\ni *= 2\n}\nreturn res\n}\n
        iteration.swift
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n: Int) -> Int {\nvar res = 0\nvar i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1\ni *= 2\n}\nreturn res\n}\n
        iteration.js
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n) {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.ts
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n: number): number {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.dart
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.rs
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfn while_loop_ii(n: i32) -> i32 {\nlet mut res = 0;\nlet mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1;\ni *= 2;\n}\nres\n}\n
        iteration.c
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.zig
        //  while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\nfn whileLoopII(n: i32) i32 {\nvar res: i32 = 0;\nvar i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += @intCast(i);\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1;\ni *= 2;\n}\nreturn res;\n}\n

        \u603b\u7684\u6765\u8bf4\uff0cfor \u5faa\u73af\u7684\u4ee3\u7801\u66f4\u52a0\u7d27\u51d1\uff0cwhile \u5faa\u73af\u66f4\u52a0\u7075\u6d3b\uff0c\u4e24\u8005\u90fd\u53ef\u4ee5\u5b9e\u73b0\u8fed\u4ee3\u7ed3\u6784\u3002\u9009\u62e9\u4f7f\u7528\u54ea\u4e00\u4e2a\u5e94\u8be5\u6839\u636e\u7279\u5b9a\u95ee\u9898\u7684\u9700\u6c42\u6765\u51b3\u5b9a\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#3","title":"3. \u00a0 \u5d4c\u5957\u5faa\u73af","text":"

        \u6211\u4eec\u53ef\u4ee5\u5728\u4e00\u4e2a\u5faa\u73af\u7ed3\u6784\u5185\u5d4c\u5957\u53e6\u4e00\u4e2a\u5faa\u73af\u7ed3\u6784\uff0c\u4e0b\u9762\u4ee5 for \u5faa\u73af\u4e3a\u4f8b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def nested_for_loop(n: int) -> str:\n\"\"\"\u53cc\u5c42 for \u5faa\u73af\"\"\"\nres = \"\"\n# \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in range(1, n + 1):\n# \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in range(1, n + 1):\nres += f\"({i}, {j}), \"\nreturn res\n
        iteration.cpp
        /* \u53cc\u5c42 for \u5faa\u73af */\nstring nestedForLoop(int n) {\nostringstream res;\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; ++i) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; ++j) {\nres << \"(\" << i << \", \" << j << \"), \";\n}\n}\nreturn res.str();\n}\n
        iteration.java
        /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\nStringBuilder res = new StringBuilder();\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres.append(\"(\" + i + \", \" + j + \"), \");\n}\n}\nreturn res.toString();\n}\n
        iteration.cs
        /* \u53cc\u5c42 for \u5faa\u73af */\nstring NestedForLoop(int n) {\nStringBuilder res = new();\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres.Append($\"({i}, {j}), \");\n}\n}\nreturn res.ToString();\n}\n
        iteration.go
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n int) string {\nres := \"\"\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i := 1; i <= n; i++ {\nfor j := 1; j <= n; j++ {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nres += fmt.Sprintf(\"(%d, %d), \", i, j)\n}\n}\nreturn res\n}\n
        iteration.swift
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n: Int) -> String {\nvar res = \"\"\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in 1 ... n {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in 1 ... n {\nres.append(\"(\\(i), \\(j)), \")\n}\n}\nreturn res\n}\n
        iteration.js
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n) {\nlet res = '';\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (let j = 1; j <= n; j++) {\nres += `(${i}, ${j}), `;\n}\n}\nreturn res;\n}\n
        iteration.ts
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n: number): string {\nlet res = '';\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (let j = 1; j <= n; j++) {\nres += `(${i}, ${j}), `;\n}\n}\nreturn res;\n}\n
        iteration.dart
        /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\nString res = \"\";\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres += \"($i, $j), \";\n}\n}\nreturn res;\n}\n
        iteration.rs
        /* \u53cc\u5c42 for \u5faa\u73af */\nfn nested_for_loop(n: i32) -> String {\nlet mut res = vec![];\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in 1..=n {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in 1..=n {\nres.push(format!(\"({}, {}), \", i, j));\n}\n}\nres.join(\"\")\n}\n
        iteration.c
        /* \u53cc\u5c42 for \u5faa\u73af */\nchar *nestedForLoop(int n) {\n// n * n \u4e3a\u5bf9\u5e94\u70b9\u6570\u91cf\uff0c\"(i, j), \" \u5bf9\u5e94\u5b57\u7b26\u4e32\u957f\u6700\u5927\u4e3a 6+10*2\uff0c\u52a0\u4e0a\u6700\u540e\u4e00\u4e2a\u7a7a\u5b57\u7b26 \\0 \u7684\u989d\u5916\u7a7a\u95f4\nint size = n * n * 26 + 1;\nchar *res = malloc(size * sizeof(char));\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nchar tmp[26];\nsnprintf(tmp, sizeof(tmp), \"(%d, %d), \", i, j);\nstrncat(res, tmp, size - strlen(res) - 1);\n}\n}\nreturn res;\n}\n
        iteration.zig
        // \u53cc\u5c42 for \u5faa\u73af\nfn nestedForLoop(allocator: Allocator, n: usize) ![]const u8 {\nvar res = std.ArrayList(u8).init(allocator);\ndefer res.deinit();\nvar buffer: [20]u8 = undefined;\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (1..n+1) |i| {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (1..n+1) |j| {\nvar _str = try std.fmt.bufPrint(&buffer, \"({d}, {d}), \", .{i, j});\ntry res.appendSlice(_str);\n}\n}\nreturn res.toOwnedSlice();\n}\n

        \u56fe 2-2 \u662f\u8be5\u5d4c\u5957\u5faa\u73af\u7684\u6d41\u7a0b\u6846\u56fe\u3002

        \u56fe 2-2 \u00a0 \u5d4c\u5957\u5faa\u73af\u7684\u6d41\u7a0b\u6846\u56fe

        \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e \\(n^2\\) \u6210\u6b63\u6bd4\uff0c\u6216\u8005\u8bf4\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u548c\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u6210\u201c\u5e73\u65b9\u5173\u7cfb\u201d\u3002

        \u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u6dfb\u52a0\u5d4c\u5957\u5faa\u73af\uff0c\u6bcf\u4e00\u6b21\u5d4c\u5957\u90fd\u662f\u4e00\u6b21\u201c\u5347\u7ef4\u201d\uff0c\u5c06\u4f1a\u4f7f\u65f6\u95f4\u590d\u6742\u5ea6\u63d0\u9ad8\u81f3\u201c\u7acb\u65b9\u5173\u7cfb\u201d\u201c\u56db\u6b21\u65b9\u5173\u7cfb\u201d\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#222","title":"2.2.2 \u00a0 \u9012\u5f52","text":"

        \u300c\u9012\u5f52 recursion\u300d\u662f\u4e00\u79cd\u7b97\u6cd5\u7b56\u7565\uff0c\u901a\u8fc7\u51fd\u6570\u8c03\u7528\u81ea\u8eab\u6765\u89e3\u51b3\u95ee\u9898\u3002\u5b83\u4e3b\u8981\u5305\u542b\u4e24\u4e2a\u9636\u6bb5\u3002

        1. \u9012\uff1a\u7a0b\u5e8f\u4e0d\u65ad\u6df1\u5165\u5730\u8c03\u7528\u81ea\u8eab\uff0c\u901a\u5e38\u4f20\u5165\u66f4\u5c0f\u6216\u66f4\u7b80\u5316\u7684\u53c2\u6570\uff0c\u76f4\u5230\u8fbe\u5230\u201c\u7ec8\u6b62\u6761\u4ef6\u201d\u3002
        2. \u5f52\uff1a\u89e6\u53d1\u201c\u7ec8\u6b62\u6761\u4ef6\u201d\u540e\uff0c\u7a0b\u5e8f\u4ece\u6700\u6df1\u5c42\u7684\u9012\u5f52\u51fd\u6570\u5f00\u59cb\u9010\u5c42\u8fd4\u56de\uff0c\u6c47\u805a\u6bcf\u4e00\u5c42\u7684\u7ed3\u679c\u3002

        \u800c\u4ece\u5b9e\u73b0\u7684\u89d2\u5ea6\u770b\uff0c\u9012\u5f52\u4ee3\u7801\u4e3b\u8981\u5305\u542b\u4e09\u4e2a\u8981\u7d20\u3002

        1. \u7ec8\u6b62\u6761\u4ef6\uff1a\u7528\u4e8e\u51b3\u5b9a\u4ec0\u4e48\u65f6\u5019\u7531\u201c\u9012\u201d\u8f6c\u201c\u5f52\u201d\u3002
        2. \u9012\u5f52\u8c03\u7528\uff1a\u5bf9\u5e94\u201c\u9012\u201d\uff0c\u51fd\u6570\u8c03\u7528\u81ea\u8eab\uff0c\u901a\u5e38\u8f93\u5165\u66f4\u5c0f\u6216\u66f4\u7b80\u5316\u7684\u53c2\u6570\u3002
        3. \u8fd4\u56de\u7ed3\u679c\uff1a\u5bf9\u5e94\u201c\u5f52\u201d\uff0c\u5c06\u5f53\u524d\u9012\u5f52\u5c42\u7ea7\u7684\u7ed3\u679c\u8fd4\u56de\u81f3\u4e0a\u4e00\u5c42\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6211\u4eec\u53ea\u9700\u8c03\u7528\u51fd\u6570 recur(n) \uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210 \\(1 + 2 + \\dots + n\\) \u7684\u8ba1\u7b97\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def recur(n: int) -> int:\n\"\"\"\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif n == 1:\nreturn 1\n# \u9012\uff1a\u9012\u5f52\u8c03\u7528\nres = recur(n - 1)\n# \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n
        recursion.cpp
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.java
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.cs
        /* \u9012\u5f52 */\nint Recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = Recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.go
        /* \u9012\u5f52 */\nfunc recur(n int) int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nres := recur(n - 1)\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n}\n
        recursion.swift
        /* \u9012\u5f52 */\nfunc recur(n: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nlet res = recur(n: n - 1)\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n}\n
        recursion.js
        /* \u9012\u5f52 */\nfunction recur(n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nconst res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.ts
        /* \u9012\u5f52 */\nfunction recur(n: number): number {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nconst res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.dart
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.rs
        /* \u9012\u5f52 */\nfn recur(n: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1;\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nlet res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nn + res\n}\n
        recursion.c
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.zig
        // \u9012\u5f52\u51fd\u6570\nfn recur(n: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1) {\nreturn 1;\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nvar res: i32 = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n

        \u56fe 2-3 \u5c55\u793a\u4e86\u8be5\u51fd\u6570\u7684\u9012\u5f52\u8fc7\u7a0b\u3002

        \u56fe 2-3 \u00a0 \u6c42\u548c\u51fd\u6570\u7684\u9012\u5f52\u8fc7\u7a0b

        \u867d\u7136\u4ece\u8ba1\u7b97\u89d2\u5ea6\u770b\uff0c\u8fed\u4ee3\u4e0e\u9012\u5f52\u53ef\u4ee5\u5f97\u5230\u76f8\u540c\u7684\u7ed3\u679c\uff0c\u4f46\u5b83\u4eec\u4ee3\u8868\u4e86\u4e24\u79cd\u5b8c\u5168\u4e0d\u540c\u7684\u601d\u8003\u548c\u89e3\u51b3\u95ee\u9898\u7684\u8303\u5f0f\u3002

        • \u8fed\u4ee3\uff1a\u201c\u81ea\u4e0b\u800c\u4e0a\u201d\u5730\u89e3\u51b3\u95ee\u9898\u3002\u4ece\u6700\u57fa\u7840\u7684\u6b65\u9aa4\u5f00\u59cb\uff0c\u7136\u540e\u4e0d\u65ad\u91cd\u590d\u6216\u7d2f\u52a0\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u76f4\u5230\u4efb\u52a1\u5b8c\u6210\u3002
        • \u9012\u5f52\uff1a\u201c\u81ea\u4e0a\u800c\u4e0b\u201d\u5730\u89e3\u51b3\u95ee\u9898\u3002\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u8fd9\u4e9b\u5b50\u95ee\u9898\u548c\u539f\u95ee\u9898\u5177\u6709\u76f8\u540c\u7684\u5f62\u5f0f\u3002\u63a5\u4e0b\u6765\u5c06\u5b50\u95ee\u9898\u7ee7\u7eed\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u5230\u57fa\u672c\u60c5\u51b5\u65f6\u505c\u6b62\uff08\u57fa\u672c\u60c5\u51b5\u7684\u89e3\u662f\u5df2\u77e5\u7684\uff09\u3002

        \u4ee5\u4e0a\u8ff0\u6c42\u548c\u51fd\u6570\u4e3a\u4f8b\uff0c\u8bbe\u95ee\u9898 \\(f(n) = 1 + 2 + \\dots + n\\) \u3002

        • \u8fed\u4ee3\uff1a\u5728\u5faa\u73af\u4e2d\u6a21\u62df\u6c42\u548c\u8fc7\u7a0b\uff0c\u4ece \\(1\\) \u904d\u5386\u5230 \\(n\\) \uff0c\u6bcf\u8f6e\u6267\u884c\u6c42\u548c\u64cd\u4f5c\uff0c\u5373\u53ef\u6c42\u5f97 \\(f(n)\\) \u3002
        • \u9012\u5f52\uff1a\u5c06\u95ee\u9898\u5206\u89e3\u4e3a\u5b50\u95ee\u9898 \\(f(n) = n + f(n-1)\\) \uff0c\u4e0d\u65ad\uff08\u9012\u5f52\u5730\uff09\u5206\u89e3\u4e0b\u53bb\uff0c\u76f4\u81f3\u57fa\u672c\u60c5\u51b5 \\(f(1) = 1\\) \u65f6\u7ec8\u6b62\u3002
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#1","title":"1. \u00a0 \u8c03\u7528\u6808","text":"

        \u9012\u5f52\u51fd\u6570\u6bcf\u6b21\u8c03\u7528\u81ea\u8eab\u65f6\uff0c\u7cfb\u7edf\u90fd\u4f1a\u4e3a\u65b0\u5f00\u542f\u7684\u51fd\u6570\u5206\u914d\u5185\u5b58\uff0c\u4ee5\u5b58\u50a8\u5c40\u90e8\u53d8\u91cf\u3001\u8c03\u7528\u5730\u5740\u548c\u5176\u4ed6\u4fe1\u606f\u7b49\u3002\u8fd9\u5c06\u5bfc\u81f4\u4e24\u65b9\u9762\u7684\u7ed3\u679c\u3002

        • \u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u6570\u636e\u90fd\u5b58\u50a8\u5728\u79f0\u4e3a\u201c\u6808\u5e27\u7a7a\u95f4\u201d\u7684\u5185\u5b58\u533a\u57df\u4e2d\uff0c\u76f4\u81f3\u51fd\u6570\u8fd4\u56de\u540e\u624d\u4f1a\u88ab\u91ca\u653e\u3002\u56e0\u6b64\uff0c\u9012\u5f52\u901a\u5e38\u6bd4\u8fed\u4ee3\u66f4\u52a0\u8017\u8d39\u5185\u5b58\u7a7a\u95f4\u3002
        • \u9012\u5f52\u8c03\u7528\u51fd\u6570\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u5f00\u9500\u3002\u56e0\u6b64\u9012\u5f52\u901a\u5e38\u6bd4\u5faa\u73af\u7684\u65f6\u95f4\u6548\u7387\u66f4\u4f4e\u3002

        \u5982\u56fe 2-4 \u6240\u793a\uff0c\u5728\u89e6\u53d1\u7ec8\u6b62\u6761\u4ef6\u524d\uff0c\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684\u9012\u5f52\u51fd\u6570\uff0c\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \u3002

        \u56fe 2-4 \u00a0 \u9012\u5f52\u8c03\u7528\u6df1\u5ea6

        \u5728\u5b9e\u9645\u4e2d\uff0c\u7f16\u7a0b\u8bed\u8a00\u5141\u8bb8\u7684\u9012\u5f52\u6df1\u5ea6\u901a\u5e38\u662f\u6709\u9650\u7684\uff0c\u8fc7\u6df1\u7684\u9012\u5f52\u53ef\u80fd\u5bfc\u81f4\u6808\u6ea2\u51fa\u9519\u8bef\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#2","title":"2. \u00a0 \u5c3e\u9012\u5f52","text":"

        \u6709\u8da3\u7684\u662f\uff0c\u5982\u679c\u51fd\u6570\u5728\u8fd4\u56de\u524d\u7684\u6700\u540e\u4e00\u6b65\u624d\u8fdb\u884c\u9012\u5f52\u8c03\u7528\uff0c\u5219\u8be5\u51fd\u6570\u53ef\u4ee5\u88ab\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u4f18\u5316\uff0c\u4f7f\u5176\u5728\u7a7a\u95f4\u6548\u7387\u4e0a\u4e0e\u8fed\u4ee3\u76f8\u5f53\u3002\u8fd9\u79cd\u60c5\u51b5\u88ab\u79f0\u4e3a\u300c\u5c3e\u9012\u5f52 tail recursion\u300d\u3002

        • \u666e\u901a\u9012\u5f52\uff1a\u5f53\u51fd\u6570\u8fd4\u56de\u5230\u4e0a\u4e00\u5c42\u7ea7\u7684\u51fd\u6570\u540e\uff0c\u9700\u8981\u7ee7\u7eed\u6267\u884c\u4ee3\u7801\uff0c\u56e0\u6b64\u7cfb\u7edf\u9700\u8981\u4fdd\u5b58\u4e0a\u4e00\u5c42\u8c03\u7528\u7684\u4e0a\u4e0b\u6587\u3002
        • \u5c3e\u9012\u5f52\uff1a\u9012\u5f52\u8c03\u7528\u662f\u51fd\u6570\u8fd4\u56de\u524d\u7684\u6700\u540e\u4e00\u4e2a\u64cd\u4f5c\uff0c\u8fd9\u610f\u5473\u7740\u51fd\u6570\u8fd4\u56de\u5230\u4e0a\u4e00\u5c42\u7ea7\u540e\uff0c\u65e0\u987b\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u56e0\u6b64\u7cfb\u7edf\u65e0\u987b\u4fdd\u5b58\u4e0a\u4e00\u5c42\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u3002

        \u4ee5\u8ba1\u7b97 \\(1 + 2 + \\dots + n\\) \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u7ed3\u679c\u53d8\u91cf res \u8bbe\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u4ece\u800c\u5b9e\u73b0\u5c3e\u9012\u5f52\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def tail_recur(n, res):\n\"\"\"\u5c3e\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif n == 0:\nreturn res\n# \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tail_recur(n - 1, res + n)\n
        recursion.cpp
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.java
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.cs
        /* \u5c3e\u9012\u5f52 */\nint TailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn TailRecur(n - 1, res + n);\n}\n
        recursion.go
        /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n int, res int) int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n-1, res+n)\n}\n
        recursion.swift
        /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n: Int, res: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n: n - 1, res: res + n)\n}\n
        recursion.js
        /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n, res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.ts
        /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n: number, res: number): number {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.dart
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.rs
        /* \u5c3e\u9012\u5f52 */\nfn tail_recur(n: i32, res: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res;\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\ntail_recur(n - 1, res + n)\n}\n
        recursion.c
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.zig
        // \u5c3e\u9012\u5f52\u51fd\u6570\nfn tailRecur(n: i32, res: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0) {\nreturn res;\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n

        \u5c3e\u9012\u5f52\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u56fe 2-5 \u6240\u793a\u3002\u5bf9\u6bd4\u666e\u901a\u9012\u5f52\u548c\u5c3e\u9012\u5f52\uff0c\u4e24\u8005\u7684\u6c42\u548c\u64cd\u4f5c\u7684\u6267\u884c\u70b9\u662f\u4e0d\u540c\u7684\u3002

        • \u666e\u901a\u9012\u5f52\uff1a\u6c42\u548c\u64cd\u4f5c\u662f\u5728\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u4e2d\u6267\u884c\u7684\uff0c\u6bcf\u5c42\u8fd4\u56de\u540e\u90fd\u8981\u518d\u6267\u884c\u4e00\u6b21\u6c42\u548c\u64cd\u4f5c\u3002
        • \u5c3e\u9012\u5f52\uff1a\u6c42\u548c\u64cd\u4f5c\u662f\u5728\u201c\u9012\u201d\u7684\u8fc7\u7a0b\u4e2d\u6267\u884c\u7684\uff0c\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u53ea\u9700\u5c42\u5c42\u8fd4\u56de\u3002

        \u56fe 2-5 \u00a0 \u5c3e\u9012\u5f52\u8fc7\u7a0b

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u8bb8\u591a\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u5e76\u4e0d\u652f\u6301\u5c3e\u9012\u5f52\u4f18\u5316\u3002\u4f8b\u5982\uff0cPython \u9ed8\u8ba4\u4e0d\u652f\u6301\u5c3e\u9012\u5f52\u4f18\u5316\uff0c\u56e0\u6b64\u5373\u4f7f\u51fd\u6570\u662f\u5c3e\u9012\u5f52\u5f62\u5f0f\uff0c\u4ecd\u7136\u53ef\u80fd\u4f1a\u9047\u5230\u6808\u6ea2\u51fa\u95ee\u9898\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#3_1","title":"3. \u00a0 \u9012\u5f52\u6811","text":"

        \u5f53\u5904\u7406\u4e0e\u201c\u5206\u6cbb\u201d\u76f8\u5173\u7684\u7b97\u6cd5\u95ee\u9898\u65f6\uff0c\u9012\u5f52\u5f80\u5f80\u6bd4\u8fed\u4ee3\u7684\u601d\u8def\u66f4\u52a0\u76f4\u89c2\u3001\u4ee3\u7801\u66f4\u52a0\u6613\u8bfb\u3002\u4ee5\u201c\u6590\u6ce2\u90a3\u5951\u6570\u5217\u201d\u4e3a\u4f8b\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6590\u6ce2\u90a3\u5951\u6570\u5217 \\(0, 1, 1, 2, 3, 5, 8, 13, \\dots\\) \uff0c\u6c42\u8be5\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\u3002

        \u8bbe\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\u4e3a \\(f(n)\\) \uff0c\u6613\u5f97\u4e24\u4e2a\u7ed3\u8bba\u3002

        • \u6570\u5217\u7684\u524d\u4e24\u4e2a\u6570\u5b57\u4e3a \\(f(1) = 0\\) \u548c \\(f(2) = 1\\) \u3002
        • \u6570\u5217\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u662f\u524d\u4e24\u4e2a\u6570\u5b57\u7684\u548c\uff0c\u5373 \\(f(n) = f(n - 1) + f(n - 2)\\) \u3002

        \u6309\u7167\u9012\u63a8\u5173\u7cfb\u8fdb\u884c\u9012\u5f52\u8c03\u7528\uff0c\u5c06\u524d\u4e24\u4e2a\u6570\u5b57\u4f5c\u4e3a\u7ec8\u6b62\u6761\u4ef6\uff0c\u4fbf\u53ef\u5199\u51fa\u9012\u5f52\u4ee3\u7801\u3002\u8c03\u7528 fib(n) \u5373\u53ef\u5f97\u5230\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def fib(n: int) -> int:\n\"\"\"\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 or n == 2:\nreturn n - 1\n# \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nres = fib(n - 1) + fib(n - 2)\n# \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n
        recursion.cpp
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.java
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.cs
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint Fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = Fib(n - 1) + Fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.go
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunc fib(n int) int {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nres := fib(n-1) + fib(n-2)\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n}\n
        recursion.swift
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunc fib(n: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nlet res = fib(n: n - 1) + fib(n: n - 2)\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n}\n
        recursion.js
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunction fib(n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n === 1 || n === 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nconst res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.ts
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunction fib(n: number): number {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n === 1 || n === 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nconst res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.dart
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.rs
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfn fib(n: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1;\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nlet res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c\nres\n}\n
        recursion.c
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.zig
        // \u6590\u6ce2\u90a3\u5951\u6570\u5217\nfn fib(n: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 or n == 2) {\nreturn n - 1;\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nvar res: i32 = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u6211\u4eec\u5728\u51fd\u6570\u5185\u9012\u5f52\u8c03\u7528\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u4ece\u4e00\u4e2a\u8c03\u7528\u4ea7\u751f\u4e86\u4e24\u4e2a\u8c03\u7528\u5206\u652f\u3002\u5982\u56fe 2-6 \u6240\u793a\uff0c\u8fd9\u6837\u4e0d\u65ad\u9012\u5f52\u8c03\u7528\u4e0b\u53bb\uff0c\u6700\u7ec8\u5c06\u4ea7\u751f\u4e00\u68f5\u5c42\u6570\u4e3a \\(n\\) \u7684\u300c\u9012\u5f52\u6811 recursion tree\u300d\u3002

        \u56fe 2-6 \u00a0 \u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u9012\u5f52\u6811

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9012\u5f52\u4f53\u73b0\u4e86\u201c\u5c06\u95ee\u9898\u5206\u89e3\u4e3a\u66f4\u5c0f\u5b50\u95ee\u9898\u201d\u7684\u601d\u7ef4\u8303\u5f0f\uff0c\u8fd9\u79cd\u5206\u6cbb\u7b56\u7565\u81f3\u5173\u91cd\u8981\u3002

        • \u4ece\u7b97\u6cd5\u89d2\u5ea6\u770b\uff0c\u641c\u7d22\u3001\u6392\u5e8f\u3001\u56de\u6eaf\u3001\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u7b49\u8bb8\u591a\u91cd\u8981\u7b97\u6cd5\u7b56\u7565\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u5e94\u7528\u4e86\u8fd9\u79cd\u601d\u7ef4\u65b9\u5f0f\u3002
        • \u4ece\u6570\u636e\u7ed3\u6784\u89d2\u5ea6\u770b\uff0c\u9012\u5f52\u5929\u7136\u9002\u5408\u5904\u7406\u94fe\u8868\u3001\u6811\u548c\u56fe\u7684\u76f8\u5173\u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u4eec\u975e\u5e38\u9002\u5408\u7528\u5206\u6cbb\u601d\u60f3\u8fdb\u884c\u5206\u6790\u3002
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#223","title":"2.2.3 \u00a0 \u4e24\u8005\u5bf9\u6bd4","text":"

        \u603b\u7ed3\u4ee5\u4e0a\u5185\u5bb9\uff0c\u5982\u8868 2-1 \u6240\u793a\uff0c\u8fed\u4ee3\u548c\u9012\u5f52\u5728\u5b9e\u73b0\u3001\u6027\u80fd\u548c\u9002\u7528\u6027\u4e0a\u6709\u6240\u4e0d\u540c\u3002

        \u8868 2-1 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52\u7279\u70b9\u5bf9\u6bd4

        \u8fed\u4ee3 \u9012\u5f52 \u5b9e\u73b0\u65b9\u5f0f \u5faa\u73af\u7ed3\u6784 \u51fd\u6570\u8c03\u7528\u81ea\u8eab \u65f6\u95f4\u6548\u7387 \u6548\u7387\u901a\u5e38\u8f83\u9ad8\uff0c\u65e0\u51fd\u6570\u8c03\u7528\u5f00\u9500 \u6bcf\u6b21\u51fd\u6570\u8c03\u7528\u90fd\u4f1a\u4ea7\u751f\u5f00\u9500 \u5185\u5b58\u4f7f\u7528 \u901a\u5e38\u4f7f\u7528\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4 \u7d2f\u79ef\u51fd\u6570\u8c03\u7528\u53ef\u80fd\u4f7f\u7528\u5927\u91cf\u7684\u6808\u5e27\u7a7a\u95f4 \u9002\u7528\u95ee\u9898 \u9002\u7528\u4e8e\u7b80\u5355\u5faa\u73af\u4efb\u52a1\uff0c\u4ee3\u7801\u76f4\u89c2\u3001\u53ef\u8bfb\u6027\u597d \u9002\u7528\u4e8e\u5b50\u95ee\u9898\u5206\u89e3\uff0c\u5982\u6811\u3001\u56fe\u3001\u5206\u6cbb\u3001\u56de\u6eaf\u7b49\uff0c\u4ee3\u7801\u7ed3\u6784\u7b80\u6d01\u3001\u6e05\u6670

        Tip

        \u5982\u679c\u611f\u89c9\u4ee5\u4e0b\u5185\u5bb9\u7406\u89e3\u56f0\u96be\uff0c\u53ef\u4ee5\u5728\u8bfb\u5b8c\u201c\u6808\u201d\u7ae0\u8282\u540e\u518d\u6765\u590d\u4e60\u3002

        \u90a3\u4e48\uff0c\u8fed\u4ee3\u548c\u9012\u5f52\u5177\u6709\u4ec0\u4e48\u5185\u5728\u8054\u7cfb\u5462\uff1f\u4ee5\u4e0a\u8ff0\u7684\u9012\u5f52\u51fd\u6570\u4e3a\u4f8b\uff0c\u6c42\u548c\u64cd\u4f5c\u5728\u9012\u5f52\u7684\u201c\u5f52\u201d\u9636\u6bb5\u8fdb\u884c\u3002\u8fd9\u610f\u5473\u7740\u6700\u521d\u88ab\u8c03\u7528\u7684\u51fd\u6570\u5b9e\u9645\u4e0a\u662f\u6700\u540e\u5b8c\u6210\u5176\u6c42\u548c\u64cd\u4f5c\u7684\uff0c\u8fd9\u79cd\u5de5\u4f5c\u673a\u5236\u4e0e\u6808\u7684\u201c\u5148\u5165\u540e\u51fa\u201d\u539f\u5219\u662f\u5f02\u66f2\u540c\u5de5\u7684\u3002

        \u4e8b\u5b9e\u4e0a\uff0c\u201c\u8c03\u7528\u6808\u201d\u548c\u201c\u6808\u5e27\u7a7a\u95f4\u201d\u8fd9\u7c7b\u9012\u5f52\u672f\u8bed\u5df2\u7ecf\u6697\u793a\u4e86\u9012\u5f52\u4e0e\u6808\u4e4b\u95f4\u7684\u5bc6\u5207\u5173\u7cfb\u3002

        1. \u9012\uff1a\u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5728\u201c\u8c03\u7528\u6808\u201d\u4e0a\u4e3a\u8be5\u51fd\u6570\u5206\u914d\u65b0\u7684\u6808\u5e27\uff0c\u7528\u4e8e\u5b58\u50a8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3001\u53c2\u6570\u3001\u8fd4\u56de\u5730\u5740\u7b49\u6570\u636e\u3002
        2. \u5f52\uff1a\u5f53\u51fd\u6570\u5b8c\u6210\u6267\u884c\u5e76\u8fd4\u56de\u65f6\uff0c\u5bf9\u5e94\u7684\u6808\u5e27\u4f1a\u4ece\u201c\u8c03\u7528\u6808\u201d\u4e0a\u88ab\u79fb\u9664\uff0c\u6062\u590d\u4e4b\u524d\u51fd\u6570\u7684\u6267\u884c\u73af\u5883\u3002

        \u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u8c03\u7528\u6808\u7684\u884c\u4e3a\uff0c\u4ece\u800c\u5c06\u9012\u5f52\u8f6c\u5316\u4e3a\u8fed\u4ee3\u5f62\u5f0f\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def for_loop_recur(n: int) -> int:\n\"\"\"\u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52\"\"\"\n# \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack = []\nres = 0\n# \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in range(n, 0, -1):\n# \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.append(i)\n# \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile stack:\n# \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop()\n# res = 1+2+3+...+n\nreturn res\n
        recursion.cpp
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack<int> stack;\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.empty()) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.top();\nstack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.java
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nStack<Integer> stack = new Stack<>();\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.isEmpty()) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.cs
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint ForLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nStack<int> stack = new();\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.Push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.Count > 0) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.Pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.go
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunc forLoopRecur(n int) int {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack := list.New()\nres := 0\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i := n; i > 0; i-- {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.PushBack(i)\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nfor stack.Len() != 0 {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.Back().Value.(int)\nstack.Remove(stack.Back())\n}\n// res = 1+2+3+...+n\nreturn res\n}\n
        recursion.swift
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunc forLoopRecur(n: Int) -> Int {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nvar stack: [Int] = []\nvar res = 0\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in stride(from: n, to: 0, by: -1) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.append(i)\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile !stack.isEmpty {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.removeLast()\n}\n// res = 1+2+3+...+n\nreturn res\n}\n
        recursion.js
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunction forLoopRecur(n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nconst stack = [];\nlet res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (let i = 1; i <= n; i++) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.length) { // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.ts
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunction forLoopRecur(n: number): number {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808 \nconst stack: number[] = [];\nlet res: number = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (let i = 1; i <= n; i++) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.length) { // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.dart
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nList<int> stack = [];\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.add(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.isEmpty) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.removeLast();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.rs
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfn for_loop_recur(n: i32) -> i32 {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nlet mut stack = Vec::new();\nlet mut res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in (1..=n).rev() {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile !stack.is_empty() {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop().unwrap();\n}\n// res = 1+2+3+...+n\nres\n}\n
        recursion.c
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\nint stack[1000]; // \u501f\u52a9\u4e00\u4e2a\u5927\u6570\u7ec4\u6765\u6a21\u62df\u6808\nint top = -1;    // \u6808\u9876\u7d22\u5f15\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack[1 + top++] = i;\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (top >= 0) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack[top--];\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.zig
        // \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52\nfn forLoopRecur(comptime n: i32) i32 {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nvar stack: [n]i32 = undefined;\nvar res: i32 = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nvar i: usize = n;\nwhile (i > 0) {\nstack[i - 1] = @intCast(i);\ni -= 1;\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nvar index: usize = n;\nwhile (index > 0) {\nindex -= 1;\nres += stack[index];\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u5f53\u9012\u5f52\u88ab\u8f6c\u6362\u4e3a\u8fed\u4ee3\u540e\uff0c\u4ee3\u7801\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u4e86\u3002\u5c3d\u7ba1\u8fed\u4ee3\u548c\u9012\u5f52\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362\uff0c\u4f46\u4e5f\u4e0d\u4e00\u5b9a\u503c\u5f97\u8fd9\u6837\u505a\uff0c\u6709\u4ee5\u4e0b\u4e24\u70b9\u539f\u56e0\u3002

        • \u8f6c\u5316\u540e\u7684\u4ee3\u7801\u53ef\u80fd\u66f4\u52a0\u96be\u4ee5\u7406\u89e3\uff0c\u53ef\u8bfb\u6027\u66f4\u5dee\u3002
        • \u5bf9\u4e8e\u67d0\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\u7684\u884c\u4e3a\u53ef\u80fd\u975e\u5e38\u56f0\u96be\u3002

        \u603b\u4e4b\uff0c\u9009\u62e9\u8fed\u4ee3\u8fd8\u662f\u9012\u5f52\u53d6\u51b3\u4e8e\u7279\u5b9a\u95ee\u9898\u7684\u6027\u8d28\u3002\u5728\u7f16\u7a0b\u5b9e\u8df5\u4e2d\uff0c\u6743\u8861\u4e24\u8005\u7684\u4f18\u52a3\u5e76\u6839\u636e\u60c5\u5883\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/","title":"2.1 \u00a0 \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30","text":"

        \u5728\u7b97\u6cd5\u8bbe\u8ba1\u4e2d\uff0c\u6211\u4eec\u5148\u540e\u8ffd\u6c42\u4ee5\u4e0b\u4e24\u4e2a\u5c42\u9762\u7684\u76ee\u6807\u3002

        1. \u627e\u5230\u95ee\u9898\u89e3\u6cd5\uff1a\u7b97\u6cd5\u9700\u8981\u5728\u89c4\u5b9a\u7684\u8f93\u5165\u8303\u56f4\u5185\u53ef\u9760\u5730\u6c42\u5f97\u95ee\u9898\u7684\u6b63\u786e\u89e3\u3002
        2. \u5bfb\u6c42\u6700\u4f18\u89e3\u6cd5\uff1a\u540c\u4e00\u4e2a\u95ee\u9898\u53ef\u80fd\u5b58\u5728\u591a\u79cd\u89e3\u6cd5\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u5230\u5c3d\u53ef\u80fd\u9ad8\u6548\u7684\u7b97\u6cd5\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u80fd\u591f\u89e3\u51b3\u95ee\u9898\u7684\u524d\u63d0\u4e0b\uff0c\u7b97\u6cd5\u6548\u7387\u5df2\u6210\u4e3a\u8861\u91cf\u7b97\u6cd5\u4f18\u52a3\u7684\u4e3b\u8981\u8bc4\u4ef7\u6307\u6807\uff0c\u5b83\u5305\u62ec\u4ee5\u4e0b\u4e24\u4e2a\u7ef4\u5ea6\u3002

        • \u65f6\u95f4\u6548\u7387\uff1a\u7b97\u6cd5\u8fd0\u884c\u901f\u5ea6\u7684\u5feb\u6162\u3002
        • \u7a7a\u95f4\u6548\u7387\uff1a\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u7684\u5927\u5c0f\u3002

        \u7b80\u800c\u8a00\u4e4b\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u8bbe\u8ba1\u201c\u65e2\u5feb\u53c8\u7701\u201d\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u3002\u800c\u6709\u6548\u5730\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u53ea\u6709\u8fd9\u6837\u6211\u4eec\u624d\u80fd\u5c06\u5404\u79cd\u7b97\u6cd5\u8fdb\u884c\u5bf9\u6bd4\uff0c\u8fdb\u800c\u6307\u5bfc\u7b97\u6cd5\u8bbe\u8ba1\u4e0e\u4f18\u5316\u8fc7\u7a0b\u3002

        \u6548\u7387\u8bc4\u4f30\u65b9\u6cd5\u4e3b\u8981\u5206\u4e3a\u4e24\u79cd\uff1a\u5b9e\u9645\u6d4b\u8bd5\u3001\u7406\u8bba\u4f30\u7b97\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/#211","title":"2.1.1 \u00a0 \u5b9e\u9645\u6d4b\u8bd5","text":"

        \u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u7b97\u6cd5 A \u548c\u7b97\u6cd5 B \uff0c\u5b83\u4eec\u90fd\u80fd\u89e3\u51b3\u540c\u4e00\u95ee\u9898\uff0c\u73b0\u5728\u9700\u8981\u5bf9\u6bd4\u8fd9\u4e24\u4e2a\u7b97\u6cd5\u7684\u6548\u7387\u3002\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u627e\u4e00\u53f0\u8ba1\u7b97\u673a\uff0c\u8fd0\u884c\u8fd9\u4e24\u4e2a\u7b97\u6cd5\uff0c\u5e76\u76d1\u63a7\u8bb0\u5f55\u5b83\u4eec\u7684\u8fd0\u884c\u65f6\u95f4\u548c\u5185\u5b58\u5360\u7528\u60c5\u51b5\u3002\u8fd9\u79cd\u8bc4\u4f30\u65b9\u5f0f\u80fd\u591f\u53cd\u6620\u771f\u5b9e\u60c5\u51b5\uff0c\u4f46\u4e5f\u5b58\u5728\u8f83\u5927\u7684\u5c40\u9650\u6027\u3002

        \u4e00\u65b9\u9762\uff0c\u96be\u4ee5\u6392\u9664\u6d4b\u8bd5\u73af\u5883\u7684\u5e72\u6270\u56e0\u7d20\u3002\u786c\u4ef6\u914d\u7f6e\u4f1a\u5f71\u54cd\u7b97\u6cd5\u7684\u6027\u80fd\u3002\u6bd4\u5982\u5728\u67d0\u53f0\u8ba1\u7b97\u673a\u4e2d\uff0c\u7b97\u6cd5 A \u7684\u8fd0\u884c\u65f6\u95f4\u6bd4\u7b97\u6cd5 B \u77ed\uff1b\u4f46\u5728\u53e6\u4e00\u53f0\u914d\u7f6e\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e2d\uff0c\u53ef\u80fd\u5f97\u5230\u76f8\u53cd\u7684\u6d4b\u8bd5\u7ed3\u679c\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u9700\u8981\u5728\u5404\u79cd\u673a\u5668\u4e0a\u8fdb\u884c\u6d4b\u8bd5\uff0c\u7edf\u8ba1\u5e73\u5747\u6548\u7387\uff0c\u800c\u8fd9\u662f\u4e0d\u73b0\u5b9e\u7684\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5c55\u5f00\u5b8c\u6574\u6d4b\u8bd5\u975e\u5e38\u8017\u8d39\u8d44\u6e90\u3002\u968f\u7740\u8f93\u5165\u6570\u636e\u91cf\u7684\u53d8\u5316\uff0c\u7b97\u6cd5\u4f1a\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u6548\u7387\u3002\u4f8b\u5982\uff0c\u5728\u8f93\u5165\u6570\u636e\u91cf\u8f83\u5c0f\u65f6\uff0c\u7b97\u6cd5 A \u7684\u8fd0\u884c\u65f6\u95f4\u6bd4\u7b97\u6cd5 B \u77ed\uff1b\u800c\u5728\u8f93\u5165\u6570\u636e\u91cf\u8f83\u5927\u65f6\uff0c\u6d4b\u8bd5\u7ed3\u679c\u53ef\u80fd\u6070\u6070\u76f8\u53cd\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5f97\u5230\u6709\u8bf4\u670d\u529b\u7684\u7ed3\u8bba\uff0c\u6211\u4eec\u9700\u8981\u6d4b\u8bd5\u5404\u79cd\u89c4\u6a21\u7684\u8f93\u5165\u6570\u636e\uff0c\u800c\u8fd9\u9700\u8981\u8017\u8d39\u5927\u91cf\u7684\u8ba1\u7b97\u8d44\u6e90\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/#212","title":"2.1.2 \u00a0 \u7406\u8bba\u4f30\u7b97","text":"

        \u7531\u4e8e\u5b9e\u9645\u6d4b\u8bd5\u5177\u6709\u8f83\u5927\u7684\u5c40\u9650\u6027\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u4ec5\u901a\u8fc7\u4e00\u4e9b\u8ba1\u7b97\u6765\u8bc4\u4f30\u7b97\u6cd5\u7684\u6548\u7387\u3002\u8fd9\u79cd\u4f30\u7b97\u65b9\u6cd5\u88ab\u79f0\u4e3a\u300c\u6e10\u8fd1\u590d\u6742\u5ea6\u5206\u6790 asymptotic complexity analysis\u300d\uff0c\u7b80\u79f0\u300c\u590d\u6742\u5ea6\u5206\u6790\u300d\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u80fd\u591f\u4f53\u73b0\u7b97\u6cd5\u8fd0\u884c\u6240\u9700\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b83\u63cf\u8ff0\u4e86\u968f\u7740\u8f93\u5165\u6570\u636e\u5927\u5c0f\u7684\u589e\u52a0\uff0c\u7b97\u6cd5\u6267\u884c\u6240\u9700\u65f6\u95f4\u548c\u7a7a\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u3002\u8fd9\u4e2a\u5b9a\u4e49\u6709\u4e9b\u62d7\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5206\u4e3a\u4e09\u4e2a\u91cd\u70b9\u6765\u7406\u89e3\u3002

        • \u201c\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\u201d\u5206\u522b\u5bf9\u5e94\u300c\u65f6\u95f4\u590d\u6742\u5ea6 time complexity\u300d\u548c\u300c\u7a7a\u95f4\u590d\u6742\u5ea6 space complexity\u300d\u3002
        • \u201c\u968f\u7740\u8f93\u5165\u6570\u636e\u5927\u5c0f\u7684\u589e\u52a0\u201d\u610f\u5473\u7740\u590d\u6742\u5ea6\u53cd\u6620\u4e86\u7b97\u6cd5\u8fd0\u884c\u6548\u7387\u4e0e\u8f93\u5165\u6570\u636e\u4f53\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002
        • \u201c\u65f6\u95f4\u548c\u7a7a\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u201d\u8868\u793a\u590d\u6742\u5ea6\u5206\u6790\u5173\u6ce8\u7684\u4e0d\u662f\u8fd0\u884c\u65f6\u95f4\u6216\u5360\u7528\u7a7a\u95f4\u7684\u5177\u4f53\u503c\uff0c\u800c\u662f\u65f6\u95f4\u6216\u7a7a\u95f4\u589e\u957f\u7684\u201c\u5feb\u6162\u201d\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u514b\u670d\u4e86\u5b9e\u9645\u6d4b\u8bd5\u65b9\u6cd5\u7684\u5f0a\u7aef\uff0c\u4f53\u73b0\u5728\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u9762\u3002

        • \u5b83\u72ec\u7acb\u4e8e\u6d4b\u8bd5\u73af\u5883\uff0c\u5206\u6790\u7ed3\u679c\u9002\u7528\u4e8e\u6240\u6709\u8fd0\u884c\u5e73\u53f0\u3002
        • \u5b83\u53ef\u4ee5\u4f53\u73b0\u4e0d\u540c\u6570\u636e\u91cf\u4e0b\u7684\u7b97\u6cd5\u6548\u7387\uff0c\u5c24\u5176\u662f\u5728\u5927\u6570\u636e\u91cf\u4e0b\u7684\u7b97\u6cd5\u6027\u80fd\u3002

        Tip

        \u5982\u679c\u4f60\u4ecd\u5bf9\u590d\u6742\u5ea6\u7684\u6982\u5ff5\u611f\u5230\u56f0\u60d1\uff0c\u65e0\u987b\u62c5\u5fc3\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u7eed\u7ae0\u8282\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u628a\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u7684\u201c\u6807\u5c3a\u201d\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u8861\u91cf\u6267\u884c\u67d0\u4e2a\u7b97\u6cd5\u6240\u9700\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\uff0c\u5bf9\u6bd4\u4e0d\u540c\u7b97\u6cd5\u4e4b\u95f4\u7684\u6548\u7387\u3002

        \u590d\u6742\u5ea6\u662f\u4e2a\u6570\u5b66\u6982\u5ff5\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u53ef\u80fd\u6bd4\u8f83\u62bd\u8c61\uff0c\u5b66\u4e60\u96be\u5ea6\u76f8\u5bf9\u8f83\u9ad8\u3002\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u770b\uff0c\u590d\u6742\u5ea6\u5206\u6790\u53ef\u80fd\u4e0d\u592a\u9002\u5408\u4f5c\u4e3a\u6700\u5148\u4ecb\u7ecd\u7684\u5185\u5bb9\u3002\u7136\u800c\uff0c\u5f53\u6211\u4eec\u8ba8\u8bba\u67d0\u4e2a\u6570\u636e\u7ed3\u6784\u6216\u7b97\u6cd5\u7684\u7279\u70b9\u65f6\uff0c\u96be\u4ee5\u907f\u514d\u8981\u5206\u6790\u5176\u8fd0\u884c\u901f\u5ea6\u548c\u7a7a\u95f4\u4f7f\u7528\u60c5\u51b5\u3002

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u5efa\u8bae\u4f60\u5728\u6df1\u5165\u5b66\u4e60\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u4e4b\u524d\uff0c\u5148\u5bf9\u590d\u6742\u5ea6\u5206\u6790\u5efa\u7acb\u521d\u6b65\u7684\u4e86\u89e3\uff0c\u4ee5\u4fbf\u80fd\u591f\u5b8c\u6210\u7b80\u5355\u7b97\u6cd5\u7684\u590d\u6742\u5ea6\u5206\u6790\u3002

        "},{"location":"chapter_computational_complexity/space_complexity/","title":"2.4 \u00a0 \u7a7a\u95f4\u590d\u6742\u5ea6","text":"

        \u300c\u7a7a\u95f4\u590d\u6742\u5ea6 space complexity\u300d\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u968f\u7740\u6570\u636e\u91cf\u53d8\u5927\u65f6\u7684\u589e\u957f\u8d8b\u52bf\u3002\u8fd9\u4e2a\u6982\u5ff5\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u975e\u5e38\u7c7b\u4f3c\uff0c\u53ea\u9700\u5c06\u201c\u8fd0\u884c\u65f6\u95f4\u201d\u66ff\u6362\u4e3a\u201c\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u201d\u3002

        "},{"location":"chapter_computational_complexity/space_complexity/#241","title":"2.4.1 \u00a0 \u7b97\u6cd5\u76f8\u5173\u7a7a\u95f4","text":"

        \u7b97\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002

        • \u8f93\u5165\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u7684\u8f93\u5165\u6570\u636e\u3002
        • \u6682\u5b58\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u53d8\u91cf\u3001\u5bf9\u8c61\u3001\u51fd\u6570\u4e0a\u4e0b\u6587\u7b49\u6570\u636e\u3002
        • \u8f93\u51fa\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u7684\u8f93\u51fa\u6570\u636e\u3002

        \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u7edf\u8ba1\u8303\u56f4\u662f\u201c\u6682\u5b58\u7a7a\u95f4\u201d\u52a0\u4e0a\u201c\u8f93\u51fa\u7a7a\u95f4\u201d\u3002

        \u6682\u5b58\u7a7a\u95f4\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\u3002

        • \u6682\u5b58\u6570\u636e\uff1a\u7528\u4e8e\u4fdd\u5b58\u7b97\u6cd5\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u5404\u79cd\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u7b49\u3002
        • \u6808\u5e27\u7a7a\u95f4\uff1a\u7528\u4e8e\u4fdd\u5b58\u8c03\u7528\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u6570\u636e\u3002\u7cfb\u7edf\u5728\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u4f1a\u5728\u6808\u9876\u90e8\u521b\u5efa\u4e00\u4e2a\u6808\u5e27\uff0c\u51fd\u6570\u8fd4\u56de\u540e\uff0c\u6808\u5e27\u7a7a\u95f4\u4f1a\u88ab\u91ca\u653e\u3002
        • \u6307\u4ee4\u7a7a\u95f4\uff1a\u7528\u4e8e\u4fdd\u5b58\u7f16\u8bd1\u540e\u7684\u7a0b\u5e8f\u6307\u4ee4\uff0c\u5728\u5b9e\u9645\u7edf\u8ba1\u4e2d\u901a\u5e38\u5ffd\u7565\u4e0d\u8ba1\u3002

        \u5728\u5206\u6790\u4e00\u6bb5\u7a0b\u5e8f\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u7edf\u8ba1\u6682\u5b58\u6570\u636e\u3001\u6808\u5e27\u7a7a\u95f4\u548c\u8f93\u51fa\u6570\u636e\u4e09\u90e8\u5206\uff0c\u5982\u56fe 2-15 \u6240\u793a\u3002

        \u56fe 2-15 \u00a0 \u7b97\u6cd5\u4f7f\u7528\u7684\u76f8\u5173\u7a7a\u95f4

        \u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class Node:\n\"\"\"\u7c7b\"\"\"\ndef __init__(self, x: int):\nself.val: int = x              # \u8282\u70b9\u503c\nself.next: Node | None = None  # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\ndef function() -> int:\n\"\"\"\u51fd\u6570\"\"\"\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\ndef algorithm(n) -> int:  # \u8f93\u5165\u6570\u636e\nA = 0                 # \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff0c\u4e00\u822c\u7528\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff09\nb = 0                 # \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nnode = Node(0)        # \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nc = function()        # \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn A + b + c      # \u8f93\u51fa\u6570\u636e\n
        /* \u7ed3\u6784\u4f53 */\nstruct Node {\nint val;\nNode *next;\nNode(int x) : val(x), next(nullptr) {}\n};\n/* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nconst int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode* node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = func();           // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nint val;\nNode next;\nNode(int x) { val = x; }\n}\n/* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nfinal int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = new Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node(int x) {\nint val = x;\nNode next;\n}\n/* \u51fd\u6570 */\nint Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint Algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nconst int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = new(0);       // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = Function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7ed3\u6784\u4f53 */\ntype node struct {\nval  int\nnext *node\n}\n/* \u521b\u5efa node \u7ed3\u6784\u4f53  */\nfunc newNode(val int) *node {\nreturn &node{val: val}\n}\n/* \u51fd\u6570 */\nfunc function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\nfunc algorithm(n int) int { // \u8f93\u5165\u6570\u636e\nconst a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nb := 0                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nnewNode(0)              // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nc := function()         // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c        // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nvar val: Int\nvar next: Node?\ninit(x: Int) {\nval = x\n}\n}\n/* \u51fd\u6570 */\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\nfunc algorithm(n: Int) -> Int { // \u8f93\u5165\u6570\u636e\nlet a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nvar b = 0             // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nlet node = Node(x: 0) // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nlet c = function()    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c      // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nval;\nnext;\nconstructor(val) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n/* \u51fd\u6570 */\nfunction constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\nfunction algorithm(n) {       // \u8f93\u5165\u6570\u636e\nconst a = 0;              // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nconst node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nconst c = constFunc();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nval: number;\nnext: Node | null;\nconstructor(val?: number) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n/* \u51fd\u6570 */\nfunction constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\nfunction algorithm(n: number): number { // \u8f93\u5165\u6570\u636e\nconst a = 0;                        // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet b = 0;                          // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nconst node = new Node(0);           // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nconst c = constFunc();              // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;                   // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nint val;\nNode next;\nNode(this.val, [this.next]);\n}\n/* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {  // \u8f93\u5165\u6570\u636e\nconst int a = 0;      // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;            // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = function();   // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;     // \u8f93\u51fa\u6570\u636e\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u7ed3\u6784\u4f53 */\nstruct Node {\nval: i32,\nnext: Option<Rc<RefCell<Node>>>,\n}\n/* \u521b\u5efa Node \u7ed3\u6784\u4f53 */\nimpl Node {\nfn new(val: i32) -> Self {\nSelf { val: val, next: None }\n}\n}\n/* \u51fd\u6570 */\nfn function() -> i32 {      // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nfn algorithm(n: i32) -> i32 {       // \u8f93\u5165\u6570\u636e\nconst a: i32 = 0;               // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet mut b = 0;                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nlet node = Node::new(0);        // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nlet c = function();             // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;               // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) { // \u8f93\u5165\u6570\u636e\nconst int a = 0;   // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;         // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nint c = func();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;  // \u8f93\u51fa\u6570\u636e\n}\n
        \n
        "},{"location":"chapter_computational_complexity/space_complexity/#242","title":"2.4.2 \u00a0 \u63a8\u7b97\u65b9\u6cd5","text":"

        \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u5927\u81f4\u76f8\u540c\uff0c\u53ea\u9700\u5c06\u7edf\u8ba1\u5bf9\u8c61\u4ece\u201c\u64cd\u4f5c\u6570\u91cf\u201d\u8f6c\u4e3a\u201c\u4f7f\u7528\u7a7a\u95f4\u5927\u5c0f\u201d\u3002

        \u800c\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u540c\u7684\u662f\uff0c\u6211\u4eec\u901a\u5e38\u53ea\u5173\u6ce8\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u3002\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u7a7a\u95f4\u662f\u4e00\u9879\u786c\u6027\u8981\u6c42\uff0c\u6211\u4eec\u5fc5\u987b\u786e\u4fdd\u5728\u6240\u6709\u8f93\u5165\u6570\u636e\u4e0b\u90fd\u6709\u8db3\u591f\u7684\u5185\u5b58\u7a7a\u95f4\u9884\u7559\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e2d\u7684\u201c\u6700\u5dee\u201d\u6709\u4e24\u5c42\u542b\u4e49\u3002

        1. \u4ee5\u6700\u5dee\u8f93\u5165\u6570\u636e\u4e3a\u51c6\uff1a\u5f53 \\(n < 10\\) \u65f6\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff1b\u4f46\u5f53 \\(n > 10\\) \u65f6\uff0c\u521d\u59cb\u5316\u7684\u6570\u7ec4 nums \u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\uff0c\u56e0\u6b64\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        2. \u4ee5\u7b97\u6cd5\u8fd0\u884c\u4e2d\u7684\u5cf0\u503c\u5185\u5b58\u4e3a\u51c6\uff1a\u4f8b\u5982\uff0c\u7a0b\u5e8f\u5728\u6267\u884c\u6700\u540e\u4e00\u884c\u4e4b\u524d\uff0c\u5360\u7528 \\(O(1)\\) \u7a7a\u95f4\uff1b\u5f53\u521d\u59cb\u5316\u6570\u7ec4 nums \u65f6\uff0c\u7a0b\u5e8f\u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\uff0c\u56e0\u6b64\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 0               # O(1)\nb = [0] * 10000     # O(1)\nif n > 10:\nnums = [0] * n  # O(n)\n
        void algorithm(int n) {\nint a = 0;               // O(1)\nvector<int> b(10000);    // O(1)\nif (n > 10)\nvector<int> nums(n); // O(n)\n}\n
        void algorithm(int n) {\nint a = 0;                   // O(1)\nint[] b = new int[10000];    // O(1)\nif (n > 10)\nint[] nums = new int[n]; // O(n)\n}\n
        void Algorithm(int n) {\nint a = 0;                   // O(1)\nint[] b = new int[10000];    // O(1)\nif (n > 10) {\nint[] nums = new int[n]; // O(n)\n}\n}\n
        func algorithm(n int) {\na := 0                      // O(1)\nb := make([]int, 10000)     // O(1)\nvar nums []int\nif n > 10 {\nnums := make([]int, n)  // O(n)\n}\nfmt.Println(a, b, nums)\n}\n
        func algorithm(n: Int) {\nlet a = 0 // O(1)\nlet b = Array(repeating: 0, count: 10000) // O(1)\nif n > 10 {\nlet nums = Array(repeating: 0, count: n) // O(n)\n}\n}\n
        function algorithm(n) {\nconst a = 0;                   // O(1)\nconst b = new Array(10000);    // O(1)\nif (n > 10) {\nconst nums = new Array(n); // O(n)\n}\n}\n
        function algorithm(n: number): void {\nconst a = 0;                   // O(1)\nconst b = new Array(10000);    // O(1)\nif (n > 10) {\nconst nums = new Array(n); // O(n)\n}\n}\n
        void algorithm(int n) {\nint a = 0;                            // O(1)\nList<int> b = List.filled(10000, 0);  // O(1)\nif (n > 10) {\nList<int> nums = List.filled(n, 0); // O(n)\n}\n}\n
        fn algorithm(n: i32) {\nlet a = 0;                              // O(1)\nlet b = [0; 10000];                     // O(1)\nif n > 10 {\nlet nums = vec![0; n as usize];     // O(n)\n}\n}\n
        void algorithm(int n) {\nint a = 0;               // O(1)\nint b[10000];            // O(1)\nif (n > 10)\nint nums[n] = {0};   // O(n)\n}\n
        \n

        \u5728\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u7edf\u8ba1\u6808\u5e27\u7a7a\u95f4\u3002\u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def function() -> int:\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\ndef loop(n: int):\n\"\"\"\u5faa\u73af O(1)\"\"\"\nfor _ in range(n):\nfunction()\ndef recur(n: int) -> int:\n\"\"\"\u9012\u5f52 O(n)\"\"\"\nif n == 1: return\nreturn recur(n - 1)\n
        int func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        int function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        int Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid Loop(int n) {\nfor (int i = 0; i < n; i++) {\nFunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nint Recur(int n) {\nif (n == 1) return 1;\nreturn Recur(n - 1);\n}\n
        func function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5faa\u73af O(1) */\nfunc loop(n int) {\nfor i := 0; i < n; i++ {\nfunction()\n}\n}\n/* \u9012\u5f52 O(n) */\nfunc recur(n int) {\nif n == 1 {\nreturn\n}\nrecur(n - 1)\n}\n
        @discardableResult\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5faa\u73af O(1) */\nfunc loop(n: Int) {\nfor _ in 0 ..< n {\nfunction()\n}\n}\n/* \u9012\u5f52 O(n) */\nfunc recur(n: Int) {\nif n == 1 {\nreturn\n}\nrecur(n: n - 1)\n}\n
        function constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n) {\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n) {\nif (n === 1) return;\nreturn recur(n - 1);\n}\n
        function constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n: number): void {\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n: number): void {\nif (n === 1) return;\nreturn recur(n - 1);\n}\n
        int function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        fn function() -> i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfn loop(n: i32) {\nfor i in 0..n {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(n: i32) {\nif n == 1 {\nreturn;\n}\nrecur(n - 1);\n}\n
        int func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        \n

        \u51fd\u6570 loop() \u548c recur() \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n)\\) \uff0c\u4f46\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0d\u540c\u3002

        • \u51fd\u6570 loop() \u5728\u5faa\u73af\u4e2d\u8c03\u7528\u4e86 \\(n\\) \u6b21 function() \uff0c\u6bcf\u8f6e\u4e2d\u7684 function() \u90fd\u8fd4\u56de\u5e76\u91ca\u653e\u4e86\u6808\u5e27\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \u3002
        • \u9012\u5f52\u51fd\u6570 recur() \u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f1a\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684 recur() \uff0c\u4ece\u800c\u5360\u7528 \\(O(n)\\) \u7684\u6808\u5e27\u7a7a\u95f4\u3002
        "},{"location":"chapter_computational_complexity/space_complexity/#243","title":"2.4.3 \u00a0 \u5e38\u89c1\u7c7b\u578b","text":"

        \u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u56fe 2-16 \u5c55\u793a\u4e86\u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\uff08\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\uff09\u3002

        \\[ \\begin{aligned} O(1) < O(\\log n) < O(n) < O(n^2) < O(2^n) \\newline \\text{\u5e38\u6570\u9636} < \\text{\u5bf9\u6570\u9636} < \\text{\u7ebf\u6027\u9636} < \\text{\u5e73\u65b9\u9636} < \\text{\u6307\u6570\u9636} \\end{aligned} \\]

        \u56fe 2-16 \u00a0 \u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b

        "},{"location":"chapter_computational_complexity/space_complexity/#1-o1","title":"1. \u00a0 \u5e38\u6570\u9636 \\(O(1)\\)","text":"

        \u5e38\u6570\u9636\u5e38\u89c1\u4e8e\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u5faa\u73af\u4e2d\u521d\u59cb\u5316\u53d8\u91cf\u6216\u8c03\u7528\u51fd\u6570\u800c\u5360\u7528\u7684\u5185\u5b58\uff0c\u5728\u8fdb\u5165\u4e0b\u4e00\u5faa\u73af\u540e\u5c31\u4f1a\u88ab\u91ca\u653e\uff0c\u56e0\u6b64\u4e0d\u4f1a\u7d2f\u79ef\u5360\u7528\u7a7a\u95f4\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def function() -> int:\n\"\"\"\u51fd\u6570\"\"\"\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\ndef constant(n: int):\n\"\"\"\u5e38\u6570\u9636\"\"\"\n# \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\na = 0\nnums = [0] * 10000\nnode = ListNode(0)\n# \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in range(n):\nc = 0\n# \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in range(n):\nfunction()\n
        space_complexity.cpp
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst int a = 0;\nint b = 0;\nvector<int> nums(10000);\nListNode node(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n
        space_complexity.java
        /* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nfinal int a = 0;\nint b = 0;\nint[] nums = new int[10000];\nListNode node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n
        space_complexity.cs
        /* \u51fd\u6570 */\nint Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid Constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nint a = 0;\nint b = 0;\nint[] nums = new int[10000];\nListNode node = new(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nFunction();\n}\n}\n
        space_complexity.go
        /* \u51fd\u6570 */\nfunc function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\n/* \u5e38\u6570\u9636 */\nfunc spaceConstant(n int) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0\nb := 0\nnums := make([]int, 10000)\nListNode := newNode(0)\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nvar c int\nfor i := 0; i < n; i++ {\nc = 0\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor i := 0; i < n; i++ {\nfunction()\n}\nfmt.Println(a, b, nums, c, ListNode)\n}\n
        space_complexity.swift
        /* \u51fd\u6570 */\n@discardableResult\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5e38\u6570\u9636 */\nfunc constant(n: Int) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nlet a = 0\nvar b = 0\nlet nums = Array(repeating: 0, count: 10000)\nlet node = ListNode(x: 0)\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in 0 ..< n {\nlet c = 0\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in 0 ..< n {\nfunction()\n}\n}\n
        space_complexity.js
        /* \u51fd\u6570 */\nfunction constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nfunction constant(n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0;\nconst b = 0;\nconst nums = new Array(10000);\nconst node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconst c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n
        space_complexity.ts
        /* \u51fd\u6570 */\nfunction constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nfunction constant(n: number): void {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0;\nconst b = 0;\nconst nums = new Array(10000);\nconst node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconst c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n
        space_complexity.dart
        /* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nfinal int a = 0;\nint b = 0;\nList<int> nums = List.filled(10000, 0);\nListNode node = ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (var i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (var i = 0; i < n; i++) {\nfunction();\n}\n}\n
        space_complexity.rs
        /* \u51fd\u6570 */\nfn function() ->i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\n#[allow(unused)]\nfn constant(n: i32) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst A: i32 = 0;\nlet b = 0;\nlet nums = vec![0; 10000];\nlet node = ListNode::new(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor i in 0..n {\nlet c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor i in 0..n {\nfunction();\n}\n}\n
        space_complexity.c
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst int a = 0;\nint b = 0;\nint nums[1000];\nListNode *node = newListNode(0);\nfree(node);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n
        space_complexity.zig
        // \u51fd\u6570\nfn function() i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n// \u5e38\u6570\u9636\nfn constant(n: i32) void {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a: i32 = 0;\nvar b: i32 = 0;\nvar nums = [_]i32{0}**10000;\nvar node = inc.ListNode(i32){.val = 0};\nvar i: i32 = 0;\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nwhile (i < n) : (i += 1) {\nvar c: i32 = 0;\n_ = c;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\ni = 0;\nwhile (i < n) : (i += 1) {\n_ = function();\n}\n_ = a;\n_ = b;\n_ = nums;\n_ = node;\n}\n
        "},{"location":"chapter_computational_complexity/space_complexity/#2-on","title":"2. \u00a0 \u7ebf\u6027\u9636 \\(O(n)\\)","text":"

        \u7ebf\u6027\u9636\u5e38\u89c1\u4e8e\u5143\u7d20\u6570\u91cf\u4e0e \\(n\\) \u6210\u6b63\u6bd4\u7684\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u7b49\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def linear(n: int):\n\"\"\"\u7ebf\u6027\u9636\"\"\"\n# \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nnums = [0] * n\n# \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nhmap = dict[int, str]()\nfor i in range(n):\nhmap[i] = str(i)\n
        space_complexity.cpp
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nvector<int> nums(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvector<ListNode> nodes;\nfor (int i = 0; i < n; i++) {\nnodes.push_back(ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nunordered_map<int, string> map;\nfor (int i = 0; i < n; i++) {\nmap[i] = to_string(i);\n}\n}\n
        space_complexity.java
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint[] nums = new int[n];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nnodes.add(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nMap<Integer, String> map = new HashMap<>();\nfor (int i = 0; i < n; i++) {\nmap.put(i, String.valueOf(i));\n}\n}\n
        space_complexity.cs
        /* \u7ebf\u6027\u9636 */\nvoid Linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint[] nums = new int[n];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = [];\nfor (int i = 0; i < n; i++) {\nnodes.Add(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nDictionary<int, string> map = [];\nfor (int i = 0; i < n; i++) {\nmap.Add(i, i.ToString());\n}\n}\n
        space_complexity.go
        /* \u7ebf\u6027\u9636 */\nfunc spaceLinear(n int) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\n_ = make([]int, n)\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar nodes []*node\nfor i := 0; i < n; i++ {\nnodes = append(nodes, newNode(i))\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nm := make(map[int]string, n)\nfor i := 0; i < n; i++ {\nm[i] = strconv.Itoa(i)\n}\n}\n
        space_complexity.swift
        /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nlet nums = Array(repeating: 0, count: n)\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet nodes = (0 ..< n).map { ListNode(x: $0) }\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet map = Dictionary(uniqueKeysWithValues: (0 ..< n).map { ($0, \"\\($0)\") })\n}\n
        space_complexity.js
        /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nconst nums = new Array(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst nodes = [];\nfor (let i = 0; i < n; i++) {\nnodes.push(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst map = new Map();\nfor (let i = 0; i < n; i++) {\nmap.set(i, i.toString());\n}\n}\n
        space_complexity.ts
        /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): void {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nconst nums = new Array(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst nodes: ListNode[] = [];\nfor (let i = 0; i < n; i++) {\nnodes.push(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst map = new Map();\nfor (let i = 0; i < n; i++) {\nmap.set(i, i.toString());\n}\n}\n
        space_complexity.dart
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nList<int> nums = List.filled(n, 0);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = [];\nfor (var i = 0; i < n; i++) {\nnodes.add(ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nMap<int, String> map = HashMap();\nfor (var i = 0; i < n; i++) {\nmap.putIfAbsent(i, () => i.toString());\n}\n}\n
        space_complexity.rs
        /* \u7ebf\u6027\u9636 */\n#[allow(unused)]\nfn linear(n: i32) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut nums = vec![0; n as usize];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut nodes = Vec::new();\nfor i in 0..n {\nnodes.push(ListNode::new(i))\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut map = HashMap::new();\nfor i in 0..n {\nmap.insert(i, i.to_string());\n}\n}\n
        space_complexity.c
        /* \u54c8\u5e0c\u8868 */\ntypedef struct {\nint key;\nint val;\nUT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n/* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint *nums = malloc(sizeof(int) * n);\nfree(nums);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nListNode **nodes = malloc(sizeof(ListNode *) * n);\nfor (int i = 0; i < n; i++) {\nnodes[i] = newListNode(i);\n}\n// \u5185\u5b58\u91ca\u653e\nfor (int i = 0; i < n; i++) {\nfree(nodes[i]);\n}\nfree(nodes);\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nHashTable *h = NULL;\nfor (int i = 0; i < n; i++) {\nHashTable *tmp = malloc(sizeof(HashTable));\ntmp->key = i;\ntmp->val = i;\nHASH_ADD_INT(h, key, tmp);\n}\n// \u5185\u5b58\u91ca\u653e\nHashTable *curr, *tmp;\nHASH_ITER(hh, h, curr, tmp) {\nHASH_DEL(h, curr);\nfree(curr);\n}\n}\n
        space_complexity.zig
        // \u7ebf\u6027\u9636\nfn linear(comptime n: i32) !void {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nvar nums = [_]i32{0}**n;\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar nodes = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nodes.deinit();\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\ntry nodes.append(i);\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar map = std.AutoArrayHashMap(i32, []const u8).init(std.heap.page_allocator);\ndefer map.deinit();\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\nconst string = try std.fmt.allocPrint(std.heap.page_allocator, \"{d}\", .{j});\ndefer std.heap.page_allocator.free(string);\ntry map.put(i, string);\n}\n_ = nums;\n}\n

        \u5982\u56fe 2-17 \u6240\u793a\uff0c\u6b64\u51fd\u6570\u7684\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u5373\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684 linear_recur() \u51fd\u6570\uff0c\u4f7f\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def linear_recur(n: int):\n\"\"\"\u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nprint(\"\u9012\u5f52 n =\", n)\nif n == 1:\nreturn\nlinear_recur(n - 1)\n
        space_complexity.cpp
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\ncout << \"\u9012\u5f52 n = \" << n << endl;\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.java
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nSystem.out.println(\"\u9012\u5f52 n = \" + n);\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.cs
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid LinearRecur(int n) {\nConsole.WriteLine(\"\u9012\u5f52 n = \" + n);\nif (n == 1) return;\nLinearRecur(n - 1);\n}\n
        space_complexity.go
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceLinearRecur(n int) {\nfmt.Println(\"\u9012\u5f52 n =\", n)\nif n == 1 {\nreturn\n}\nspaceLinearRecur(n - 1)\n}\n
        space_complexity.swift
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc linearRecur(n: Int) {\nprint(\"\u9012\u5f52 n = \\(n)\")\nif n == 1 {\nreturn\n}\nlinearRecur(n: n - 1)\n}\n
        space_complexity.js
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n) {\nconsole.log(`\u9012\u5f52 n = ${n}`);\nif (n === 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.ts
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n: number): void {\nconsole.log(`\u9012\u5f52 n = ${n}`);\nif (n === 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.dart
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nprint('\u9012\u5f52 n = $n');\nif (n == 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.rs
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn linear_recur(n: i32) {\nprintln!(\"\u9012\u5f52 n = {}\", n);\nif n == 1 {return};\nlinear_recur(n - 1);\n}\n
        space_complexity.c
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nprintf(\"\u9012\u5f52 n = %d\\r\\n\", n);\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.zig
        // \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn linearRecur(comptime n: i32) void {\nstd.debug.print(\"\u9012\u5f52 n = {}\\n\", .{n});\nif (n == 1) return;\nlinearRecur(n - 1);\n}\n

        \u56fe 2-17 \u00a0 \u9012\u5f52\u51fd\u6570\u4ea7\u751f\u7684\u7ebf\u6027\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#3-on2","title":"3. \u00a0 \u5e73\u65b9\u9636 \\(O(n^2)\\)","text":"

        \u5e73\u65b9\u9636\u5e38\u89c1\u4e8e\u77e9\u9635\u548c\u56fe\uff0c\u5143\u7d20\u6570\u91cf\u4e0e \\(n\\) \u6210\u5e73\u65b9\u5173\u7cfb\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def quadratic(n: int):\n\"\"\"\u5e73\u65b9\u9636\"\"\"\n# \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nnum_matrix = [[0] * n for _ in range(n)]\n
        space_complexity.cpp
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nvector<vector<int>> numMatrix;\nfor (int i = 0; i < n; i++) {\nvector<int> tmp;\nfor (int j = 0; j < n; j++) {\ntmp.push_back(0);\n}\nnumMatrix.push_back(tmp);\n}\n}\n
        space_complexity.java
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nint[][] numMatrix = new int[n][n];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<Integer>> numList = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nList<Integer> tmp = new ArrayList<>();\nfor (int j = 0; j < n; j++) {\ntmp.add(0);\n}\nnumList.add(tmp);\n}\n}\n
        space_complexity.cs
        /* \u5e73\u65b9\u9636 */\nvoid Quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nint[,] numMatrix = new int[n, n];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numList = [];\nfor (int i = 0; i < n; i++) {\nList<int> tmp = [];\nfor (int j = 0; j < n; j++) {\ntmp.Add(0);\n}\nnumList.Add(tmp);\n}\n}\n
        space_complexity.go
        /* \u5e73\u65b9\u9636 */\nfunc spaceQuadratic(n int) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nnumMatrix := make([][]int, n)\nfor i := 0; i < n; i++ {\nnumMatrix[i] = make([]int, n)\n}\n}\n
        space_complexity.swift
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet numList = Array(repeating: Array(repeating: 0, count: n), count: n)\n}\n
        space_complexity.js
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numMatrix = Array(n)\n.fill(null)\n.map(() => Array(n).fill(null));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numList = [];\nfor (let i = 0; i < n; i++) {\nconst tmp = [];\nfor (let j = 0; j < n; j++) {\ntmp.push(0);\n}\nnumList.push(tmp);\n}\n}\n
        space_complexity.ts
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): void {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numMatrix = Array(n)\n.fill(null)\n.map(() => Array(n).fill(null));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numList = [];\nfor (let i = 0; i < n; i++) {\nconst tmp = [];\nfor (let j = 0; j < n; j++) {\ntmp.push(0);\n}\nnumList.push(tmp);\n}\n}\n
        space_complexity.dart
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numMatrix = List.generate(n, (_) => List.filled(n, 0));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numList = [];\nfor (var i = 0; i < n; i++) {\nList<int> tmp = [];\nfor (int j = 0; j < n; j++) {\ntmp.add(0);\n}\nnumList.add(tmp);\n}\n}\n
        space_complexity.rs
        /* \u5e73\u65b9\u9636 */\n#[allow(unused)]\nfn quadratic(n: i32) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet num_matrix = vec![vec![0; n as usize]; n as usize];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet mut num_list = Vec::new();\nfor i in 0..n {\nlet mut tmp = Vec::new();\nfor j in 0..n {\ntmp.push(0);\n}\nnum_list.push(tmp);\n}\n}\n
        space_complexity.c
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nint **numMatrix = malloc(sizeof(int *) * n);\nfor (int i = 0; i < n; i++) {\nint *tmp = malloc(sizeof(int) * n);\nfor (int j = 0; j < n; j++) {\ntmp[j] = 0;\n}\nnumMatrix[i] = tmp;\n}\n// \u5185\u5b58\u91ca\u653e\nfor (int i = 0; i < n; i++) {\nfree(numMatrix[i]);\n}\nfree(numMatrix);\n}\n
        space_complexity.zig
        // \u5e73\u65b9\u9636\nfn quadratic(n: i32) !void {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nvar nodes = std.ArrayList(std.ArrayList(i32)).init(std.heap.page_allocator);\ndefer nodes.deinit();\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\nvar tmp = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer tmp.deinit();\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\ntry tmp.append(0);\n}\ntry nodes.append(tmp);\n}\n}\n

        \u5982\u56fe 2-18 \u6240\u793a\uff0c\u8be5\u51fd\u6570\u7684\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u5728\u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u4e2d\u90fd\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u6570\u7ec4\uff0c\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\)\u3001\\(n-1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u5e73\u5747\u957f\u5ea6\u4e3a \\(n / 2\\) \uff0c\u56e0\u6b64\u603b\u4f53\u5360\u7528 \\(O(n^2)\\) \u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def quadratic_recur(n: int) -> int:\n\"\"\"\u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n <= 0:\nreturn 0\n# \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nnums = [0] * n\nreturn quadratic_recur(n - 1)\n
        space_complexity.cpp
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\nvector<int> nums(n);\ncout << \"\u9012\u5f52 n = \" << n << \" \u4e2d\u7684 nums \u957f\u5ea6 = \" << nums.size() << endl;\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.java
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nint[] nums = new int[n];\nSystem.out.println(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.length);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.cs
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint QuadraticRecur(int n) {\nif (n <= 0) return 0;\nint[] nums = new int[n];\nConsole.WriteLine(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.Length);\nreturn QuadraticRecur(n - 1);\n}\n
        space_complexity.go
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceQuadraticRecur(n int) int {\nif n <= 0 {\nreturn 0\n}\nnums := make([]int, n)\nfmt.Printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d \\n\", n, len(nums))\nreturn spaceQuadraticRecur(n - 1)\n}\n
        space_complexity.swift
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\n@discardableResult\nfunc quadraticRecur(n: Int) -> Int {\nif n <= 0 {\nreturn 0\n}\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nlet nums = Array(repeating: 0, count: n)\nprint(\"\u9012\u5f52 n = \\(n) \u4e2d\u7684 nums \u957f\u5ea6 = \\(nums.count)\")\nreturn quadraticRecur(n: n - 1)\n}\n
        space_complexity.js
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n) {\nif (n <= 0) return 0;\nconst nums = new Array(n);\nconsole.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.ts
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n: number): number {\nif (n <= 0) return 0;\nconst nums = new Array(n);\nconsole.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.dart
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0) return 0;\nList<int> nums = List.filled(n, 0);\nprint('\u9012\u5f52 n = $n \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}');\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.rs
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn quadratic_recur(n: i32) -> i32 {\nif n <= 0 {return 0};\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nlet nums = vec![0; n as usize];\nprintln!(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\", n, nums.len());\nreturn quadratic_recur(n - 1);\n}\n
        space_complexity.c
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\nint *nums = malloc(sizeof(int) * n);\nprintf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d\\r\\n\", n, n);\nint res = quadraticRecur(n - 1);\nfree(nums);\nreturn res;\n}\n
        space_complexity.zig
        // \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn quadraticRecur(comptime n: i32) i32 {\nif (n <= 0) return 0;\nvar nums = [_]i32{0}**n;\nstd.debug.print(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\\n\", .{n, nums.len});\nreturn quadraticRecur(n - 1);\n}\n

        \u56fe 2-18 \u00a0 \u9012\u5f52\u51fd\u6570\u4ea7\u751f\u7684\u5e73\u65b9\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#4-o2n","title":"4. \u00a0 \u6307\u6570\u9636 \\(O(2^n)\\)","text":"

        \u6307\u6570\u9636\u5e38\u89c1\u4e8e\u4e8c\u53c9\u6811\u3002\u89c2\u5bdf\u56fe 2-19 \uff0c\u9ad8\u5ea6\u4e3a \\(n\\) \u7684\u201c\u6ee1\u4e8c\u53c9\u6811\u201d\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(2^n - 1\\) \uff0c\u5360\u7528 \\(O(2^n)\\) \u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def build_tree(n: int) -> TreeNode | None:\n\"\"\"\u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09\"\"\"\nif n == 0:\nreturn None\nroot = TreeNode(0)\nroot.left = build_tree(n - 1)\nroot.right = build_tree(n - 1)\nreturn root\n
        space_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\nif (n == 0)\nreturn nullptr;\nTreeNode *root = new TreeNode(0);\nroot->left = buildTree(n - 1);\nroot->right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.java
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode buildTree(int n) {\nif (n == 0)\nreturn null;\nTreeNode root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.cs
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? BuildTree(int n) {\nif (n == 0) return null;\nTreeNode root = new(0) {\nleft = BuildTree(n - 1),\nright = BuildTree(n - 1)\n};\nreturn root;\n}\n
        space_complexity.go
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n int) *treeNode {\nif n == 0 {\nreturn nil\n}\nroot := newTreeNode(0)\nroot.left = buildTree(n - 1)\nroot.right = buildTree(n - 1)\nreturn root\n}\n
        space_complexity.swift
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n: Int) -> TreeNode? {\nif n == 0 {\nreturn nil\n}\nlet root = TreeNode(x: 0)\nroot.left = buildTree(n: n - 1)\nroot.right = buildTree(n: n - 1)\nreturn root\n}\n
        space_complexity.js
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n) {\nif (n === 0) return null;\nconst root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.ts
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n: number): TreeNode | null {\nif (n === 0) return null;\nconst root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.dart
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? buildTree(int n) {\nif (n == 0) return null;\nTreeNode root = TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.rs
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfn build_tree(n: i32) -> Option<Rc<RefCell<TreeNode>>> {\nif n == 0 {return None};\nlet root = TreeNode::new(0);\nroot.borrow_mut().left = build_tree(n - 1);\nroot.borrow_mut().right = build_tree(n - 1);\nreturn Some(root);\n}\n
        space_complexity.c
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\nif (n == 0)\nreturn NULL;\nTreeNode *root = newTreeNode(0);\nroot->left = buildTree(n - 1);\nroot->right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.zig
        // \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09\nfn buildTree(mem_allocator: std.mem.Allocator, n: i32) !?*inc.TreeNode(i32) {\nif (n == 0) return null;\nconst root = try mem_allocator.create(inc.TreeNode(i32));\nroot.init(0);\nroot.left = try buildTree(mem_allocator, n - 1);\nroot.right = try buildTree(mem_allocator, n - 1);\nreturn root;\n}\n

        \u56fe 2-19 \u00a0 \u6ee1\u4e8c\u53c9\u6811\u4ea7\u751f\u7684\u6307\u6570\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#5-olog-n","title":"5. \u00a0 \u5bf9\u6570\u9636 \\(O(\\log n)\\)","text":"

        \u5bf9\u6570\u9636\u5e38\u89c1\u4e8e\u5206\u6cbb\u7b97\u6cd5\u3002\u4f8b\u5982\u5f52\u5e76\u6392\u5e8f\uff0c\u8f93\u5165\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\uff0c\u6bcf\u8f6e\u9012\u5f52\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5212\u5206\u4e3a\u4e24\u534a\uff0c\u5f62\u6210\u9ad8\u5ea6\u4e3a \\(\\log n\\) \u7684\u9012\u5f52\u6811\uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u6808\u5e27\u7a7a\u95f4\u3002

        \u518d\u4f8b\u5982\u5c06\u6570\u5b57\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u8f93\u5165\u4e00\u4e2a\u6b63\u6574\u6570 \\(n\\) \uff0c\u5b83\u7684\u4f4d\u6570\u4e3a \\(\\log_{10} n + 1\\) \uff0c\u5373\u5bf9\u5e94\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a \\(\\log_{10} n + 1\\) \uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log_{10} n + 1) = O(\\log n)\\) \u3002

        "},{"location":"chapter_computational_complexity/space_complexity/#244","title":"2.4.4 \u00a0 \u6743\u8861\u65f6\u95f4\u4e0e\u7a7a\u95f4","text":"

        \u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u90fd\u80fd\u8fbe\u5230\u6700\u4f18\u3002\u7136\u800c\u5728\u5b9e\u9645\u60c5\u51b5\u4e2d\uff0c\u540c\u65f6\u4f18\u5316\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u975e\u5e38\u56f0\u96be\u3002

        \u964d\u4f4e\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u9700\u8981\u4ee5\u63d0\u5347\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a\u4ee3\u4ef7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u6211\u4eec\u5c06\u727a\u7272\u5185\u5b58\u7a7a\u95f4\u6765\u63d0\u5347\u7b97\u6cd5\u8fd0\u884c\u901f\u5ea6\u7684\u601d\u8def\u79f0\u4e3a\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\uff1b\u53cd\u4e4b\uff0c\u5219\u79f0\u4e3a\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u3002

        \u9009\u62e9\u54ea\u79cd\u601d\u8def\u53d6\u51b3\u4e8e\u6211\u4eec\u66f4\u770b\u91cd\u54ea\u4e2a\u65b9\u9762\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u65f6\u95f4\u6bd4\u7a7a\u95f4\u66f4\u5b9d\u8d35\uff0c\u56e0\u6b64\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u901a\u5e38\u662f\u66f4\u5e38\u7528\u7684\u7b56\u7565\u3002\u5f53\u7136\uff0c\u5728\u6570\u636e\u91cf\u5f88\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u63a7\u5236\u7a7a\u95f4\u590d\u6742\u5ea6\u4e5f\u975e\u5e38\u91cd\u8981\u3002

        "},{"location":"chapter_computational_complexity/summary/","title":"2.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_computational_complexity/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"

        \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30

        • \u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u662f\u8861\u91cf\u7b97\u6cd5\u4f18\u52a3\u7684\u4e24\u4e2a\u4e3b\u8981\u8bc4\u4ef7\u6307\u6807\u3002
        • \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5b9e\u9645\u6d4b\u8bd5\u6765\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\uff0c\u4f46\u96be\u4ee5\u6d88\u9664\u6d4b\u8bd5\u73af\u5883\u7684\u5f71\u54cd\uff0c\u4e14\u4f1a\u8017\u8d39\u5927\u91cf\u8ba1\u7b97\u8d44\u6e90\u3002
        • \u590d\u6742\u5ea6\u5206\u6790\u53ef\u4ee5\u6d88\u9664\u5b9e\u9645\u6d4b\u8bd5\u7684\u5f0a\u7aef\uff0c\u5206\u6790\u7ed3\u679c\u9002\u7528\u4e8e\u6240\u6709\u8fd0\u884c\u5e73\u53f0\uff0c\u5e76\u4e14\u80fd\u591f\u63ed\u793a\u7b97\u6cd5\u5728\u4e0d\u540c\u6570\u636e\u89c4\u6a21\u4e0b\u7684\u6548\u7387\u3002

        \u65f6\u95f4\u590d\u6742\u5ea6

        • \u65f6\u95f4\u590d\u6742\u5ea6\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u6570\u636e\u91cf\u589e\u957f\u7684\u8d8b\u52bf\uff0c\u53ef\u4ee5\u6709\u6548\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u5931\u6548\uff0c\u5982\u5728\u8f93\u5165\u7684\u6570\u636e\u91cf\u8f83\u5c0f\u6216\u65f6\u95f4\u590d\u6742\u5ea6\u76f8\u540c\u65f6\uff0c\u65e0\u6cd5\u7cbe\u786e\u5bf9\u6bd4\u7b97\u6cd5\u6548\u7387\u7684\u4f18\u52a3\u3002
        • \u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4f7f\u7528\u5927 \\(O\\) \u7b26\u53f7\u8868\u793a\uff0c\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0a\u754c\uff0c\u53cd\u6620\u5f53 \\(n\\) \u8d8b\u5411\u6b63\u65e0\u7a77\u65f6\uff0c\u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u7684\u589e\u957f\u7ea7\u522b\u3002
        • \u63a8\u7b97\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u4e3a\u4e24\u6b65\uff0c\u9996\u5148\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff0c\u7136\u540e\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c\u3002
        • \u5e38\u89c1\u65f6\u95f4\u590d\u6742\u5ea6\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\u6709 \\(O(1)\\)\u3001\\(O(\\log n)\\)\u3001\\(O(n)\\)\u3001\\(O(n \\log n)\\)\u3001\\(O(n^2)\\)\u3001\\(O(2^n)\\) \u548c \\(O(n!)\\) \u7b49\u3002
        • \u67d0\u4e9b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u975e\u56fa\u5b9a\uff0c\u800c\u662f\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u6709\u5173\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u4e3a\u6700\u5dee\u3001\u6700\u4f73\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u51e0\u4e4e\u4e0d\u7528\uff0c\u56e0\u4e3a\u8f93\u5165\u6570\u636e\u4e00\u822c\u9700\u8981\u6ee1\u8db3\u4e25\u683c\u6761\u4ef6\u624d\u80fd\u8fbe\u5230\u6700\u4f73\u60c5\u51b5\u3002
        • \u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u53cd\u6620\u7b97\u6cd5\u5728\u968f\u673a\u6570\u636e\u8f93\u5165\u4e0b\u7684\u8fd0\u884c\u6548\u7387\uff0c\u6700\u63a5\u8fd1\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u7b97\u6cd5\u6027\u80fd\u3002\u8ba1\u7b97\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u9700\u8981\u7edf\u8ba1\u8f93\u5165\u6570\u636e\u5206\u5e03\u4ee5\u53ca\u7efc\u5408\u540e\u7684\u6570\u5b66\u671f\u671b\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6

        • \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u968f\u6570\u636e\u91cf\u589e\u957f\u7684\u8d8b\u52bf\u3002
        • \u7b97\u6cd5\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u76f8\u5173\u5185\u5b58\u7a7a\u95f4\u53ef\u5206\u4e3a\u8f93\u5165\u7a7a\u95f4\u3001\u6682\u5b58\u7a7a\u95f4\u3001\u8f93\u51fa\u7a7a\u95f4\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u7a7a\u95f4\u4e0d\u7eb3\u5165\u7a7a\u95f4\u590d\u6742\u5ea6\u8ba1\u7b97\u3002\u6682\u5b58\u7a7a\u95f4\u53ef\u5206\u4e3a\u6682\u5b58\u6570\u636e\u3001\u6808\u5e27\u7a7a\u95f4\u548c\u6307\u4ee4\u7a7a\u95f4\uff0c\u5176\u4e2d\u6808\u5e27\u7a7a\u95f4\u901a\u5e38\u4ec5\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u5f71\u54cd\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u6211\u4eec\u901a\u5e38\u53ea\u5173\u6ce8\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\uff0c\u5373\u7edf\u8ba1\u7b97\u6cd5\u5728\u6700\u5dee\u8f93\u5165\u6570\u636e\u548c\u6700\u5dee\u8fd0\u884c\u65f6\u523b\u4e0b\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u5e38\u89c1\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\u6709 \\(O(1)\\)\u3001\\(O(\\log n)\\)\u3001\\(O(n)\\)\u3001\\(O(n^2)\\) \u548c \\(O(2^n)\\) \u7b49\u3002
        "},{"location":"chapter_computational_complexity/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u5c3e\u9012\u5f52\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u5417\uff1f

        \u7406\u8bba\u4e0a\uff0c\u5c3e\u9012\u5f52\u51fd\u6570\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(1)\\) \u3002\u4e0d\u8fc7\u7edd\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\uff08\u4f8b\u5982 Java\u3001Python\u3001C++\u3001Go\u3001C# \u7b49\uff09\u4e0d\u652f\u6301\u81ea\u52a8\u4f18\u5316\u5c3e\u9012\u5f52\uff0c\u56e0\u6b64\u901a\u5e38\u8ba4\u4e3a\u7a7a\u95f4\u590d\u6742\u5ea6\u662f \\(O(n)\\) \u3002

        \u51fd\u6570\u548c\u65b9\u6cd5\u8fd9\u4e24\u4e2a\u672f\u8bed\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f

        \u300c\u51fd\u6570 function\u300d\u53ef\u4ee5\u88ab\u72ec\u7acb\u6267\u884c\uff0c\u6240\u6709\u53c2\u6570\u90fd\u4ee5\u663e\u5f0f\u4f20\u9012\u3002\u300c\u65b9\u6cd5 method\u300d\u4e0e\u4e00\u4e2a\u5bf9\u8c61\u5173\u8054\uff0c\u88ab\u9690\u5f0f\u4f20\u9012\u7ed9\u8c03\u7528\u5b83\u7684\u5bf9\u8c61\uff0c\u80fd\u591f\u5bf9\u7c7b\u7684\u5b9e\u4f8b\u4e2d\u5305\u542b\u7684\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u3002

        \u4e0b\u9762\u4ee5\u51e0\u79cd\u5e38\u89c1\u7684\u7f16\u7a0b\u8bed\u8a00\u4e3a\u4f8b\u6765\u8bf4\u660e\u3002

        • C \u8bed\u8a00\u662f\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\u8bed\u8a00\uff0c\u6ca1\u6709\u9762\u5411\u5bf9\u8c61\u7684\u6982\u5ff5\uff0c\u6240\u4ee5\u53ea\u6709\u51fd\u6570\u3002\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u7ed3\u6784\u4f53\uff08struct\uff09\u6765\u6a21\u62df\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u4e0e\u7ed3\u6784\u4f53\u76f8\u5173\u8054\u7684\u51fd\u6570\u5c31\u76f8\u5f53\u4e8e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u65b9\u6cd5\u3002
        • Java \u548c C# \u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4ee3\u7801\u5757\uff08\u65b9\u6cd5\uff09\u901a\u5e38\u4f5c\u4e3a\u67d0\u4e2a\u7c7b\u7684\u4e00\u90e8\u5206\u3002\u9759\u6001\u65b9\u6cd5\u7684\u884c\u4e3a\u7c7b\u4f3c\u4e8e\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u88ab\u7ed1\u5b9a\u5728\u7c7b\u4e0a\uff0c\u4e0d\u80fd\u8bbf\u95ee\u7279\u5b9a\u7684\u5b9e\u4f8b\u53d8\u91cf\u3002
        • C++ \u548c Python \u65e2\u652f\u6301\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\uff08\u51fd\u6570\uff09\uff0c\u4e5f\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08\u65b9\u6cd5\uff09\u3002

        \u56fe\u89e3\u201c\u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\u201d\u53cd\u6620\u7684\u662f\u5426\u662f\u5360\u7528\u7a7a\u95f4\u7684\u7edd\u5bf9\u5927\u5c0f\uff1f

        \u4e0d\u662f\uff0c\u8be5\u56fe\u5c55\u793a\u7684\u662f\u7a7a\u95f4\u590d\u6742\u5ea6\uff0c\u5176\u53cd\u6620\u7684\u662f\u589e\u957f\u8d8b\u52bf\uff0c\u800c\u4e0d\u662f\u5360\u7528\u7a7a\u95f4\u7684\u7edd\u5bf9\u5927\u5c0f\u3002

        \u5047\u8bbe\u53d6 \\(n = 8\\) \uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u6bcf\u6761\u66f2\u7ebf\u7684\u503c\u4e0e\u51fd\u6570\u5bf9\u5e94\u4e0d\u4e0a\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u6761\u66f2\u7ebf\u90fd\u5305\u542b\u4e00\u4e2a\u5e38\u6570\u9879\uff0c\u7528\u4e8e\u5c06\u53d6\u503c\u8303\u56f4\u538b\u7f29\u5230\u4e00\u4e2a\u89c6\u89c9\u8212\u9002\u7684\u8303\u56f4\u5185\u3002

        \u5728\u5b9e\u9645\u4e2d\uff0c\u56e0\u4e3a\u6211\u4eec\u901a\u5e38\u4e0d\u77e5\u9053\u6bcf\u4e2a\u65b9\u6cd5\u7684\u201c\u5e38\u6570\u9879\u201d\u590d\u6742\u5ea6\u662f\u591a\u5c11\uff0c\u6240\u4ee5\u4e00\u822c\u65e0\u6cd5\u4ec5\u51ed\u590d\u6742\u5ea6\u6765\u9009\u62e9 \\(n = 8\\) \u4e4b\u4e0b\u7684\u6700\u4f18\u89e3\u6cd5\u3002\u4f46\u5bf9\u4e8e \\(n = 8^5\\) \u5c31\u5f88\u597d\u9009\u4e86\uff0c\u8fd9\u65f6\u589e\u957f\u8d8b\u52bf\u5df2\u7ecf\u5360\u4e3b\u5bfc\u4e86\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/","title":"2.3 \u00a0 \u65f6\u95f4\u590d\u6742\u5ea6","text":"

        \u8fd0\u884c\u65f6\u95f4\u53ef\u4ee5\u76f4\u89c2\u4e14\u51c6\u786e\u5730\u53cd\u6620\u7b97\u6cd5\u7684\u6548\u7387\u3002\u5982\u679c\u6211\u4eec\u60f3\u51c6\u786e\u9884\u4f30\u4e00\u6bb5\u4ee3\u7801\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u5e94\u8be5\u5982\u4f55\u64cd\u4f5c\u5462\uff1f

        1. \u786e\u5b9a\u8fd0\u884c\u5e73\u53f0\uff0c\u5305\u62ec\u786c\u4ef6\u914d\u7f6e\u3001\u7f16\u7a0b\u8bed\u8a00\u3001\u7cfb\u7edf\u73af\u5883\u7b49\uff0c\u8fd9\u4e9b\u56e0\u7d20\u90fd\u4f1a\u5f71\u54cd\u4ee3\u7801\u7684\u8fd0\u884c\u6548\u7387\u3002
        2. \u8bc4\u4f30\u5404\u79cd\u8ba1\u7b97\u64cd\u4f5c\u6240\u9700\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u4f8b\u5982\u52a0\u6cd5\u64cd\u4f5c + \u9700\u8981 1 ns \uff0c\u4e58\u6cd5\u64cd\u4f5c * \u9700\u8981 10 ns \uff0c\u6253\u5370\u64cd\u4f5c print() \u9700\u8981 5 ns \u7b49\u3002
        3. \u7edf\u8ba1\u4ee3\u7801\u4e2d\u6240\u6709\u7684\u8ba1\u7b97\u64cd\u4f5c\uff0c\u5e76\u5c06\u6240\u6709\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u95f4\u6c42\u548c\uff0c\u4ece\u800c\u5f97\u5230\u8fd0\u884c\u65f6\u95f4\u3002

        \u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\ndef algorithm(n: int):\na = 2      # 1 ns\na = a + 1  # 1 ns\na = a * 2  # 10 ns\n# \u5faa\u73af n \u6b21\nfor _ in range(n):  # 1 ns\nprint(0)        # 5 ns\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\ncout << 0 << endl;         // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nSystem.out.println(0);     // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid Algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nConsole.WriteLine(0);      // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n int) {\na := 2     // 1 ns\na = a + 1  // 1 ns\na = a * 2  // 10 ns\n// \u5faa\u73af n \u6b21\nfor i := 0; i < n; i++ {  // 1 ns\nfmt.Println(a)        // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n: Int) {\nvar a = 2 // 1 ns\na = a + 1 // 1 ns\na = a * 2 // 10 ns\n// \u5faa\u73af n \u6b21\nfor _ in 0 ..< n { // 1 ns\nprint(0) // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n) {\nvar a = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nconsole.log(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n: number): void {\nvar a: number = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nconsole.log(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprint(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: i32) {\nlet mut a = 2;      // 1 ns\na = a + 1;          // 1 ns\na = a * 2;          // 10 ns\n// \u5faa\u73af n \u6b21\nfor _ in 0..n {     // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprintln!(\"{}\", 0);  // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprintf(\"%d\", 0);            // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: usize) void {\nvar a: i32 = 2; // 1 ns\na += 1; // 1 ns\na *= 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor (0..n) |_| { // 1 ns\nstd.debug.print(\"{}\\n\", .{0}); // 5 ns\n}\n}\n

        \u6839\u636e\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5f97\u5230\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u4e3a \\((6n + 12)\\) ns \uff1a

        \\[ 1 + 1 + 10 + (1 + 5) \\times n = 6n + 12 \\]

        \u4f46\u5b9e\u9645\u4e0a\uff0c\u7edf\u8ba1\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u65e2\u4e0d\u5408\u7406\u4e5f\u4e0d\u73b0\u5b9e\u3002\u9996\u5148\uff0c\u6211\u4eec\u4e0d\u5e0c\u671b\u5c06\u9884\u4f30\u65f6\u95f4\u548c\u8fd0\u884c\u5e73\u53f0\u7ed1\u5b9a\uff0c\u56e0\u4e3a\u7b97\u6cd5\u9700\u8981\u5728\u5404\u79cd\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002\u5176\u6b21\uff0c\u6211\u4eec\u5f88\u96be\u83b7\u77e5\u6bcf\u79cd\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u8fd9\u7ed9\u9884\u4f30\u8fc7\u7a0b\u5e26\u6765\u4e86\u6781\u5927\u7684\u96be\u5ea6\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#231","title":"2.3.1 \u00a0 \u7edf\u8ba1\u65f6\u95f4\u589e\u957f\u8d8b\u52bf","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u7edf\u8ba1\u7684\u4e0d\u662f\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\uff0c\u800c\u662f\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u7740\u6570\u636e\u91cf\u53d8\u5927\u65f6\u7684\u589e\u957f\u8d8b\u52bf\u3002

        \u201c\u65f6\u95f4\u589e\u957f\u8d8b\u52bf\u201d\u8fd9\u4e2a\u6982\u5ff5\u6bd4\u8f83\u62bd\u8c61\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u52a0\u4ee5\u7406\u89e3\u3002\u5047\u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u7ed9\u5b9a\u4e09\u4e2a\u7b97\u6cd5 A\u3001B \u548c C \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_A(n: int):\nprint(0)\n# \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\ndef algorithm_B(n: int):\nfor _ in range(n):\nprint(0)\n# \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_C(n: int):\nfor _ in range(1000000):\nprint(0)\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\ncout << 0 << endl;\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\ncout << 0 << endl;\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\ncout << 0 << endl;\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\nSystem.out.println(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\nSystem.out.println(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\nSystem.out.println(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmA(int n) {\nConsole.WriteLine(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid AlgorithmB(int n) {\nfor (int i = 0; i < n; i++) {\nConsole.WriteLine(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmC(int n) {\nfor (int i = 0; i < 1000000; i++) {\nConsole.WriteLine(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_A(n int) {\nfmt.Println(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithm_B(n int) {\nfor i := 0; i < n; i++ {\nfmt.Println(0)\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_C(n int) {\nfor i := 0; i < 1000000; i++ {\nfmt.Println(0)\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmA(n: Int) {\nprint(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithmB(n: Int) {\nfor _ in 0 ..< n {\nprint(0)\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmC(n: Int) {\nfor _ in 0 ..< 1000000 {\nprint(0)\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n) {\nconsole.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n) {\nfor (let i = 0; i < n; i++) {\nconsole.log(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n) {\nfor (let i = 0; i < 1000000; i++) {\nconsole.log(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n: number): void {\nconsole.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n: number): void {\nfor (let i = 0; i < n; i++) {\nconsole.log(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n: number): void {\nfor (let i = 0; i < 1000000; i++) {\nconsole.log(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmA(int n) {\nprint(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithmB(int n) {\nfor (int i = 0; i < n; i++) {\nprint(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmC(int n) {\nfor (int i = 0; i < 1000000; i++) {\nprint(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: i32) {\nprintln!(\"{}\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) {\nfor _ in 0..n {\nprintln!(\"{}\", 0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) {\nfor _ in 0..1000000 {\nprintln!(\"{}\", 0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\nprintf(\"%d\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\nprintf(\"%d\", 0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\nprintf(\"%d\", 0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: usize) void {\n_ = n;\nstd.debug.print(\"{}\\n\", .{0});\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) void {\nfor (0..n) |_| {\nstd.debug.print(\"{}\\n\", .{0});\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) void {\n_ = n;\nfor (0..1000000) |_| { std.debug.print(\"{}\\n\", .{0});\n}\n}\n

        \u56fe 2-7 \u5c55\u793a\u4e86\u4ee5\u4e0a\u4e09\u4e2a\u7b97\u6cd5\u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        • \u7b97\u6cd5 A \u53ea\u6709 \\(1\\) \u4e2a\u6253\u5370\u64cd\u4f5c\uff0c\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u4e0d\u968f\u7740 \\(n\\) \u589e\u5927\u800c\u589e\u957f\u3002\u6211\u4eec\u79f0\u6b64\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u201c\u5e38\u6570\u9636\u201d\u3002
        • \u7b97\u6cd5 B \u4e2d\u7684\u6253\u5370\u64cd\u4f5c\u9700\u8981\u5faa\u73af \\(n\\) \u6b21\uff0c\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u7740 \\(n\\) \u589e\u5927\u5448\u7ebf\u6027\u589e\u957f\u3002\u6b64\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u88ab\u79f0\u4e3a\u201c\u7ebf\u6027\u9636\u201d\u3002
        • \u7b97\u6cd5 C \u4e2d\u7684\u6253\u5370\u64cd\u4f5c\u9700\u8981\u5faa\u73af \\(1000000\\) \u6b21\uff0c\u867d\u7136\u8fd0\u884c\u65f6\u95f4\u5f88\u957f\uff0c\u4f46\u5b83\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\u3002\u56e0\u6b64 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c A \u76f8\u540c\uff0c\u4ecd\u4e3a\u201c\u5e38\u6570\u9636\u201d\u3002

        \u56fe 2-7 \u00a0 \u7b97\u6cd5 A\u3001B \u548c C \u7684\u65f6\u95f4\u589e\u957f\u8d8b\u52bf

        \u76f8\u8f83\u4e8e\u76f4\u63a5\u7edf\u8ba1\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u6709\u54ea\u4e9b\u7279\u70b9\u5462\uff1f

        • \u65f6\u95f4\u590d\u6742\u5ea6\u80fd\u591f\u6709\u6548\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u3002\u4f8b\u5982\uff0c\u7b97\u6cd5 B \u7684\u8fd0\u884c\u65f6\u95f4\u5448\u7ebf\u6027\u589e\u957f\uff0c\u5728 \\(n > 1\\) \u65f6\u6bd4\u7b97\u6cd5 A \u66f4\u6162\uff0c\u5728 \\(n > 1000000\\) \u65f6\u6bd4\u7b97\u6cd5 C \u66f4\u6162\u3002\u4e8b\u5b9e\u4e0a\uff0c\u53ea\u8981\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u8db3\u591f\u5927\uff0c\u590d\u6742\u5ea6\u4e3a\u201c\u5e38\u6570\u9636\u201d\u7684\u7b97\u6cd5\u4e00\u5b9a\u4f18\u4e8e\u201c\u7ebf\u6027\u9636\u201d\u7684\u7b97\u6cd5\uff0c\u8fd9\u6b63\u662f\u65f6\u95f4\u589e\u957f\u8d8b\u52bf\u7684\u542b\u4e49\u3002
        • \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u66f4\u7b80\u4fbf\u3002\u663e\u7136\uff0c\u8fd0\u884c\u5e73\u53f0\u548c\u8ba1\u7b97\u64cd\u4f5c\u7c7b\u578b\u90fd\u4e0e\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u65e0\u5173\u3002\u56e0\u6b64\u5728\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u5c06\u6240\u6709\u8ba1\u7b97\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u95f4\u89c6\u4e3a\u76f8\u540c\u7684\u201c\u5355\u4f4d\u65f6\u95f4\u201d\uff0c\u4ece\u800c\u5c06\u201c\u8ba1\u7b97\u64cd\u4f5c\u8fd0\u884c\u65f6\u95f4\u7edf\u8ba1\u201d\u7b80\u5316\u4e3a\u201c\u8ba1\u7b97\u64cd\u4f5c\u6570\u91cf\u7edf\u8ba1\u201d\uff0c\u8fd9\u6837\u4e00\u6765\u4f30\u7b97\u96be\u5ea6\u5c31\u5927\u5927\u964d\u4f4e\u4e86\u3002
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u5b58\u5728\u4e00\u5b9a\u7684\u5c40\u9650\u6027\u3002\u4f8b\u5982\uff0c\u5c3d\u7ba1\u7b97\u6cd5 A \u548c C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u76f8\u540c\uff0c\u4f46\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u5dee\u522b\u5f88\u5927\u3002\u540c\u6837\uff0c\u5c3d\u7ba1\u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6bd4 C \u9ad8\uff0c\u4f46\u5728\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u8f83\u5c0f\u65f6\uff0c\u7b97\u6cd5 B \u660e\u663e\u4f18\u4e8e\u7b97\u6cd5 C \u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5f88\u96be\u4ec5\u51ed\u65f6\u95f4\u590d\u6742\u5ea6\u5224\u65ad\u7b97\u6cd5\u6548\u7387\u7684\u9ad8\u4f4e\u3002\u5f53\u7136\uff0c\u5c3d\u7ba1\u5b58\u5728\u4e0a\u8ff0\u95ee\u9898\uff0c\u590d\u6742\u5ea6\u5206\u6790\u4ecd\u7136\u662f\u8bc4\u5224\u7b97\u6cd5\u6548\u7387\u6700\u6709\u6548\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\u3002
        "},{"location":"chapter_computational_complexity/time_complexity/#232","title":"2.3.2 \u00a0 \u51fd\u6570\u6e10\u8fd1\u4e0a\u754c","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u8f93\u5165\u5927\u5c0f\u4e3a \\(n\\) \u7684\u51fd\u6570\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 1      # +1\na = a + 1  # +1\na = a * 2  # +1\n# \u5faa\u73af n \u6b21\nfor i in range(n):  # +1\nprint(0)        # +1\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\ncout << 0 << endl;    // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nSystem.out.println(0);    // +1\n}\n}\n
        void Algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nConsole.WriteLine(0);   // +1\n}\n}\n
        func algorithm(n int) {\na := 1      // +1\na = a + 1   // +1\na = a * 2   // +1\n// \u5faa\u73af n \u6b21\nfor i := 0; i < n; i++ {   // +1\nfmt.Println(a)         // +1\n}\n}\n
        func algorithm(n: Int) {\nvar a = 1 // +1\na = a + 1 // +1\na = a * 2 // +1\n// \u5faa\u73af n \u6b21\nfor _ in 0 ..< n { // +1\nprint(0) // +1\n}\n}\n
        function algorithm(n) {\nvar a = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nconsole.log(0); // +1\n}\n}\n
        function algorithm(n: number): void{\nvar a: number = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nconsole.log(0); // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1; // +1\na = a + 1; // +1\na = a * 2; // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprint(0); // +1\n}\n}\n
        fn algorithm(n: i32) {\nlet mut a = 1;   // +1\na = a + 1;      // +1\na = a * 2;      // +1\n// \u5faa\u73af n \u6b21\nfor _ in 0..n { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprintln!(\"{}\", 0); // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprintf(\"%d\", 0);            // +1\n}\n}  
        fn algorithm(n: usize) void {\nvar a: i32 = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor (0..n) |_| { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nstd.debug.print(\"{}\\n\", .{0}); // +1\n}\n}\n

        \u8bbe\u7b97\u6cd5\u7684\u64cd\u4f5c\u6570\u91cf\u662f\u4e00\u4e2a\u5173\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u7684\u51fd\u6570\uff0c\u8bb0\u4e3a \\(T(n)\\) \uff0c\u5219\u4ee5\u4e0a\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e3a\uff1a

        \\[ T(n) = 3 + 2n \\]

        \\(T(n)\\) \u662f\u4e00\u6b21\u51fd\u6570\uff0c\u8bf4\u660e\u5176\u8fd0\u884c\u65f6\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u662f\u7ebf\u6027\u7684\uff0c\u56e0\u6b64\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u7ebf\u6027\u9636\u3002

        \u6211\u4eec\u5c06\u7ebf\u6027\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u8bb0\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4e2a\u6570\u5b66\u7b26\u53f7\u79f0\u4e3a\u300c\u5927 \\(O\\) \u8bb0\u53f7 big-\\(O\\) notation\u300d\uff0c\u8868\u793a\u51fd\u6570 \\(T(n)\\) \u7684\u300c\u6e10\u8fd1\u4e0a\u754c asymptotic upper bound\u300d\u3002

        \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u672c\u8d28\u4e0a\u662f\u8ba1\u7b97\u201c\u64cd\u4f5c\u6570\u91cf \\(T(n)\\)\u201d\u7684\u6e10\u8fd1\u4e0a\u754c\uff0c\u5b83\u5177\u6709\u660e\u786e\u7684\u6570\u5b66\u5b9a\u4e49\u3002

        \u51fd\u6570\u6e10\u8fd1\u4e0a\u754c

        \u82e5\u5b58\u5728\u6b63\u5b9e\u6570 \\(c\\) \u548c\u5b9e\u6570 \\(n_0\\) \uff0c\u4f7f\u5f97\u5bf9\u4e8e\u6240\u6709\u7684 \\(n > n_0\\) \uff0c\u5747\u6709 \\(T(n) \\leq c \\cdot f(n)\\) \uff0c\u5219\u53ef\u8ba4\u4e3a \\(f(n)\\) \u7ed9\u51fa\u4e86 \\(T(n)\\) \u7684\u4e00\u4e2a\u6e10\u8fd1\u4e0a\u754c\uff0c\u8bb0\u4e3a \\(T(n) = O(f(n))\\) \u3002

        \u5982\u56fe 2-8 \u6240\u793a\uff0c\u8ba1\u7b97\u6e10\u8fd1\u4e0a\u754c\u5c31\u662f\u5bfb\u627e\u4e00\u4e2a\u51fd\u6570 \\(f(n)\\) \uff0c\u4f7f\u5f97\u5f53 \\(n\\) \u8d8b\u5411\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\\(T(n)\\) \u548c \\(f(n)\\) \u5904\u4e8e\u76f8\u540c\u7684\u589e\u957f\u7ea7\u522b\uff0c\u4ec5\u76f8\u5dee\u4e00\u4e2a\u5e38\u6570\u9879 \\(c\\) \u7684\u500d\u6570\u3002

        \u56fe 2-8 \u00a0 \u51fd\u6570\u7684\u6e10\u8fd1\u4e0a\u754c

        "},{"location":"chapter_computational_complexity/time_complexity/#233","title":"2.3.3 \u00a0 \u63a8\u7b97\u65b9\u6cd5","text":"

        \u6e10\u8fd1\u4e0a\u754c\u7684\u6570\u5b66\u5473\u513f\u6709\u70b9\u91cd\uff0c\u5982\u679c\u4f60\u611f\u89c9\u6ca1\u6709\u5b8c\u5168\u7406\u89e3\uff0c\u4e5f\u65e0\u987b\u62c5\u5fc3\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u638c\u63e1\u63a8\u7b97\u65b9\u6cd5\uff0c\u5728\u4e0d\u65ad\u7684\u5b9e\u8df5\u4e2d\uff0c\u5c31\u53ef\u4ee5\u9010\u6e10\u9886\u609f\u5176\u6570\u5b66\u610f\u4e49\u3002

        \u6839\u636e\u5b9a\u4e49\uff0c\u786e\u5b9a \\(f(n)\\) \u4e4b\u540e\uff0c\u6211\u4eec\u4fbf\u53ef\u5f97\u5230\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(f(n))\\) \u3002\u90a3\u4e48\u5982\u4f55\u786e\u5b9a\u6e10\u8fd1\u4e0a\u754c \\(f(n)\\) \u5462\uff1f\u603b\u4f53\u5206\u4e3a\u4e24\u6b65\uff1a\u9996\u5148\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff0c\u7136\u540e\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#1","title":"1. \u00a0 \u7b2c\u4e00\u6b65\uff1a\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf","text":"

        \u9488\u5bf9\u4ee3\u7801\uff0c\u9010\u884c\u4ece\u4e0a\u5230\u4e0b\u8ba1\u7b97\u5373\u53ef\u3002\u7136\u800c\uff0c\u7531\u4e8e\u4e0a\u8ff0 \\(c \\cdot f(n)\\) \u4e2d\u7684\u5e38\u6570\u9879 \\(c\\) \u53ef\u4ee5\u53d6\u4efb\u610f\u5927\u5c0f\uff0c\u56e0\u6b64\u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u4e2d\u7684\u5404\u79cd\u7cfb\u6570\u3001\u5e38\u6570\u9879\u90fd\u53ef\u4ee5\u5ffd\u7565\u3002\u6839\u636e\u6b64\u539f\u5219\uff0c\u53ef\u4ee5\u603b\u7ed3\u51fa\u4ee5\u4e0b\u8ba1\u6570\u7b80\u5316\u6280\u5de7\u3002

        1. \u5ffd\u7565 \\(T(n)\\) \u4e2d\u7684\u5e38\u6570\u9879\u3002\u56e0\u4e3a\u5b83\u4eec\u90fd\u4e0e \\(n\\) \u65e0\u5173\uff0c\u6240\u4ee5\u5bf9\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u4ea7\u751f\u5f71\u54cd\u3002
        2. \u7701\u7565\u6240\u6709\u7cfb\u6570\u3002\u4f8b\u5982\uff0c\u5faa\u73af \\(2n\\) \u6b21\u3001\\(5n + 1\\) \u6b21\u7b49\uff0c\u90fd\u53ef\u4ee5\u7b80\u5316\u8bb0\u4e3a \\(n\\) \u6b21\uff0c\u56e0\u4e3a \\(n\\) \u524d\u9762\u7684\u7cfb\u6570\u5bf9\u65f6\u95f4\u590d\u6742\u5ea6\u6ca1\u6709\u5f71\u54cd\u3002
        3. \u5faa\u73af\u5d4c\u5957\u65f6\u4f7f\u7528\u4e58\u6cd5\u3002\u603b\u64cd\u4f5c\u6570\u91cf\u7b49\u4e8e\u5916\u5c42\u5faa\u73af\u548c\u5185\u5c42\u5faa\u73af\u64cd\u4f5c\u6570\u91cf\u4e4b\u79ef\uff0c\u6bcf\u4e00\u5c42\u5faa\u73af\u4f9d\u7136\u53ef\u4ee5\u5206\u522b\u5957\u7528\u7b2c 1. \u70b9\u548c\u7b2c 2. \u70b9\u7684\u6280\u5de7\u3002

        \u7ed9\u5b9a\u4e00\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e0a\u8ff0\u6280\u5de7\u6765\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 1      # +0\uff08\u6280\u5de7 1\uff09\na = a + n  # +0\uff08\u6280\u5de7 1\uff09\n# +n\uff08\u6280\u5de7 2\uff09\nfor i in range(5 * n + 1):\nprint(0)\n# +n*n\uff08\u6280\u5de7 3\uff09\nfor i in range(2 * n):\nfor j in range(n + 1):\nprint(0)\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\ncout << 0 << endl;\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\ncout << 0 << endl;\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nSystem.out.println(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nSystem.out.println(0);\n}\n}\n}\n
        void Algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nConsole.WriteLine(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nConsole.WriteLine(0);\n}\n}\n}\n
        func algorithm(n int) {\na := 1     // +0\uff08\u6280\u5de7 1\uff09\na = a + n  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor i := 0; i < 5 * n + 1; i++ {\nfmt.Println(0)\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor i := 0; i < 2 * n; i++ {\nfor j := 0; j < n + 1; j++ {\nfmt.Println(0)\n}\n}\n}\n
        func algorithm(n: Int) {\nvar a = 1 // +0\uff08\u6280\u5de7 1\uff09\na = a + n // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor _ in 0 ..< (5 * n + 1) {\nprint(0)\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor _ in 0 ..< (2 * n) {\nfor _ in 0 ..< (n + 1) {\nprint(0)\n}\n}\n}\n
        function algorithm(n) {\nlet a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (let i = 0; i < 5 * n + 1; i++) {\nconsole.log(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (let i = 0; i < 2 * n; i++) {\nfor (let j = 0; j < n + 1; j++) {\nconsole.log(0);\n}\n}\n}\n
        function algorithm(n: number): void {\nlet a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (let i = 0; i < 5 * n + 1; i++) {\nconsole.log(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (let i = 0; i < 2 * n; i++) {\nfor (let j = 0; j < n + 1; j++) {\nconsole.log(0);\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1; // +0\uff08\u6280\u5de7 1\uff09\na = a + n; // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nprint(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nprint(0);\n}\n}\n}\n
        fn algorithm(n: i32) {\nlet mut a = 1;     // +0\uff08\u6280\u5de7 1\uff09\na = a + n;        // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor i in 0..(5 * n + 1) {\nprintln!(\"{}\", 0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor i in 0..(2 * n) {\nfor j in 0..(n + 1) {\nprintln!(\"{}\", 0);\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nprintf(\"%d\", 0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nprintf(\"%d\", 0);\n}\n}\n}\n
        fn algorithm(n: usize) void {\nvar a: i32 = 1;     // +0\uff08\u6280\u5de7 1\uff09\na = a + @as(i32, @intCast(n));        // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor(0..(5 * n + 1)) |_| {\nstd.debug.print(\"{}\\n\", .{0}); }\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor(0..(2 * n)) |_| {\nfor(0..(n + 1)) |_| {\nstd.debug.print(\"{}\\n\", .{0}); }\n}\n}\n

        \u4ee5\u4e0b\u516c\u5f0f\u5c55\u793a\u4e86\u4f7f\u7528\u4e0a\u8ff0\u6280\u5de7\u524d\u540e\u7684\u7edf\u8ba1\u7ed3\u679c\uff0c\u4e24\u8005\u63a8\u7b97\u51fa\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \u3002

        \\[ \\begin{aligned} T(n) & = 2n(n + 1) + (5n + 1) + 2 & \\text{\u5b8c\u6574\u7edf\u8ba1 (-.-|||)} \\newline & = 2n^2 + 7n + 3 \\newline T(n) & = n^2 + n & \\text{\u5077\u61d2\u7edf\u8ba1 (o.O)} \\end{aligned} \\]"},{"location":"chapter_computational_complexity/time_complexity/#2","title":"2. \u00a0 \u7b2c\u4e8c\u6b65\uff1a\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\u7531 \\(T(n)\\) \u4e2d\u6700\u9ad8\u9636\u7684\u9879\u6765\u51b3\u5b9a\u3002\u8fd9\u662f\u56e0\u4e3a\u5728 \\(n\\) \u8d8b\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\u6700\u9ad8\u9636\u7684\u9879\u5c06\u53d1\u6325\u4e3b\u5bfc\u4f5c\u7528\uff0c\u5176\u4ed6\u9879\u7684\u5f71\u54cd\u90fd\u53ef\u4ee5\u5ffd\u7565\u3002

        \u8868 2-2 \u5c55\u793a\u4e86\u4e00\u4e9b\u4f8b\u5b50\uff0c\u5176\u4e2d\u4e00\u4e9b\u5938\u5f20\u7684\u503c\u662f\u4e3a\u4e86\u5f3a\u8c03\u201c\u7cfb\u6570\u65e0\u6cd5\u64bc\u52a8\u9636\u6570\u201d\u8fd9\u4e00\u7ed3\u8bba\u3002\u5f53 \\(n\\) \u8d8b\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\u8fd9\u4e9b\u5e38\u6570\u53d8\u5f97\u65e0\u8db3\u8f7b\u91cd\u3002

        \u8868 2-2 \u00a0 \u4e0d\u540c\u64cd\u4f5c\u6570\u91cf\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(f(n))\\) \\(100000\\) \\(O(1)\\) \\(3n + 2\\) \\(O(n)\\) \\(2n^2 + 3n + 2\\) \\(O(n^2)\\) \\(n^3 + 10000n^2\\) \\(O(n^3)\\) \\(2^n + 10000n^{10000}\\) \\(O(2^n)\\)"},{"location":"chapter_computational_complexity/time_complexity/#234","title":"2.3.4 \u00a0 \u5e38\u89c1\u7c7b\u578b","text":"

        \u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u5e38\u89c1\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\u5982\u56fe 2-9 \u6240\u793a\uff08\u6309\u7167\u4ece\u4f4e\u5230\u9ad8\u7684\u987a\u5e8f\u6392\u5217\uff09\u3002

        \\[ \\begin{aligned} O(1) < O(\\log n) < O(n) < O(n \\log n) < O(n^2) < O(2^n) < O(n!) \\newline \\text{\u5e38\u6570\u9636} < \\text{\u5bf9\u6570\u9636} < \\text{\u7ebf\u6027\u9636} < \\text{\u7ebf\u6027\u5bf9\u6570\u9636} < \\text{\u5e73\u65b9\u9636} < \\text{\u6307\u6570\u9636} < \\text{\u9636\u4e58\u9636} \\end{aligned} \\]

        \u56fe 2-9 \u00a0 \u5e38\u89c1\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7c7b\u578b

        "},{"location":"chapter_computational_complexity/time_complexity/#1-o1","title":"1. \u00a0 \u5e38\u6570\u9636 \\(O(1)\\)","text":"

        \u5e38\u6570\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\uff0c\u5373\u4e0d\u968f\u7740 \\(n\\) \u7684\u53d8\u5316\u800c\u53d8\u5316\u3002

        \u5728\u4ee5\u4e0b\u51fd\u6570\u4e2d\uff0c\u5c3d\u7ba1\u64cd\u4f5c\u6570\u91cf size \u53ef\u80fd\u5f88\u5927\uff0c\u4f46\u7531\u4e8e\u5176\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def constant(n: int) -> int:\n\"\"\"\u5e38\u6570\u9636\"\"\"\ncount = 0\nsize = 100000\nfor _ in range(size):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.java
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e38\u6570\u9636 */\nint Constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.go
        /* \u5e38\u6570\u9636 */\nfunc constant(n int) int {\ncount := 0\nsize := 100000\nfor i := 0; i < size; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e38\u6570\u9636 */\nfunc constant(n: Int) -> Int {\nvar count = 0\nlet size = 100_000\nfor _ in 0 ..< size {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e38\u6570\u9636 */\nfunction constant(n) {\nlet count = 0;\nconst size = 100000;\nfor (let i = 0; i < size; i++) count++;\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e38\u6570\u9636 */\nfunction constant(n: number): number {\nlet count = 0;\nconst size = 100000;\nfor (let i = 0; i < size; i++) count++;\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (var i = 0; i < size; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e38\u6570\u9636 */\nfn constant(n: i32) -> i32 {\n_ = n;\nlet mut count = 0;\nlet size = 100_000;\nfor _ in 0..size {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nint i = 0;\nfor (int i = 0; i < size; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e38\u6570\u9636\nfn constant(n: i32) i32 {\n_ = n;\nvar count: i32 = 0;\nconst size: i32 = 100_000;\nvar i: i32 = 0;\nwhile(i<size) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n
        "},{"location":"chapter_computational_complexity/time_complexity/#2-on","title":"2. \u00a0 \u7ebf\u6027\u9636 \\(O(n)\\)","text":"

        \u7ebf\u6027\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u76f8\u5bf9\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u4ee5\u7ebf\u6027\u7ea7\u522b\u589e\u957f\u3002\u7ebf\u6027\u9636\u901a\u5e38\u51fa\u73b0\u5728\u5355\u5c42\u5faa\u73af\u4e2d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def linear(n: int) -> int:\n\"\"\"\u7ebf\u6027\u9636\"\"\"\ncount = 0\nfor _ in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u9636 */\nint Linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u9636 */\nfunc linear(n int) int {\ncount := 0\nfor i := 0; i < n; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) -> Int {\nvar count = 0\nfor _ in 0 ..< n {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\nlet count = 0;\nfor (let i = 0; i < n; i++) count++;\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): number {\nlet count = 0;\nfor (let i = 0; i < n; i++) count++;\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (var i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u9636 */\nfn linear(n: i32) -> i32 {\nlet mut count = 0;\nfor _ in 0..n {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u9636\nfn linear(n: i32) i32 {\nvar count: i32 = 0;\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n

        \u904d\u5386\u6570\u7ec4\u548c\u904d\u5386\u94fe\u8868\u7b49\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u6570\u7ec4\u6216\u94fe\u8868\u7684\u957f\u5ea6\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def array_traversal(nums: list[int]) -> int:\n\"\"\"\u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\"\"\"\ncount = 0\n# \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor num in nums:\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(vector<int> &nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int num : nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int[] nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int num : nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint ArrayTraversal(int[] nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nforeach (int num in nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums []int) int {\ncount := 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor range nums {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums: [Int]) -> Int {\nvar count = 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor _ in nums {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums) {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (let i = 0; i < nums.length; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums: number[]): number {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (let i = 0; i < nums.length; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(List<int> nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (var _num in nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfn array_traversal(nums: &[i32]) -> i32 {\nlet mut count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor _ in nums {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int *nums, int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\nfn arrayTraversal(nums: []i32) i32 {\nvar count: i32 = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (nums) |_| {\ncount += 1;\n}\nreturn count;\n}\n

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u9700\u6839\u636e\u8f93\u5165\u6570\u636e\u7684\u7c7b\u578b\u6765\u5177\u4f53\u786e\u5b9a\u3002\u6bd4\u5982\u5728\u7b2c\u4e00\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53d8\u91cf \\(n\\) \u4e3a\u8f93\u5165\u6570\u636e\u5927\u5c0f\uff1b\u5728\u7b2c\u4e8c\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u4e3a\u6570\u636e\u5927\u5c0f\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#3-on2","title":"3. \u00a0 \u5e73\u65b9\u9636 \\(O(n^2)\\)","text":"

        \u5e73\u65b9\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u76f8\u5bf9\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u4ee5\u5e73\u65b9\u7ea7\u522b\u589e\u957f\u3002\u5e73\u65b9\u9636\u901a\u5e38\u51fa\u73b0\u5728\u5d4c\u5957\u5faa\u73af\u4e2d\uff0c\u5916\u5c42\u5faa\u73af\u548c\u5185\u5c42\u5faa\u73af\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n)\\) \uff0c\u56e0\u6b64\u603b\u4f53\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def quadratic(n: int) -> int:\n\"\"\"\u5e73\u65b9\u9636\"\"\"\ncount = 0\n# \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor i in range(n):\nfor j in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e73\u65b9\u9636 */\nint Quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n int) int {\ncount := 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor i := 0; i < n; i++ {\nfor j := 0; j < n; j++ {\ncount++\n}\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) -> Int {\nvar count = 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor _ in 0 ..< n {\nfor _ in 0 ..< n {\ncount += 1\n}\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): number {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e73\u65b9\u9636 */\nfn quadratic(n: i32) -> i32 {\nlet mut count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor _ in 0..n {\nfor _ in 0..n {\ncount += 1;\n}\n}\ncount\n}\n
        time_complexity.c
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e73\u65b9\u9636\nfn quadratic(n: i32) i32 {\nvar count: i32 = 0;\nvar i: i32 = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nwhile (i < n) : (i += 1) {\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\ncount += 1;\n}\n}\nreturn count;\n}\n

        \u56fe 2-10 \u5bf9\u6bd4\u4e86\u5e38\u6570\u9636\u3001\u7ebf\u6027\u9636\u548c\u5e73\u65b9\u9636\u4e09\u79cd\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \u56fe 2-10 \u00a0 \u5e38\u6570\u9636\u3001\u7ebf\u6027\u9636\u548c\u5e73\u65b9\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4ee5\u5192\u6ce1\u6392\u5e8f\u4e3a\u4f8b\uff0c\u5916\u5c42\u5faa\u73af\u6267\u884c \\(n - 1\\) \u6b21\uff0c\u5185\u5c42\u5faa\u73af\u6267\u884c \\(n-1\\)\u3001\\(n-2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u6b21\uff0c\u5e73\u5747\u4e3a \\(n / 2\\) \u6b21\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O((n - 1) n / 2) = O(n^2)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def bubble_sort(nums: list[int]) -> int:\n\"\"\"\u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\"\"\"\ncount = 0  # \u8ba1\u6570\u5668\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(len(nums) - 1, 0, -1):\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\ntmp: int = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\ncount += 3  # \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\nreturn count\n
        time_complexity.cpp
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(vector<int> &nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int[] nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint BubbleSort(int[] nums) {\nint count = 0;  // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\ncount += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums []int) int {\ncount := 0 // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\ntmp := nums[j]\nnums[j] = nums[j+1]\nnums[j+1] = tmp\ncount += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums: inout [Int]) -> Int {\nvar count = 0 // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0 ..< i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\ncount += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums) {\nlet count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums: number[]): number {\nlet count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(List<int> nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (var i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (var j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfn bubble_sort(nums: &mut [i32]) -> i32 {\nlet mut count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\ncount\n}\n
        time_complexity.c
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int *nums, int n) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = n - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\nfn bubbleSort(nums: []i32) i32 {\nvar count: i32 = 0;  // \u8ba1\u6570\u5668 \n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: i32 = @as(i32, @intCast(nums.len)) - 1;\nwhile (i > 0) : (i -= 1) {\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        "},{"location":"chapter_computational_complexity/time_complexity/#4-o2n","title":"4. \u00a0 \u6307\u6570\u9636 \\(O(2^n)\\)","text":"

        \u751f\u7269\u5b66\u7684\u201c\u7ec6\u80de\u5206\u88c2\u201d\u662f\u6307\u6570\u9636\u589e\u957f\u7684\u5178\u578b\u4f8b\u5b50\uff1a\u521d\u59cb\u72b6\u6001\u4e3a \\(1\\) \u4e2a\u7ec6\u80de\uff0c\u5206\u88c2\u4e00\u8f6e\u540e\u53d8\u4e3a \\(2\\) \u4e2a\uff0c\u5206\u88c2\u4e24\u8f6e\u540e\u53d8\u4e3a \\(4\\) \u4e2a\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u5206\u88c2 \\(n\\) \u8f6e\u540e\u6709 \\(2^n\\) \u4e2a\u7ec6\u80de\u3002

        \u56fe 2-11 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6a21\u62df\u4e86\u7ec6\u80de\u5206\u88c2\u7684\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def exponential(n: int) -> int:\n\"\"\"\u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\ncount = 0\nbase = 1\n# \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in range(n):\nfor _ in range(base):\ncount += 1\nbase *= 2\n# count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n
        time_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.java
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.cs
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Exponential(int n) {\nint count = 0, bas = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < bas; j++) {\ncount++;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.go
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc exponential(n int) int {\ncount, base := 0, 1\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor i := 0; i < n; i++ {\nfor j := 0; j < base; j++ {\ncount++\n}\nbase *= 2\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n}\n
        time_complexity.swift
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc exponential(n: Int) -> Int {\nvar count = 0\nvar base = 1\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in 0 ..< n {\nfor _ in 0 ..< base {\ncount += 1\n}\nbase *= 2\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n}\n
        time_complexity.js
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n) {\nlet count = 0,\nbase = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.ts
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n: number): number {\nlet count = 0,\nbase = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.dart
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (var i = 0; i < n; i++) {\nfor (var j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.rs
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn exponential(n: i32) -> i32 {\nlet mut count = 0;\nlet mut base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in 0..n {\nfor _ in 0..base {\ncount += 1\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\ncount\n}\n
        time_complexity.c
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0;\nint bas = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < bas; j++) {\ncount++;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.zig
        // \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn exponential(n: i32) i32 {\nvar count: i32 = 0;\nvar bas: i32 = 1;\nvar i: i32 = 0;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nwhile (i < n) : (i += 1) {\nvar j: i32 = 0;\nwhile (j < bas) : (j += 1) {\ncount += 1;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n

        \u56fe 2-11 \u00a0 \u6307\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u5728\u5b9e\u9645\u7b97\u6cd5\u4e2d\uff0c\u6307\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u9012\u5f52\u51fd\u6570\u4e2d\u3002\u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u5176\u9012\u5f52\u5730\u4e00\u5206\u4e3a\u4e8c\uff0c\u7ecf\u8fc7 \\(n\\) \u6b21\u5206\u88c2\u540e\u505c\u6b62\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def exp_recur(n: int) -> int:\n\"\"\"\u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n == 1:\nreturn 1\nreturn exp_recur(n - 1) + exp_recur(n - 1) + 1\n
        time_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.java
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.cs
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint ExpRecur(int n) {\nif (n == 1) return 1;\nreturn ExpRecur(n - 1) + ExpRecur(n - 1) + 1;\n}\n
        time_complexity.go
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc expRecur(n int) int {\nif n == 1 {\nreturn 1\n}\nreturn expRecur(n-1) + expRecur(n-1) + 1\n}\n
        time_complexity.swift
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc expRecur(n: Int) -> Int {\nif n == 1 {\nreturn 1\n}\nreturn expRecur(n: n - 1) + expRecur(n: n - 1) + 1\n}\n
        time_complexity.js
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction expRecur(n) {\nif (n === 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.ts
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction expRecur(n: number): number {\nif (n === 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.dart
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.rs
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn exp_recur(n: i32) -> i32 {\nif n == 1 {\nreturn 1;\n}\nexp_recur(n - 1) + exp_recur(n - 1) + 1\n}\n
        time_complexity.c
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.zig
        // \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn expRecur(n: i32) i32 {\nif (n == 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n

        \u6307\u6570\u9636\u589e\u957f\u975e\u5e38\u8fc5\u901f\uff0c\u5728\u7a77\u4e3e\u6cd5\uff08\u66b4\u529b\u641c\u7d22\u3001\u56de\u6eaf\u7b49\uff09\u4e2d\u6bd4\u8f83\u5e38\u89c1\u3002\u5bf9\u4e8e\u6570\u636e\u89c4\u6a21\u8f83\u5927\u7684\u95ee\u9898\uff0c\u6307\u6570\u9636\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u6216\u8d2a\u5fc3\u7b97\u6cd5\u7b49\u6765\u89e3\u51b3\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#5-olog-n","title":"5. \u00a0 \u5bf9\u6570\u9636 \\(O(\\log n)\\)","text":"

        \u4e0e\u6307\u6570\u9636\u76f8\u53cd\uff0c\u5bf9\u6570\u9636\u53cd\u6620\u4e86\u201c\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\u201d\u7684\u60c5\u51b5\u3002\u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u7531\u4e8e\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\uff0c\u56e0\u6b64\u5faa\u73af\u6b21\u6570\u662f \\(\\log_2 n\\) \uff0c\u5373 \\(2^n\\) \u7684\u53cd\u51fd\u6570\u3002

        \u56fe 2-12 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6a21\u62df\u4e86\u201c\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\u201d\u7684\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log_2 n)\\) \uff0c\u7b80\u8bb0\u4e3a \\(O(\\log n)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def logarithmic(n: float) -> int:\n\"\"\"\u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\ncount = 0\nwhile n > 1:\nn = n / 2\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn /= 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc logarithmic(n float64) int {\ncount := 0\nfor n > 1 {\nn = n / 2\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc logarithmic(n: Double) -> Int {\nvar count = 0\nvar n = n\nwhile n > 1 {\nn = n / 2\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n) {\nlet count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n: number): number {\nlet count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(num n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn logarithmic(mut n: f32) -> i32 {\nlet mut count = 0;\nwhile n > 1.0 {\nn = n / 2.0;\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn logarithmic(n: f32) i32 {\nvar count: i32 = 0;\nvar n_var = n;\nwhile (n_var > 1)\n{\nn_var = n_var / 2;\ncount +=1;\n}\nreturn count;\n}\n

        \u56fe 2-12 \u00a0 \u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4e0e\u6307\u6570\u9636\u7c7b\u4f3c\uff0c\u5bf9\u6570\u9636\u4e5f\u5e38\u51fa\u73b0\u4e8e\u9012\u5f52\u51fd\u6570\u4e2d\u3002\u4ee5\u4e0b\u4ee3\u7801\u5f62\u6210\u4e86\u4e00\u68f5\u9ad8\u5ea6\u4e3a \\(\\log_2 n\\) \u7684\u9012\u5f52\u6811\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def log_recur(n: float) -> int:\n\"\"\"\u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n <= 1:\nreturn 0\nreturn log_recur(n / 2) + 1\n
        time_complexity.cpp
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.java
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.cs
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint LogRecur(float n) {\nif (n <= 1) return 0;\nreturn LogRecur(n / 2) + 1;\n}\n
        time_complexity.go
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc logRecur(n float64) int {\nif n <= 1 {\nreturn 0\n}\nreturn logRecur(n/2) + 1\n}\n
        time_complexity.swift
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc logRecur(n: Double) -> Int {\nif n <= 1 {\nreturn 0\n}\nreturn logRecur(n: n / 2) + 1\n}\n
        time_complexity.js
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n) {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.ts
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n: number): number {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.dart
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(num n) {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.rs
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn log_recur(n: f32) -> i32 {\nif n <= 1.0 {\nreturn 0;\n}\nlog_recur(n / 2.0) + 1\n}\n
        time_complexity.c
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.zig
        // \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn logRecur(n: f32) i32 {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n

        \u5bf9\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u7b97\u6cd5\u4e2d\uff0c\u4f53\u73b0\u4e86\u201c\u4e00\u5206\u4e3a\u591a\u201d\u548c\u201c\u5316\u7e41\u4e3a\u7b80\u201d\u7684\u7b97\u6cd5\u601d\u60f3\u3002\u5b83\u589e\u957f\u7f13\u6162\uff0c\u662f\u4ec5\u6b21\u4e8e\u5e38\u6570\u9636\u7684\u7406\u60f3\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \\(O(\\log n)\\) \u7684\u5e95\u6570\u662f\u591a\u5c11\uff1f

        \u51c6\u786e\u6765\u8bf4\uff0c\u201c\u4e00\u5206\u4e3a \\(m\\)\u201d\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(\\log_m n)\\) \u3002\u800c\u901a\u8fc7\u5bf9\u6570\u6362\u5e95\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5177\u6709\u4e0d\u540c\u5e95\u6570\u3001\u76f8\u7b49\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a

        \\[ O(\\log_m n) = O(\\log_k n / \\log_k m) = O(\\log_k n) \\]

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5e95\u6570 \\(m\\) \u53ef\u4ee5\u5728\u4e0d\u5f71\u54cd\u590d\u6742\u5ea6\u7684\u524d\u63d0\u4e0b\u8f6c\u6362\u3002\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f1a\u7701\u7565\u5e95\u6570 \\(m\\) \uff0c\u5c06\u5bf9\u6570\u9636\u76f4\u63a5\u8bb0\u4e3a \\(O(\\log n)\\) \u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#6-on-log-n","title":"6. \u00a0 \u7ebf\u6027\u5bf9\u6570\u9636 \\(O(n \\log n)\\)","text":"

        \u7ebf\u6027\u5bf9\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u5d4c\u5957\u5faa\u73af\u4e2d\uff0c\u4e24\u5c42\u5faa\u73af\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u522b\u4e3a \\(O(\\log n)\\) \u548c \\(O(n)\\) \u3002\u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def linear_log_recur(n: float) -> int:\n\"\"\"\u7ebf\u6027\u5bf9\u6570\u9636\"\"\"\nif n <= 1:\nreturn 1\ncount: int = linear_log_recur(n // 2) + linear_log_recur(n // 2)\nfor _ in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint LinearLogRecur(float n) {\nif (n <= 1) return 1;\nint count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n float64) int {\nif n <= 1 {\nreturn 1\n}\ncount := linearLogRecur(n/2) + linearLogRecur(n/2)\nfor i := 0.0; i < n; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n: Double) -> Int {\nif n <= 1 {\nreturn 1\n}\nvar count = linearLogRecur(n: n / 2) + linearLogRecur(n: n / 2)\nfor _ in stride(from: 0, to: n, by: 1) {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n) {\nif (n <= 1) return 1;\nlet count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (let i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n: number): number {\nif (n <= 1) return 1;\nlet count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (let i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(num n) {\nif (n <= 1) return 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (var i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfn linear_log_recur(n: f32) -> i32 {\nif n <= 1.0 {\nreturn 1;\n}\nlet mut count = linear_log_recur(n / 2.0) + linear_log_recur(n / 2.0);\nfor _ in 0 ..n as i32 {\ncount += 1;\n}\nreturn count\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u5bf9\u6570\u9636\nfn linearLogRecur(n: f32) i32 {\nif (n <= 1) return 1;\nvar count: i32 = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nvar i: f32 = 0;\nwhile (i < n) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n

        \u56fe 2-13 \u5c55\u793a\u4e86\u7ebf\u6027\u5bf9\u6570\u9636\u7684\u751f\u6210\u65b9\u5f0f\u3002\u4e8c\u53c9\u6811\u7684\u6bcf\u4e00\u5c42\u7684\u64cd\u4f5c\u603b\u6570\u90fd\u4e3a \\(n\\) \uff0c\u6811\u5171\u6709 \\(\\log_2 n + 1\\) \u5c42\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u56fe 2-13 \u00a0 \u7ebf\u6027\u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4e3b\u6d41\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u4e3a \\(O(n \\log n)\\) \uff0c\u4f8b\u5982\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u7b49\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#7-on","title":"7. \u00a0 \u9636\u4e58\u9636 \\(O(n!)\\)","text":"

        \u9636\u4e58\u9636\u5bf9\u5e94\u6570\u5b66\u4e0a\u7684\u201c\u5168\u6392\u5217\u201d\u95ee\u9898\u3002\u7ed9\u5b9a \\(n\\) \u4e2a\u4e92\u4e0d\u91cd\u590d\u7684\u5143\u7d20\uff0c\u6c42\u5176\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u65b9\u6848\uff0c\u65b9\u6848\u6570\u91cf\u4e3a\uff1a

        \\[ n! = n \\times (n - 1) \\times (n - 2) \\times \\dots \\times 2 \\times 1 \\]

        \u9636\u4e58\u901a\u5e38\u4f7f\u7528\u9012\u5f52\u5b9e\u73b0\u3002\u5982\u56fe 2-14 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u7b2c\u4e00\u5c42\u5206\u88c2\u51fa \\(n\\) \u4e2a\uff0c\u7b2c\u4e8c\u5c42\u5206\u88c2\u51fa \\(n - 1\\) \u4e2a\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u7b2c \\(n\\) \u5c42\u65f6\u505c\u6b62\u5206\u88c2\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def factorial_recur(n: int) -> int:\n\"\"\"\u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n == 0:\nreturn 1\ncount = 0\n# \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in range(n):\ncount += factorial_recur(n - 1)\nreturn count\n
        time_complexity.cpp
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint FactorialRecur(int n) {\nif (n == 0) return 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += FactorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n int) int {\nif n == 0 {\nreturn 1\n}\ncount := 0\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor i := 0; i < n; i++ {\ncount += factorialRecur(n - 1)\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n: Int) -> Int {\nif n == 0 {\nreturn 1\n}\nvar count = 0\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in 0 ..< n {\ncount += factorialRecur(n: n - 1)\n}\nreturn count\n}\n
        time_complexity.js
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n) {\nif (n === 0) return 1;\nlet count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (let i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n: number): number {\nif (n === 0) return 1;\nlet count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (let i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0) return 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (var i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn factorial_recur(n: i32) -> i32 {\nif n == 0 {\nreturn 1;\n}\nlet mut count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in 0..n {\ncount += factorial_recur(n - 1);\n}\ncount\n}\n
        time_complexity.c
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn factorialRecur(n: i32) i32 {\nif (n == 0) return 1;\nvar count: i32 = 0;\nvar i: i32 = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nwhile (i < n) : (i += 1) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n

        \u56fe 2-14 \u00a0 \u9636\u4e58\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u8bf7\u6ce8\u610f\uff0c\u56e0\u4e3a\u5f53 \\(n \\geq 4\\) \u65f6\u6052\u6709 \\(n! > 2^n\\) \uff0c\u6240\u4ee5\u9636\u4e58\u9636\u6bd4\u6307\u6570\u9636\u589e\u957f\u5f97\u66f4\u5feb\uff0c\u5728 \\(n\\) \u8f83\u5927\u65f6\u4e5f\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#235","title":"2.3.5 \u00a0 \u6700\u5dee\u3001\u6700\u4f73\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6","text":"

        \u7b97\u6cd5\u7684\u65f6\u95f4\u6548\u7387\u5f80\u5f80\u4e0d\u662f\u56fa\u5b9a\u7684\uff0c\u800c\u662f\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u6709\u5173\u3002\u5047\u8bbe\u8f93\u5165\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d nums \u7531\u4ece \\(1\\) \u81f3 \\(n\\) \u7684\u6570\u5b57\u7ec4\u6210\uff0c\u6bcf\u4e2a\u6570\u5b57\u53ea\u51fa\u73b0\u4e00\u6b21\uff1b\u4f46\u5143\u7d20\u987a\u5e8f\u662f\u968f\u673a\u6253\u4e71\u7684\uff0c\u4efb\u52a1\u76ee\u6807\u662f\u8fd4\u56de\u5143\u7d20 \\(1\\) \u7684\u7d22\u5f15\u3002\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4ee5\u4e0b\u7ed3\u8bba\u3002

        • \u5f53 nums = [?, ?, ..., 1] \uff0c\u5373\u5f53\u672b\u5c3e\u5143\u7d20\u662f \\(1\\) \u65f6\uff0c\u9700\u8981\u5b8c\u6574\u904d\u5386\u6570\u7ec4\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002
        • \u5f53 nums = [1, ?, ?, ...] \uff0c\u5373\u5f53\u9996\u4e2a\u5143\u7d20\u4e3a \\(1\\) \u65f6\uff0c\u65e0\u8bba\u6570\u7ec4\u591a\u957f\u90fd\u4e0d\u9700\u8981\u7ee7\u7eed\u904d\u5386\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(\\Omega(1)\\) \u3002

        \u201c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u201d\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0a\u754c\uff0c\u4f7f\u7528\u5927 \\(O\\) \u8bb0\u53f7\u8868\u793a\u3002\u76f8\u5e94\u5730\uff0c\u201c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u201d\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0b\u754c\uff0c\u7528 \\(\\Omega\\) \u8bb0\u53f7\u8868\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig worst_best_time_complexity.py
        def random_numbers(n: int) -> list[int]:\n\"\"\"\u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a: 1, 2, ..., n \uff0c\u987a\u5e8f\u88ab\u6253\u4e71\"\"\"\n# \u751f\u6210\u6570\u7ec4 nums =: 1, 2, 3, ..., n\nnums = [i for i in range(1, n + 1)]\n# \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nrandom.shuffle(nums)\nreturn nums\ndef find_one(nums: list[int]) -> int:\n\"\"\"\u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\"\"\"\nfor i in range(len(nums)):\n# \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n# \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1:\nreturn i\nreturn -1\n
        worst_best_time_complexity.cpp
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nvector<int> randomNumbers(int n) {\nvector<int> nums(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u4f7f\u7528\u7cfb\u7edf\u65f6\u95f4\u751f\u6210\u968f\u673a\u79cd\u5b50\nunsigned seed = chrono::system_clock::now().time_since_epoch().count();\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nshuffle(nums.begin(), nums.end(), default_random_engine(seed));\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(vector<int> &nums) {\nfor (int i = 0; i < nums.size(); i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.java
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint[] randomNumbers(int n) {\nInteger[] nums = new Integer[n];\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nCollections.shuffle(Arrays.asList(nums));\n// Integer[] -> int[]\nint[] res = new int[n];\nfor (int i = 0; i < n; i++) {\nres[i] = nums[i];\n}\nreturn res;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int[] nums) {\nfor (int i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.cs
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint[] RandomNumbers(int n) {\nint[] nums = new int[n];\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (int i = 0; i < nums.Length; i++) {\nint index = new Random().Next(i, nums.Length);\n(nums[i], nums[index]) = (nums[index], nums[i]);\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint FindOne(int[] nums) {\nfor (int i = 0; i < nums.Length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.go
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunc randomNumbers(n int) []int {\nnums := make([]int, n)\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor i := 0; i < n; i++ {\nnums[i] = i + 1\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nrand.Shuffle(len(nums), func(i, j int) {\nnums[i], nums[j] = nums[j], nums[i]\n})\nreturn nums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums []int) int {\nfor i := 0; i < len(nums); i++ {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn i\n}\n}\nreturn -1\n}\n
        worst_best_time_complexity.swift
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunc randomNumbers(n: Int) -> [Int] {\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nvar nums = Array(1 ... n)\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle()\nreturn nums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums: [Int]) -> Int {\nfor i in nums.indices {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn i\n}\n}\nreturn -1\n}\n
        worst_best_time_complexity.js
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunction randomNumbers(n) {\nconst nums = Array(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (let i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (let i = 0; i < n; i++) {\nconst r = Math.floor(Math.random() * (i + 1));\nconst temp = nums[i];\nnums[i] = nums[r];\nnums[r] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums) {\nfor (let i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] === 1) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        worst_best_time_complexity.ts
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunction randomNumbers(n: number): number[] {\nconst nums = Array(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (let i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (let i = 0; i < n; i++) {\nconst r = Math.floor(Math.random() * (i + 1));\nconst temp = nums[i];\nnums[i] = nums[r];\nnums[r] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums: number[]): number {\nfor (let i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] === 1) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        worst_best_time_complexity.dart
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nList<int> randomNumbers(int n) {\nfinal nums = List.filled(n, 0);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (var i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle();\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(List<int> nums) {\nfor (var i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1) return i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.rs
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfn random_numbers(n: i32) -> Vec<i32> {\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nlet mut nums = (1..=n).collect::<Vec<i32>>();\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle(&mut thread_rng());\nnums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfn find_one(nums: &[i32]) -> Option<usize> {\nfor i in 0..nums.len() {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn Some(i);\n}\n}\nNone\n}\n
        worst_best_time_complexity.c
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint *randomNumbers(int n) {\n// \u5206\u914d\u5806\u533a\u5185\u5b58\uff08\u521b\u5efa\u4e00\u7ef4\u53ef\u53d8\u957f\u6570\u7ec4\uff1a\u6570\u7ec4\u4e2d\u5143\u7d20\u6570\u91cf\u4e3a n \uff0c\u5143\u7d20\u7c7b\u578b\u4e3a int \uff09\nint *nums = (int *)malloc(n * sizeof(int));\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (int i = n - 1; i > 0; i--) {\nint j = rand() % (i + 1);\nint temp = nums[i];\nnums[i] = nums[j];\nnums[j] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int *nums, int n) {\nfor (int i = 0; i < n; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.zig
        // \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71\nfn randomNumbers(comptime n: usize) [n]i32 {\nvar nums: [n]i32 = undefined;\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (&nums, 0..) |*num, i| {\nnum.* = @as(i32, @intCast(i)) + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nconst rand = std.crypto.random;\nrand.shuffle(i32, &nums);\nreturn nums;\n}\n// \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\nfn findOne(nums: []i32) i32 {\nfor (nums, 0..) |num, i| {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (num == 1) return @intCast(i);\n}\nreturn -1;\n}\n

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6211\u4eec\u5728\u5b9e\u9645\u4e2d\u5f88\u5c11\u4f7f\u7528\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u56e0\u4e3a\u901a\u5e38\u53ea\u6709\u5728\u5f88\u5c0f\u6982\u7387\u4e0b\u624d\u80fd\u8fbe\u5230\uff0c\u53ef\u80fd\u4f1a\u5e26\u6765\u4e00\u5b9a\u7684\u8bef\u5bfc\u6027\u3002\u800c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u66f4\u4e3a\u5b9e\u7528\uff0c\u56e0\u4e3a\u5b83\u7ed9\u51fa\u4e86\u4e00\u4e2a\u6548\u7387\u5b89\u5168\u503c\uff0c\u8ba9\u6211\u4eec\u53ef\u4ee5\u653e\u5fc3\u5730\u4f7f\u7528\u7b97\u6cd5\u3002

        \u4ece\u4e0a\u8ff0\u793a\u4f8b\u53ef\u4ee5\u770b\u51fa\uff0c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u53ea\u51fa\u73b0\u4e8e\u201c\u7279\u6b8a\u7684\u6570\u636e\u5206\u5e03\u201d\uff0c\u8fd9\u4e9b\u60c5\u51b5\u7684\u51fa\u73b0\u6982\u7387\u53ef\u80fd\u5f88\u5c0f\uff0c\u5e76\u4e0d\u80fd\u771f\u5b9e\u5730\u53cd\u6620\u7b97\u6cd5\u8fd0\u884c\u6548\u7387\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f53\u73b0\u7b97\u6cd5\u5728\u968f\u673a\u8f93\u5165\u6570\u636e\u4e0b\u7684\u8fd0\u884c\u6548\u7387\uff0c\u7528 \\(\\Theta\\) \u8bb0\u53f7\u6765\u8868\u793a\u3002

        \u5bf9\u4e8e\u90e8\u5206\u7b97\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u63a8\u7b97\u51fa\u968f\u673a\u6570\u636e\u5206\u5e03\u4e0b\u7684\u5e73\u5747\u60c5\u51b5\u3002\u6bd4\u5982\u4e0a\u8ff0\u793a\u4f8b\uff0c\u7531\u4e8e\u8f93\u5165\u6570\u7ec4\u662f\u88ab\u6253\u4e71\u7684\uff0c\u56e0\u6b64\u5143\u7d20 \\(1\\) \u51fa\u73b0\u5728\u4efb\u610f\u7d22\u5f15\u7684\u6982\u7387\u90fd\u662f\u76f8\u7b49\u7684\uff0c\u90a3\u4e48\u7b97\u6cd5\u7684\u5e73\u5747\u5faa\u73af\u6b21\u6570\u5c31\u662f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a \\(n / 2\\) \uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(\\Theta(n / 2) = \\Theta(n)\\) \u3002

        \u4f46\u5bf9\u4e8e\u8f83\u4e3a\u590d\u6742\u7684\u7b97\u6cd5\uff0c\u8ba1\u7b97\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5f80\u5f80\u6bd4\u8f83\u56f0\u96be\uff0c\u56e0\u4e3a\u5f88\u96be\u5206\u6790\u51fa\u5728\u6570\u636e\u5206\u5e03\u4e0b\u7684\u6574\u4f53\u6570\u5b66\u671f\u671b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4f5c\u4e3a\u7b97\u6cd5\u6548\u7387\u7684\u8bc4\u5224\u6807\u51c6\u3002

        \u4e3a\u4ec0\u4e48\u5f88\u5c11\u770b\u5230 \\(\\Theta\\) \u7b26\u53f7\uff1f

        \u53ef\u80fd\u7531\u4e8e \\(O\\) \u7b26\u53f7\u8fc7\u4e8e\u6717\u6717\u4e0a\u53e3\uff0c\u56e0\u6b64\u6211\u4eec\u5e38\u5e38\u4f7f\u7528\u5b83\u6765\u8868\u793a\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u4f46\u4ece\u4e25\u683c\u610f\u4e49\u4e0a\u8bb2\uff0c\u8fd9\u79cd\u505a\u6cd5\u5e76\u4e0d\u89c4\u8303\u3002\u5728\u672c\u4e66\u548c\u5176\u4ed6\u8d44\u6599\u4e2d\uff0c\u82e5\u9047\u5230\u7c7b\u4f3c\u201c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u201d\u7684\u8868\u8ff0\uff0c\u8bf7\u5c06\u5176\u76f4\u63a5\u7406\u89e3\u4e3a \\(\\Theta(n)\\) \u3002

        "},{"location":"chapter_data_structure/","title":"\u7b2c 3 \u7ae0 \u00a0 \u6570\u636e\u7ed3\u6784","text":"

        Abstract

        \u6570\u636e\u7ed3\u6784\u5982\u540c\u4e00\u526f\u7a33\u56fa\u800c\u591a\u6837\u7684\u6846\u67b6\u3002

        \u5b83\u4e3a\u6570\u636e\u7684\u6709\u5e8f\u7ec4\u7ec7\u63d0\u4f9b\u4e86\u84dd\u56fe\uff0c\u7b97\u6cd5\u5f97\u4ee5\u5728\u6b64\u57fa\u7840\u4e0a\u751f\u52a8\u8d77\u6765\u3002

        "},{"location":"chapter_data_structure/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 3.1 \u00a0 \u6570\u636e\u7ed3\u6784\u5206\u7c7b
        • 3.2 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b
        • 3.3 \u00a0 \u6570\u5b57\u7f16\u7801 *
        • 3.4 \u00a0 \u5b57\u7b26\u7f16\u7801 *
        • 3.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_data_structure/basic_data_types/","title":"3.2 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b","text":"

        \u5f53\u8c08\u53ca\u8ba1\u7b97\u673a\u4e2d\u7684\u6570\u636e\u65f6\uff0c\u6211\u4eec\u4f1a\u60f3\u5230\u6587\u672c\u3001\u56fe\u7247\u3001\u89c6\u9891\u3001\u8bed\u97f3\u30013D \u6a21\u578b\u7b49\u5404\u79cd\u5f62\u5f0f\u3002\u5c3d\u7ba1\u8fd9\u4e9b\u6570\u636e\u7684\u7ec4\u7ec7\u5f62\u5f0f\u5404\u5f02\uff0c\u4f46\u5b83\u4eec\u90fd\u7531\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6784\u6210\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u662f CPU \u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u8fd0\u7b97\u7684\u7c7b\u578b\uff0c\u5728\u7b97\u6cd5\u4e2d\u76f4\u63a5\u88ab\u4f7f\u7528\uff0c\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002

        • \u6574\u6570\u7c7b\u578b byte\u3001short\u3001int\u3001long \u3002
        • \u6d6e\u70b9\u6570\u7c7b\u578b float\u3001double \uff0c\u7528\u4e8e\u8868\u793a\u5c0f\u6570\u3002
        • \u5b57\u7b26\u7c7b\u578b char \uff0c\u7528\u4e8e\u8868\u793a\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u6bcd\u3001\u6807\u70b9\u7b26\u53f7\u751a\u81f3\u8868\u60c5\u7b26\u53f7\u7b49\u3002
        • \u5e03\u5c14\u7c7b\u578b bool \uff0c\u7528\u4e8e\u8868\u793a\u201c\u662f\u201d\u4e0e\u201c\u5426\u201d\u5224\u65ad\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4ee5\u4e8c\u8fdb\u5236\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u3002\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5373\u4e3a \\(1\\) \u6bd4\u7279\u3002\u5728\u7edd\u5927\u591a\u6570\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\\(1\\) \u5b57\u8282\uff08byte\uff09\u7531 \\(8\\) \u6bd4\u7279\uff08bit\uff09\u7ec4\u6210\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u53d6\u51b3\u4e8e\u5176\u5360\u7528\u7684\u7a7a\u95f4\u5927\u5c0f\u3002\u4e0b\u9762\u4ee5 Java \u4e3a\u4f8b\u3002

        • \u6574\u6570\u7c7b\u578b byte \u5360\u7528 \\(1\\) byte = \\(8\\) bits \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{8}\\) \u4e2a\u6570\u5b57\u3002
        • \u6574\u6570\u7c7b\u578b int \u5360\u7528 \\(4\\) bytes = \\(32\\) bits \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{32}\\) \u4e2a\u6570\u5b57\u3002

        \u8868 3-1 \u5217\u4e3e\u4e86 Java \u4e2d\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5360\u7528\u7a7a\u95f4\u3001\u53d6\u503c\u8303\u56f4\u548c\u9ed8\u8ba4\u503c\u3002\u6b64\u8868\u683c\u65e0\u987b\u6b7b\u8bb0\u786c\u80cc\uff0c\u5927\u81f4\u7406\u89e3\u5373\u53ef\uff0c\u9700\u8981\u65f6\u53ef\u4ee5\u901a\u8fc7\u67e5\u8868\u6765\u56de\u5fc6\u3002

        \u8868 3-1 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5360\u7528\u7a7a\u95f4\u548c\u53d6\u503c\u8303\u56f4

        \u7c7b\u578b \u7b26\u53f7 \u5360\u7528\u7a7a\u95f4 \u6700\u5c0f\u503c \u6700\u5927\u503c \u9ed8\u8ba4\u503c \u6574\u6570 byte 1 byte \\(-2^7\\) (\\(-128\\)) \\(2^7 - 1\\) (\\(127\\)) \\(0\\) short 2 bytes \\(-2^{15}\\) \\(2^{15} - 1\\) \\(0\\) int 4 bytes \\(-2^{31}\\) \\(2^{31} - 1\\) \\(0\\) long 8 bytes \\(-2^{63}\\) \\(2^{63} - 1\\) \\(0\\) \u6d6e\u70b9\u6570 float 4 bytes \\(1.175 \\times 10^{-38}\\) \\(3.403 \\times 10^{38}\\) \\(0.0\\text{f}\\) double 8 bytes \\(2.225 \\times 10^{-308}\\) \\(1.798 \\times 10^{308}\\) \\(0.0\\) \u5b57\u7b26 char 2 bytes \\(0\\) \\(2^{16} - 1\\) \\(0\\) \u5e03\u5c14 bool 1 byte \\(\\text{false}\\) \\(\\text{true}\\) \\(\\text{false}\\)

        \u8bf7\u6ce8\u610f\uff0c\u8868 3-1 \u9488\u5bf9\u7684\u662f Java \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u60c5\u51b5\u3002\u6bcf\u79cd\u7f16\u7a0b\u8bed\u8a00\u6709\u5404\u81ea\u7684\u6570\u636e\u7c7b\u578b\u5b9a\u4e49\uff0c\u5b83\u4eec\u7684\u5360\u7528\u7a7a\u95f4\u3001\u53d6\u503c\u8303\u56f4\u548c\u9ed8\u8ba4\u503c\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002

        • \u5728 Python \u4e2d\uff0c\u6574\u6570\u7c7b\u578b int \u53ef\u4ee5\u662f\u4efb\u610f\u5927\u5c0f\uff0c\u53ea\u53d7\u9650\u4e8e\u53ef\u7528\u5185\u5b58\uff1b\u6d6e\u70b9\u6570 float \u662f\u53cc\u7cbe\u5ea6 64 \u4f4d\uff1b\u6ca1\u6709 char \u7c7b\u578b\uff0c\u5355\u4e2a\u5b57\u7b26\u5b9e\u9645\u4e0a\u662f\u957f\u5ea6\u4e3a 1 \u7684\u5b57\u7b26\u4e32 str \u3002
        • C \u548c C++ \u672a\u660e\u786e\u89c4\u5b9a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5927\u5c0f\uff0c\u800c\u56e0\u5b9e\u73b0\u548c\u5e73\u53f0\u5404\u5f02\u3002\u8868 3-1 \u9075\u5faa LP64 \u6570\u636e\u6a21\u578b\uff0c\u5176\u7528\u4e8e\u5305\u62ec Linux \u548c macOS \u5728\u5185\u7684 Unix 64 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\u3002
        • \u5b57\u7b26 char \u7684\u5927\u5c0f\u5728 C \u548c C++ \u4e2d\u4e3a 1 \u5b57\u8282\uff0c\u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\u53d6\u51b3\u4e8e\u7279\u5b9a\u7684\u5b57\u7b26\u7f16\u7801\u65b9\u6cd5\uff0c\u8be6\u89c1\u201c\u5b57\u7b26\u7f16\u7801\u201d\u7ae0\u8282\u3002
        • \u5373\u4f7f\u8868\u793a\u5e03\u5c14\u91cf\u4ec5\u9700 1 \u4f4d\uff08\\(0\\) \u6216 \\(1\\)\uff09\uff0c\u5b83\u5728\u5185\u5b58\u4e2d\u901a\u5e38\u5b58\u50a8\u4e3a 1 \u5b57\u8282\u3002\u8fd9\u662f\u56e0\u4e3a\u73b0\u4ee3\u8ba1\u7b97\u673a CPU \u901a\u5e38\u5c06 1 \u5b57\u8282\u4f5c\u4e3a\u6700\u5c0f\u5bfb\u5740\u5185\u5b58\u5355\u5143\u3002

        \u90a3\u4e48\uff0c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e0e\u6570\u636e\u7ed3\u6784\u4e4b\u95f4\u6709\u4ec0\u4e48\u8054\u7cfb\u5462\uff1f\u6211\u4eec\u77e5\u9053\uff0c\u6570\u636e\u7ed3\u6784\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u4e0e\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\u3002\u8fd9\u53e5\u8bdd\u7684\u4e3b\u8bed\u662f\u201c\u7ed3\u6784\u201d\u800c\u975e\u201c\u6570\u636e\u201d\u3002

        \u5982\u679c\u60f3\u8868\u793a\u201c\u4e00\u6392\u6570\u5b57\u201d\uff0c\u6211\u4eec\u81ea\u7136\u4f1a\u60f3\u5230\u4f7f\u7528\u6570\u7ec4\u3002\u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u7684\u7ebf\u6027\u7ed3\u6784\u53ef\u4ee5\u8868\u793a\u6570\u5b57\u7684\u76f8\u90bb\u5173\u7cfb\u548c\u987a\u5e8f\u5173\u7cfb\uff0c\u4f46\u81f3\u4e8e\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u6574\u6570 int\u3001\u5c0f\u6570 float \u6216\u662f\u5b57\u7b26 char \uff0c\u5219\u4e0e\u201c\u6570\u636e\u7ed3\u6784\u201d\u65e0\u5173\u3002

        \u6362\u53e5\u8bdd\u8bf4\uff0c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u201c\u5185\u5bb9\u7c7b\u578b\u201d\uff0c\u800c\u6570\u636e\u7ed3\u6784\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u201c\u7ec4\u7ec7\u65b9\u5f0f\u201d\u3002\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6211\u4eec\u7528\u76f8\u540c\u7684\u6570\u636e\u7ed3\u6784\uff08\u6570\u7ec4\uff09\u6765\u5b58\u50a8\u4e0e\u8868\u793a\u4e0d\u540c\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec int\u3001float\u3001char\u3001bool \u7b49\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nnumbers: list[int] = [0] * 5\ndecimals: list[float] = [0.0] * 5\n# Python \u7684\u5b57\u7b26\u5b9e\u9645\u4e0a\u662f\u957f\u5ea6\u4e3a 1 \u7684\u5b57\u7b26\u4e32\ncharacters: list[str] = ['0'] * 5\nbools: list[bool] = [False] * 5\n# Python \u7684\u5217\u8868\u53ef\u4ee5\u81ea\u7531\u5b58\u50a8\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5bf9\u8c61\u5f15\u7528\ndata = [0, 0.0, 'a', False, ListNode(0)]\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint numbers[5];\nfloat decimals[5];\nchar characters[5];\nbool bools[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint[] numbers = new int[5];\nfloat[] decimals = new float[5];\nchar[] characters = new char[5];\nboolean[] bools = new boolean[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint[] numbers = new int[5];\nfloat[] decimals = new float[5];\nchar[] characters = new char[5];\nbool[] bools = new bool[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nvar numbers = [5]int{}\nvar decimals = [5]float64{}\nvar characters = [5]byte{}\nvar bools = [5]bool{}\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nlet numbers = Array(repeating: Int(), count: 5)\nlet decimals = Array(repeating: Double(), count: 5)\nlet characters = Array(repeating: Character(\"a\"), count: 5)\nlet bools = Array(repeating: Bool(), count: 5)\n
        // JavaScript \u7684\u6570\u7ec4\u53ef\u4ee5\u81ea\u7531\u5b58\u50a8\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5bf9\u8c61\nconst array = [0, 0.0, 'a', false];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nconst numbers: number[] = [];\nconst characters: string[] = [];\nconst bools: boolean[] = [];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nList<int> numbers = List.filled(5, 0);\nList<double> decimals = List.filled(5, 0.0);\nList<String> characters = List.filled(5, 'a');\nList<bool> bools = List.filled(5, false);\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nlet numbers: Vec<i32> = vec![0; 5];\nlet decimals: Vec<f32> = vec![0.0, 5];\nlet characters: Vec<char> = vec!['0'; 5];\nlet bools: Vec<bool> = vec![false; 5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint numbers[10];\nfloat decimals[10];\nchar characters[10];\nbool bools[10];\n
        \n
        "},{"location":"chapter_data_structure/character_encoding/","title":"3.4 \u00a0 \u5b57\u7b26\u7f16\u7801 *","text":"

        \u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u662f\u4ee5\u4e8c\u8fdb\u5236\u6570\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\uff0c\u5b57\u7b26 char \u4e5f\u4e0d\u4f8b\u5916\u3002\u4e3a\u4e86\u8868\u793a\u5b57\u7b26\uff0c\u6211\u4eec\u9700\u8981\u5efa\u7acb\u4e00\u5957\u201c\u5b57\u7b26\u96c6\u201d\uff0c\u89c4\u5b9a\u6bcf\u4e2a\u5b57\u7b26\u548c\u4e8c\u8fdb\u5236\u6570\u4e4b\u95f4\u7684\u4e00\u4e00\u5bf9\u5e94\u5173\u7cfb\u3002\u6709\u4e86\u5b57\u7b26\u96c6\u4e4b\u540e\uff0c\u8ba1\u7b97\u673a\u5c31\u53ef\u4ee5\u901a\u8fc7\u67e5\u8868\u5b8c\u6210\u4e8c\u8fdb\u5236\u6570\u5230\u5b57\u7b26\u7684\u8f6c\u6362\u3002

        "},{"location":"chapter_data_structure/character_encoding/#341-ascii","title":"3.4.1 \u00a0 ASCII \u5b57\u7b26\u96c6","text":"

        \u300cASCII \u7801\u300d\u662f\u6700\u65e9\u51fa\u73b0\u7684\u5b57\u7b26\u96c6\uff0c\u5176\u5168\u79f0\u4e3a American Standard Code for Information Interchange\uff08\u7f8e\u56fd\u6807\u51c6\u4fe1\u606f\u4ea4\u6362\u4ee3\u7801\uff09\u3002\u5b83\u4f7f\u7528 7 \u4f4d\u4e8c\u8fdb\u5236\u6570\uff08\u4e00\u4e2a\u5b57\u8282\u7684\u4f4e 7 \u4f4d\uff09\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6700\u591a\u80fd\u591f\u8868\u793a 128 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u5982\u56fe 3-6 \u6240\u793a\uff0cASCII \u7801\u5305\u62ec\u82f1\u6587\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u3001\u6570\u5b57 0 ~ 9\u3001\u4e00\u4e9b\u6807\u70b9\u7b26\u53f7\uff0c\u4ee5\u53ca\u4e00\u4e9b\u63a7\u5236\u5b57\u7b26\uff08\u5982\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\uff09\u3002

        \u56fe 3-6 \u00a0 ASCII \u7801

        \u7136\u800c\uff0cASCII \u7801\u4ec5\u80fd\u591f\u8868\u793a\u82f1\u6587\u3002\u968f\u7740\u8ba1\u7b97\u673a\u7684\u5168\u7403\u5316\uff0c\u8bde\u751f\u4e86\u4e00\u79cd\u80fd\u591f\u8868\u793a\u66f4\u591a\u8bed\u8a00\u7684\u5b57\u7b26\u96c6\u300cEASCII\u300d\u3002\u5b83\u5728 ASCII \u7684 7 \u4f4d\u57fa\u7840\u4e0a\u6269\u5c55\u5230 8 \u4f4d\uff0c\u80fd\u591f\u8868\u793a 256 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002

        \u5728\u4e16\u754c\u8303\u56f4\u5185\uff0c\u9646\u7eed\u51fa\u73b0\u4e86\u4e00\u6279\u9002\u7528\u4e8e\u4e0d\u540c\u5730\u533a\u7684 EASCII \u5b57\u7b26\u96c6\u3002\u8fd9\u4e9b\u5b57\u7b26\u96c6\u7684\u524d 128 \u4e2a\u5b57\u7b26\u7edf\u4e00\u4e3a ASCII \u7801\uff0c\u540e 128 \u4e2a\u5b57\u7b26\u5b9a\u4e49\u4e0d\u540c\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u8bed\u8a00\u7684\u9700\u6c42\u3002

        "},{"location":"chapter_data_structure/character_encoding/#342-gbk","title":"3.4.2 \u00a0 GBK \u5b57\u7b26\u96c6","text":"

        \u540e\u6765\u4eba\u4eec\u53d1\u73b0\uff0cEASCII \u7801\u4ecd\u7136\u65e0\u6cd5\u6ee1\u8db3\u8bb8\u591a\u8bed\u8a00\u7684\u5b57\u7b26\u6570\u91cf\u8981\u6c42\u3002\u6bd4\u5982\u6c49\u5b57\u6709\u8fd1\u5341\u4e07\u4e2a\uff0c\u5149\u65e5\u5e38\u4f7f\u7528\u7684\u5c31\u6709\u51e0\u5343\u4e2a\u3002\u4e2d\u56fd\u56fd\u5bb6\u6807\u51c6\u603b\u5c40\u4e8e 1980 \u5e74\u53d1\u5e03\u4e86\u300cGB2312\u300d\u5b57\u7b26\u96c6\uff0c\u5176\u6536\u5f55\u4e86 6763 \u4e2a\u6c49\u5b57\uff0c\u57fa\u672c\u6ee1\u8db3\u4e86\u6c49\u5b57\u7684\u8ba1\u7b97\u673a\u5904\u7406\u9700\u8981\u3002

        \u7136\u800c\uff0cGB2312 \u65e0\u6cd5\u5904\u7406\u90e8\u5206\u7f55\u89c1\u5b57\u548c\u7e41\u4f53\u5b57\u3002\u300cGBK\u300d\u5b57\u7b26\u96c6\u662f\u5728 GB2312 \u7684\u57fa\u7840\u4e0a\u6269\u5c55\u5f97\u5230\u7684\uff0c\u5b83\u5171\u6536\u5f55\u4e86 21886 \u4e2a\u6c49\u5b57\u3002\u5728 GBK \u7684\u7f16\u7801\u65b9\u6848\u4e2d\uff0cASCII \u5b57\u7b26\u4f7f\u7528\u4e00\u4e2a\u5b57\u8282\u8868\u793a\uff0c\u6c49\u5b57\u4f7f\u7528\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u3002

        "},{"location":"chapter_data_structure/character_encoding/#343-unicode","title":"3.4.3 \u00a0 Unicode \u5b57\u7b26\u96c6","text":"

        \u968f\u7740\u8ba1\u7b97\u673a\u6280\u672f\u7684\u84ec\u52c3\u53d1\u5c55\uff0c\u5b57\u7b26\u96c6\u4e0e\u7f16\u7801\u6807\u51c6\u767e\u82b1\u9f50\u653e\uff0c\u800c\u8fd9\u5e26\u6765\u4e86\u8bb8\u591a\u95ee\u9898\u3002\u4e00\u65b9\u9762\uff0c\u8fd9\u4e9b\u5b57\u7b26\u96c6\u4e00\u822c\u53ea\u5b9a\u4e49\u4e86\u7279\u5b9a\u8bed\u8a00\u7684\u5b57\u7b26\uff0c\u65e0\u6cd5\u5728\u591a\u8bed\u8a00\u73af\u5883\u4e0b\u6b63\u5e38\u5de5\u4f5c\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u540c\u4e00\u79cd\u8bed\u8a00\u5b58\u5728\u591a\u79cd\u5b57\u7b26\u96c6\u6807\u51c6\uff0c\u5982\u679c\u4e24\u53f0\u8ba1\u7b97\u673a\u4f7f\u7528\u7684\u662f\u4e0d\u540c\u7684\u7f16\u7801\u6807\u51c6\uff0c\u5219\u5728\u4fe1\u606f\u4f20\u9012\u65f6\u5c31\u4f1a\u51fa\u73b0\u4e71\u7801\u3002

        \u90a3\u4e2a\u65f6\u4ee3\u7684\u7814\u7a76\u4eba\u5458\u5c31\u5728\u60f3\uff1a\u5982\u679c\u63a8\u51fa\u4e00\u4e2a\u8db3\u591f\u5b8c\u6574\u7684\u5b57\u7b26\u96c6\uff0c\u5c06\u4e16\u754c\u8303\u56f4\u5185\u7684\u6240\u6709\u8bed\u8a00\u548c\u7b26\u53f7\u90fd\u6536\u5f55\u5176\u4e2d\uff0c\u4e0d\u5c31\u53ef\u4ee5\u89e3\u51b3\u8de8\u8bed\u8a00\u73af\u5883\u548c\u4e71\u7801\u95ee\u9898\u4e86\u5417\uff1f\u5728\u8fd9\u79cd\u60f3\u6cd5\u7684\u9a71\u52a8\u4e0b\uff0c\u4e00\u4e2a\u5927\u800c\u5168\u7684\u5b57\u7b26\u96c6 Unicode \u5e94\u8fd0\u800c\u751f\u3002

        \u300cUnicode\u300d\u7684\u4e2d\u6587\u540d\u79f0\u4e3a\u201c\u7edf\u4e00\u7801\u201d\uff0c\u7406\u8bba\u4e0a\u80fd\u5bb9\u7eb3 100 \u591a\u4e07\u4e2a\u5b57\u7b26\u3002\u5b83\u81f4\u529b\u4e8e\u5c06\u5168\u7403\u8303\u56f4\u5185\u7684\u5b57\u7b26\u7eb3\u5165\u7edf\u4e00\u7684\u5b57\u7b26\u96c6\u4e4b\u4e2d\uff0c\u63d0\u4f9b\u4e00\u79cd\u901a\u7528\u7684\u5b57\u7b26\u96c6\u6765\u5904\u7406\u548c\u663e\u793a\u5404\u79cd\u8bed\u8a00\u6587\u5b57\uff0c\u51cf\u5c11\u56e0\u4e3a\u7f16\u7801\u6807\u51c6\u4e0d\u540c\u800c\u4ea7\u751f\u7684\u4e71\u7801\u95ee\u9898\u3002

        \u81ea 1991 \u5e74\u53d1\u5e03\u4ee5\u6765\uff0cUnicode \u4e0d\u65ad\u6269\u5145\u65b0\u7684\u8bed\u8a00\u4e0e\u5b57\u7b26\u3002\u622a\u81f3 2022 \u5e74 9 \u6708\uff0cUnicode \u5df2\u7ecf\u5305\u542b 149186 \u4e2a\u5b57\u7b26\uff0c\u5305\u62ec\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u7b26\u3001\u7b26\u53f7\u751a\u81f3\u8868\u60c5\u7b26\u53f7\u7b49\u3002\u5728\u5e9e\u5927\u7684 Unicode \u5b57\u7b26\u96c6\u4e2d\uff0c\u5e38\u7528\u7684\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\uff0c\u6709\u4e9b\u751f\u50fb\u7684\u5b57\u7b26\u5360\u7528 3 \u5b57\u8282\u751a\u81f3 4 \u5b57\u8282\u3002

        Unicode \u662f\u4e00\u79cd\u901a\u7528\u5b57\u7b26\u96c6\uff0c\u672c\u8d28\u4e0a\u662f\u7ed9\u6bcf\u4e2a\u5b57\u7b26\u5206\u914d\u4e00\u4e2a\u7f16\u53f7\uff08\u79f0\u4e3a\u201c\u7801\u70b9\u201d\uff09\uff0c\u4f46\u5b83\u5e76\u6ca1\u6709\u89c4\u5b9a\u5728\u8ba1\u7b97\u673a\u4e2d\u5982\u4f55\u5b58\u50a8\u8fd9\u4e9b\u5b57\u7b26\u7801\u70b9\u3002\u6211\u4eec\u4e0d\u7981\u4f1a\u95ee\uff1a\u5f53\u591a\u79cd\u957f\u5ea6\u7684 Unicode \u7801\u70b9\u540c\u65f6\u51fa\u73b0\u5728\u4e00\u4e2a\u6587\u672c\u4e2d\u65f6\uff0c\u7cfb\u7edf\u5982\u4f55\u89e3\u6790\u5b57\u7b26\uff1f\u4f8b\u5982\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a 2 \u5b57\u8282\u7684\u7f16\u7801\uff0c\u7cfb\u7edf\u5982\u4f55\u786e\u8ba4\u5b83\u662f\u4e00\u4e2a 2 \u5b57\u8282\u7684\u5b57\u7b26\u8fd8\u662f\u4e24\u4e2a 1 \u5b57\u8282\u7684\u5b57\u7b26\uff1f

        \u5bf9\u4e8e\u4ee5\u4e0a\u95ee\u9898\uff0c\u4e00\u79cd\u76f4\u63a5\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u6240\u6709\u5b57\u7b26\u5b58\u50a8\u4e3a\u7b49\u957f\u7684\u7f16\u7801\u3002\u5982\u56fe 3-7 \u6240\u793a\uff0c\u201cHello\u201d\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 1 \u5b57\u8282\uff0c\u201c\u7b97\u6cd5\u201d\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9ad8\u4f4d\u586b 0 \u5c06\u201cHello \u7b97\u6cd5\u201d\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u7f16\u7801\u4e3a 2 \u5b57\u8282\u957f\u5ea6\u3002\u8fd9\u6837\u7cfb\u7edf\u5c31\u53ef\u4ee5\u6bcf\u9694 2 \u5b57\u8282\u89e3\u6790\u4e00\u4e2a\u5b57\u7b26\uff0c\u6062\u590d\u8fd9\u4e2a\u77ed\u8bed\u7684\u5185\u5bb9\u4e86\u3002

        \u56fe 3-7 \u00a0 Unicode \u7f16\u7801\u793a\u4f8b

        \u7136\u800c ASCII \u7801\u5df2\u7ecf\u5411\u6211\u4eec\u8bc1\u660e\uff0c\u7f16\u7801\u82f1\u6587\u53ea\u9700 1 \u5b57\u8282\u3002\u82e5\u91c7\u7528\u4e0a\u8ff0\u65b9\u6848\uff0c\u82f1\u6587\u6587\u672c\u5360\u7528\u7a7a\u95f4\u7684\u5927\u5c0f\u5c06\u4f1a\u662f ASCII \u7f16\u7801\u4e0b\u7684\u4e24\u500d\uff0c\u975e\u5e38\u6d6a\u8d39\u5185\u5b58\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u66f4\u52a0\u9ad8\u6548\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\u3002

        "},{"location":"chapter_data_structure/character_encoding/#344-utf-8","title":"3.4.4 \u00a0 UTF-8 \u7f16\u7801","text":"

        \u76ee\u524d\uff0cUTF-8 \u5df2\u6210\u4e3a\u56fd\u9645\u4e0a\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\u3002\u5b83\u662f\u4e00\u79cd\u53ef\u53d8\u957f\u5ea6\u7684\u7f16\u7801\uff0c\u4f7f\u7528 1 \u5230 4 \u5b57\u8282\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6839\u636e\u5b57\u7b26\u7684\u590d\u6742\u6027\u800c\u53d8\u3002ASCII \u5b57\u7b26\u53ea\u9700 1 \u5b57\u8282\uff0c\u62c9\u4e01\u5b57\u6bcd\u548c\u5e0c\u814a\u5b57\u6bcd\u9700\u8981 2 \u5b57\u8282\uff0c\u5e38\u7528\u7684\u4e2d\u6587\u5b57\u7b26\u9700\u8981 3 \u5b57\u8282\uff0c\u5176\u4ed6\u7684\u4e00\u4e9b\u751f\u50fb\u5b57\u7b26\u9700\u8981 4 \u5b57\u8282\u3002

        UTF-8 \u7684\u7f16\u7801\u89c4\u5219\u5e76\u4e0d\u590d\u6742\uff0c\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\u3002

        • \u5bf9\u4e8e\u957f\u5ea6\u4e3a 1 \u5b57\u8282\u7684\u5b57\u7b26\uff0c\u5c06\u6700\u9ad8\u4f4d\u8bbe\u7f6e\u4e3a \\(0\\) \uff0c\u5176\u4f59 7 \u4f4d\u8bbe\u7f6e\u4e3a Unicode \u7801\u70b9\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cASCII \u5b57\u7b26\u5728 Unicode \u5b57\u7b26\u96c6\u4e2d\u5360\u636e\u4e86\u524d 128 \u4e2a\u7801\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cUTF-8 \u7f16\u7801\u53ef\u4ee5\u5411\u4e0b\u517c\u5bb9 ASCII \u7801\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 UTF-8 \u6765\u89e3\u6790\u5e74\u4ee3\u4e45\u8fdc\u7684 ASCII \u7801\u6587\u672c\u3002
        • \u5bf9\u4e8e\u957f\u5ea6\u4e3a \\(n\\) \u5b57\u8282\u7684\u5b57\u7b26\uff08\u5176\u4e2d \\(n > 1\\)\uff09\uff0c\u5c06\u9996\u4e2a\u5b57\u8282\u7684\u9ad8 \\(n\\) \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(1\\) \uff0c\u7b2c \\(n + 1\\) \u4f4d\u8bbe\u7f6e\u4e3a \\(0\\) \uff1b\u4ece\u7b2c\u4e8c\u4e2a\u5b57\u8282\u5f00\u59cb\uff0c\u5c06\u6bcf\u4e2a\u5b57\u8282\u7684\u9ad8 2 \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(10\\) \uff1b\u5176\u4f59\u6240\u6709\u4f4d\u7528\u4e8e\u586b\u5145\u5b57\u7b26\u7684 Unicode \u7801\u70b9\u3002

        \u56fe 3-8 \u5c55\u793a\u4e86\u201cHello\u7b97\u6cd5\u201d\u5bf9\u5e94\u7684 UTF-8 \u7f16\u7801\u3002\u89c2\u5bdf\u53d1\u73b0\uff0c\u7531\u4e8e\u6700\u9ad8 \\(n\\) \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(1\\) \uff0c\u56e0\u6b64\u7cfb\u7edf\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6\u6700\u9ad8\u4f4d \\(1\\) \u7684\u4e2a\u6570\u6765\u89e3\u6790\u51fa\u5b57\u7b26\u7684\u957f\u5ea6\u4e3a \\(n\\) \u3002

        \u4f46\u4e3a\u4ec0\u4e48\u8981\u5c06\u5176\u4f59\u6240\u6709\u5b57\u8282\u7684\u9ad8 2 \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(10\\) \u5462\uff1f\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e2a \\(10\\) \u80fd\u591f\u8d77\u5230\u6821\u9a8c\u7b26\u7684\u4f5c\u7528\u3002\u5047\u8bbe\u7cfb\u7edf\u4ece\u4e00\u4e2a\u9519\u8bef\u7684\u5b57\u8282\u5f00\u59cb\u89e3\u6790\u6587\u672c\uff0c\u5b57\u8282\u5934\u90e8\u7684 \\(10\\) \u80fd\u591f\u5e2e\u52a9\u7cfb\u7edf\u5feb\u901f\u5224\u65ad\u51fa\u5f02\u5e38\u3002

        \u4e4b\u6240\u4ee5\u5c06 \\(10\\) \u5f53\u4f5c\u6821\u9a8c\u7b26\uff0c\u662f\u56e0\u4e3a\u5728 UTF-8 \u7f16\u7801\u89c4\u5219\u4e0b\uff0c\u4e0d\u53ef\u80fd\u6709\u5b57\u7b26\u7684\u6700\u9ad8\u4e24\u4f4d\u662f \\(10\\) \u3002\u8fd9\u4e2a\u7ed3\u8bba\u53ef\u4ee5\u7528\u53cd\u8bc1\u6cd5\u6765\u8bc1\u660e\uff1a\u5047\u8bbe\u4e00\u4e2a\u5b57\u7b26\u7684\u6700\u9ad8\u4e24\u4f4d\u662f \\(10\\) \uff0c\u8bf4\u660e\u8be5\u5b57\u7b26\u7684\u957f\u5ea6\u4e3a \\(1\\) \uff0c\u5bf9\u5e94 ASCII \u7801\u3002\u800c ASCII \u7801\u7684\u6700\u9ad8\u4f4d\u5e94\u8be5\u662f \\(0\\) \uff0c\u4e0e\u5047\u8bbe\u77db\u76fe\u3002

        \u56fe 3-8 \u00a0 UTF-8 \u7f16\u7801\u793a\u4f8b

        \u9664\u4e86 UTF-8 \u4e4b\u5916\uff0c\u5e38\u89c1\u7684\u7f16\u7801\u65b9\u5f0f\u8fd8\u5305\u62ec\u4ee5\u4e0b\u4e24\u79cd\u3002

        • UTF-16 \u7f16\u7801\uff1a\u4f7f\u7528 2 \u6216 4 \u5b57\u8282\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002\u6240\u6709\u7684 ASCII \u5b57\u7b26\u548c\u5e38\u7528\u7684\u975e\u82f1\u6587\u5b57\u7b26\uff0c\u90fd\u7528 2 \u5b57\u8282\u8868\u793a\uff1b\u5c11\u6570\u5b57\u7b26\u9700\u8981\u7528\u5230 4 \u5b57\u8282\u8868\u793a\u3002\u5bf9\u4e8e 2 \u5b57\u8282\u7684\u5b57\u7b26\uff0cUTF-16 \u7f16\u7801\u4e0e Unicode \u7801\u70b9\u76f8\u7b49\u3002
        • UTF-32 \u7f16\u7801\uff1a\u6bcf\u4e2a\u5b57\u7b26\u90fd\u4f7f\u7528 4 \u5b57\u8282\u3002\u8fd9\u610f\u5473\u7740 UTF-32 \u6bd4 UTF-8 \u548c UTF-16 \u66f4\u5360\u7528\u7a7a\u95f4\uff0c\u7279\u522b\u662f\u5bf9\u4e8e ASCII \u5b57\u7b26\u5360\u6bd4\u8f83\u9ad8\u7684\u6587\u672c\u3002

        \u4ece\u5b58\u50a8\u7a7a\u95f4\u5360\u7528\u7684\u89d2\u5ea6\u770b\uff0c\u4f7f\u7528 UTF-8 \u8868\u793a\u82f1\u6587\u5b57\u7b26\u975e\u5e38\u9ad8\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9700 1 \u5b57\u8282\uff1b\u4f7f\u7528 UTF-16 \u7f16\u7801\u67d0\u4e9b\u975e\u82f1\u6587\u5b57\u7b26\uff08\u4f8b\u5982\u4e2d\u6587\uff09\u4f1a\u66f4\u52a0\u9ad8\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9700 2 \u5b57\u8282\uff0c\u800c UTF-8 \u53ef\u80fd\u9700\u8981 3 \u5b57\u8282\u3002

        \u4ece\u517c\u5bb9\u6027\u7684\u89d2\u5ea6\u770b\uff0cUTF-8 \u7684\u901a\u7528\u6027\u6700\u4f73\uff0c\u8bb8\u591a\u5de5\u5177\u548c\u5e93\u4f18\u5148\u652f\u6301 UTF-8 \u3002

        "},{"location":"chapter_data_structure/character_encoding/#345","title":"3.4.5 \u00a0 \u7f16\u7a0b\u8bed\u8a00\u7684\u5b57\u7b26\u7f16\u7801","text":"

        \u5bf9\u4e8e\u4ee5\u5f80\u7684\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\uff0c\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u7684\u5b57\u7b26\u4e32\u90fd\u91c7\u7528 UTF-16 \u6216 UTF-32 \u8fd9\u7c7b\u7b49\u957f\u7684\u7f16\u7801\u3002\u5728\u7b49\u957f\u7f16\u7801\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u770b\u4f5c\u6570\u7ec4\u6765\u5904\u7406\uff0c\u8fd9\u79cd\u505a\u6cd5\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\u3002

        • \u968f\u673a\u8bbf\u95ee\uff1aUTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u8fdb\u884c\u968f\u673a\u8bbf\u95ee\u3002UTF-8 \u662f\u4e00\u79cd\u53d8\u957f\u7f16\u7801\uff0c\u8981\u60f3\u627e\u5230\u7b2c \\(i\\) \u4e2a\u5b57\u7b26\uff0c\u6211\u4eec\u9700\u8981\u4ece\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u5904\u904d\u5386\u5230\u7b2c \\(i\\) \u4e2a\u5b57\u7b26\uff0c\u8fd9\u9700\u8981 \\(O(n)\\) \u7684\u65f6\u95f4\u3002
        • \u5b57\u7b26\u8ba1\u6570\uff1a\u4e0e\u968f\u673a\u8bbf\u95ee\u7c7b\u4f3c\uff0c\u8ba1\u7b97 UTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e5f\u662f \\(O(1)\\) \u7684\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u8ba1\u7b97 UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u9700\u8981\u904d\u5386\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
        • \u5b57\u7b26\u4e32\u64cd\u4f5c\uff1a\u5728 UTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4e0a\uff0c\u5f88\u591a\u5b57\u7b26\u4e32\u64cd\u4f5c\uff08\u5982\u5206\u5272\u3001\u8fde\u63a5\u3001\u63d2\u5165\u3001\u5220\u9664\u7b49\uff09\u66f4\u5bb9\u6613\u8fdb\u884c\u3002\u5728 UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4e0a\uff0c\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u901a\u5e38\u9700\u8981\u989d\u5916\u7684\u8ba1\u7b97\uff0c\u4ee5\u786e\u4fdd\u4e0d\u4f1a\u4ea7\u751f\u65e0\u6548\u7684 UTF-8 \u7f16\u7801\u3002

        \u5b9e\u9645\u4e0a\uff0c\u7f16\u7a0b\u8bed\u8a00\u7684\u5b57\u7b26\u7f16\u7801\u65b9\u6848\u8bbe\u8ba1\u662f\u4e00\u4e2a\u5f88\u6709\u8da3\u7684\u8bdd\u9898\uff0c\u6d89\u53ca\u8bb8\u591a\u56e0\u7d20\u3002

        • Java \u7684 String \u7c7b\u578b\u4f7f\u7528 UTF-16 \u7f16\u7801\uff0c\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\u3002\u8fd9\u662f\u56e0\u4e3a Java \u8bed\u8a00\u8bbe\u8ba1\u4e4b\u521d\uff0c\u4eba\u4eec\u8ba4\u4e3a 16 \u4f4d\u8db3\u4ee5\u8868\u793a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u3002\u7136\u800c\uff0c\u8fd9\u662f\u4e00\u4e2a\u4e0d\u6b63\u786e\u7684\u5224\u65ad\u3002\u540e\u6765 Unicode \u89c4\u8303\u6269\u5c55\u5230\u4e86\u8d85\u8fc7 16 \u4f4d\uff0c\u6240\u4ee5 Java \u4e2d\u7684\u5b57\u7b26\u73b0\u5728\u53ef\u80fd\u7531\u4e00\u5bf9 16 \u4f4d\u7684\u503c\uff08\u79f0\u4e3a\u201c\u4ee3\u7406\u5bf9\u201d\uff09\u8868\u793a\u3002
        • JavaScript \u548c TypeScript \u7684\u5b57\u7b26\u4e32\u4f7f\u7528 UTF-16 \u7f16\u7801\u7684\u539f\u56e0\u4e0e Java \u7c7b\u4f3c\u3002\u5f53 1995 \u5e74 Netscape \u516c\u53f8\u9996\u6b21\u63a8\u51fa JavaScript \u8bed\u8a00\u65f6\uff0cUnicode \u8fd8\u5904\u4e8e\u53d1\u5c55\u65e9\u671f\uff0c\u90a3\u65f6\u5019\u4f7f\u7528 16 \u4f4d\u7684\u7f16\u7801\u5c31\u8db3\u4ee5\u8868\u793a\u6240\u6709\u7684 Unicode \u5b57\u7b26\u4e86\u3002
        • C# \u4f7f\u7528 UTF-16 \u7f16\u7801\uff0c\u4e3b\u8981\u662f\u56e0\u4e3a .NET \u5e73\u53f0\u662f\u7531 Microsoft \u8bbe\u8ba1\u7684\uff0c\u800c Microsoft \u7684\u5f88\u591a\u6280\u672f\uff08\u5305\u62ec Windows \u64cd\u4f5c\u7cfb\u7edf\uff09\u90fd\u5e7f\u6cdb\u4f7f\u7528 UTF-16 \u7f16\u7801\u3002

        \u7531\u4e8e\u4ee5\u4e0a\u7f16\u7a0b\u8bed\u8a00\u5bf9\u5b57\u7b26\u6570\u91cf\u7684\u4f4e\u4f30\uff0c\u5b83\u4eec\u4e0d\u5f97\u4e0d\u91c7\u53d6\u201c\u4ee3\u7406\u5bf9\u201d\u7684\u65b9\u5f0f\u6765\u8868\u793a\u8d85\u8fc7 16 \u4f4d\u957f\u5ea6\u7684 Unicode \u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u4e0d\u5f97\u5df2\u4e3a\u4e4b\u7684\u65e0\u5948\u4e4b\u4e3e\u3002\u4e00\u65b9\u9762\uff0c\u5305\u542b\u4ee3\u7406\u5bf9\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u4e00\u4e2a\u5b57\u7b26\u53ef\u80fd\u5360\u7528 2 \u5b57\u8282\u6216 4 \u5b57\u8282\uff0c\u4ece\u800c\u4e27\u5931\u4e86\u7b49\u957f\u7f16\u7801\u7684\u4f18\u52bf\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u5904\u7406\u4ee3\u7406\u5bf9\u9700\u8981\u589e\u52a0\u989d\u5916\u4ee3\u7801\uff0c\u8fd9\u63d0\u9ad8\u4e86\u7f16\u7a0b\u7684\u590d\u6742\u6027\u548c\u8c03\u8bd5\u96be\u5ea6\u3002

        \u51fa\u4e8e\u4ee5\u4e0a\u539f\u56e0\uff0c\u90e8\u5206\u7f16\u7a0b\u8bed\u8a00\u63d0\u51fa\u4e86\u4e00\u4e9b\u4e0d\u540c\u7684\u7f16\u7801\u65b9\u6848\u3002

        • Python \u4e2d\u7684 str \u4f7f\u7528 Unicode \u7f16\u7801\uff0c\u5e76\u91c7\u7528\u4e00\u79cd\u7075\u6d3b\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5b58\u50a8\u7684\u5b57\u7b26\u957f\u5ea6\u53d6\u51b3\u4e8e\u5b57\u7b26\u4e32\u4e2d\u6700\u5927\u7684 Unicode \u7801\u70b9\u3002\u82e5\u5b57\u7b26\u4e32\u4e2d\u5168\u90e8\u662f ASCII \u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 1 \u4e2a\u5b57\u8282\uff1b\u5982\u679c\u6709\u5b57\u7b26\u8d85\u51fa\u4e86 ASCII \u8303\u56f4\uff0c\u4f46\u5168\u90e8\u5728\u57fa\u672c\u591a\u8bed\u8a00\u5e73\u9762\uff08BMP\uff09\u5185\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u4e2a\u5b57\u8282\uff1b\u5982\u679c\u6709\u8d85\u51fa BMP \u7684\u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 4 \u4e2a\u5b57\u8282\u3002
        • Go \u8bed\u8a00\u7684 string \u7c7b\u578b\u5728\u5185\u90e8\u4f7f\u7528 UTF-8 \u7f16\u7801\u3002Go \u8bed\u8a00\u8fd8\u63d0\u4f9b\u4e86 rune \u7c7b\u578b\uff0c\u5b83\u7528\u4e8e\u8868\u793a\u5355\u4e2a Unicode \u7801\u70b9\u3002
        • Rust \u8bed\u8a00\u7684 str \u548c String \u7c7b\u578b\u5728\u5185\u90e8\u4f7f\u7528 UTF-8 \u7f16\u7801\u3002Rust \u4e5f\u63d0\u4f9b\u4e86 char \u7c7b\u578b\uff0c\u7528\u4e8e\u8868\u793a\u5355\u4e2a Unicode \u7801\u70b9\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ee5\u4e0a\u8ba8\u8bba\u7684\u90fd\u662f\u5b57\u7b26\u4e32\u5728\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u8fd9\u548c\u5b57\u7b26\u4e32\u5982\u4f55\u5728\u6587\u4ef6\u4e2d\u5b58\u50a8\u6216\u5728\u7f51\u7edc\u4e2d\u4f20\u8f93\u662f\u4e0d\u540c\u7684\u95ee\u9898\u3002\u5728\u6587\u4ef6\u5b58\u50a8\u6216\u7f51\u7edc\u4f20\u8f93\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u5b57\u7b26\u4e32\u7f16\u7801\u4e3a UTF-8 \u683c\u5f0f\uff0c\u4ee5\u8fbe\u5230\u6700\u4f18\u7684\u517c\u5bb9\u6027\u548c\u7a7a\u95f4\u6548\u7387\u3002

        "},{"location":"chapter_data_structure/classification_of_data_structure/","title":"3.1 \u00a0 \u6570\u636e\u7ed3\u6784\u5206\u7c7b","text":"

        \u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u5305\u62ec\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\uff0c\u5b83\u4eec\u53ef\u4ee5\u4ece\u201c\u903b\u8f91\u7ed3\u6784\u201d\u548c\u201c\u7269\u7406\u7ed3\u6784\u201d\u4e24\u4e2a\u7ef4\u5ea6\u8fdb\u884c\u5206\u7c7b\u3002

        "},{"location":"chapter_data_structure/classification_of_data_structure/#311","title":"3.1.1 \u00a0 \u903b\u8f91\u7ed3\u6784\uff1a\u7ebf\u6027\u4e0e\u975e\u7ebf\u6027","text":"

        \u903b\u8f91\u7ed3\u6784\u63ed\u793a\u4e86\u6570\u636e\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\u3002\u5728\u6570\u7ec4\u548c\u94fe\u8868\u4e2d\uff0c\u6570\u636e\u6309\u7167\u4e00\u5b9a\u987a\u5e8f\u6392\u5217\uff0c\u4f53\u73b0\u4e86\u6570\u636e\u4e4b\u95f4\u7684\u7ebf\u6027\u5173\u7cfb\uff1b\u800c\u5728\u6811\u4e2d\uff0c\u6570\u636e\u4ece\u9876\u90e8\u5411\u4e0b\u6309\u5c42\u6b21\u6392\u5217\uff0c\u8868\u73b0\u51fa\u201c\u7956\u5148\u201d\u4e0e\u201c\u540e\u4ee3\u201d\u4e4b\u95f4\u7684\u6d3e\u751f\u5173\u7cfb\uff1b\u56fe\u5219\u7531\u8282\u70b9\u548c\u8fb9\u6784\u6210\uff0c\u53cd\u6620\u4e86\u590d\u6742\u7684\u7f51\u7edc\u5173\u7cfb\u3002

        \u5982\u56fe 3-1 \u6240\u793a\uff0c\u903b\u8f91\u7ed3\u6784\u53ef\u5206\u4e3a\u201c\u7ebf\u6027\u201d\u548c\u201c\u975e\u7ebf\u6027\u201d\u4e24\u5927\u7c7b\u3002\u7ebf\u6027\u7ed3\u6784\u6bd4\u8f83\u76f4\u89c2\uff0c\u6307\u6570\u636e\u5728\u903b\u8f91\u5173\u7cfb\u4e0a\u5448\u7ebf\u6027\u6392\u5217\uff1b\u975e\u7ebf\u6027\u7ed3\u6784\u5219\u76f8\u53cd\uff0c\u5448\u975e\u7ebf\u6027\u6392\u5217\u3002

        • \u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3002
        • \u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1a\u6811\u3001\u5806\u3001\u56fe\u3001\u54c8\u5e0c\u8868\u3002

        \u56fe 3-1 \u00a0 \u7ebf\u6027\u6570\u636e\u7ed3\u6784\u4e0e\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784

        \u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5212\u5206\u4e3a\u6811\u5f62\u7ed3\u6784\u548c\u7f51\u72b6\u7ed3\u6784\u3002

        • \u7ebf\u6027\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868\u3001\u961f\u5217\u3001\u6808\u3001\u54c8\u5e0c\u8868\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u4e00\u5bf9\u4e00\u7684\u987a\u5e8f\u5173\u7cfb\u3002
        • \u6811\u5f62\u7ed3\u6784\uff1a\u6811\u3001\u5806\u3001\u54c8\u5e0c\u8868\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u4e00\u5bf9\u591a\u7684\u5173\u7cfb\u3002
        • \u7f51\u72b6\u7ed3\u6784\uff1a\u56fe\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u591a\u5bf9\u591a\u7684\u5173\u7cfb\u3002
        "},{"location":"chapter_data_structure/classification_of_data_structure/#312","title":"3.1.2 \u00a0 \u7269\u7406\u7ed3\u6784\uff1a\u8fde\u7eed\u4e0e\u5206\u6563","text":"

        \u5f53\u7b97\u6cd5\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6b63\u5728\u5904\u7406\u7684\u6570\u636e\u4e3b\u8981\u88ab\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u56fe 3-2 \u5c55\u793a\u4e86\u4e00\u4e2a\u8ba1\u7b97\u673a\u5185\u5b58\u6761\uff0c\u5176\u4e2d\u6bcf\u4e2a\u9ed1\u8272\u65b9\u5757\u90fd\u5305\u542b\u4e00\u5757\u5185\u5b58\u7a7a\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5185\u5b58\u60f3\u8c61\u6210\u4e00\u4e2a\u5de8\u5927\u7684 Excel \u8868\u683c\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u53ef\u4ee5\u5b58\u50a8\u4e00\u5b9a\u5927\u5c0f\u7684\u6570\u636e\u3002

        \u7cfb\u7edf\u901a\u8fc7\u5185\u5b58\u5730\u5740\u6765\u8bbf\u95ee\u76ee\u6807\u4f4d\u7f6e\u7684\u6570\u636e\u3002\u5982\u56fe 3-2 \u6240\u793a\uff0c\u8ba1\u7b97\u673a\u6839\u636e\u7279\u5b9a\u89c4\u5219\u4e3a\u8868\u683c\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u5206\u914d\u7f16\u53f7\uff0c\u786e\u4fdd\u6bcf\u4e2a\u5185\u5b58\u7a7a\u95f4\u90fd\u6709\u552f\u4e00\u7684\u5185\u5b58\u5730\u5740\u3002\u6709\u4e86\u8fd9\u4e9b\u5730\u5740\uff0c\u7a0b\u5e8f\u4fbf\u53ef\u4ee5\u8bbf\u95ee\u5185\u5b58\u4e2d\u7684\u6570\u636e\u3002

        \u56fe 3-2 \u00a0 \u5185\u5b58\u6761\u3001\u5185\u5b58\u7a7a\u95f4\u3001\u5185\u5b58\u5730\u5740

        Tip

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5c06\u5185\u5b58\u6bd4\u4f5c Excel \u8868\u683c\u662f\u4e00\u4e2a\u7b80\u5316\u7684\u7c7b\u6bd4\uff0c\u5b9e\u9645\u5185\u5b58\u7684\u5de5\u4f5c\u673a\u5236\u6bd4\u8f83\u590d\u6742\uff0c\u6d89\u53ca\u5230\u5730\u5740\u7a7a\u95f4\u3001\u5185\u5b58\u7ba1\u7406\u3001\u7f13\u5b58\u673a\u5236\u3001\u865a\u62df\u548c\u7269\u7406\u5185\u5b58\u7b49\u6982\u5ff5\u3002

        \u5185\u5b58\u662f\u6240\u6709\u7a0b\u5e8f\u7684\u5171\u4eab\u8d44\u6e90\uff0c\u5f53\u67d0\u5757\u5185\u5b58\u88ab\u67d0\u4e2a\u7a0b\u5e8f\u5360\u7528\u65f6\uff0c\u5219\u65e0\u6cd5\u88ab\u5176\u4ed6\u7a0b\u5e8f\u540c\u65f6\u4f7f\u7528\u4e86\u3002\u56e0\u6b64\u5728\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u8bbe\u8ba1\u4e2d\uff0c\u5185\u5b58\u8d44\u6e90\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u6bd4\u5982\uff0c\u7b97\u6cd5\u6240\u5360\u7528\u7684\u5185\u5b58\u5cf0\u503c\u4e0d\u5e94\u8d85\u8fc7\u7cfb\u7edf\u5269\u4f59\u7a7a\u95f2\u5185\u5b58\uff1b\u5982\u679c\u7f3a\u5c11\u8fde\u7eed\u5927\u5757\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u90a3\u4e48\u6240\u9009\u7528\u7684\u6570\u636e\u7ed3\u6784\u5fc5\u987b\u80fd\u591f\u5b58\u50a8\u5728\u5206\u6563\u7684\u5185\u5b58\u7a7a\u95f4\u5185\u3002

        \u5982\u56fe 3-3 \u6240\u793a\uff0c\u7269\u7406\u7ed3\u6784\u53cd\u6620\u4e86\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u53ef\u5206\u4e3a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\uff08\u6570\u7ec4\uff09\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\uff08\u94fe\u8868\uff09\u3002\u7269\u7406\u7ed3\u6784\u4ece\u5e95\u5c42\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u8bbf\u95ee\u3001\u66f4\u65b0\u3001\u589e\u5220\u7b49\u64cd\u4f5c\u65b9\u6cd5\uff0c\u4e24\u79cd\u7269\u7406\u7ed3\u6784\u5728\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u65b9\u9762\u5448\u73b0\u51fa\u4e92\u8865\u7684\u7279\u70b9\u3002

        \u56fe 3-3 \u00a0 \u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u4e0e\u5206\u6563\u7a7a\u95f4\u5b58\u50a8

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6240\u6709\u6570\u636e\u7ed3\u6784\u90fd\u662f\u57fa\u4e8e\u6570\u7ec4\u3001\u94fe\u8868\u6216\u4e8c\u8005\u7684\u7ec4\u5408\u5b9e\u73b0\u7684\u3002\u4f8b\u5982\uff0c\u6808\u548c\u961f\u5217\u65e2\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\uff1b\u800c\u54c8\u5e0c\u8868\u7684\u5b9e\u73b0\u53ef\u80fd\u540c\u65f6\u5305\u542b\u6570\u7ec4\u548c\u94fe\u8868\u3002

        • \u57fa\u4e8e\u6570\u7ec4\u53ef\u5b9e\u73b0\uff1a\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u3001\u77e9\u9635\u3001\u5f20\u91cf\uff08\u7ef4\u5ea6 \\(\\geq 3\\) \u7684\u6570\u7ec4\uff09\u7b49\u3002
        • \u57fa\u4e8e\u94fe\u8868\u53ef\u5b9e\u73b0\uff1a\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u7b49\u3002

        \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u79f0\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d\uff0c\u8fd9\u610f\u5473\u7740\u6b64\u7c7b\u6570\u636e\u7ed3\u6784\u5728\u521d\u59cb\u5316\u540e\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u79f0\u201c\u52a8\u6001\u6570\u636e\u7ed3\u6784\u201d\uff0c\u8fd9\u7c7b\u6570\u636e\u7ed3\u6784\u5728\u521d\u59cb\u5316\u540e\uff0c\u4ecd\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u5bf9\u5176\u957f\u5ea6\u8fdb\u884c\u8c03\u6574\u3002

        Tip

        \u5982\u679c\u4f60\u611f\u89c9\u7269\u7406\u7ed3\u6784\u7406\u89e3\u8d77\u6765\u6709\u56f0\u96be\uff0c\u5efa\u8bae\u5148\u9605\u8bfb\u4e0b\u4e00\u7ae0\uff0c\u7136\u540e\u518d\u56de\u987e\u672c\u8282\u5185\u5bb9\u3002

        "},{"location":"chapter_data_structure/number_encoding/","title":"3.3 \u00a0 \u6570\u5b57\u7f16\u7801 *","text":"

        Note

        \u5728\u672c\u4e66\u4e2d\uff0c\u6807\u9898\u5e26\u6709 * \u7b26\u53f7\u7684\u662f\u9009\u8bfb\u7ae0\u8282\u3002\u5982\u679c\u4f60\u65f6\u95f4\u6709\u9650\u6216\u611f\u5230\u7406\u89e3\u56f0\u96be\uff0c\u53ef\u4ee5\u5148\u8df3\u8fc7\uff0c\u7b49\u5b66\u5b8c\u5fc5\u8bfb\u7ae0\u8282\u540e\u518d\u5355\u72ec\u653b\u514b\u3002

        "},{"location":"chapter_data_structure/number_encoding/#331","title":"3.3.1 \u00a0 \u6574\u6570\u7f16\u7801","text":"

        \u5728\u4e0a\u4e00\u8282\u7684\u8868\u683c\u4e2d\u6211\u4eec\u53d1\u73b0\uff0c\u6240\u6709\u6574\u6570\u7c7b\u578b\u80fd\u591f\u8868\u793a\u7684\u8d1f\u6570\u90fd\u6bd4\u6b63\u6570\u591a\u4e00\u4e2a\uff0c\u4f8b\u5982 byte \u7684\u53d6\u503c\u8303\u56f4\u662f \\([-128, 127]\\) \u3002\u8fd9\u4e2a\u73b0\u8c61\u6bd4\u8f83\u53cd\u76f4\u89c9\uff0c\u5b83\u7684\u5185\u5728\u539f\u56e0\u6d89\u53ca\u539f\u7801\u3001\u53cd\u7801\u3001\u8865\u7801\u7684\u76f8\u5173\u77e5\u8bc6\u3002

        \u9996\u5148\u9700\u8981\u6307\u51fa\uff0c\u6570\u5b57\u662f\u4ee5\u201c\u8865\u7801\u201d\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u3002\u5728\u5206\u6790\u8fd9\u6837\u505a\u7684\u539f\u56e0\u4e4b\u524d\uff0c\u9996\u5148\u7ed9\u51fa\u4e09\u8005\u7684\u5b9a\u4e49\u3002

        • \u539f\u7801\uff1a\u6211\u4eec\u5c06\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u6700\u9ad8\u4f4d\u89c6\u4e3a\u7b26\u53f7\u4f4d\uff0c\u5176\u4e2d \\(0\\) \u8868\u793a\u6b63\u6570\uff0c\\(1\\) \u8868\u793a\u8d1f\u6570\uff0c\u5176\u4f59\u4f4d\u8868\u793a\u6570\u5b57\u7684\u503c\u3002
        • \u53cd\u7801\uff1a\u6b63\u6570\u7684\u53cd\u7801\u4e0e\u5176\u539f\u7801\u76f8\u540c\uff0c\u8d1f\u6570\u7684\u53cd\u7801\u662f\u5bf9\u5176\u539f\u7801\u9664\u7b26\u53f7\u4f4d\u5916\u7684\u6240\u6709\u4f4d\u53d6\u53cd\u3002
        • \u8865\u7801\uff1a\u6b63\u6570\u7684\u8865\u7801\u4e0e\u5176\u539f\u7801\u76f8\u540c\uff0c\u8d1f\u6570\u7684\u8865\u7801\u662f\u5728\u5176\u53cd\u7801\u7684\u57fa\u7840\u4e0a\u52a0 \\(1\\) \u3002

        \u56fe 3-4 \u5c55\u793a\u4e86\u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\u4e4b\u95f4\u7684\u8f6c\u6362\u65b9\u6cd5\u3002

        \u56fe 3-4 \u00a0 \u539f\u7801\u3001\u53cd\u7801\u4e0e\u8865\u7801\u4e4b\u95f4\u7684\u76f8\u4e92\u8f6c\u6362

        \u300c\u539f\u7801 sign\u2013magnitude\u300d\u867d\u7136\u6700\u76f4\u89c2\uff0c\u4f46\u5b58\u5728\u4e00\u4e9b\u5c40\u9650\u6027\u3002\u4e00\u65b9\u9762\uff0c\u8d1f\u6570\u7684\u539f\u7801\u4e0d\u80fd\u76f4\u63a5\u7528\u4e8e\u8fd0\u7b97\u3002\u4f8b\u5982\u5728\u539f\u7801\u4e0b\u8ba1\u7b97 \\(1 + (-2)\\) \uff0c\u5f97\u5230\u7684\u7ed3\u679c\u662f \\(-3\\) \uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u5bf9\u7684\u3002

        \\[ \\begin{aligned} & 1 + (-2) \\newline & \\rightarrow 0000 \\; 0001 + 1000 \\; 0010 \\newline & = 1000 \\; 0011 \\newline & \\rightarrow -3 \\end{aligned} \\]

        \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8ba1\u7b97\u673a\u5f15\u5165\u4e86\u300c\u53cd\u7801 1's complement\u300d\u3002\u5982\u679c\u6211\u4eec\u5148\u5c06\u539f\u7801\u8f6c\u6362\u4e3a\u53cd\u7801\uff0c\u5e76\u5728\u53cd\u7801\u4e0b\u8ba1\u7b97 \\(1 + (-2)\\) \uff0c\u6700\u540e\u5c06\u7ed3\u679c\u4ece\u53cd\u7801\u8f6c\u6362\u56de\u539f\u7801\uff0c\u5219\u53ef\u5f97\u5230\u6b63\u786e\u7ed3\u679c \\(-1\\) \u3002

        \\[ \\begin{aligned} & 1 + (-2) \\newline & \\rightarrow 0000 \\; 0001 \\; \\text{(\u539f\u7801)} + 1000 \\; 0010 \\; \\text{(\u539f\u7801)} \\newline & = 0000 \\; 0001 \\; \\text{(\u53cd\u7801)} + 1111 \\; 1101 \\; \\text{(\u53cd\u7801)} \\newline & = 1111 \\; 1110 \\; \\text{(\u53cd\u7801)} \\newline & = 1000 \\; 0001 \\; \\text{(\u539f\u7801)} \\newline & \\rightarrow -1 \\end{aligned} \\]

        \u53e6\u4e00\u65b9\u9762\uff0c\u6570\u5b57\u96f6\u7684\u539f\u7801\u6709 \\(+0\\) \u548c \\(-0\\) \u4e24\u79cd\u8868\u793a\u65b9\u5f0f\u3002\u8fd9\u610f\u5473\u7740\u6570\u5b57\u96f6\u5bf9\u5e94\u4e24\u4e2a\u4e0d\u540c\u7684\u4e8c\u8fdb\u5236\u7f16\u7801\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5e26\u6765\u6b67\u4e49\u3002\u6bd4\u5982\u5728\u6761\u4ef6\u5224\u65ad\u4e2d\uff0c\u5982\u679c\u6ca1\u6709\u533a\u5206\u6b63\u96f6\u548c\u8d1f\u96f6\uff0c\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5224\u65ad\u7ed3\u679c\u51fa\u9519\u3002\u800c\u5982\u679c\u6211\u4eec\u60f3\u5904\u7406\u6b63\u96f6\u548c\u8d1f\u96f6\u6b67\u4e49\uff0c\u5219\u9700\u8981\u5f15\u5165\u989d\u5916\u7684\u5224\u65ad\u64cd\u4f5c\uff0c\u8fd9\u53ef\u80fd\u4f1a\u964d\u4f4e\u8ba1\u7b97\u673a\u7684\u8fd0\u7b97\u6548\u7387\u3002

        \\[ \\begin{aligned} +0 & \\rightarrow 0000 \\; 0000 \\newline -0 & \\rightarrow 1000 \\; 0000 \\end{aligned} \\]

        \u4e0e\u539f\u7801\u4e00\u6837\uff0c\u53cd\u7801\u4e5f\u5b58\u5728\u6b63\u8d1f\u96f6\u6b67\u4e49\u95ee\u9898\uff0c\u56e0\u6b64\u8ba1\u7b97\u673a\u8fdb\u4e00\u6b65\u5f15\u5165\u4e86\u300c\u8865\u7801 2's complement\u300d\u3002\u6211\u4eec\u5148\u6765\u89c2\u5bdf\u4e00\u4e0b\u8d1f\u96f6\u7684\u539f\u7801\u3001\u53cd\u7801\u3001\u8865\u7801\u7684\u8f6c\u6362\u8fc7\u7a0b\uff1a

        \\[ \\begin{aligned} -0 \\rightarrow \\; & 1000 \\; 0000 \\; \\text{(\u539f\u7801)} \\newline = \\; & 1111 \\; 1111 \\; \\text{(\u53cd\u7801)} \\newline = 1 \\; & 0000 \\; 0000 \\; \\text{(\u8865\u7801)} \\newline \\end{aligned} \\]

        \u5728\u8d1f\u96f6\u7684\u53cd\u7801\u57fa\u7840\u4e0a\u52a0 \\(1\\) \u4f1a\u4ea7\u751f\u8fdb\u4f4d\uff0c\u4f46 byte \u7c7b\u578b\u7684\u957f\u5ea6\u53ea\u6709 8 \u4f4d\uff0c\u56e0\u6b64\u6ea2\u51fa\u5230\u7b2c 9 \u4f4d\u7684 \\(1\\) \u4f1a\u88ab\u820d\u5f03\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8d1f\u96f6\u7684\u8865\u7801\u4e3a \\(0000 \\; 0000\\) \uff0c\u4e0e\u6b63\u96f6\u7684\u8865\u7801\u76f8\u540c\u3002\u8fd9\u610f\u5473\u7740\u5728\u8865\u7801\u8868\u793a\u4e2d\u53ea\u5b58\u5728\u4e00\u4e2a\u96f6\uff0c\u6b63\u8d1f\u96f6\u6b67\u4e49\u4ece\u800c\u5f97\u5230\u89e3\u51b3\u3002

        \u8fd8\u5269\u6700\u540e\u4e00\u4e2a\u7591\u60d1\uff1abyte \u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u662f \\([-128, 127]\\) \uff0c\u591a\u51fa\u6765\u7684\u4e00\u4e2a\u8d1f\u6570 \\(-128\\) \u662f\u5982\u4f55\u5f97\u5230\u7684\u5462\uff1f\u6211\u4eec\u6ce8\u610f\u5230\uff0c\u533a\u95f4 \\([-127, +127]\\) \u5185\u7684\u6240\u6709\u6574\u6570\u90fd\u6709\u5bf9\u5e94\u7684\u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\uff0c\u5e76\u4e14\u539f\u7801\u548c\u8865\u7801\u4e4b\u95f4\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362\u3002

        \u7136\u800c\uff0c\u8865\u7801 \\(1000 \\; 0000\\) \u662f\u4e00\u4e2a\u4f8b\u5916\uff0c\u5b83\u5e76\u6ca1\u6709\u5bf9\u5e94\u7684\u539f\u7801\u3002\u6839\u636e\u8f6c\u6362\u65b9\u6cd5\uff0c\u6211\u4eec\u5f97\u5230\u8be5\u8865\u7801\u7684\u539f\u7801\u4e3a \\(0000 \\; 0000\\) \u3002\u8fd9\u663e\u7136\u662f\u77db\u76fe\u7684\uff0c\u56e0\u4e3a\u8be5\u539f\u7801\u8868\u793a\u6570\u5b57 \\(0\\) \uff0c\u5b83\u7684\u8865\u7801\u5e94\u8be5\u662f\u81ea\u8eab\u3002\u8ba1\u7b97\u673a\u89c4\u5b9a\u8fd9\u4e2a\u7279\u6b8a\u7684\u8865\u7801 \\(1000 \\; 0000\\) \u4ee3\u8868 \\(-128\\) \u3002\u5b9e\u9645\u4e0a\uff0c\\((-1) + (-127)\\) \u5728\u8865\u7801\u4e0b\u7684\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f \\(-128\\) \u3002

        \\[ \\begin{aligned} & (-127) + (-1) \\newline & \\rightarrow 1111 \\; 1111 \\; \\text{(\u539f\u7801)} + 1000 \\; 0001 \\; \\text{(\u539f\u7801)} \\newline & = 1000 \\; 0000 \\; \\text{(\u53cd\u7801)} + 1111 \\; 1110 \\; \\text{(\u53cd\u7801)} \\newline & = 1000 \\; 0001 \\; \\text{(\u8865\u7801)} + 1111 \\; 1111 \\; \\text{(\u8865\u7801)} \\newline & = 1000 \\; 0000 \\; \\text{(\u8865\u7801)} \\newline & \\rightarrow -128 \\end{aligned} \\]

        \u4f60\u53ef\u80fd\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u4e0a\u8ff0\u6240\u6709\u8ba1\u7b97\u90fd\u662f\u52a0\u6cd5\u8fd0\u7b97\u3002\u8fd9\u6697\u793a\u7740\u4e00\u4e2a\u91cd\u8981\u4e8b\u5b9e\uff1a\u8ba1\u7b97\u673a\u5185\u90e8\u7684\u786c\u4ef6\u7535\u8def\u4e3b\u8981\u662f\u57fa\u4e8e\u52a0\u6cd5\u8fd0\u7b97\u8bbe\u8ba1\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u52a0\u6cd5\u8fd0\u7b97\u76f8\u5bf9\u4e8e\u5176\u4ed6\u8fd0\u7b97\uff08\u6bd4\u5982\u4e58\u6cd5\u3001\u9664\u6cd5\u548c\u51cf\u6cd5\uff09\u6765\u8bf4\uff0c\u786c\u4ef6\u5b9e\u73b0\u8d77\u6765\u66f4\u7b80\u5355\uff0c\u66f4\u5bb9\u6613\u8fdb\u884c\u5e76\u884c\u5316\u5904\u7406\uff0c\u8fd0\u7b97\u901f\u5ea6\u66f4\u5feb\u3002

        \u8bf7\u6ce8\u610f\uff0c\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u8ba1\u7b97\u673a\u53ea\u80fd\u505a\u52a0\u6cd5\u3002\u901a\u8fc7\u5c06\u52a0\u6cd5\u4e0e\u4e00\u4e9b\u57fa\u672c\u903b\u8f91\u8fd0\u7b97\u7ed3\u5408\uff0c\u8ba1\u7b97\u673a\u80fd\u591f\u5b9e\u73b0\u5404\u79cd\u5176\u4ed6\u7684\u6570\u5b66\u8fd0\u7b97\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u51cf\u6cd5 \\(a - b\\) \u53ef\u4ee5\u8f6c\u6362\u4e3a\u8ba1\u7b97\u52a0\u6cd5 \\(a + (-b)\\) \uff1b\u8ba1\u7b97\u4e58\u6cd5\u548c\u9664\u6cd5\u53ef\u4ee5\u8f6c\u6362\u4e3a\u8ba1\u7b97\u591a\u6b21\u52a0\u6cd5\u6216\u51cf\u6cd5\u3002

        \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u8ba1\u7b97\u673a\u4f7f\u7528\u8865\u7801\u7684\u539f\u56e0\uff1a\u57fa\u4e8e\u8865\u7801\u8868\u793a\uff0c\u8ba1\u7b97\u673a\u53ef\u4ee5\u7528\u540c\u6837\u7684\u7535\u8def\u548c\u64cd\u4f5c\u6765\u5904\u7406\u6b63\u6570\u548c\u8d1f\u6570\u7684\u52a0\u6cd5\uff0c\u4e0d\u9700\u8981\u8bbe\u8ba1\u7279\u6b8a\u7684\u786c\u4ef6\u7535\u8def\u6765\u5904\u7406\u51cf\u6cd5\uff0c\u5e76\u4e14\u65e0\u987b\u7279\u522b\u5904\u7406\u6b63\u8d1f\u96f6\u7684\u6b67\u4e49\u95ee\u9898\u3002\u8fd9\u5927\u5927\u7b80\u5316\u4e86\u786c\u4ef6\u8bbe\u8ba1\uff0c\u63d0\u9ad8\u4e86\u8fd0\u7b97\u6548\u7387\u3002

        \u8865\u7801\u7684\u8bbe\u8ba1\u975e\u5e38\u7cbe\u5999\uff0c\u56e0\u7bc7\u5e45\u5173\u7cfb\u6211\u4eec\u5c31\u5148\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u5efa\u8bae\u6709\u5174\u8da3\u7684\u8bfb\u8005\u8fdb\u4e00\u6b65\u6df1\u5165\u4e86\u89e3\u3002

        "},{"location":"chapter_data_structure/number_encoding/#332","title":"3.3.2 \u00a0 \u6d6e\u70b9\u6570\u7f16\u7801","text":"

        \u7ec6\u5fc3\u7684\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\uff1aint \u548c float \u957f\u5ea6\u76f8\u540c\uff0c\u90fd\u662f 4 bytes \uff0c\u4f46\u4e3a\u4ec0\u4e48 float \u7684\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e int \uff1f\u8fd9\u975e\u5e38\u53cd\u76f4\u89c9\uff0c\u56e0\u4e3a\u6309\u7406\u8bf4 float \u9700\u8981\u8868\u793a\u5c0f\u6570\uff0c\u53d6\u503c\u8303\u56f4\u5e94\u8be5\u53d8\u5c0f\u624d\u5bf9\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8fd9\u662f\u56e0\u4e3a\u6d6e\u70b9\u6570 float \u91c7\u7528\u4e86\u4e0d\u540c\u7684\u8868\u793a\u65b9\u5f0f\u3002\u8bb0\u4e00\u4e2a 32-bit \u957f\u5ea6\u7684\u4e8c\u8fdb\u5236\u6570\u4e3a\uff1a

        \\[ b_{31} b_{30} b_{29} \\ldots b_2 b_1 b_0 \\]

        \u6839\u636e IEEE 754 \u6807\u51c6\uff0c32-bit \u957f\u5ea6\u7684 float \u7531\u4ee5\u4e0b\u4e09\u4e2a\u90e8\u5206\u6784\u6210\u3002

        • \u7b26\u53f7\u4f4d \\(\\mathrm{S}\\) \uff1a\u5360 1 bit \uff0c\u5bf9\u5e94 \\(b_{31}\\) \u3002
        • \u6307\u6570\u4f4d \\(\\mathrm{E}\\) \uff1a\u5360 8 bits \uff0c\u5bf9\u5e94 \\(b_{30} b_{29} \\ldots b_{23}\\) \u3002
        • \u5206\u6570\u4f4d \\(\\mathrm{N}\\) \uff1a\u5360 23 bits \uff0c\u5bf9\u5e94 \\(b_{22} b_{21} \\ldots b_0\\) \u3002

        \u4e8c\u8fdb\u5236\u6570 float \u5bf9\u5e94\u503c\u7684\u8ba1\u7b97\u65b9\u6cd5\u4e3a\uff1a

        \\[ \\text {val} = (-1)^{b_{31}} \\times 2^{\\left(b_{30} b_{29} \\ldots b_{23}\\right)_2-127} \\times\\left(1 . b_{22} b_{21} \\ldots b_0\\right)_2 \\]

        \u8f6c\u5316\u5230\u5341\u8fdb\u5236\u4e0b\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a

        \\[ \\text {val}=(-1)^{\\mathrm{S}} \\times 2^{\\mathrm{E} -127} \\times (1 + \\mathrm{N}) \\]

        \u5176\u4e2d\u5404\u9879\u7684\u53d6\u503c\u8303\u56f4\u4e3a\uff1a

        \\[ \\begin{aligned} \\mathrm{S} \\in & \\{ 0, 1\\}, \\quad \\mathrm{E} \\in \\{ 1, 2, \\dots, 254 \\} \\newline (1 + \\mathrm{N}) = & (1 + \\sum_{i=1}^{23} b_{23-i} 2^{-i}) \\subset [1, 2 - 2^{-23}] \\end{aligned} \\]

        \u56fe 3-5 \u00a0 IEEE 754 \u6807\u51c6\u4e0b\u7684 float \u7684\u8ba1\u7b97\u793a\u4f8b

        \u89c2\u5bdf\u56fe 3-5 \uff0c\u7ed9\u5b9a\u4e00\u4e2a\u793a\u4f8b\u6570\u636e \\(\\mathrm{S} = 0\\) \uff0c \\(\\mathrm{E} = 124\\) \uff0c\\(\\mathrm{N} = 2^{-2} + 2^{-3} = 0.375\\) \uff0c\u5219\u6709\uff1a

        \\[ \\text { val } = (-1)^0 \\times 2^{124 - 127} \\times (1 + 0.375) = 0.171875 \\]

        \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u56de\u7b54\u6700\u521d\u7684\u95ee\u9898\uff1afloat \u7684\u8868\u793a\u65b9\u5f0f\u5305\u542b\u6307\u6570\u4f4d\uff0c\u5bfc\u81f4\u5176\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e int \u3002\u6839\u636e\u4ee5\u4e0a\u8ba1\u7b97\uff0cfloat \u53ef\u8868\u793a\u7684\u6700\u5927\u6b63\u6570\u4e3a \\(2^{254 - 127} \\times (2 - 2^{-23}) \\approx 3.4 \\times 10^{38}\\) \uff0c\u5207\u6362\u7b26\u53f7\u4f4d\u4fbf\u53ef\u5f97\u5230\u6700\u5c0f\u8d1f\u6570\u3002

        \u5c3d\u7ba1\u6d6e\u70b9\u6570 float \u6269\u5c55\u4e86\u53d6\u503c\u8303\u56f4\uff0c\u4f46\u5176\u526f\u4f5c\u7528\u662f\u727a\u7272\u4e86\u7cbe\u5ea6\u3002\u6574\u6570\u7c7b\u578b int \u5c06\u5168\u90e8 32 \u4f4d\u7528\u4e8e\u8868\u793a\u6570\u5b57\uff0c\u6570\u5b57\u662f\u5747\u5300\u5206\u5e03\u7684\uff1b\u800c\u7531\u4e8e\u6307\u6570\u4f4d\u7684\u5b58\u5728\uff0c\u6d6e\u70b9\u6570 float \u7684\u6570\u503c\u8d8a\u5927\uff0c\u76f8\u90bb\u4e24\u4e2a\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u503c\u5c31\u4f1a\u8d8b\u5411\u8d8a\u5927\u3002

        \u5982\u8868 3-2 \u6240\u793a\uff0c\u6307\u6570\u4f4d \\(E = 0\\) \u548c \\(E = 255\\) \u5177\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u7528\u4e8e\u8868\u793a\u96f6\u3001\u65e0\u7a77\u5927\u3001\\(\\mathrm{NaN}\\) \u7b49\u3002

        \u8868 3-2 \u00a0 \u6307\u6570\u4f4d\u542b\u4e49

        \u6307\u6570\u4f4d E \u5206\u6570\u4f4d \\(\\mathrm{N} = 0\\) \u5206\u6570\u4f4d \\(\\mathrm{N} \\ne 0\\) \u8ba1\u7b97\u516c\u5f0f \\(0\\) \\(\\pm 0\\) \u6b21\u6b63\u89c4\u6570 \\((-1)^{\\mathrm{S}} \\times 2^{-126} \\times (0.\\mathrm{N})\\) \\(1, 2, \\dots, 254\\) \u6b63\u89c4\u6570 \u6b63\u89c4\u6570 \\((-1)^{\\mathrm{S}} \\times 2^{(\\mathrm{E} -127)} \\times (1.\\mathrm{N})\\) \\(255\\) \\(\\pm \\infty\\) \\(\\mathrm{NaN}\\)

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6b21\u6b63\u89c4\u6570\u663e\u8457\u63d0\u5347\u4e86\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u3002\u6700\u5c0f\u6b63\u6b63\u89c4\u6570\u4e3a \\(2^{-126}\\) \uff0c\u6700\u5c0f\u6b63\u6b21\u6b63\u89c4\u6570\u4e3a \\(2^{-126} \\times 2^{-23}\\) \u3002

        \u53cc\u7cbe\u5ea6 double \u4e5f\u91c7\u7528\u7c7b\u4f3c\u4e8e float \u7684\u8868\u793a\u65b9\u6cd5\uff0c\u5728\u6b64\u4e0d\u505a\u8d58\u8ff0\u3002

        "},{"location":"chapter_data_structure/summary/","title":"3.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_data_structure/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u4ece\u903b\u8f91\u7ed3\u6784\u548c\u7269\u7406\u7ed3\u6784\u4e24\u4e2a\u89d2\u5ea6\u8fdb\u884c\u5206\u7c7b\u3002\u903b\u8f91\u7ed3\u6784\u63cf\u8ff0\u4e86\u6570\u636e\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\uff0c\u800c\u7269\u7406\u7ed3\u6784\u63cf\u8ff0\u4e86\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\u3002
        • \u5e38\u89c1\u7684\u903b\u8f91\u7ed3\u6784\u5305\u62ec\u7ebf\u6027\u3001\u6811\u72b6\u548c\u7f51\u72b6\u7b49\u3002\u901a\u5e38\u6211\u4eec\u6839\u636e\u903b\u8f91\u7ed3\u6784\u5c06\u6570\u636e\u7ed3\u6784\u5206\u4e3a\u7ebf\u6027\uff08\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\uff09\u548c\u975e\u7ebf\u6027\uff08\u6811\u3001\u56fe\u3001\u5806\uff09\u4e24\u79cd\u3002\u54c8\u5e0c\u8868\u7684\u5b9e\u73b0\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002
        • \u5f53\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u88ab\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u3002\u6bcf\u4e2a\u5185\u5b58\u7a7a\u95f4\u90fd\u62e5\u6709\u5bf9\u5e94\u7684\u5185\u5b58\u5730\u5740\uff0c\u7a0b\u5e8f\u901a\u8fc7\u8fd9\u4e9b\u5185\u5b58\u5730\u5740\u8bbf\u95ee\u6570\u636e\u3002
        • \u7269\u7406\u7ed3\u6784\u4e3b\u8981\u5206\u4e3a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\uff08\u6570\u7ec4\uff09\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\uff08\u94fe\u8868\uff09\u3002\u6240\u6709\u6570\u636e\u7ed3\u6784\u90fd\u662f\u7531\u6570\u7ec4\u3001\u94fe\u8868\u6216\u4e24\u8005\u7684\u7ec4\u5408\u5b9e\u73b0\u7684\u3002
        • \u8ba1\u7b97\u673a\u4e2d\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5305\u62ec\u6574\u6570 byte\u3001short\u3001int\u3001long \uff0c\u6d6e\u70b9\u6570 float\u3001double \uff0c\u5b57\u7b26 char \u548c\u5e03\u5c14 boolean \u3002\u5b83\u4eec\u7684\u53d6\u503c\u8303\u56f4\u53d6\u51b3\u4e8e\u5360\u7528\u7a7a\u95f4\u5927\u5c0f\u548c\u8868\u793a\u65b9\u5f0f\u3002
        • \u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u7f16\u7801\u6570\u5b57\u7684\u4e09\u79cd\u65b9\u6cd5\uff0c\u5b83\u4eec\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\u3002\u6574\u6570\u7684\u539f\u7801\u7684\u6700\u9ad8\u4f4d\u662f\u7b26\u53f7\u4f4d\uff0c\u5176\u4f59\u4f4d\u662f\u6570\u5b57\u7684\u503c\u3002
        • \u6574\u6570\u5728\u8ba1\u7b97\u673a\u4e2d\u662f\u4ee5\u8865\u7801\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\u3002\u5728\u8865\u7801\u8868\u793a\u4e0b\uff0c\u8ba1\u7b97\u673a\u53ef\u4ee5\u5bf9\u6b63\u6570\u548c\u8d1f\u6570\u7684\u52a0\u6cd5\u4e00\u89c6\u540c\u4ec1\uff0c\u4e0d\u9700\u8981\u4e3a\u51cf\u6cd5\u64cd\u4f5c\u5355\u72ec\u8bbe\u8ba1\u7279\u6b8a\u7684\u786c\u4ef6\u7535\u8def\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u6b63\u8d1f\u96f6\u6b67\u4e49\u7684\u95ee\u9898\u3002
        • \u6d6e\u70b9\u6570\u7684\u7f16\u7801\u7531 1 \u4f4d\u7b26\u53f7\u4f4d\u30018 \u4f4d\u6307\u6570\u4f4d\u548c 23 \u4f4d\u5206\u6570\u4f4d\u6784\u6210\u3002\u7531\u4e8e\u5b58\u5728\u6307\u6570\u4f4d\uff0c\u56e0\u6b64\u6d6e\u70b9\u6570\u7684\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e\u6574\u6570\uff0c\u4ee3\u4ef7\u662f\u727a\u7272\u4e86\u7cbe\u5ea6\u3002
        • ASCII \u7801\u662f\u6700\u65e9\u51fa\u73b0\u7684\u82f1\u6587\u5b57\u7b26\u96c6\uff0c\u957f\u5ea6\u4e3a 1 \u5b57\u8282\uff0c\u5171\u6536\u5f55 127 \u4e2a\u5b57\u7b26\u3002GBK \u5b57\u7b26\u96c6\u662f\u5e38\u7528\u7684\u4e2d\u6587\u5b57\u7b26\u96c6\uff0c\u5171\u6536\u5f55\u4e24\u4e07\u591a\u4e2a\u6c49\u5b57\u3002Unicode \u81f4\u529b\u4e8e\u63d0\u4f9b\u4e00\u4e2a\u5b8c\u6574\u7684\u5b57\u7b26\u96c6\u6807\u51c6\uff0c\u6536\u5f55\u4e16\u754c\u5185\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u7b26\uff0c\u4ece\u800c\u89e3\u51b3\u7531\u4e8e\u5b57\u7b26\u7f16\u7801\u65b9\u6cd5\u4e0d\u4e00\u81f4\u800c\u5bfc\u81f4\u7684\u4e71\u7801\u95ee\u9898\u3002
        • UTF-8 \u662f\u6700\u53d7\u6b22\u8fce\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\uff0c\u901a\u7528\u6027\u975e\u5e38\u597d\u3002\u5b83\u662f\u4e00\u79cd\u53d8\u957f\u7684\u7f16\u7801\u65b9\u6cd5\uff0c\u5177\u6709\u5f88\u597d\u7684\u6269\u5c55\u6027\uff0c\u6709\u6548\u63d0\u5347\u4e86\u5b58\u50a8\u7a7a\u95f4\u7684\u4f7f\u7528\u6548\u7387\u3002UTF-16 \u548c UTF-32 \u662f\u7b49\u957f\u7684\u7f16\u7801\u65b9\u6cd5\u3002\u5728\u7f16\u7801\u4e2d\u6587\u65f6\uff0cUTF-16 \u6bd4 UTF-8 \u7684\u5360\u7528\u7a7a\u95f4\u66f4\u5c0f\u3002Java \u548c C# \u7b49\u7f16\u7a0b\u8bed\u8a00\u9ed8\u8ba4\u4f7f\u7528 UTF-16 \u7f16\u7801\u3002
        "},{"location":"chapter_data_structure/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u4e3a\u4ec0\u4e48\u54c8\u5e0c\u8868\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1f

        \u54c8\u5e0c\u8868\u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u800c\u4e3a\u4e86\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u4f7f\u7528\u201c\u94fe\u5f0f\u5730\u5740\u201d\uff08\u540e\u7eed\u54c8\u5e0c\u8868\u7ae0\u8282\u4f1a\u8bb2\uff09\uff1a\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6876\u6307\u5411\u4e00\u4e2a\u94fe\u8868\uff0c\u5f53\u94fe\u8868\u957f\u5ea6\u8d85\u8fc7\u4e00\u5b9a\u9608\u503c\u65f6\uff0c\u53c8\u53ef\u80fd\u88ab\u8f6c\u5316\u4e3a\u6811\uff08\u901a\u5e38\u4e3a\u7ea2\u9ed1\u6811\uff09\u3002 \u4ece\u5b58\u50a8\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u54c8\u5e0c\u8868\u7684\u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u6876\u69fd\u4f4d\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u503c\uff0c\u4e5f\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u94fe\u8868\u6216\u6811\u3002\u56e0\u6b64\uff0c\u54c8\u5e0c\u8868\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\uff08\u6570\u7ec4\u3001\u94fe\u8868\uff09\u548c\u975e\u7ebf\u6027\uff08\u6811\uff09\u6570\u636e\u7ed3\u6784\u3002

        char \u7c7b\u578b\u7684\u957f\u5ea6\u662f 1 byte \u5417\uff1f

        char \u7c7b\u578b\u7684\u957f\u5ea6\u7531\u7f16\u7a0b\u8bed\u8a00\u91c7\u7528\u7684\u7f16\u7801\u65b9\u6cd5\u51b3\u5b9a\u3002\u4f8b\u5982\uff0cJava\u3001JavaScript\u3001TypeScript\u3001C# \u90fd\u91c7\u7528 UTF-16 \u7f16\u7801\uff08\u4fdd\u5b58 Unicode \u7801\u70b9\uff09\uff0c\u56e0\u6b64 char \u7c7b\u578b\u7684\u957f\u5ea6\u4e3a 2 bytes \u3002

        \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u88ab\u79f0\u4e3a\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d \u662f\u5426\u6709\u6b67\u4e49\uff1f\u56e0\u4e3a\u6808\u4e5f\u53ef\u4ee5\u8fdb\u884c\u51fa\u6808\u548c\u5165\u6808\u7b49\u64cd\u4f5c\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u201c\u52a8\u6001\u201d\u7684\u3002

        \u6808\u786e\u5b9e\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u7684\u6570\u636e\u64cd\u4f5c\uff0c\u4f46\u6570\u636e\u7ed3\u6784\u4ecd\u7136\u662f\u201c\u9759\u6001\u201d\uff08\u957f\u5ea6\u4e0d\u53ef\u53d8\uff09\u7684\u3002\u5c3d\u7ba1\u57fa\u4e8e\u6570\u7ec4\u7684\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u52a8\u6001\u5730\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\uff0c\u4f46\u5b83\u4eec\u7684\u5bb9\u91cf\u662f\u56fa\u5b9a\u7684\u3002\u5982\u679c\u6570\u636e\u91cf\u8d85\u51fa\u4e86\u9884\u5206\u914d\u7684\u5927\u5c0f\uff0c\u5c31\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u8001\u6570\u7ec4\u7684\u5185\u5bb9\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002

        \u5728\u6784\u5efa\u6808\uff08\u961f\u5217\uff09\u7684\u65f6\u5019\uff0c\u672a\u6307\u5b9a\u5b83\u7684\u5927\u5c0f\uff0c\u4e3a\u4ec0\u4e48\u5b83\u4eec\u662f\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d\u5462\uff1f

        \u5728\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u65e0\u987b\u4eba\u5de5\u6307\u5b9a\u6808\uff08\u961f\u5217\uff09\u7684\u521d\u59cb\u5bb9\u91cf\uff0c\u8fd9\u4e2a\u5de5\u4f5c\u662f\u7531\u7c7b\u5185\u90e8\u81ea\u52a8\u5b8c\u6210\u7684\u3002\u4f8b\u5982\uff0cJava \u7684 ArrayList \u7684\u521d\u59cb\u5bb9\u91cf\u901a\u5e38\u4e3a 10 \u3002\u53e6\u5916\uff0c\u6269\u5bb9\u64cd\u4f5c\u4e5f\u662f\u81ea\u52a8\u5b9e\u73b0\u7684\u3002\u8be6\u89c1\u672c\u4e66\u7684\u201c\u5217\u8868\u201d\u7ae0\u8282\u3002

        "},{"location":"chapter_divide_and_conquer/","title":"\u7b2c 12 \u7ae0 \u00a0 \u5206\u6cbb","text":"

        Abstract

        \u96be\u9898\u88ab\u9010\u5c42\u62c6\u89e3\uff0c\u6bcf\u4e00\u6b21\u7684\u62c6\u89e3\u90fd\u4f7f\u5b83\u53d8\u5f97\u66f4\u4e3a\u7b80\u5355\u3002

        \u5206\u800c\u6cbb\u4e4b\u63ed\u793a\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u4e8b\u5b9e\uff1a\u4ece\u7b80\u5355\u505a\u8d77\uff0c\u4e00\u5207\u90fd\u4e0d\u518d\u590d\u6742\u3002

        "},{"location":"chapter_divide_and_conquer/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 12.1 \u00a0 \u5206\u6cbb\u7b97\u6cd5
        • 12.2 \u00a0 \u5206\u6cbb\u641c\u7d22\u7b56\u7565
        • 12.3 \u00a0 \u6784\u5efa\u6811\u95ee\u9898
        • 12.4 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898
        • 12.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_divide_and_conquer/binary_search_recur/","title":"12.2 \u00a0 \u5206\u6cbb\u641c\u7d22\u7b56\u7565","text":"

        \u6211\u4eec\u5df2\u7ecf\u5b66\u8fc7\uff0c\u641c\u7d22\u7b97\u6cd5\u5206\u4e3a\u4e24\u5927\u7c7b\u3002

        • \u66b4\u529b\u641c\u7d22\uff1a\u5b83\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        • \u81ea\u9002\u5e94\u641c\u7d22\uff1a\u5b83\u5229\u7528\u7279\u6709\u7684\u6570\u636e\u7ec4\u7ec7\u5f62\u5f0f\u6216\u5148\u9a8c\u4fe1\u606f\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \u3002

        \u5b9e\u9645\u4e0a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u7684\u641c\u7d22\u7b97\u6cd5\u901a\u5e38\u662f\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u5b9e\u73b0\u7684\uff0c\u4f8b\u5982\u4e8c\u5206\u67e5\u627e\u548c\u6811\u3002

        • \u4e8c\u5206\u67e5\u627e\u7684\u6bcf\u4e00\u6b65\u90fd\u5c06\u95ee\u9898\uff08\u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff09\u5206\u89e3\u4e3a\u4e00\u4e2a\u5c0f\u95ee\u9898\uff08\u5728\u6570\u7ec4\u7684\u4e00\u534a\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff09\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e00\u76f4\u6301\u7eed\u5230\u6570\u7ec4\u4e3a\u7a7a\u6216\u627e\u5230\u76ee\u6807\u5143\u7d20\u4e3a\u6b62\u3002
        • \u6811\u662f\u5206\u6cbb\u601d\u60f3\u7684\u4ee3\u8868\uff0c\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u3001AVL \u6811\u3001\u5806\u7b49\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7686\u4e3a \\(O(\\log n)\\) \u3002

        \u4e8c\u5206\u67e5\u627e\u7684\u5206\u6cbb\u7b56\u7565\u5982\u4e0b\u6240\u793a\u3002

        • \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u4e8c\u5206\u67e5\u627e\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\uff08\u5728\u6570\u7ec4\u4e2d\u8fdb\u884c\u67e5\u627e\uff09\u5206\u89e3\u4e3a\u5b50\u95ee\u9898\uff08\u5728\u6570\u7ec4\u7684\u4e00\u534a\u4e2d\u8fdb\u884c\u67e5\u627e\uff09\uff0c\u8fd9\u662f\u901a\u8fc7\u6bd4\u8f83\u4e2d\u95f4\u5143\u7d20\u548c\u76ee\u6807\u5143\u7d20\u6765\u5b9e\u73b0\u7684\u3002
        • \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5728\u4e8c\u5206\u67e5\u627e\u4e2d\uff0c\u6bcf\u8f6e\u53ea\u5904\u7406\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u5b83\u4e0d\u53d7\u5176\u4ed6\u5b50\u95ee\u9898\u7684\u5f71\u54cd\u3002
        • \u5b50\u95ee\u9898\u7684\u89e3\u65e0\u987b\u5408\u5e76\uff1a\u4e8c\u5206\u67e5\u627e\u65e8\u5728\u67e5\u627e\u4e00\u4e2a\u7279\u5b9a\u5143\u7d20\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\u3002\u5f53\u5b50\u95ee\u9898\u5f97\u5230\u89e3\u51b3\u65f6\uff0c\u539f\u95ee\u9898\u4e5f\u4f1a\u540c\u65f6\u5f97\u5230\u89e3\u51b3\u3002

        \u5206\u6cbb\u80fd\u591f\u63d0\u5347\u641c\u7d22\u6548\u7387\uff0c\u672c\u8d28\u4e0a\u662f\u56e0\u4e3a\u66b4\u529b\u641c\u7d22\u6bcf\u8f6e\u53ea\u80fd\u6392\u9664\u4e00\u4e2a\u9009\u9879\uff0c\u800c\u5206\u6cbb\u641c\u7d22\u6bcf\u8f6e\u53ef\u4ee5\u6392\u9664\u4e00\u534a\u9009\u9879\u3002

        "},{"location":"chapter_divide_and_conquer/binary_search_recur/#1","title":"1. \u00a0 \u57fa\u4e8e\u5206\u6cbb\u5b9e\u73b0\u4e8c\u5206\u67e5\u627e","text":"

        \u5728\u4e4b\u524d\u7684\u7ae0\u8282\u4e2d\uff0c\u4e8c\u5206\u67e5\u627e\u662f\u57fa\u4e8e\u9012\u63a8\uff08\u8fed\u4ee3\uff09\u5b9e\u73b0\u7684\u3002\u73b0\u5728\u6211\u4eec\u57fa\u4e8e\u5206\u6cbb\uff08\u9012\u5f52\uff09\u6765\u5b9e\u73b0\u5b83\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684\uff0c\u8bf7\u67e5\u627e\u5143\u7d20 target \u3002

        \u4ece\u5206\u6cbb\u89d2\u5ea6\uff0c\u6211\u4eec\u5c06\u641c\u7d22\u533a\u95f4 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u8bb0\u4e3a \\(f(i, j)\\) \u3002

        \u4ee5\u539f\u95ee\u9898 \\(f(0, n-1)\\) \u4e3a\u8d77\u59cb\u70b9\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\u3002

        1. \u8ba1\u7b97\u641c\u7d22\u533a\u95f4 \\([i, j]\\) \u7684\u4e2d\u70b9 \\(m\\) \uff0c\u6839\u636e\u5b83\u6392\u9664\u4e00\u534a\u641c\u7d22\u533a\u95f4\u3002
        2. \u9012\u5f52\u6c42\u89e3\u89c4\u6a21\u51cf\u5c0f\u4e00\u534a\u7684\u5b50\u95ee\u9898\uff0c\u53ef\u80fd\u4e3a \\(f(i, m-1)\\) \u6216 \\(f(m+1, j)\\) \u3002
        3. \u5faa\u73af\u7b2c 1. \u6b65\u548c\u7b2c 2. \u6b65\uff0c\u76f4\u81f3\u627e\u5230 target \u6216\u533a\u95f4\u4e3a\u7a7a\u65f6\u8fd4\u56de\u3002

        \u56fe 12-4 \u5c55\u793a\u4e86\u5728\u6570\u7ec4\u4e2d\u4e8c\u5206\u67e5\u627e\u5143\u7d20 \\(6\\) \u7684\u5206\u6cbb\u8fc7\u7a0b\u3002

        \u56fe 12-4 \u00a0 \u4e8c\u5206\u67e5\u627e\u7684\u5206\u6cbb\u8fc7\u7a0b

        \u5728\u5b9e\u73b0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs() \u6765\u6c42\u89e3\u95ee\u9898 \\(f(i, j)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_recur.py
        def dfs(nums: list[int], target: int, i: int, j: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j)\"\"\"\n# \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j:\nreturn -1\n# \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm = (i + j) // 2\nif nums[m] < target:\n# \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j)\nelif nums[m] > target:\n# \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1)\nelse:\n# \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\ndef binary_search(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\"\"\"\nn = len(nums)\n# \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1)\n
        binary_search_recur.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(vector<int> &nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(vector<int> &nums, int target) {\nint n = nums.size();\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.java
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(int[] nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int[] nums, int target) {\nint n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.cs
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint DFS(int[] nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn DFS(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn DFS(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint BinarySearch(int[] nums, int target) {\nint n = nums.Length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn DFS(nums, target, 0, n - 1);\n}\n
        binary_search_recur.go
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunc dfs(nums []int, target, i, j int) int {\n// \u5982\u679c\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u6ca1\u6709\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j {\nreturn -1\n}\n//    \u8ba1\u7b97\u7d22\u5f15\u4e2d\u70b9\nm := i + ((j - i) >> 1)\n//\u5224\u65ad\u4e2d\u70b9\u4e0e\u76ee\u6807\u5143\u7d20\u5927\u5c0f\nif nums[m] < target {\n// \u5c0f\u4e8e\u5219\u9012\u5f52\u53f3\u534a\u6570\u7ec4\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m+1, j)\n} else if nums[m] > target {\n// \u5c0f\u4e8e\u5219\u9012\u5f52\u5de6\u534a\u6570\u7ec4\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m-1)\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums []int, target int) int {\nn := len(nums)\nreturn dfs(nums, target, 0, n-1)\n}\n
        binary_search_recur.swift
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunc dfs(nums: [Int], target: Int, i: Int, j: Int) -> Int {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j {\nreturn -1\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nlet m = (i + j) / 2\nif nums[m] < target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums: nums, target: target, i: m + 1, j: j)\n} else if nums[m] > target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums: nums, target: target, i: i, j: m - 1)\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\nlet n = nums.count\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums: nums, target: target, i: 0, j: n - 1)\n}\n
        binary_search_recur.js
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunction dfs(nums, target, i, j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = i + ((j - i) >> 1);\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums, target) {\nconst n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.ts
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunction dfs(nums: number[], target: number, i: number, j: number): number {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = i + ((j - i) >> 1);\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums: number[], target: number): number {\nconst n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.dart
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(List<int> nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) ~/ 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(List<int> nums, int target) {\nint n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.rs
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfn dfs(nums: &[i32], target: i32, i: i32, j: i32) -> i32 {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j { return -1; }\nlet m: i32 = (i + j) / 2;\nif nums[m as usize] < target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if nums[m as usize] > target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\nlet n = nums.len() as i32;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\ndfs(nums, target, 0, n - 1)\n}\n
        binary_search_recur.c
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(int nums[], int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int nums[], int target, int numsSize) {\nint n = numsSize;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{binarySearch}\n
        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/","title":"12.3 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \uff0c\u8bf7\u4ece\u4e2d\u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u3002\u5047\u8bbe\u4e8c\u53c9\u6811\u4e2d\u6ca1\u6709\u503c\u91cd\u590d\u7684\u8282\u70b9\u3002

        \u56fe 12-5 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#1","title":"1. \u00a0 \u5224\u65ad\u662f\u5426\u4e3a\u5206\u6cbb\u95ee\u9898","text":"

        \u539f\u95ee\u9898\u5b9a\u4e49\u4e3a\u4ece preorder \u548c inorder \u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u662f\u4e00\u4e2a\u5178\u578b\u7684\u5206\u6cbb\u95ee\u9898\u3002

        • \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u4ece\u5206\u6cbb\u7684\u89d2\u5ea6\u5207\u5165\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u539f\u95ee\u9898\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\u3001\u6784\u5efa\u53f3\u5b50\u6811\uff0c\u52a0\u4e0a\u4e00\u6b65\u64cd\u4f5c\uff1a\u521d\u59cb\u5316\u6839\u8282\u70b9\u3002\u800c\u5bf9\u4e8e\u6bcf\u68f5\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u590d\u7528\u4ee5\u4e0a\u5212\u5206\u65b9\u6cd5\uff0c\u5c06\u5176\u5212\u5206\u4e3a\u66f4\u5c0f\u7684\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u76f4\u81f3\u8fbe\u5230\u6700\u5c0f\u5b50\u95ee\u9898\uff08\u7a7a\u5b50\u6811\uff09\u65f6\u7ec8\u6b62\u3002
        • \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u5b83\u4eec\u4e4b\u95f4\u6ca1\u6709\u4ea4\u96c6\u3002\u5728\u6784\u5efa\u5de6\u5b50\u6811\u65f6\uff0c\u6211\u4eec\u53ea\u9700\u5173\u6ce8\u4e2d\u5e8f\u904d\u5386\u548c\u524d\u5e8f\u904d\u5386\u4e2d\u4e0e\u5de6\u5b50\u6811\u5bf9\u5e94\u7684\u90e8\u5206\u3002\u53f3\u5b50\u6811\u540c\u7406\u3002
        • \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u4e00\u65e6\u5f97\u5230\u4e86\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u5b83\u4eec\u94fe\u63a5\u5230\u6839\u8282\u70b9\u4e0a\uff0c\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002
        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#2","title":"2. \u00a0 \u5982\u4f55\u5212\u5206\u5b50\u6811","text":"

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u8fd9\u9053\u9898\u53ef\u4ee5\u4f7f\u7528\u5206\u6cbb\u6765\u6c42\u89e3\uff0c\u4f46\u5982\u4f55\u901a\u8fc7\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \u6765\u5212\u5206\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u5462\uff1f

        \u6839\u636e\u5b9a\u4e49\uff0cpreorder \u548c inorder \u90fd\u53ef\u4ee5\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\u3002

        • \u524d\u5e8f\u904d\u5386\uff1a[ \u6839\u8282\u70b9 | \u5de6\u5b50\u6811 | \u53f3\u5b50\u6811 ] \uff0c\u4f8b\u5982\u56fe 12-5 \u7684\u6811\u5bf9\u5e94 [ 3 | 9 | 2 1 7 ] \u3002
        • \u4e2d\u5e8f\u904d\u5386\uff1a[ \u5de6\u5b50\u6811 | \u6839\u8282\u70b9 \uff5c \u53f3\u5b50\u6811 ] \uff0c\u4f8b\u5982\u56fe 12-5 \u7684\u6811\u5bf9\u5e94 [ 9 | 3 | 1 2 7 ] \u3002

        \u4ee5\u4e0a\u56fe\u6570\u636e\u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u56fe 12-6 \u6240\u793a\u7684\u6b65\u9aa4\u5f97\u5230\u5212\u5206\u7ed3\u679c\u3002

        1. \u524d\u5e8f\u904d\u5386\u7684\u9996\u5143\u7d20 3 \u662f\u6839\u8282\u70b9\u7684\u503c\u3002
        2. \u67e5\u627e\u6839\u8282\u70b9 3 \u5728 inorder \u4e2d\u7684\u7d22\u5f15\uff0c\u5229\u7528\u8be5\u7d22\u5f15\u53ef\u5c06 inorder \u5212\u5206\u4e3a [ 9 | 3 \uff5c 1 2 7 ] \u3002
        3. \u6839\u636e inorder \u5212\u5206\u7ed3\u679c\uff0c\u6613\u5f97\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u7684\u8282\u70b9\u6570\u91cf\u5206\u522b\u4e3a 1 \u548c 3 \uff0c\u4ece\u800c\u53ef\u5c06 preorder \u5212\u5206\u4e3a [ 3 | 9 | 2 1 7 ] \u3002

        \u56fe 12-6 \u00a0 \u5728\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u4e2d\u5212\u5206\u5b50\u6811

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#3","title":"3. \u00a0 \u57fa\u4e8e\u53d8\u91cf\u63cf\u8ff0\u5b50\u6811\u533a\u95f4","text":"

        \u6839\u636e\u4ee5\u4e0a\u5212\u5206\u65b9\u6cd5\uff0c\u6211\u4eec\u5df2\u7ecf\u5f97\u5230\u6839\u8282\u70b9\u3001\u5de6\u5b50\u6811\u3001\u53f3\u5b50\u6811\u5728 preorder \u548c inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u3002\u800c\u4e3a\u4e86\u63cf\u8ff0\u8fd9\u4e9b\u7d22\u5f15\u533a\u95f4\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u51e0\u4e2a\u6307\u9488\u53d8\u91cf\u3002

        • \u5c06\u5f53\u524d\u6811\u7684\u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15\u8bb0\u4e3a \\(i\\) \u3002
        • \u5c06\u5f53\u524d\u6811\u7684\u6839\u8282\u70b9\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u8bb0\u4e3a \\(m\\) \u3002
        • \u5c06\u5f53\u524d\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u8bb0\u4e3a \\([l, r]\\) \u3002

        \u5982\u8868 12-1 \u6240\u793a\uff0c\u901a\u8fc7\u4ee5\u4e0a\u53d8\u91cf\u5373\u53ef\u8868\u793a\u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15\uff0c\u4ee5\u53ca\u5b50\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u3002

        \u8868 12-1 \u00a0 \u6839\u8282\u70b9\u548c\u5b50\u6811\u5728\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u4e2d\u7684\u7d22\u5f15

        \u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15 \u5b50\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4 \u5f53\u524d\u6811 \\(i\\) \\([l, r]\\) \u5de6\u5b50\u6811 \\(i + 1\\) \\([l, m-1]\\) \u53f3\u5b50\u6811 \\(i + 1 + (m - l)\\) \\([m+1, r]\\)

        \u8bf7\u6ce8\u610f\uff0c\u53f3\u5b50\u6811\u6839\u8282\u70b9\u7d22\u5f15\u4e2d\u7684 \\((m-l)\\) \u7684\u542b\u4e49\u662f\u201c\u5de6\u5b50\u6811\u7684\u8282\u70b9\u6570\u91cf\u201d\uff0c\u5efa\u8bae\u914d\u5408\u56fe 12-7 \u7406\u89e3\u3002

        \u56fe 12-7 \u00a0 \u6839\u8282\u70b9\u548c\u5de6\u53f3\u5b50\u6811\u7684\u7d22\u5f15\u533a\u95f4\u8868\u793a

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#4","title":"4. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u63d0\u5347\u67e5\u8be2 \\(m\\) \u7684\u6548\u7387\uff0c\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 hmap \u6765\u5b58\u50a8\u6570\u7ec4 inorder \u4e2d\u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig build_tree.py
        def dfs(\npreorder: list[int],\ninorder_map: dict[int, int],\ni: int,\nl: int,\nr: int,\n) -> TreeNode | None:\n\"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb\"\"\"\n# \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0:\nreturn None\n# \u521d\u59cb\u5316\u6839\u8282\u70b9\nroot = TreeNode(preorder[i])\n# \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nm = inorder_map[preorder[i]]\n# \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorder_map, i + 1, l, m - 1)\n# \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r)\n# \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\ndef build_tree(preorder: list[int], inorder: list[int]) -> TreeNode | None:\n\"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\"\"\"\n# \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\ninorder_map = {val: i for i, val in enumerate(inorder)}\nroot = dfs(preorder, inorder_map, 0, 0, len(inorder) - 1)\nreturn root\n
        build_tree.cpp
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode *dfs(vector<int> &preorder, unordered_map<int, int> &inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn NULL;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode *root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot->left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nunordered_map<int, int> inorderMap;\nfor (int i = 0; i < inorder.size(); i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode *root = dfs(preorder, inorderMap, 0, 0, inorder.size() - 1);\nreturn root;\n}\n
        build_tree.java
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode dfs(int[] preorder, Map<Integer, Integer> inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode buildTree(int[] preorder, int[] inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nMap<Integer, Integer> inorderMap = new HashMap<>();\nfor (int i = 0; i < inorder.length; i++) {\ninorderMap.put(inorder[i], i);\n}\nTreeNode root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.cs
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? DFS(int[] preorder, Dictionary<int, int> inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode root = new(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = DFS(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = DFS(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode? BuildTree(int[] preorder, int[] inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nDictionary<int, int> inorderMap = [];\nfor (int i = 0; i < inorder.Length; i++) {\ninorderMap.TryAdd(inorder[i], i);\n}\nTreeNode? root = DFS(preorder, inorderMap, 0, 0, inorder.Length - 1);\nreturn root;\n}\n
        build_tree.go
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunc dfsBuildTree(preorder []int, inorderMap map[int]int, i, l, r int) *TreeNode {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r-l < 0 {\nreturn nil\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nroot := NewTreeNode(preorder[i])\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nm := inorderMap[preorder[i]]\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.Left = dfsBuildTree(preorder, inorderMap, i+1, l, m-1)\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.Right = dfsBuildTree(preorder, inorderMap, i+1+m-l, m+1, r)\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunc buildTree(preorder, inorder []int) *TreeNode {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\ninorderMap := make(map[int]int, len(inorder))\nfor i := 0; i < len(inorder); i++ {\ninorderMap[inorder[i]] = i\n}\nroot := dfsBuildTree(preorder, inorderMap, 0, 0, len(inorder)-1)\nreturn root\n}\n
        build_tree.swift
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunc dfs(preorder: [Int], inorderMap: [Int: Int], i: Int, l: Int, r: Int) -> TreeNode? {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0 {\nreturn nil\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nlet root = TreeNode(x: preorder[i])\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nlet m = inorderMap[preorder[i]]!\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1, l: l, r: m - 1)\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1 + m - l, l: m + 1, r: r)\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunc buildTree(preorder: [Int], inorder: [Int]) -> TreeNode? {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = inorder.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }\nreturn dfs(preorder: preorder, inorderMap: inorderMap, i: 0, l: 0, r: inorder.count - 1)\n}\n
        build_tree.js
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(preorder, inorderMap, i, l, r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) return null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nconst root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nconst m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunction buildTree(preorder, inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = new Map();\nfor (let i = 0; i < inorder.length; i++) {\ninorderMap.set(inorder[i], i);\n}\nconst root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.ts
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(\npreorder: number[],\ninorderMap: Map<number, number>,\ni: number,\nl: number,\nr: number\n): TreeNode | null {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) return null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nconst root: TreeNode = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nconst m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunction buildTree(preorder: number[], inorder: number[]): TreeNode | null {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = new Map<number, number>();\nfor (let i = 0; i < inorder.length; i++) {\ninorderMap.set(inorder[i], i);\n}\nconst root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.dart
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? dfs(\nList<int> preorder,\nMap<int, int> inorderMap,\nint i,\nint l,\nint r,\n) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) {\nreturn null;\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode? root = TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]]!;\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode? buildTree(List<int> preorder, List<int> inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nMap<int, int> inorderMap = {};\nfor (int i = 0; i < inorder.length; i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode? root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.rs
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfn dfs(preorder: &[i32], inorder_map: &HashMap<i32, i32>, i: i32, l: i32, r: i32) -> Option<Rc<RefCell<TreeNode>>> {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0 { return None; }\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nlet root = TreeNode::new(preorder[i as usize]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nlet m = inorder_map.get(&preorder[i as usize]).unwrap();\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.borrow_mut().left = dfs(preorder, inorder_map, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.borrow_mut().right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nSome(root)\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfn build_tree(preorder: &[i32], inorder: &[i32]) -> Option<Rc<RefCell<TreeNode>>> {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet mut inorder_map: HashMap<i32, i32> = HashMap::new();\nfor i in 0..inorder.len() {\ninorder_map.insert(inorder[i], i as i32);\n}\nlet root = dfs(preorder, &inorder_map, 0, 0, inorder.len() as i32 - 1);\nroot\n}\n
        build_tree.c
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode *dfs(int *preorder, int *inorderMap, int i, int l, int r, int size) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn NULL;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode *root = (TreeNode *)malloc(sizeof(TreeNode));\nroot->val = preorder[i];\nroot->left = NULL;\nroot->right = NULL;\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot->left = dfs(preorder, inorderMap, i + 1, l, m - 1, size);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r, size);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode *buildTree(int *preorder, int preorderSize, int *inorder, int inorderSize) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nint *inorderMap = (int *)malloc(sizeof(int) * MAX_SIZE);\nfor (int i = 0; i < inorderSize; i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode *root = dfs(preorder, inorderMap, 0, 0, inorderSize - 1, inorderSize);\nfree(inorderMap);\nreturn root;\n}\n
        build_tree.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{buildTree}\n

        \u56fe 12-8 \u5c55\u793a\u4e86\u6784\u5efa\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b\uff0c\u5404\u4e2a\u8282\u70b9\u662f\u5728\u5411\u4e0b\u201c\u9012\u201d\u7684\u8fc7\u7a0b\u4e2d\u5efa\u7acb\u7684\uff0c\u800c\u5404\u6761\u8fb9\uff08\u5f15\u7528\uff09\u662f\u5728\u5411\u4e0a\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u4e2d\u5efa\u7acb\u7684\u3002

        <1><2><3><4><5><6><7><8><9>

        \u56fe 12-8 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b

        \u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u5185\u7684\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \u7684\u5212\u5206\u7ed3\u679c\u5982\u56fe 12-9 \u6240\u793a\u3002

        \u56fe 12-9 \u00a0 \u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u4e2d\u7684\u5212\u5206\u7ed3\u679c

        \u8bbe\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u521d\u59cb\u5316\u6bcf\u4e00\u4e2a\u8282\u70b9\uff08\u6267\u884c\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs() \uff09\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u56e0\u6b64\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u54c8\u5e0c\u8868\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u9012\u5f52\u6df1\u5ea6\u8fbe\u5230 \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u7684\u6808\u5e27\u7a7a\u95f4\u3002\u56e0\u6b64\u603b\u4f53\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/","title":"12.1 \u00a0 \u5206\u6cbb\u7b97\u6cd5","text":"

        \u300c\u5206\u6cbb divide and conquer\u300d\uff0c\u5168\u79f0\u5206\u800c\u6cbb\u4e4b\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u91cd\u8981\u4e14\u5e38\u89c1\u7684\u7b97\u6cd5\u7b56\u7565\u3002\u5206\u6cbb\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\uff0c\u5305\u62ec\u201c\u5206\u201d\u548c\u201c\u6cbb\u201d\u4e24\u4e2a\u6b65\u9aa4\u3002

        1. \u5206\uff08\u5212\u5206\u9636\u6bb5\uff09\uff1a\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u4e24\u4e2a\u6216\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u5230\u8fbe\u6700\u5c0f\u5b50\u95ee\u9898\u65f6\u7ec8\u6b62\u3002
        2. \u6cbb\uff08\u5408\u5e76\u9636\u6bb5\uff09\uff1a\u4ece\u5df2\u77e5\u89e3\u7684\u6700\u5c0f\u5b50\u95ee\u9898\u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\uff0c\u4ece\u800c\u6784\u5efa\u51fa\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u5982\u56fe 12-1 \u6240\u793a\uff0c\u201c\u5f52\u5e76\u6392\u5e8f\u201d\u662f\u5206\u6cbb\u7b56\u7565\u7684\u5178\u578b\u5e94\u7528\u4e4b\u4e00\u3002

        1. \u5206\uff1a\u9012\u5f52\u5730\u5c06\u539f\u6570\u7ec4\uff08\u539f\u95ee\u9898\uff09\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\uff09\uff0c\u76f4\u5230\u5b50\u6570\u7ec4\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\uff08\u6700\u5c0f\u5b50\u95ee\u9898\uff09\u3002
        2. \u6cbb\uff1a\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u6709\u5e8f\u7684\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\u8fdb\u884c\u5408\u5e76\uff0c\u4ece\u800c\u5f97\u5230\u6709\u5e8f\u7684\u539f\u6570\u7ec4\uff08\u539f\u95ee\u9898\u7684\u89e3\uff09\u3002

        \u56fe 12-1 \u00a0 \u5f52\u5e76\u6392\u5e8f\u7684\u5206\u6cbb\u7b56\u7565

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1211","title":"12.1.1 \u00a0 \u5982\u4f55\u5224\u65ad\u5206\u6cbb\u95ee\u9898","text":"

        \u4e00\u4e2a\u95ee\u9898\u662f\u5426\u9002\u5408\u4f7f\u7528\u5206\u6cbb\u89e3\u51b3\uff0c\u901a\u5e38\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u51e0\u4e2a\u5224\u65ad\u4f9d\u636e\u3002

        1. \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u539f\u95ee\u9898\u53ef\u4ee5\u5206\u89e3\u6210\u89c4\u6a21\u66f4\u5c0f\u3001\u7c7b\u4f3c\u7684\u5b50\u95ee\u9898\uff0c\u4ee5\u53ca\u80fd\u591f\u4ee5\u76f8\u540c\u65b9\u5f0f\u9012\u5f52\u5730\u8fdb\u884c\u5212\u5206\u3002
        2. \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5b50\u95ee\u9898\u4e4b\u95f4\u6ca1\u6709\u91cd\u53e0\uff0c\u4e92\u4e0d\u4f9d\u8d56\uff0c\u53ef\u4ee5\u72ec\u7acb\u89e3\u51b3\u3002
        3. \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u539f\u95ee\u9898\u7684\u89e3\u901a\u8fc7\u5408\u5e76\u5b50\u95ee\u9898\u7684\u89e3\u5f97\u6765\u3002

        \u663e\u7136\uff0c\u5f52\u5e76\u6392\u5e8f\u6ee1\u8db3\u4ee5\u4e0a\u4e09\u6761\u5224\u65ad\u4f9d\u636e\u3002

        1. \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u9012\u5f52\u5730\u5c06\u6570\u7ec4\uff08\u539f\u95ee\u9898\uff09\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\uff09\u3002
        2. \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u6bcf\u4e2a\u5b50\u6570\u7ec4\u90fd\u53ef\u4ee5\u72ec\u7acb\u5730\u8fdb\u884c\u6392\u5e8f\uff08\u5b50\u95ee\u9898\u53ef\u4ee5\u72ec\u7acb\u8fdb\u884c\u6c42\u89e3\uff09\u3002
        3. \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u4e24\u4e2a\u6709\u5e8f\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\u53ef\u4ee5\u5408\u5e76\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\uff08\u539f\u95ee\u9898\u7684\u89e3\uff09\u3002
        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1212","title":"12.1.2 \u00a0 \u901a\u8fc7\u5206\u6cbb\u63d0\u5347\u6548\u7387","text":"

        \u5206\u6cbb\u4e0d\u4ec5\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u7b97\u6cd5\u95ee\u9898\uff0c\u5f80\u5f80\u8fd8\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002\u5728\u6392\u5e8f\u7b97\u6cd5\u4e2d\uff0c\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u76f8\u8f83\u4e8e\u9009\u62e9\u3001\u5192\u6ce1\u3001\u63d2\u5165\u6392\u5e8f\u66f4\u5feb\uff0c\u5c31\u662f\u56e0\u4e3a\u5b83\u4eec\u5e94\u7528\u4e86\u5206\u6cbb\u7b56\u7565\u3002

        \u90a3\u4e48\uff0c\u6211\u4eec\u4e0d\u7981\u53d1\u95ee\uff1a\u4e3a\u4ec0\u4e48\u5206\u6cbb\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\uff0c\u5176\u5e95\u5c42\u903b\u8f91\u662f\u4ec0\u4e48\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06\u5927\u95ee\u9898\u5206\u89e3\u4e3a\u591a\u4e2a\u5b50\u95ee\u9898\u3001\u89e3\u51b3\u5b50\u95ee\u9898\u3001\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u5408\u5e76\u4e3a\u539f\u95ee\u9898\u7684\u89e3\uff0c\u8fd9\u51e0\u6b65\u7684\u6548\u7387\u4e3a\u4ec0\u4e48\u6bd4\u76f4\u63a5\u89e3\u51b3\u539f\u95ee\u9898\u7684\u6548\u7387\u66f4\u9ad8\uff1f\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u4ece\u64cd\u4f5c\u6570\u91cf\u548c\u5e76\u884c\u8ba1\u7b97\u4e24\u65b9\u9762\u6765\u8ba8\u8bba\u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1","title":"1. \u00a0 \u64cd\u4f5c\u6570\u91cf\u4f18\u5316","text":"

        \u4ee5\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u4e3a\u4f8b\uff0c\u5176\u5904\u7406\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\u9700\u8981 \\(O(n^2)\\) \u65f6\u95f4\u3002\u5047\u8bbe\u6211\u4eec\u6309\u7167\u56fe 12-2 \u6240\u793a\u7684\u65b9\u5f0f\uff0c\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u5219\u5212\u5206\u9700\u8981 \\(O(n)\\) \u65f6\u95f4\uff0c\u6392\u5e8f\u6bcf\u4e2a\u5b50\u6570\u7ec4\u9700\u8981 \\(O((n / 2)^2)\\) \u65f6\u95f4\uff0c\u5408\u5e76\u4e24\u4e2a\u5b50\u6570\u7ec4\u9700\u8981 \\(O(n)\\) \u65f6\u95f4\uff0c\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\uff1a

        \\[ O(n + (\\frac{n}{2})^2 \\times 2 + n) = O(\\frac{n^2}{2} + 2n) \\]

        \u56fe 12-2 \u00a0 \u5212\u5206\u6570\u7ec4\u524d\u540e\u7684\u5192\u6ce1\u6392\u5e8f

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8ba1\u7b97\u4ee5\u4e0b\u4e0d\u7b49\u5f0f\uff0c\u5176\u5de6\u8fb9\u548c\u53f3\u8fb9\u5206\u522b\u4e3a\u5212\u5206\u524d\u548c\u5212\u5206\u540e\u7684\u64cd\u4f5c\u603b\u6570\uff1a

        \\[ \\begin{aligned} n^2 & > \\frac{n^2}{2} + 2n \\newline n^2 - \\frac{n^2}{2} - 2n & > 0 \\newline n(n - 4) & > 0 \\end{aligned} \\]

        \u8fd9\u610f\u5473\u7740\u5f53 \\(n > 4\\) \u65f6\uff0c\u5212\u5206\u540e\u7684\u64cd\u4f5c\u6570\u91cf\u66f4\u5c11\uff0c\u6392\u5e8f\u6548\u7387\u5e94\u8be5\u66f4\u9ad8\u3002\u8bf7\u6ce8\u610f\uff0c\u5212\u5206\u540e\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u7136\u662f\u5e73\u65b9\u9636 \\(O(n^2)\\) \uff0c\u53ea\u662f\u590d\u6742\u5ea6\u4e2d\u7684\u5e38\u6570\u9879\u53d8\u5c0f\u4e86\u3002

        \u8fdb\u4e00\u6b65\u60f3\uff0c\u5982\u679c\u6211\u4eec\u628a\u5b50\u6570\u7ec4\u4e0d\u65ad\u5730\u518d\u4ece\u4e2d\u70b9\u5904\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\u65f6\u505c\u6b62\u5212\u5206\u5462\uff1f\u8fd9\u79cd\u601d\u8def\u5b9e\u9645\u4e0a\u5c31\u662f\u201c\u5f52\u5e76\u6392\u5e8f\u201d\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u518d\u601d\u8003\uff0c\u5982\u679c\u6211\u4eec\u591a\u8bbe\u7f6e\u51e0\u4e2a\u5212\u5206\u70b9\uff0c\u5c06\u539f\u6570\u7ec4\u5e73\u5747\u5212\u5206\u4e3a \\(k\\) \u4e2a\u5b50\u6570\u7ec4\u5462\uff1f\u8fd9\u79cd\u60c5\u51b5\u4e0e\u201c\u6876\u6392\u5e8f\u201d\u975e\u5e38\u7c7b\u4f3c\uff0c\u5b83\u975e\u5e38\u9002\u5408\u6392\u5e8f\u6d77\u91cf\u6570\u636e\uff0c\u7406\u8bba\u4e0a\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230 \\(O(n + k)\\) \u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#2","title":"2. \u00a0 \u5e76\u884c\u8ba1\u7b97\u4f18\u5316","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u5206\u6cbb\u751f\u6210\u7684\u5b50\u95ee\u9898\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u56e0\u6b64\u901a\u5e38\u53ef\u4ee5\u5e76\u884c\u89e3\u51b3\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5206\u6cbb\u4e0d\u4ec5\u53ef\u4ee5\u964d\u4f4e\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u8fd8\u6709\u5229\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e76\u884c\u4f18\u5316\u3002

        \u5e76\u884c\u4f18\u5316\u5728\u591a\u6838\u6216\u591a\u5904\u7406\u5668\u7684\u73af\u5883\u4e2d\u5c24\u5176\u6709\u6548\uff0c\u56e0\u4e3a\u7cfb\u7edf\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u66f4\u52a0\u5145\u5206\u5730\u5229\u7528\u8ba1\u7b97\u8d44\u6e90\uff0c\u4ece\u800c\u663e\u8457\u51cf\u5c11\u603b\u4f53\u7684\u8fd0\u884c\u65f6\u95f4\u3002

        \u6bd4\u5982\u5728\u56fe 12-3 \u6240\u793a\u7684\u201c\u6876\u6392\u5e8f\u201d\u4e2d\uff0c\u6211\u4eec\u5c06\u6d77\u91cf\u7684\u6570\u636e\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff0c\u5219\u53ef\u6240\u6709\u6876\u7684\u6392\u5e8f\u4efb\u52a1\u5206\u6563\u5230\u5404\u4e2a\u8ba1\u7b97\u5355\u5143\uff0c\u5b8c\u6210\u540e\u518d\u5408\u5e76\u7ed3\u679c\u3002

        \u56fe 12-3 \u00a0 \u6876\u6392\u5e8f\u7684\u5e76\u884c\u8ba1\u7b97

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1213","title":"12.1.3 \u00a0 \u5206\u6cbb\u5e38\u89c1\u5e94\u7528","text":"

        \u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u53ef\u4ee5\u7528\u6765\u89e3\u51b3\u8bb8\u591a\u7ecf\u5178\u7b97\u6cd5\u95ee\u9898\u3002

        • \u5bfb\u627e\u6700\u8fd1\u70b9\u5bf9\uff1a\u8be5\u7b97\u6cd5\u9996\u5148\u5c06\u70b9\u96c6\u5206\u6210\u4e24\u90e8\u5206\uff0c\u7136\u540e\u5206\u522b\u627e\u51fa\u4e24\u90e8\u5206\u4e2d\u7684\u6700\u8fd1\u70b9\u5bf9\uff0c\u6700\u540e\u627e\u51fa\u8de8\u8d8a\u4e24\u90e8\u5206\u7684\u6700\u8fd1\u70b9\u5bf9\u3002
        • \u5927\u6574\u6570\u4e58\u6cd5\uff1a\u4f8b\u5982 Karatsuba \u7b97\u6cd5\uff0c\u5b83\u5c06\u5927\u6574\u6570\u4e58\u6cd5\u5206\u89e3\u4e3a\u51e0\u4e2a\u8f83\u5c0f\u7684\u6574\u6570\u7684\u4e58\u6cd5\u548c\u52a0\u6cd5\u3002
        • \u77e9\u9635\u4e58\u6cd5\uff1a\u4f8b\u5982 Strassen \u7b97\u6cd5\uff0c\u5b83\u5c06\u5927\u77e9\u9635\u4e58\u6cd5\u5206\u89e3\u4e3a\u591a\u4e2a\u5c0f\u77e9\u9635\u7684\u4e58\u6cd5\u548c\u52a0\u6cd5\u3002
        • \u6c49\u8bfa\u5854\u95ee\u9898\uff1a\u6c49\u8bfa\u5854\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u89e3\u51b3\uff0c\u8fd9\u662f\u5178\u578b\u7684\u5206\u6cbb\u7b56\u7565\u5e94\u7528\u3002
        • \u6c42\u89e3\u9006\u5e8f\u5bf9\uff1a\u5728\u4e00\u4e2a\u5e8f\u5217\u4e2d\uff0c\u5982\u679c\u524d\u9762\u7684\u6570\u5b57\u5927\u4e8e\u540e\u9762\u7684\u6570\u5b57\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u6570\u5b57\u6784\u6210\u4e00\u4e2a\u9006\u5e8f\u5bf9\u3002\u6c42\u89e3\u9006\u5e8f\u5bf9\u95ee\u9898\u53ef\u4ee5\u5229\u7528\u5206\u6cbb\u7684\u601d\u60f3\uff0c\u501f\u52a9\u5f52\u5e76\u6392\u5e8f\u8fdb\u884c\u6c42\u89e3\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u5728\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u7684\u8bbe\u8ba1\u4e2d\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\u3002

        • \u4e8c\u5206\u67e5\u627e\uff1a\u4e8c\u5206\u67e5\u627e\u662f\u5c06\u6709\u5e8f\u6570\u7ec4\u4ece\u4e2d\u70b9\u7d22\u5f15\u5904\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u7136\u540e\u6839\u636e\u76ee\u6807\u503c\u4e0e\u4e2d\u95f4\u5143\u7d20\u503c\u6bd4\u8f83\u7ed3\u679c\uff0c\u51b3\u5b9a\u6392\u9664\u54ea\u4e00\u534a\u533a\u95f4\uff0c\u5e76\u5728\u5269\u4f59\u533a\u95f4\u6267\u884c\u76f8\u540c\u7684\u4e8c\u5206\u64cd\u4f5c\u3002
        • \u5f52\u5e76\u6392\u5e8f\uff1a\u672c\u8282\u5f00\u5934\u5df2\u4ecb\u7ecd\uff0c\u4e0d\u518d\u8d58\u8ff0\u3002
        • \u5feb\u901f\u6392\u5e8f\uff1a\u5feb\u901f\u6392\u5e8f\u662f\u9009\u53d6\u4e00\u4e2a\u57fa\u51c6\u503c\uff0c\u7136\u540e\u628a\u6570\u7ec4\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5c0f\uff0c\u53e6\u4e00\u5b50\u6570\u7ec4\u7684\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5927\uff0c\u518d\u5bf9\u8fd9\u4e24\u90e8\u5206\u8fdb\u884c\u76f8\u540c\u7684\u5212\u5206\u64cd\u4f5c\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u53ea\u5269\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002
        • \u6876\u6392\u5e8f\uff1a\u6876\u6392\u5e8f\u7684\u57fa\u672c\u601d\u60f3\u662f\u5c06\u6570\u636e\u5206\u6563\u5230\u591a\u4e2a\u6876\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u6876\u5185\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u540e\u5c06\u5404\u4e2a\u6876\u7684\u5143\u7d20\u4f9d\u6b21\u53d6\u51fa\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002
        • \u6811\uff1a\u4f8b\u5982\u4e8c\u53c9\u641c\u7d22\u6811\u3001AVL \u6811\u3001\u7ea2\u9ed1\u6811\u3001B \u6811\u3001B+ \u6811\u7b49\uff0c\u5b83\u4eec\u7684\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u7b49\u64cd\u4f5c\u90fd\u53ef\u4ee5\u89c6\u4e3a\u5206\u6cbb\u7b56\u7565\u7684\u5e94\u7528\u3002
        • \u5806\uff1a\u5806\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u5176\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u63d2\u5165\u3001\u5220\u9664\u548c\u5806\u5316\uff0c\u5b9e\u9645\u4e0a\u90fd\u9690\u542b\u4e86\u5206\u6cbb\u7684\u601d\u60f3\u3002
        • \u54c8\u5e0c\u8868\uff1a\u867d\u7136\u54c8\u5e0c\u8868\u6765\u5e76\u4e0d\u76f4\u63a5\u5e94\u7528\u5206\u6cbb\uff0c\u4f46\u67d0\u4e9b\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u95f4\u63a5\u5e94\u7528\u4e86\u5206\u6cbb\u7b56\u7565\uff0c\u4f8b\u5982\uff0c\u94fe\u5f0f\u5730\u5740\u4e2d\u7684\u957f\u94fe\u8868\u4f1a\u88ab\u8f6c\u5316\u4e3a\u7ea2\u9ed1\u6811\uff0c\u4ee5\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002

        \u53ef\u4ee5\u770b\u51fa\uff0c\u5206\u6cbb\u662f\u4e00\u79cd\u201c\u6da6\u7269\u7ec6\u65e0\u58f0\u201d\u7684\u7b97\u6cd5\u601d\u60f3\uff0c\u9690\u542b\u5728\u5404\u79cd\u7b97\u6cd5\u4e0e\u6570\u636e\u7ed3\u6784\u4e4b\u4e2d\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/","title":"12.4 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898","text":"

        \u5728\u5f52\u5e76\u6392\u5e8f\u548c\u6784\u5efa\u4e8c\u53c9\u6811\u4e2d\uff0c\u6211\u4eec\u90fd\u662f\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u4e24\u4e2a\u89c4\u6a21\u4e3a\u539f\u95ee\u9898\u4e00\u534a\u7684\u5b50\u95ee\u9898\u3002\u7136\u800c\u5bf9\u4e8e\u6c49\u8bfa\u5854\u95ee\u9898\uff0c\u6211\u4eec\u91c7\u7528\u4e0d\u540c\u7684\u5206\u89e3\u7b56\u7565\u3002

        Question

        \u7ed9\u5b9a\u4e09\u6839\u67f1\u5b50\uff0c\u8bb0\u4e3a A\u3001B \u548c C \u3002\u8d77\u59cb\u72b6\u6001\u4e0b\uff0c\u67f1\u5b50 A \u4e0a\u5957\u7740 \\(n\\) \u4e2a\u5706\u76d8\uff0c\u5b83\u4eec\u4ece\u4e0a\u5230\u4e0b\u6309\u7167\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u6392\u5217\u3002\u6211\u4eec\u7684\u4efb\u52a1\u662f\u8981\u628a\u8fd9 \\(n\\) \u4e2a\u5706\u76d8\u79fb\u5230\u67f1\u5b50 C \u4e0a\uff0c\u5e76\u4fdd\u6301\u5b83\u4eec\u7684\u539f\u6709\u987a\u5e8f\u4e0d\u53d8\uff08\u5982\u56fe 12-10 \u6240\u793a\uff09\u3002\u5728\u79fb\u52a8\u5706\u76d8\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\u3002

        1. \u5706\u76d8\u53ea\u80fd\u4ece\u4e00\u6839\u67f1\u5b50\u9876\u90e8\u62ff\u51fa\uff0c\u4ece\u53e6\u4e00\u6839\u67f1\u5b50\u9876\u90e8\u653e\u5165\u3002
        2. \u6bcf\u6b21\u53ea\u80fd\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\u3002
        3. \u5c0f\u5706\u76d8\u5fc5\u987b\u65f6\u523b\u4f4d\u4e8e\u5927\u5706\u76d8\u4e4b\u4e0a\u3002

        \u56fe 12-10 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898\u793a\u4f8b

        \u6211\u4eec\u5c06\u89c4\u6a21\u4e3a \\(i\\) \u7684\u6c49\u8bfa\u5854\u95ee\u9898\u8bb0\u4f5c \\(f(i)\\) \u3002\u4f8b\u5982 \\(f(3)\\) \u4ee3\u8868\u5c06 \\(3\\) \u4e2a\u5706\u76d8\u4ece A \u79fb\u52a8\u81f3 C \u7684\u6c49\u8bfa\u5854\u95ee\u9898\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#1","title":"1. \u00a0 \u8003\u8651\u57fa\u672c\u60c5\u51b5","text":"

        \u5982\u56fe 12-11 \u6240\u793a\uff0c\u5bf9\u4e8e\u95ee\u9898 \\(f(1)\\) \uff0c\u5373\u5f53\u53ea\u6709\u4e00\u4e2a\u5706\u76d8\u65f6\uff0c\u6211\u4eec\u5c06\u5b83\u76f4\u63a5\u4ece A \u79fb\u52a8\u81f3 C \u5373\u53ef\u3002

        <1><2>

        \u56fe 12-11 \u00a0 \u89c4\u6a21\u4e3a 1 \u95ee\u9898\u7684\u89e3

        \u5982\u56fe 12-12 \u6240\u793a\uff0c\u5bf9\u4e8e\u95ee\u9898 \\(f(2)\\) \uff0c\u5373\u5f53\u6709\u4e24\u4e2a\u5706\u76d8\u65f6\uff0c\u7531\u4e8e\u8981\u65f6\u523b\u6ee1\u8db3\u5c0f\u5706\u76d8\u5728\u5927\u5706\u76d8\u4e4b\u4e0a\uff0c\u56e0\u6b64\u9700\u8981\u501f\u52a9 B \u6765\u5b8c\u6210\u79fb\u52a8\u3002

        1. \u5148\u5c06\u4e0a\u9762\u7684\u5c0f\u5706\u76d8\u4ece A \u79fb\u81f3 B \u3002
        2. \u518d\u5c06\u5927\u5706\u76d8\u4ece A \u79fb\u81f3 C \u3002
        3. \u6700\u540e\u5c06\u5c0f\u5706\u76d8\u4ece B \u79fb\u81f3 C \u3002
        <1><2><3><4>

        \u56fe 12-12 \u00a0 \u89c4\u6a21\u4e3a 2 \u95ee\u9898\u7684\u89e3

        \u89e3\u51b3\u95ee\u9898 \\(f(2)\\) \u7684\u8fc7\u7a0b\u53ef\u603b\u7ed3\u4e3a\uff1a\u5c06\u4e24\u4e2a\u5706\u76d8\u501f\u52a9 B \u4ece A \u79fb\u81f3 C \u3002\u5176\u4e2d\uff0cC \u79f0\u4e3a\u76ee\u6807\u67f1\u3001B \u79f0\u4e3a\u7f13\u51b2\u67f1\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#2","title":"2. \u00a0 \u5b50\u95ee\u9898\u5206\u89e3","text":"

        \u5bf9\u4e8e\u95ee\u9898 \\(f(3)\\) \uff0c\u5373\u5f53\u6709\u4e09\u4e2a\u5706\u76d8\u65f6\uff0c\u60c5\u51b5\u53d8\u5f97\u7a0d\u5fae\u590d\u6742\u4e86\u4e00\u4e9b\u3002

        \u56e0\u4e3a\u5df2\u77e5 \\(f(1)\\) \u548c \\(f(2)\\) \u7684\u89e3\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ece\u5206\u6cbb\u89d2\u5ea6\u601d\u8003\uff0c\u5c06 A \u9876\u90e8\u7684\u4e24\u4e2a\u5706\u76d8\u770b\u4f5c\u4e00\u4e2a\u6574\u4f53\uff0c\u6267\u884c\u56fe 12-13 \u6240\u793a\u7684\u6b65\u9aa4\u3002\u8fd9\u6837\u4e09\u4e2a\u5706\u76d8\u5c31\u88ab\u987a\u5229\u5730\u4ece A \u79fb\u81f3 C \u4e86\u3002

        1. \u4ee4 B \u4e3a\u76ee\u6807\u67f1\u3001C \u4e3a\u7f13\u51b2\u67f1\uff0c\u5c06\u4e24\u4e2a\u5706\u76d8\u4ece A \u79fb\u81f3 B \u3002
        2. \u5c06 A \u4e2d\u5269\u4f59\u7684\u4e00\u4e2a\u5706\u76d8\u4ece A \u76f4\u63a5\u79fb\u52a8\u81f3 C \u3002
        3. \u4ee4 C \u4e3a\u76ee\u6807\u67f1\u3001A \u4e3a\u7f13\u51b2\u67f1\uff0c\u5c06\u4e24\u4e2a\u5706\u76d8\u4ece B \u79fb\u81f3 C \u3002
        <1><2><3><4>

        \u56fe 12-13 \u00a0 \u89c4\u6a21\u4e3a 3 \u95ee\u9898\u7684\u89e3

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u6211\u4eec\u5c06\u95ee\u9898 \\(f(3)\\) \u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(2)\\) \u548c\u5b50\u95ee\u9898 \\(f(1)\\) \u3002\u6309\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u4e4b\u540e\uff0c\u539f\u95ee\u9898\u968f\u4e4b\u5f97\u5230\u89e3\u51b3\u3002\u8fd9\u8bf4\u660e\u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff0c\u800c\u4e14\u89e3\u53ef\u4ee5\u5408\u5e76\u3002

        \u81f3\u6b64\uff0c\u6211\u4eec\u53ef\u603b\u7ed3\u51fa\u56fe 12-14 \u6240\u793a\u7684\u89e3\u51b3\u6c49\u8bfa\u5854\u95ee\u9898\u7684\u5206\u6cbb\u7b56\u7565\uff1a\u5c06\u539f\u95ee\u9898 \\(f(n)\\) \u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(n-1)\\) \u548c\u4e00\u4e2a\u5b50\u95ee\u9898 \\(f(1)\\) \uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u3002

        1. \u5c06 \\(n-1\\) \u4e2a\u5706\u76d8\u501f\u52a9 C \u4ece A \u79fb\u81f3 B \u3002
        2. \u5c06\u5269\u4f59 \\(1\\) \u4e2a\u5706\u76d8\u4ece A \u76f4\u63a5\u79fb\u81f3 C \u3002
        3. \u5c06 \\(n-1\\) \u4e2a\u5706\u76d8\u501f\u52a9 A \u4ece B \u79fb\u81f3 C \u3002

        \u5bf9\u4e8e\u8fd9\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(n-1)\\) \uff0c\u53ef\u4ee5\u901a\u8fc7\u76f8\u540c\u7684\u65b9\u5f0f\u8fdb\u884c\u9012\u5f52\u5212\u5206\uff0c\u76f4\u81f3\u8fbe\u5230\u6700\u5c0f\u5b50\u95ee\u9898 \\(f(1)\\) \u3002\u800c \\(f(1)\\) \u7684\u89e3\u662f\u5df2\u77e5\u7684\uff0c\u53ea\u9700\u4e00\u6b21\u79fb\u52a8\u64cd\u4f5c\u5373\u53ef\u3002

        \u56fe 12-14 \u00a0 \u89e3\u51b3\u6c49\u8bfa\u5854\u95ee\u9898\u7684\u5206\u6cbb\u7b56\u7565

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5728\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs(i, src, buf, tar) \uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5c06\u67f1 src \u9876\u90e8\u7684 \\(i\\) \u4e2a\u5706\u76d8\u501f\u52a9\u7f13\u51b2\u67f1 buf \u79fb\u52a8\u81f3\u76ee\u6807\u67f1 tar \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hanota.py
        def move(src: list[int], tar: list[int]):\n\"\"\"\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\"\"\"\n# \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\npan = src.pop()\n# \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.append(pan)\ndef dfs(i: int, src: list[int], buf: list[int], tar: list[int]):\n\"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i)\"\"\"\n# \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1:\nmove(src, tar)\nreturn\n# \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf)\n# \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar)\n# \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar)\ndef solve_hanota(A: list[int], B: list[int], C: list[int]):\n\"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898\"\"\"\nn = len(A)\n# \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C)\n
        hanota.cpp
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(vector<int> &src, vector<int> &tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src.back();\nsrc.pop_back();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push_back(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, vector<int> &src, vector<int> &buf, vector<int> &tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(vector<int> &A, vector<int> &B, vector<int> &C) {\nint n = A.size();\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.java
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(List<Integer> src, List<Integer> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nInteger pan = src.remove(src.size() - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, List<Integer> src, List<Integer> buf, List<Integer> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<Integer> A, List<Integer> B, List<Integer> C) {\nint n = A.size();\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.cs
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid Move(List<int> src, List<int> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src[^1];\nsrc.RemoveAt(src.Count - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.Add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid DFS(int i, List<int> src, List<int> buf, List<int> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nMove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\nDFS(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nMove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\nDFS(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid SolveHanota(List<int> A, List<int> B, List<int> C) {\nint n = A.Count;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\nDFS(n, A, B, C);\n}\n
        hanota.go
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunc move(src, tar *list.List) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\npan := src.Back()\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.PushBack(pan.Value)\n// \u79fb\u9664 src \u9876\u90e8\u5706\u76d8\nsrc.Remove(pan)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunc dfsHanota(i int, src, buf, tar *list.List) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove(src, tar)\nreturn\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfsHanota(i-1, src, tar, buf)\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar)\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfsHanota(i-1, buf, src, tar)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A, B, C *list.List) {\nn := A.Len()\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfsHanota(n, A, B, C)\n}\n
        hanota.swift
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunc move(src: inout [Int], tar: inout [Int]) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nlet pan = src.popLast()!\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.append(pan)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunc dfs(i: Int, src: inout [Int], buf: inout [Int], tar: inout [Int]) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove(src: &src, tar: &tar)\nreturn\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i: i - 1, src: &src, buf: &tar, tar: &buf)\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src: &src, tar: &tar)\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i: i - 1, src: &buf, buf: &src, tar: &tar)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A: inout [Int], B: inout [Int], C: inout [Int]) {\nlet n = A.count\n// \u5217\u8868\u5c3e\u90e8\u662f\u67f1\u5b50\u9876\u90e8\n// \u5c06 src \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(i: n, src: &A, buf: &B, tar: &C)\n}\n
        hanota.js
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunction move(src, tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nconst pan = src.pop();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunction dfs(i, src, buf, tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i === 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A, B, C) {\nconst n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.ts
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunction move(src: number[], tar: number[]): void {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nconst pan = src.pop();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunction dfs(i: number, src: number[], buf: number[], tar: number[]): void {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i === 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A: number[], B: number[], C: number[]): void {\nconst n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.dart
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(List<int> src, List<int> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src.removeLast();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, List<int> src, List<int> buf, List<int> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<int> A, List<int> B, List<int> C) {\nint n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.rs
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfn move_pan(src: &mut Vec<i32>, tar: &mut Vec<i32>) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nlet pan = src.remove(src.len() - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfn dfs(i: i32, src: &mut Vec<i32>, buf: &mut Vec<i32>, tar: &mut Vec<i32>) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove_pan(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove_pan(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfn solve_hanota(A: &mut Vec<i32>, B: &mut Vec<i32>, C: &mut Vec<i32>) {\nlet n = A.len() as i32;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.c
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(int *src, int *srcSize, int *tar, int *tarSize) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src[*srcSize - 1];\nsrc[*srcSize - 1] = 0;\n(*srcSize)--;\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar[*tarSize] = pan;\n(*tarSize)++;\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, int *src, int *srcSize, int *buf, int *bufSize, int *tar, int *tarSize) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, srcSize, tar, tarSize);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, srcSize, tar, tarSize, buf, bufSize);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, srcSize, tar, tarSize);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, bufSize, src, srcSize, tar, tarSize);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(int *A, int *ASize, int *B, int *BSize, int *C, int *CSize) {\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(*ASize, A, ASize, B, BSize, C, CSize);\n}\n
        hanota.zig
        [class]{}-[func]{move}\n[class]{}-[func]{dfs}\n[class]{}-[func]{solveHanota}\n

        \u5982\u56fe 12-15 \u6240\u793a\uff0c\u6c49\u8bfa\u5854\u95ee\u9898\u5f62\u6210\u4e00\u68f5\u9ad8\u5ea6\u4e3a \\(n\\) \u7684\u9012\u5f52\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u5bf9\u5e94\u4e00\u4e2a\u5f00\u542f\u7684 dfs() \u51fd\u6570\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u56fe 12-15 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898\u7684\u9012\u5f52\u6811

        Quote

        \u6c49\u8bfa\u5854\u95ee\u9898\u6e90\u81ea\u4e00\u4e2a\u53e4\u8001\u7684\u4f20\u8bf4\u3002\u5728\u53e4\u5370\u5ea6\u7684\u4e00\u4e2a\u5bfa\u5e99\u91cc\uff0c\u50e7\u4fa3\u4eec\u6709\u4e09\u6839\u9ad8\u5927\u7684\u94bb\u77f3\u67f1\u5b50\uff0c\u4ee5\u53ca \\(64\\) \u4e2a\u5927\u5c0f\u4e0d\u4e00\u7684\u91d1\u5706\u76d8\u3002\u50e7\u4fa3\u4eec\u4e0d\u65ad\u5730\u79fb\u52a8\u5706\u76d8\uff0c\u4ed6\u4eec\u76f8\u4fe1\u5728\u6700\u540e\u4e00\u4e2a\u5706\u76d8\u88ab\u6b63\u786e\u653e\u7f6e\u7684\u90a3\u4e00\u523b\uff0c\u8fd9\u4e2a\u4e16\u754c\u5c31\u4f1a\u7ed3\u675f\u3002

        \u7136\u800c\uff0c\u5373\u4f7f\u50e7\u4fa3\u4eec\u6bcf\u79d2\u949f\u79fb\u52a8\u4e00\u6b21\uff0c\u603b\u5171\u9700\u8981\u5927\u7ea6 \\(2^{64} \\approx 1.84\u00d710^{19}\\) \u79d2\uff0c\u5408\u7ea6 \\(5850\\) \u4ebf\u5e74\uff0c\u8fdc\u8fdc\u8d85\u8fc7\u4e86\u73b0\u5728\u5bf9\u5b87\u5b99\u5e74\u9f84\u7684\u4f30\u8ba1\u3002\u6240\u4ee5\uff0c\u5018\u82e5\u8fd9\u4e2a\u4f20\u8bf4\u662f\u771f\u7684\uff0c\u6211\u4eec\u5e94\u8be5\u4e0d\u9700\u8981\u62c5\u5fc3\u4e16\u754c\u672b\u65e5\u7684\u5230\u6765\u3002

        "},{"location":"chapter_divide_and_conquer/summary/","title":"12.5 \u00a0 \u5c0f\u7ed3","text":"
        • \u5206\u6cbb\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u7b97\u6cd5\u8bbe\u8ba1\u7b56\u7565\uff0c\u5305\u62ec\u5206\uff08\u5212\u5206\uff09\u548c\u6cbb\uff08\u5408\u5e76\uff09\u4e24\u4e2a\u9636\u6bb5\uff0c\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\u3002
        • \u5224\u65ad\u662f\u5426\u662f\u5206\u6cbb\u7b97\u6cd5\u95ee\u9898\u7684\u4f9d\u636e\u5305\u62ec\uff1a\u95ee\u9898\u80fd\u5426\u5206\u89e3\u3001\u5b50\u95ee\u9898\u662f\u5426\u72ec\u7acb\u3001\u5b50\u95ee\u9898\u80fd\u5426\u5408\u5e76\u3002
        • \u5f52\u5e76\u6392\u5e8f\u662f\u5206\u6cbb\u7b56\u7565\u7684\u5178\u578b\u5e94\u7528\uff0c\u5176\u9012\u5f52\u5730\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u7b49\u957f\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u76f4\u5230\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\u65f6\u5f00\u59cb\u9010\u5c42\u5408\u5e76\uff0c\u4ece\u800c\u5b8c\u6210\u6392\u5e8f\u3002
        • \u5f15\u5165\u5206\u6cbb\u7b56\u7565\u5f80\u5f80\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u7b56\u7565\u51cf\u5c11\u4e86\u64cd\u4f5c\u6570\u91cf\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u540e\u6709\u5229\u4e8e\u7cfb\u7edf\u7684\u5e76\u884c\u4f18\u5316\u3002
        • \u5206\u6cbb\u65e2\u53ef\u4ee5\u89e3\u51b3\u8bb8\u591a\u7b97\u6cd5\u95ee\u9898\uff0c\u4e5f\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u8bbe\u8ba1\u4e2d\uff0c\u5904\u5904\u53ef\u89c1\u5176\u8eab\u5f71\u3002
        • \u76f8\u8f83\u4e8e\u66b4\u529b\u641c\u7d22\uff0c\u81ea\u9002\u5e94\u641c\u7d22\u6548\u7387\u66f4\u9ad8\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u7684\u641c\u7d22\u7b97\u6cd5\u901a\u5e38\u662f\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u5b9e\u73b0\u7684\u3002
        • \u4e8c\u5206\u67e5\u627e\u662f\u5206\u6cbb\u7b56\u7565\u7684\u53e6\u4e00\u4e2a\u5178\u578b\u5e94\u7528\uff0c\u5b83\u4e0d\u5305\u542b\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\u7684\u6b65\u9aa4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u5206\u6cbb\u5b9e\u73b0\u4e8c\u5206\u67e5\u627e\u3002
        • \u5728\u6784\u5efa\u4e8c\u53c9\u6811\u7684\u95ee\u9898\u4e2d\uff0c\u6784\u5efa\u6811\uff08\u539f\u95ee\u9898\uff09\u53ef\u4ee5\u5212\u5206\u4e3a\u6784\u5efa\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5212\u5206\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u7684\u7d22\u5f15\u533a\u95f4\u6765\u5b9e\u73b0\u3002
        • \u5728\u6c49\u8bfa\u5854\u95ee\u9898\u4e2d\uff0c\u4e00\u4e2a\u89c4\u6a21\u4e3a \\(n\\) \u7684\u95ee\u9898\u53ef\u4ee5\u5212\u5206\u4e3a\u4e24\u4e2a\u89c4\u6a21\u4e3a \\(n-1\\) \u7684\u5b50\u95ee\u9898\u548c\u4e00\u4e2a\u89c4\u6a21\u4e3a \\(1\\) \u7684\u5b50\u95ee\u9898\u3002\u6309\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u540e\uff0c\u539f\u95ee\u9898\u968f\u4e4b\u5f97\u5230\u89e3\u51b3\u3002
        "},{"location":"chapter_dynamic_programming/","title":"\u7b2c 14 \u7ae0 \u00a0 \u52a8\u6001\u89c4\u5212","text":"

        Abstract

        \u5c0f\u6eaa\u6c47\u5165\u6cb3\u6d41\uff0c\u6c5f\u6cb3\u6c47\u5165\u5927\u6d77\u3002

        \u52a8\u6001\u89c4\u5212\u5c06\u5c0f\u95ee\u9898\u7684\u89e3\u6c47\u96c6\u6210\u5927\u95ee\u9898\u7684\u7b54\u6848\uff0c\u4e00\u6b65\u6b65\u5f15\u9886\u6211\u4eec\u8d70\u5411\u89e3\u51b3\u95ee\u9898\u7684\u5f7c\u5cb8\u3002

        "},{"location":"chapter_dynamic_programming/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 14.1 \u00a0 \u521d\u63a2\u52a8\u6001\u89c4\u5212
        • 14.2 \u00a0 DP \u95ee\u9898\u7279\u6027
        • 14.3 \u00a0 DP \u89e3\u9898\u601d\u8def
        • 14.4 \u00a0 0-1 \u80cc\u5305\u95ee\u9898
        • 14.5 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898
        • 14.6 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898
        • 14.7 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_dynamic_programming/dp_problem_features/","title":"14.2 \u00a0 \u52a8\u6001\u89c4\u5212\u95ee\u9898\u7279\u6027","text":"

        \u5728\u4e0a\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u52a8\u6001\u89c4\u5212\u662f\u5982\u4f55\u901a\u8fc7\u5b50\u95ee\u9898\u5206\u89e3\u6765\u6c42\u89e3\u539f\u95ee\u9898\u7684\u3002\u5b9e\u9645\u4e0a\uff0c\u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u901a\u7528\u7684\u7b97\u6cd5\u601d\u8def\uff0c\u5728\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u3001\u56de\u6eaf\u4e2d\u7684\u4fa7\u91cd\u70b9\u4e0d\u540c\u3002

        • \u5206\u6cbb\u7b97\u6cd5\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\u5212\u5206\u4e3a\u591a\u4e2a\u76f8\u4e92\u72ec\u7acb\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u6700\u5c0f\u5b50\u95ee\u9898\uff0c\u5e76\u5728\u56de\u6eaf\u4e2d\u5408\u5e76\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u6700\u7ec8\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002
        • \u52a8\u6001\u89c4\u5212\u4e5f\u5bf9\u95ee\u9898\u8fdb\u884c\u9012\u5f52\u5206\u89e3\uff0c\u4f46\u4e0e\u5206\u6cbb\u7b97\u6cd5\u7684\u4e3b\u8981\u533a\u522b\u662f\uff0c\u52a8\u6001\u89c4\u5212\u4e2d\u7684\u5b50\u95ee\u9898\u662f\u76f8\u4e92\u4f9d\u8d56\u7684\uff0c\u5728\u5206\u89e3\u8fc7\u7a0b\u4e2d\u4f1a\u51fa\u73b0\u8bb8\u591a\u91cd\u53e0\u5b50\u95ee\u9898\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u5728\u5c1d\u8bd5\u548c\u56de\u9000\u4e2d\u7a77\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u89e3\uff0c\u5e76\u901a\u8fc7\u526a\u679d\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u641c\u7d22\u5206\u652f\u3002\u539f\u95ee\u9898\u7684\u89e3\u7531\u4e00\u7cfb\u5217\u51b3\u7b56\u6b65\u9aa4\u6784\u6210\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6bcf\u4e2a\u51b3\u7b56\u6b65\u9aa4\u4e4b\u524d\u7684\u5b50\u5e8f\u5217\u770b\u4f5c\u4e00\u4e2a\u5b50\u95ee\u9898\u3002

        \u5b9e\u9645\u4e0a\uff0c\u52a8\u6001\u89c4\u5212\u5e38\u7528\u6765\u6c42\u89e3\u6700\u4f18\u5316\u95ee\u9898\uff0c\u5b83\u4eec\u4e0d\u4ec5\u5305\u542b\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u8fd8\u5177\u6709\u53e6\u5916\u4e24\u5927\u7279\u6027\uff1a\u6700\u4f18\u5b50\u7ed3\u6784\u3001\u65e0\u540e\u6548\u6027\u3002

        "},{"location":"chapter_dynamic_programming/dp_problem_features/#1421","title":"14.2.1 \u00a0 \u6700\u4f18\u5b50\u7ed3\u6784","text":"

        \u6211\u4eec\u5bf9\u722c\u697c\u68af\u95ee\u9898\u7a0d\u4f5c\u6539\u52a8\uff0c\u4f7f\u4e4b\u66f4\u52a0\u9002\u5408\u5c55\u793a\u6700\u4f18\u5b50\u7ed3\u6784\u6982\u5ff5\u3002

        \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7

        \u7ed9\u5b9a\u4e00\u4e2a\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u6bcf\u4e00\u9636\u697c\u68af\u4e0a\u90fd\u8d34\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u8868\u793a\u4f60\u5728\u8be5\u53f0\u9636\u6240\u9700\u8981\u4ed8\u51fa\u7684\u4ee3\u4ef7\u3002\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 \\(cost\\) \uff0c\u5176\u4e2d \\(cost[i]\\) \u8868\u793a\u5728\u7b2c \\(i\\) \u4e2a\u53f0\u9636\u9700\u8981\u4ed8\u51fa\u7684\u4ee3\u4ef7\uff0c\\(cost[0]\\) \u4e3a\u5730\u9762\uff08\u8d77\u59cb\u70b9\uff09\u3002\u8bf7\u8ba1\u7b97\u6700\u5c11\u9700\u8981\u4ed8\u51fa\u591a\u5c11\u4ee3\u4ef7\u624d\u80fd\u5230\u8fbe\u9876\u90e8\uff1f

        \u5982\u56fe 14-6 \u6240\u793a\uff0c\u82e5\u7b2c \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u9636\u7684\u4ee3\u4ef7\u5206\u522b\u4e3a \\(1\\)\u3001\\(10\\)\u3001\\(1\\) \uff0c\u5219\u4ece\u5730\u9762\u722c\u5230\u7b2c \\(3\\) \u9636\u7684\u6700\u5c0f\u4ee3\u4ef7\u4e3a \\(2\\) \u3002

        \u56fe 14-6 \u00a0 \u722c\u5230\u7b2c 3 \u9636\u7684\u6700\u5c0f\u4ee3\u4ef7

        \u8bbe \\(dp[i]\\) \u4e3a\u722c\u5230\u7b2c \\(i\\) \u9636\u7d2f\u8ba1\u4ed8\u51fa\u7684\u4ee3\u4ef7\uff0c\u7531\u4e8e\u7b2c \\(i\\) \u9636\u53ea\u53ef\u80fd\u4ece \\(i - 1\\) \u9636\u6216 \\(i - 2\\) \u9636\u8d70\u6765\uff0c\u56e0\u6b64 \\(dp[i]\\) \u53ea\u53ef\u80fd\u7b49\u4e8e \\(dp[i - 1] + cost[i]\\) \u6216 \\(dp[i - 2] + cost[i]\\) \u3002\u4e3a\u4e86\u5c3d\u53ef\u80fd\u51cf\u5c11\u4ee3\u4ef7\uff0c\u6211\u4eec\u5e94\u8be5\u9009\u62e9\u4e24\u8005\u4e2d\u8f83\u5c0f\u7684\u90a3\u4e00\u4e2a\uff1a

        \\[ dp[i] = \\min(dp[i-1], dp[i-2]) + cost[i] \\]

        \u8fd9\u4fbf\u53ef\u4ee5\u5f15\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u542b\u4e49\uff1a\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u662f\u4ece\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6784\u5efa\u5f97\u6765\u7684\u3002

        \u672c\u9898\u663e\u7136\u5177\u6709\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u6211\u4eec\u4ece\u4e24\u4e2a\u5b50\u95ee\u9898\u6700\u4f18\u89e3 \\(dp[i-1]\\) \u548c \\(dp[i-2]\\) \u4e2d\u6311\u9009\u51fa\u8f83\u4f18\u7684\u90a3\u4e00\u4e2a\uff0c\u5e76\u7528\u5b83\u6784\u5efa\u51fa\u539f\u95ee\u9898 \\(dp[i]\\) \u7684\u6700\u4f18\u89e3\u3002

        \u90a3\u4e48\uff0c\u4e0a\u4e00\u8282\u7684\u722c\u697c\u68af\u9898\u76ee\u6709\u6ca1\u6709\u6700\u4f18\u5b50\u7ed3\u6784\u5462\uff1f\u5b83\u7684\u76ee\u6807\u662f\u6c42\u89e3\u65b9\u6848\u6570\u91cf\uff0c\u770b\u4f3c\u662f\u4e00\u4e2a\u8ba1\u6570\u95ee\u9898\uff0c\u4f46\u5982\u679c\u6362\u4e00\u79cd\u95ee\u6cd5\uff1a\u201c\u6c42\u89e3\u6700\u5927\u65b9\u6848\u6570\u91cf\u201d\u3002\u6211\u4eec\u610f\u5916\u5730\u53d1\u73b0\uff0c\u867d\u7136\u9898\u76ee\u4fee\u6539\u524d\u540e\u662f\u7b49\u4ef7\u7684\uff0c\u4f46\u6700\u4f18\u5b50\u7ed3\u6784\u6d6e\u73b0\u51fa\u6765\u4e86\uff1a\u7b2c \\(n\\) \u9636\u6700\u5927\u65b9\u6848\u6570\u91cf\u7b49\u4e8e\u7b2c \\(n-1\\) \u9636\u548c\u7b2c \\(n-2\\) \u9636\u6700\u5927\u65b9\u6848\u6570\u91cf\u4e4b\u548c\u3002\u6240\u4ee5\u8bf4\uff0c\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u89e3\u91ca\u65b9\u5f0f\u6bd4\u8f83\u7075\u6d3b\uff0c\u5728\u4e0d\u540c\u95ee\u9898\u4e2d\u4f1a\u6709\u4e0d\u540c\u7684\u542b\u4e49\u3002

        \u6839\u636e\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u4ee5\u53ca\u521d\u59cb\u72b6\u6001 \\(dp[1] = cost[1]\\) \u548c \\(dp[2] = cost[2]\\) \uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u52a8\u6001\u89c4\u5212\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_cost_climbing_stairs_dp.py
        def min_cost_climbing_stairs_dp(cost: list[int]) -> int:\n\"\"\"\u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(cost) - 1\nif n == 1 or n == 2:\nreturn cost[n]\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [0] * (n + 1)\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1], dp[2] = cost[1], cost[2]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\nreturn dp[n]\n
        min_cost_climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(vector<int> &cost) {\nint n = cost.size() - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<int> dp(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.java
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(int[] cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint MinCostClimbingStairsDP(int[] cost) {\nint n = cost.Length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = Math.Min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.go
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDP(cost []int) int {\nn := len(cost) - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nmin := func(a, b int) int {\nif a < b {\nreturn a\n}\nreturn b\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1]\ndp[2] = cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i] = min(dp[i-1], dp[i-2]) + cost[i]\n}\nreturn dp[n]\n}\n
        min_cost_climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDP(cost: [Int]) -> Int {\nlet n = cost.count - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: 0, count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1]\ndp[2] = cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n}\nreturn dp[n]\n}\n
        min_cost_climbing_stairs_dp.js
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDP(cost) {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDP(cost: Array<number>): number {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(List<int> cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2) return cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<int> dp = List.filled(n + 1, 0);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfn min_cost_climbing_stairs_dp(cost: &[i32]) -> i32 {\nlet n = cost.len() - 1;\nif n == 1 || n == 2 { return cost[n]; }\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![-1; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i] = cmp::min(dp[i - 1], dp[i - 2]) + cost[i];\n}\ndp[n]\n}\n
        min_cost_climbing_stairs_dp.c
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(int cost[], int costSize) {\nint n = costSize - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint *dp = calloc(n + 1, sizeof(int));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = myMin(dp[i - 1], dp[i - 2]) + cost[i];\n}\nint res = dp[n];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        min_cost_climbing_stairs_dp.zig
        // \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212\nfn minCostClimbingStairsDP(comptime cost: []i32) i32 {\ncomptime var n = cost.len - 1;\nif (n == 1 or n == 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_]i32{-1} ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i] = @min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n

        \u56fe 14-7 \u5c55\u793a\u4e86\u4ee5\u4e0a\u4ee3\u7801\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b\u3002

        \u56fe 14-7 \u00a0 \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u672c\u9898\u4e5f\u53ef\u4ee5\u8fdb\u884c\u7a7a\u95f4\u4f18\u5316\uff0c\u5c06\u4e00\u7ef4\u538b\u7f29\u81f3\u96f6\u7ef4\uff0c\u4f7f\u5f97\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_cost_climbing_stairs_dp.py
        def min_cost_climbing_stairs_dp_comp(cost: list[int]) -> int:\n\"\"\"\u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(cost) - 1\nif n == 1 or n == 2:\nreturn cost[n]\na, b = cost[1], cost[2]\nfor i in range(3, n + 1):\na, b = b, min(a, b) + cost[i]\nreturn b\n
        min_cost_climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(vector<int> &cost) {\nint n = cost.size() - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.java
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(int[] cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint MinCostClimbingStairsDPComp(int[] cost) {\nint n = cost.Length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = Math.Min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.go
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDPComp(cost []int) int {\nn := len(cost) - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nmin := func(a, b int) int {\nif a < b {\nreturn a\n}\nreturn b\n}\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\na, b := cost[1], cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ntmp := b\nb = min(a, tmp) + cost[i]\na = tmp\n}\nreturn b\n}\n
        min_cost_climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDPComp(cost: [Int]) -> Int {\nlet n = cost.count - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nvar (a, b) = (cost[1], cost[2])\nfor i in stride(from: 3, through: n, by: 1) {\n(a, b) = (b, min(a, b) + cost[i])\n}\nreturn b\n}\n
        min_cost_climbing_stairs_dp.js
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDPComp(cost) {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\nlet a = cost[1],\nb = cost[2];\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDPComp(cost: Array<number>): number {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\nlet a = cost[1],\nb = cost[2];\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(List<int> cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2) return cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn min_cost_climbing_stairs_dp_comp(cost: &[i32]) -> i32 {\nlet n = cost.len() - 1;\nif n == 1 || n == 2 { return cost[n] };\nlet (mut a, mut b) = (cost[1], cost[2]);\nfor i in 3..=n {\nlet tmp = b;\nb = cmp::min(a, tmp) + cost[i];\na = tmp;\n}\nb\n}\n
        min_cost_climbing_stairs_dp.c
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(int cost[], int costSize) {\nint n = costSize - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = myMin(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.zig
        // \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn minCostClimbingStairsDPComp(cost: []i32) i32 {\nvar n = cost.len - 1;\nif (n == 1 or n == 2) {\nreturn cost[n];\n}\nvar a = cost[1];\nvar b = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\nvar tmp = b;\nb = @min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        "},{"location":"chapter_dynamic_programming/dp_problem_features/#1422","title":"14.2.2 \u00a0 \u65e0\u540e\u6548\u6027","text":"

        \u65e0\u540e\u6548\u6027\u662f\u52a8\u6001\u89c4\u5212\u80fd\u591f\u6709\u6548\u89e3\u51b3\u95ee\u9898\u7684\u91cd\u8981\u7279\u6027\u4e4b\u4e00\uff0c\u5176\u5b9a\u4e49\u4e3a\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u786e\u5b9a\u7684\u72b6\u6001\uff0c\u5b83\u7684\u672a\u6765\u53d1\u5c55\u53ea\u4e0e\u5f53\u524d\u72b6\u6001\u6709\u5173\uff0c\u800c\u4e0e\u8fc7\u53bb\u7ecf\u5386\u7684\u6240\u6709\u72b6\u6001\u65e0\u5173\u3002

        \u4ee5\u722c\u697c\u68af\u95ee\u9898\u4e3a\u4f8b\uff0c\u7ed9\u5b9a\u72b6\u6001 \\(i\\) \uff0c\u5b83\u4f1a\u53d1\u5c55\u51fa\u72b6\u6001 \\(i+1\\) \u548c\u72b6\u6001 \\(i+2\\) \uff0c\u5206\u522b\u5bf9\u5e94\u8df3 \\(1\\) \u6b65\u548c\u8df3 \\(2\\) \u6b65\u3002\u5728\u505a\u51fa\u8fd9\u4e24\u79cd\u9009\u62e9\u65f6\uff0c\u6211\u4eec\u65e0\u987b\u8003\u8651\u72b6\u6001 \\(i\\) \u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5b83\u4eec\u5bf9\u72b6\u6001 \\(i\\) \u7684\u672a\u6765\u6ca1\u6709\u5f71\u54cd\u3002

        \u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u7ed9\u722c\u697c\u68af\u95ee\u9898\u6dfb\u52a0\u4e00\u4e2a\u7ea6\u675f\uff0c\u60c5\u51b5\u5c31\u4e0d\u4e00\u6837\u4e86\u3002

        \u5e26\u7ea6\u675f\u722c\u697c\u68af

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u4f46\u4e0d\u80fd\u8fde\u7eed\u4e24\u8f6e\u8df3 \\(1\\) \u9636\uff0c\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5982\u56fe 14-8 \u6240\u793a\uff0c\u722c\u4e0a\u7b2c \\(3\\) \u9636\u4ec5\u5269 \\(2\\) \u79cd\u53ef\u884c\u65b9\u6848\uff0c\u5176\u4e2d\u8fde\u7eed\u4e09\u6b21\u8df3 \\(1\\) \u9636\u7684\u65b9\u6848\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\uff0c\u56e0\u6b64\u88ab\u820d\u5f03\u3002

        \u56fe 14-8 \u00a0 \u5e26\u7ea6\u675f\u722c\u5230\u7b2c 3 \u9636\u7684\u65b9\u6848\u6570\u91cf

        \u5728\u8be5\u95ee\u9898\u4e2d\uff0c\u5982\u679c\u4e0a\u4e00\u8f6e\u662f\u8df3 \\(1\\) \u9636\u4e0a\u6765\u7684\uff0c\u90a3\u4e48\u4e0b\u4e00\u8f6e\u5c31\u5fc5\u987b\u8df3 \\(2\\) \u9636\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4e0b\u4e00\u6b65\u9009\u62e9\u4e0d\u80fd\u7531\u5f53\u524d\u72b6\u6001\uff08\u5f53\u524d\u6240\u5728\u697c\u68af\u9636\u6570\uff09\u72ec\u7acb\u51b3\u5b9a\uff0c\u8fd8\u548c\u524d\u4e00\u4e2a\u72b6\u6001\uff08\u4e0a\u8f6e\u6240\u5728\u697c\u68af\u9636\u6570\uff09\u6709\u5173\u3002

        \u4e0d\u96be\u53d1\u73b0\uff0c\u6b64\u95ee\u9898\u5df2\u4e0d\u6ee1\u8db3\u65e0\u540e\u6548\u6027\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b \\(dp[i] = dp[i-1] + dp[i-2]\\) \u4e5f\u5931\u6548\u4e86\uff0c\u56e0\u4e3a \\(dp[i-1]\\) \u4ee3\u8868\u672c\u8f6e\u8df3 \\(1\\) \u9636\uff0c\u4f46\u5176\u4e2d\u5305\u542b\u4e86\u8bb8\u591a\u201c\u4e0a\u4e00\u8f6e\u662f\u8df3 \\(1\\) \u9636\u4e0a\u6765\u7684\u201d\u65b9\u6848\uff0c\u800c\u4e3a\u4e86\u6ee1\u8db3\u7ea6\u675f\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u5c06 \\(dp[i-1]\\) \u76f4\u63a5\u8ba1\u5165 \\(dp[i]\\) \u4e2d\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6269\u5c55\u72b6\u6001\u5b9a\u4e49\uff1a\u72b6\u6001 \\([i, j]\\) \u8868\u793a\u5904\u5728\u7b2c \\(i\\) \u9636\u5e76\u4e14\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(j\\) \u9636\uff0c\u5176\u4e2d \\(j \\in \\{1, 2\\}\\) \u3002\u6b64\u72b6\u6001\u5b9a\u4e49\u6709\u6548\u5730\u533a\u5206\u4e86\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(1\\) \u9636\u8fd8\u662f \\(2\\) \u9636\uff0c\u6211\u4eec\u53ef\u4ee5\u636e\u6b64\u6765\u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u4ece\u4f55\u800c\u6765\u7684\u3002

        • \u5f53\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(1\\) \u9636\u65f6\uff0c\u4e0a\u4e0a\u4e00\u8f6e\u53ea\u80fd\u9009\u62e9\u8df3 \\(2\\) \u9636\uff0c\u5373 \\(dp[i, 1]\\) \u53ea\u80fd\u4ece \\(dp[i-1, 2]\\) \u8f6c\u79fb\u8fc7\u6765\u3002
        • \u5f53\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(2\\) \u9636\u65f6\uff0c\u4e0a\u4e0a\u4e00\u8f6e\u53ef\u9009\u62e9\u8df3 \\(1\\) \u9636\u6216\u8df3 \\(2\\) \u9636\uff0c\u5373 \\(dp[i, 2]\\) \u53ef\u4ee5\u4ece \\(dp[i-2, 1]\\) \u6216 \\(dp[i-2, 2]\\) \u8f6c\u79fb\u8fc7\u6765\u3002

        \u5982\u56fe 14-9 \u6240\u793a\uff0c\u5728\u8be5\u5b9a\u4e49\u4e0b\uff0c\\(dp[i, j]\\) \u8868\u793a\u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u65b9\u6848\u6570\u3002\u6b64\u65f6\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ \\begin{cases} dp[i, 1] = dp[i-1, 2] \\\\ dp[i, 2] = dp[i-2, 1] + dp[i-2, 2] \\end{cases} \\]

        \u56fe 14-9 \u00a0 \u8003\u8651\u7ea6\u675f\u4e0b\u7684\u9012\u63a8\u5173\u7cfb

        \u6700\u7ec8\uff0c\u8fd4\u56de \\(dp[n, 1] + dp[n, 2]\\) \u5373\u53ef\uff0c\u4e24\u8005\u4e4b\u548c\u4ee3\u8868\u722c\u5230\u7b2c \\(n\\) \u9636\u7684\u65b9\u6848\u603b\u6570\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_constraint_dp.py
        def climbing_stairs_constraint_dp(n: int) -> int:\n\"\"\"\u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn 1\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [[0] * 3 for _ in range(n + 1)]\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1], dp[1][2] = 1, 0\ndp[2][1], dp[2][2] = 0, 1\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i][1] = dp[i - 1][2]\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2]\nreturn dp[n][1] + dp[n][2]\n
        climbing_stairs_constraint_dp.cpp
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<vector<int>> dp(n + 1, vector<int>(3, 0));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.java
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[][] dp = new int[n + 1][3];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.cs
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[,] dp = new int[n + 1, 3];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1, 1] = 1;\ndp[1, 2] = 0;\ndp[2, 1] = 0;\ndp[2, 2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i, 1] = dp[i - 1, 2];\ndp[i, 2] = dp[i - 2, 1] + dp[i - 2, 2];\n}\nreturn dp[n, 1] + dp[n, 2];\n}\n
        climbing_stairs_constraint_dp.go
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsConstraintDP(n int) int {\nif n == 1 || n == 2 {\nreturn 1\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([][3]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1\ndp[1][2] = 0\ndp[2][1] = 0\ndp[2][2] = 1\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i][1] = dp[i-1][2]\ndp[i][2] = dp[i-2][1] + dp[i-2][2]\n}\nreturn dp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.swift
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsConstraintDP(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn 1\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: Array(repeating: 0, count: 3), count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1\ndp[1][2] = 0\ndp[2][1] = 0\ndp[2][2] = 1\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i][1] = dp[i - 1][2]\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n}\nreturn dp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.js
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsConstraintDP(n) {\nif (n === 1 || n === 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = Array.from(new Array(n + 1), () => new Array(3));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.ts
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsConstraintDP(n: number): number {\nif (n === 1 || n === 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = Array.from({ length: n + 1 }, () => new Array(3));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.dart
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(3, 0));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.rs
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_constraint_dp(n: usize) -> i32 {\nif n == 1 || n == 2 { return 1 };\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![vec![-1; 3]; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\ndp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.c
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(3, sizeof(int));\n}\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nint res = dp[n][1] + dp[n][2];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        climbing_stairs_constraint_dp.zig
        // \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\nfn climbingStairsConstraintDP(comptime n: usize) i32 {\nif (n == 1 or n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_][3]i32{ [_]i32{ -1, -1, -1 } } ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n

        \u5728\u4e0a\u9762\u7684\u6848\u4f8b\u4e2d\uff0c\u7531\u4e8e\u4ec5\u9700\u591a\u8003\u8651\u524d\u9762\u4e00\u4e2a\u72b6\u6001\uff0c\u56e0\u6b64\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55\u72b6\u6001\u5b9a\u4e49\uff0c\u4f7f\u5f97\u95ee\u9898\u91cd\u65b0\u6ee1\u8db3\u65e0\u540e\u6548\u6027\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u95ee\u9898\u5177\u6709\u975e\u5e38\u4e25\u91cd\u7684\u201c\u6709\u540e\u6548\u6027\u201d\u3002

        \u722c\u697c\u68af\u4e0e\u969c\u788d\u751f\u6210

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\u3002\u89c4\u5b9a\u5f53\u722c\u5230\u7b2c \\(i\\) \u9636\u65f6\uff0c\u7cfb\u7edf\u81ea\u52a8\u4f1a\u5728\u7b2c \\(2i\\) \u9636\u4e0a\u653e\u4e0a\u969c\u788d\u7269\uff0c\u4e4b\u540e\u6240\u6709\u8f6e\u90fd\u4e0d\u5141\u8bb8\u8df3\u5230\u7b2c \\(2i\\) \u9636\u4e0a\u3002\u4f8b\u5982\uff0c\u524d\u4e24\u8f6e\u5206\u522b\u8df3\u5230\u4e86\u7b2c \\(2\\)\u3001\\(3\\) \u9636\u4e0a\uff0c\u5219\u4e4b\u540e\u5c31\u4e0d\u80fd\u8df3\u5230\u7b2c \\(4\\)\u3001\\(6\\) \u9636\u4e0a\u3002\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\uff0c\u4e0b\u6b21\u8df3\u8dc3\u4f9d\u8d56\u8fc7\u53bb\u6240\u6709\u7684\u72b6\u6001\uff0c\u56e0\u4e3a\u6bcf\u4e00\u6b21\u8df3\u8dc3\u90fd\u4f1a\u5728\u66f4\u9ad8\u7684\u9636\u68af\u4e0a\u8bbe\u7f6e\u969c\u788d\uff0c\u5e76\u5f71\u54cd\u672a\u6765\u7684\u8df3\u8dc3\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u95ee\u9898\uff0c\u52a8\u6001\u89c4\u5212\u5f80\u5f80\u96be\u4ee5\u89e3\u51b3\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u590d\u6742\u7684\u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff08\u4f8b\u5982\u65c5\u884c\u5546\u95ee\u9898\uff09\u4e0d\u6ee1\u8db3\u65e0\u540e\u6548\u6027\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u95ee\u9898\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9009\u62e9\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\uff0c\u4f8b\u5982\u542f\u53d1\u5f0f\u641c\u7d22\u3001\u9057\u4f20\u7b97\u6cd5\u3001\u5f3a\u5316\u5b66\u4e60\u7b49\uff0c\u4ece\u800c\u5728\u6709\u9650\u65f6\u95f4\u5185\u5f97\u5230\u53ef\u7528\u7684\u5c40\u90e8\u6700\u4f18\u89e3\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/","title":"14.3 \u00a0 \u52a8\u6001\u89c4\u5212\u89e3\u9898\u601d\u8def","text":"

        \u4e0a\u4e24\u8282\u4ecb\u7ecd\u4e86\u52a8\u6001\u89c4\u5212\u95ee\u9898\u7684\u4e3b\u8981\u7279\u5f81\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u8d77\u63a2\u7a76\u4e24\u4e2a\u66f4\u52a0\u5b9e\u7528\u7684\u95ee\u9898\u3002

        1. \u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u95ee\u9898\u662f\u4e0d\u662f\u52a8\u6001\u89c4\u5212\u95ee\u9898\uff1f
        2. \u6c42\u89e3\u52a8\u6001\u89c4\u5212\u95ee\u9898\u8be5\u4ece\u4f55\u5904\u5165\u624b\uff0c\u5b8c\u6574\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f
        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1431","title":"14.3.1 \u00a0 \u95ee\u9898\u5224\u65ad","text":"

        \u603b\u7684\u6765\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u95ee\u9898\u5305\u542b\u91cd\u53e0\u5b50\u95ee\u9898\u3001\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5e76\u6ee1\u8db3\u65e0\u540e\u6548\u6027\uff0c\u90a3\u4e48\u5b83\u901a\u5e38\u9002\u5408\u7528\u52a8\u6001\u89c4\u5212\u6c42\u89e3\u3002\u7136\u800c\uff0c\u6211\u4eec\u5f88\u96be\u4ece\u95ee\u9898\u63cf\u8ff0\u4e2d\u76f4\u63a5\u63d0\u53d6\u51fa\u8fd9\u4e9b\u7279\u6027\u3002\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f1a\u653e\u5bbd\u6761\u4ef6\uff0c\u5148\u89c2\u5bdf\u95ee\u9898\u662f\u5426\u9002\u5408\u4f7f\u7528\u56de\u6eaf\uff08\u7a77\u4e3e\uff09\u89e3\u51b3\u3002

        \u9002\u5408\u7528\u56de\u6eaf\u89e3\u51b3\u7684\u95ee\u9898\u901a\u5e38\u6ee1\u8db3\u201c\u51b3\u7b56\u6811\u6a21\u578b\u201d\uff0c\u8fd9\u79cd\u95ee\u9898\u53ef\u4ee5\u4f7f\u7528\u6811\u5f62\u7ed3\u6784\u6765\u63cf\u8ff0\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u51b3\u7b56\uff0c\u6bcf\u4e00\u6761\u8def\u5f84\u4ee3\u8868\u4e00\u4e2a\u51b3\u7b56\u5e8f\u5217\u3002

        \u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c\u95ee\u9898\u5305\u542b\u660e\u786e\u7684\u51b3\u7b56\u6982\u5ff5\uff0c\u5e76\u4e14\u89e3\u662f\u901a\u8fc7\u4e00\u7cfb\u5217\u51b3\u7b56\u4ea7\u751f\u7684\uff0c\u90a3\u4e48\u5b83\u5c31\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\uff0c\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u56de\u6eaf\u6765\u89e3\u51b3\u3002

        \u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u52a8\u6001\u89c4\u5212\u95ee\u9898\u8fd8\u6709\u4e00\u4e9b\u5224\u65ad\u7684\u201c\u52a0\u5206\u9879\u201d\u3002

        • \u95ee\u9898\u5305\u542b\u6700\u5927\uff08\u5c0f\uff09\u6216\u6700\u591a\uff08\u5c11\uff09\u7b49\u6700\u4f18\u5316\u63cf\u8ff0\u3002
        • \u95ee\u9898\u7684\u72b6\u6001\u80fd\u591f\u4f7f\u7528\u4e00\u4e2a\u5217\u8868\u3001\u591a\u7ef4\u77e9\u9635\u6216\u6811\u6765\u8868\u793a\uff0c\u5e76\u4e14\u4e00\u4e2a\u72b6\u6001\u4e0e\u5176\u5468\u56f4\u7684\u72b6\u6001\u5b58\u5728\u9012\u63a8\u5173\u7cfb\u3002

        \u76f8\u5e94\u5730\uff0c\u4e5f\u5b58\u5728\u4e00\u4e9b\u201c\u51cf\u5206\u9879\u201d\u3002

        • \u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u800c\u4e0d\u662f\u627e\u51fa\u6700\u4f18\u89e3\u3002
        • \u95ee\u9898\u63cf\u8ff0\u4e2d\u6709\u660e\u663e\u7684\u6392\u5217\u7ec4\u5408\u7684\u7279\u5f81\uff0c\u9700\u8981\u8fd4\u56de\u5177\u4f53\u7684\u591a\u4e2a\u65b9\u6848\u3002

        \u5982\u679c\u4e00\u4e2a\u95ee\u9898\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\uff0c\u5e76\u5177\u6709\u8f83\u4e3a\u660e\u663e\u7684\u201c\u52a0\u5206\u9879\u201c\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5047\u8bbe\u5b83\u662f\u4e00\u4e2a\u52a8\u6001\u89c4\u5212\u95ee\u9898\uff0c\u5e76\u5728\u6c42\u89e3\u8fc7\u7a0b\u4e2d\u9a8c\u8bc1\u5b83\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1432","title":"14.3.2 \u00a0 \u95ee\u9898\u6c42\u89e3\u6b65\u9aa4","text":"

        \u52a8\u6001\u89c4\u5212\u7684\u89e3\u9898\u6d41\u7a0b\u4f1a\u56e0\u95ee\u9898\u7684\u6027\u8d28\u548c\u96be\u5ea6\u800c\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u901a\u5e38\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u63cf\u8ff0\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u5efa\u7acb \\(dp\\) \u8868\uff0c\u63a8\u5bfc\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u7b49\u3002

        \u4e3a\u4e86\u66f4\u5f62\u8c61\u5730\u5c55\u793a\u89e3\u9898\u6b65\u9aa4\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\u201c\u6700\u5c0f\u8def\u5f84\u548c\u201d\u6765\u4e3e\u4f8b\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a \\(n \\times m\\) \u7684\u4e8c\u7ef4\u7f51\u683c grid \uff0c\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u5305\u542b\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u8868\u793a\u8be5\u5355\u5143\u683c\u7684\u4ee3\u4ef7\u3002\u673a\u5668\u4eba\u4ee5\u5de6\u4e0a\u89d2\u5355\u5143\u683c\u4e3a\u8d77\u59cb\u70b9\uff0c\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\uff0c\u76f4\u81f3\u5230\u8fbe\u53f3\u4e0b\u89d2\u5355\u5143\u683c\u3002\u8bf7\u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u6700\u5c0f\u8def\u5f84\u548c\u3002

        \u56fe 14-10 \u5c55\u793a\u4e86\u4e00\u4e2a\u4f8b\u5b50\uff0c\u7ed9\u5b9a\u7f51\u683c\u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e3a \\(13\\) \u3002

        \u56fe 14-10 \u00a0 \u6700\u5c0f\u8def\u5f84\u548c\u793a\u4f8b\u6570\u636e

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u672c\u9898\u7684\u6bcf\u4e00\u8f6e\u7684\u51b3\u7b56\u5c31\u662f\u4ece\u5f53\u524d\u683c\u5b50\u5411\u4e0b\u6216\u5411\u53f3\u8d70\u4e00\u6b65\u3002\u8bbe\u5f53\u524d\u683c\u5b50\u7684\u884c\u5217\u7d22\u5f15\u4e3a \\([i, j]\\) \uff0c\u5219\u5411\u4e0b\u6216\u5411\u53f3\u8d70\u4e00\u6b65\u540e\uff0c\u7d22\u5f15\u53d8\u4e3a \\([i+1, j]\\) \u6216 \\([i, j+1]\\) \u3002\u56e0\u6b64\uff0c\u72b6\u6001\u5e94\u5305\u542b\u884c\u7d22\u5f15\u548c\u5217\u7d22\u5f15\u4e24\u4e2a\u53d8\u91cf\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u4ece\u8d77\u59cb\u70b9 \\([0, 0]\\) \u8d70\u5230 \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\uff0c\u89e3\u8bb0\u4e3a \\(dp[i, j]\\) \u3002

        \u81f3\u6b64\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u56fe 14-11 \u6240\u793a\u7684\u4e8c\u7ef4 \\(dp\\) \u77e9\u9635\uff0c\u5176\u5c3a\u5bf8\u4e0e\u8f93\u5165\u7f51\u683c \\(grid\\) \u76f8\u540c\u3002

        \u56fe 14-11 \u00a0 \u72b6\u6001\u5b9a\u4e49\u4e0e dp \u8868

        Note

        \u52a8\u6001\u89c4\u5212\u548c\u56de\u6eaf\u8fc7\u7a0b\u53ef\u4ee5\u63cf\u8ff0\u4e3a\u4e00\u4e2a\u51b3\u7b56\u5e8f\u5217\uff0c\u800c\u72b6\u6001\u7531\u6240\u6709\u51b3\u7b56\u53d8\u91cf\u6784\u6210\u3002\u5b83\u5e94\u5f53\u5305\u542b\u63cf\u8ff0\u89e3\u9898\u8fdb\u5ea6\u7684\u6240\u6709\u53d8\u91cf\uff0c\u5176\u5305\u542b\u4e86\u8db3\u591f\u7684\u4fe1\u606f\uff0c\u80fd\u591f\u7528\u6765\u63a8\u5bfc\u51fa\u4e0b\u4e00\u4e2a\u72b6\u6001\u3002

        \u6bcf\u4e2a\u72b6\u6001\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u6211\u4eec\u4f1a\u5b9a\u4e49\u4e00\u4e2a \\(dp\\) \u8868\u6765\u5b58\u50a8\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u72b6\u6001\u7684\u6bcf\u4e2a\u72ec\u7acb\u53d8\u91cf\u90fd\u662f \\(dp\\) \u8868\u7684\u4e00\u4e2a\u7ef4\u5ea6\u3002\u4ece\u672c\u8d28\u4e0a\u770b\uff0c\\(dp\\) \u8868\u662f\u72b6\u6001\u548c\u5b50\u95ee\u9898\u7684\u89e3\u4e4b\u95f4\u7684\u6620\u5c04\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u5bf9\u4e8e\u72b6\u6001 \\([i, j]\\) \uff0c\u5b83\u53ea\u80fd\u4ece\u4e0a\u8fb9\u683c\u5b50 \\([i-1, j]\\) \u548c\u5de6\u8fb9\u683c\u5b50 \\([i, j-1]\\) \u8f6c\u79fb\u800c\u6765\u3002\u56e0\u6b64\u6700\u4f18\u5b50\u7ed3\u6784\u4e3a\uff1a\u5230\u8fbe \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u7531 \\([i, j-1]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e0e \\([i-1, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e2d\u8f83\u5c0f\u7684\u90a3\u4e00\u4e2a\u51b3\u5b9a\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u53ef\u63a8\u51fa\u56fe 14-12 \u6240\u793a\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a

        \\[ dp[i, j] = \\min(dp[i-1, j], dp[i, j-1]) + grid[i, j] \\]

        \u56fe 14-12 \u00a0 \u6700\u4f18\u5b50\u7ed3\u6784\u4e0e\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        Note

        \u6839\u636e\u5b9a\u4e49\u597d\u7684 \\(dp\\) \u8868\uff0c\u601d\u8003\u539f\u95ee\u9898\u548c\u5b50\u95ee\u9898\u7684\u5173\u7cfb\uff0c\u627e\u51fa\u901a\u8fc7\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6765\u6784\u9020\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u7684\u65b9\u6cd5\uff0c\u5373\u6700\u4f18\u5b50\u7ed3\u6784\u3002

        \u4e00\u65e6\u6211\u4eec\u627e\u5230\u4e86\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u6784\u5efa\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5728\u672c\u9898\u4e2d\uff0c\u5904\u5728\u9996\u884c\u7684\u72b6\u6001\u53ea\u80fd\u4ece\u5176\u5de6\u8fb9\u7684\u72b6\u6001\u5f97\u6765\uff0c\u5904\u5728\u9996\u5217\u7684\u72b6\u6001\u53ea\u80fd\u4ece\u5176\u4e0a\u8fb9\u7684\u72b6\u6001\u5f97\u6765\uff0c\u56e0\u6b64\u9996\u884c \\(i = 0\\) \u548c\u9996\u5217 \\(j = 0\\) \u662f\u8fb9\u754c\u6761\u4ef6\u3002

        \u5982\u56fe 14-13 \u6240\u793a\uff0c\u7531\u4e8e\u6bcf\u4e2a\u683c\u5b50\u662f\u7531\u5176\u5de6\u65b9\u683c\u5b50\u548c\u4e0a\u65b9\u683c\u5b50\u8f6c\u79fb\u800c\u6765\uff0c\u56e0\u6b64\u6211\u4eec\u4f7f\u7528\u5faa\u73af\u6765\u904d\u5386\u77e9\u9635\uff0c\u5916\u5faa\u73af\u904d\u5386\u5404\u884c\uff0c\u5185\u5faa\u73af\u904d\u5386\u5404\u5217\u3002

        \u56fe 14-13 \u00a0 \u8fb9\u754c\u6761\u4ef6\u4e0e\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        Note

        \u8fb9\u754c\u6761\u4ef6\u5728\u52a8\u6001\u89c4\u5212\u4e2d\u7528\u4e8e\u521d\u59cb\u5316 \\(dp\\) \u8868\uff0c\u5728\u641c\u7d22\u4e2d\u7528\u4e8e\u526a\u679d\u3002

        \u72b6\u6001\u8f6c\u79fb\u987a\u5e8f\u7684\u6838\u5fc3\u662f\u8981\u4fdd\u8bc1\u5728\u8ba1\u7b97\u5f53\u524d\u95ee\u9898\u7684\u89e3\u65f6\uff0c\u6240\u6709\u5b83\u4f9d\u8d56\u7684\u66f4\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u90fd\u5df2\u7ecf\u88ab\u6b63\u786e\u5730\u8ba1\u7b97\u51fa\u6765\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u76f4\u63a5\u5199\u51fa\u52a8\u6001\u89c4\u5212\u4ee3\u7801\u3002\u7136\u800c\u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u4ece\u9876\u81f3\u5e95\u7684\u601d\u60f3\uff0c\u56e0\u6b64\u6309\u7167\u201c\u66b4\u529b\u641c\u7d22 \\(\\rightarrow\\) \u8bb0\u5fc6\u5316\u641c\u7d22 \\(\\rightarrow\\) \u52a8\u6001\u89c4\u5212\u201d\u7684\u987a\u5e8f\u5b9e\u73b0\u66f4\u52a0\u7b26\u5408\u601d\u7ef4\u4e60\u60ef\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1","title":"1. \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u4ece\u72b6\u6001 \\([i, j]\\) \u5f00\u59cb\u641c\u7d22\uff0c\u4e0d\u65ad\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u72b6\u6001 \\([i-1, j]\\) \u548c \\([i, j-1]\\) \uff0c\u9012\u5f52\u51fd\u6570\u5305\u62ec\u4ee5\u4e0b\u8981\u7d20\u3002

        • \u9012\u5f52\u53c2\u6570\uff1a\u72b6\u6001 \\([i, j]\\) \u3002
        • \u8fd4\u56de\u503c\uff1a\u4ece \\([0, 0]\\) \u5230 \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c \\(dp[i, j]\\) \u3002
        • \u7ec8\u6b62\u6761\u4ef6\uff1a\u5f53 \\(i = 0\\) \u4e14 \\(j = 0\\) \u65f6\uff0c\u8fd4\u56de\u4ee3\u4ef7 \\(grid[0, 0]\\) \u3002
        • \u526a\u679d\uff1a\u5f53 \\(i < 0\\) \u65f6\u6216 \\(j < 0\\) \u65f6\u7d22\u5f15\u8d8a\u754c\uff0c\u6b64\u65f6\u8fd4\u56de\u4ee3\u4ef7 \\(+\\infty\\) \uff0c\u4ee3\u8868\u4e0d\u53ef\u884c\u3002

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dfs(grid: list[list[int]], i: int, j: int) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22\"\"\"\n# \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 and j == 0:\nreturn grid[0][0]\n# \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 or j < 0:\nreturn inf\n# \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup = min_path_sum_dfs(grid, i - 1, j)\nleft = min_path_sum_dfs(grid, i, j - 1)\n# \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(vector<vector<int>> &grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(int[][] grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Integer.MAX_VALUE;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint MinPathSumDFS(int[][] grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn int.MaxValue;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = MinPathSumDFS(grid, i - 1, j);\nint left = MinPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.Min(left, up) + grid[i][j];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc minPathSumDFS(grid [][]int, i, j int) int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn math.MaxInt\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup := minPathSumDFS(grid, i-1, j)\nleft := minPathSumDFS(grid, i, j-1)\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn int(math.Min(float64(left), float64(up))) + grid[i][j]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc minPathSumDFS(grid: [[Int]], i: Int, j: Int) -> Int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0, j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn .max\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = minPathSumDFS(grid: grid, i: i - 1, j: j)\nlet left = minPathSumDFS(grid: grid, i: i, j: j - 1)\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction minPathSumDFS(grid, i, j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFS(grid, i - 1, j);\nconst left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction minPathSumDFS(\ngrid: Array<Array<number>>,\ni: number,\nj: number\n): number {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFS(grid, i - 1, j);\nconst left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(List<List<int>> grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\n// \u5728 Dart \u4e2d\uff0cint \u7c7b\u578b\u662f\u56fa\u5b9a\u8303\u56f4\u7684\u6574\u6570\uff0c\u4e0d\u5b58\u5728\u8868\u793a\u201c\u65e0\u7a77\u5927\u201d\u7684\u503c\nreturn BigInt.from(2).pow(31).toInt();\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfn min_path_sum_dfs(grid: &Vec<Vec<i32>>, i: i32, j: i32) -> i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn i32::MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = min_path_sum_dfs(grid, i - 1, j);\nlet left = min_path_sum_dfs(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nstd::cmp::min(left, up) + grid[i as usize][j as usize]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(int grid[MAX_SIZE][MAX_SIZE], int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22\nfn minPathSumDFS(grid: anytype, i: i32, j: i32) i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 and j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 or j < 0) {\nreturn std.math.maxInt(i32);\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nvar up = minPathSumDFS(grid, i - 1, j);\nvar left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n

        \u56fe 14-14 \u7ed9\u51fa\u4e86\u4ee5 \\(dp[2, 1]\\) \u4e3a\u6839\u8282\u70b9\u7684\u9012\u5f52\u6811\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e9b\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u5176\u6570\u91cf\u4f1a\u968f\u7740\u7f51\u683c grid \u7684\u5c3a\u5bf8\u53d8\u5927\u800c\u6025\u5267\u589e\u591a\u3002

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9020\u6210\u91cd\u53e0\u5b50\u95ee\u9898\u7684\u539f\u56e0\u4e3a\uff1a\u5b58\u5728\u591a\u6761\u8def\u5f84\u53ef\u4ee5\u4ece\u5de6\u4e0a\u89d2\u5230\u8fbe\u67d0\u4e00\u5355\u5143\u683c\u3002

        \u56fe 14-14 \u00a0 \u66b4\u529b\u641c\u7d22\u9012\u5f52\u6811

        \u6bcf\u4e2a\u72b6\u6001\u90fd\u6709\u5411\u4e0b\u548c\u5411\u53f3\u4e24\u79cd\u9009\u62e9\uff0c\u4ece\u5de6\u4e0a\u89d2\u8d70\u5230\u53f3\u4e0b\u89d2\u603b\u5171\u9700\u8981 \\(m + n - 2\\) \u6b65\uff0c\u6240\u4ee5\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^{m + n})\\) \u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u79cd\u8ba1\u7b97\u65b9\u5f0f\u672a\u8003\u8651\u4e34\u8fd1\u7f51\u683c\u8fb9\u754c\u7684\u60c5\u51b5\uff0c\u5f53\u5230\u8fbe\u7f51\u7edc\u8fb9\u754c\u65f6\u53ea\u5269\u4e0b\u4e00\u79cd\u9009\u62e9\uff0c\u56e0\u6b64\u5b9e\u9645\u7684\u8def\u5f84\u6570\u91cf\u4f1a\u5c11\u4e00\u4e9b\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#2","title":"2. \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u6211\u4eec\u5f15\u5165\u4e00\u4e2a\u548c\u7f51\u683c grid \u76f8\u540c\u5c3a\u5bf8\u7684\u8bb0\u5fc6\u5217\u8868 mem \uff0c\u7528\u4e8e\u8bb0\u5f55\u5404\u4e2a\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5e76\u5c06\u91cd\u53e0\u5b50\u95ee\u9898\u8fdb\u884c\u526a\u679d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dfs_mem(\ngrid: list[list[int]], mem: list[list[int]], i: int, j: int\n) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 and j == 0:\nreturn grid[0][0]\n# \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 or j < 0:\nreturn inf\n# \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1:\nreturn mem[i][j]\n# \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup = min_path_sum_dfs_mem(grid, mem, i - 1, j)\nleft = min_path_sum_dfs_mem(grid, mem, i, j - 1)\n# \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j]\nreturn mem[i][j]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(vector<vector<int>> &grid, vector<vector<int>> &mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\nreturn mem[i][j];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(int[][] grid, int[][] mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Integer.MAX_VALUE;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint MinPathSumDFSMem(int[][] grid, int[][] mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn int.MaxValue;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = MinPathSumDFSMem(grid, mem, i - 1, j);\nint left = MinPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.Min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc minPathSumDFSMem(grid, mem [][]int, i, j int) int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn math.MaxInt\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1 {\nreturn mem[i][j]\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup := minPathSumDFSMem(grid, mem, i-1, j)\nleft := minPathSumDFSMem(grid, mem, i, j-1)\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = int(math.Min(float64(left), float64(up))) + grid[i][j]\nreturn mem[i][j]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc minPathSumDFSMem(grid: [[Int]], mem: inout [[Int]], i: Int, j: Int) -> Int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0, j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn .max\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1 {\nreturn mem[i][j]\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = minPathSumDFSMem(grid: grid, mem: &mem, i: i - 1, j: j)\nlet left = minPathSumDFSMem(grid: grid, mem: &mem, i: i, j: j - 1)\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j]\nreturn mem[i][j]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(grid, mem, i, j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] !== -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFSMem(grid, mem, i - 1, j);\nconst left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(\ngrid: Array<Array<number>>,\nmem: Array<Array<number>>,\ni: number,\nj: number\n): number {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFSMem(grid, mem, i - 1, j);\nconst left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(List<List<int>> grid, List<List<int>> mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\n// \u5728 Dart \u4e2d\uff0cint \u7c7b\u578b\u662f\u56fa\u5b9a\u8303\u56f4\u7684\u6574\u6570\uff0c\u4e0d\u5b58\u5728\u8868\u793a\u201c\u65e0\u7a77\u5927\u201d\u7684\u503c\nreturn BigInt.from(2).pow(31).toInt();\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn min_path_sum_dfs_mem(grid: &Vec<Vec<i32>>, mem: &mut Vec<Vec<i32>>, i: i32, j: i32) -> i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn i32::MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i as usize][j as usize] != -1 {\nreturn mem[i as usize][j as usize];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = min_path_sum_dfs_mem(grid, mem, i - 1, j);\nlet left = min_path_sum_dfs_mem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i as usize][j as usize] = std::cmp::min(left, up) + grid[i as usize][j as usize];\nmem[i as usize][j as usize]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(int grid[MAX_SIZE][MAX_SIZE], int mem[MAX_SIZE][MAX_SIZE], int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\nreturn mem[i][j];\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn minPathSumDFSMem(grid: anytype, mem: anytype, i: i32, j: i32) i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 and j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 or j < 0) {\nreturn std.math.maxInt(i32);\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] != -1) {\nreturn mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nvar up = minPathSumDFSMem(grid, mem, i - 1, j);\nvar left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] = @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\nreturn mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n

        \u5982\u56fe 14-15 \u6240\u793a\uff0c\u5728\u5f15\u5165\u8bb0\u5fc6\u5316\u540e\uff0c\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\u53ea\u9700\u8ba1\u7b97\u4e00\u6b21\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u72b6\u6001\u603b\u6570\uff0c\u5373\u7f51\u683c\u5c3a\u5bf8 \\(O(nm)\\) \u3002

        \u56fe 14-15 \u00a0 \u8bb0\u5fc6\u5316\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#3","title":"3. \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u57fa\u4e8e\u8fed\u4ee3\u5b9e\u73b0\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dp(grid: list[list[int]]) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(grid), len(grid[0])\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * m for _ in range(n)]\ndp[0][0] = grid[0][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in range(1, m):\ndp[0][j] = dp[0][j - 1] + grid[0][j]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in range(1, n):\ndp[i][0] = dp[i - 1][0] + grid[i][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n):\nfor j in range(1, m):\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\nreturn dp[n - 1][m - 1]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(vector<vector<int>> &grid) {\nint n = grid.size(), m = grid[0].size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n, vector<int>(m));\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(int[][] grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n][m];\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint MinPathSumDP(int[][] grid) {\nint n = grid.Length, m = grid[0].Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n, m];\ndp[0, 0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0, j] = dp[0, j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i, 0] = dp[i - 1, 0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i, j] = Math.Min(dp[i, j - 1], dp[i - 1, j]) + grid[i][j];\n}\n}\nreturn dp[n - 1, m - 1];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDP(grid [][]int) int {\nn, m := len(grid), len(grid[0])\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n)\nfor i := 0; i < n; i++ {\ndp[i] = make([]int, m)\n}\ndp[0][0] = grid[0][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j := 1; j < m; j++ {\ndp[0][j] = dp[0][j-1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i := 1; i < n; i++ {\ndp[i][0] = dp[i-1][0] + grid[i][0]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i < n; i++ {\nfor j := 1; j < m; j++ {\ndp[i][j] = int(math.Min(float64(dp[i][j-1]), float64(dp[i-1][j]))) + grid[i][j]\n}\n}\nreturn dp[n-1][m-1]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDP(grid: [[Int]]) -> Int {\nlet n = grid.count\nlet m = grid[0].count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: m), count: n)\ndp[0][0] = grid[0][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in stride(from: 1, to: m, by: 1) {\ndp[0][j] = dp[0][j - 1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in stride(from: 1, to: n, by: 1) {\ndp[i][0] = dp[i - 1][0] + grid[i][0]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, to: n, by: 1) {\nfor j in stride(from: 1, to: m, by: 1) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n}\n}\nreturn dp[n - 1][m - 1]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid) {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n }, () =>\nArray.from({ length: m }, () => 0)\n);\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (let i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i < n; i++) {\nfor (let j = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid: Array<Array<number>>): number {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n }, () =>\nArray.from({ length: m }, () => 0)\n);\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (let i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i < n; i++) {\nfor (let j: number = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(List<List<int>> grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n, (i) => List.filled(m, 0));\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfn min_path_sum_dp(grid: &Vec<Vec<i32>>) -> i32 {\nlet (n, m) = (grid.len(), grid[0].len());\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; m]; n];\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in 1..m {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in 1..n {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..n {\nfor j in 1..m {\ndp[i][j] = std::cmp::min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\ndp[n - 1][m - 1]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(int grid[MAX_SIZE][MAX_SIZE], int n, int m) {\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc(n * sizeof(int *));\nfor (int i = 0; i < n; i++) {\ndp[i] = calloc(m, sizeof(int));\n}\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = myMin(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nint res = dp[n - 1][m - 1];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i < n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\nfn minPathSumDP(comptime grid: anytype) i32 {\ncomptime var n = grid.len;\ncomptime var m = grid[0].len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][m]i32{[_]i32{0} ** m} ** n;\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (1..m) |j| {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (1..n) |i| {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n) |i| {\nfor (1..m) |j| {\ndp[i][j] = @min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n

        \u56fe 14-16 \u5c55\u793a\u4e86\u6700\u5c0f\u8def\u5f84\u548c\u7684\u72b6\u6001\u8f6c\u79fb\u8fc7\u7a0b\uff0c\u5176\u904d\u5386\u4e86\u6574\u4e2a\u7f51\u683c\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nm)\\) \u3002

        \u6570\u7ec4 dp \u5927\u5c0f\u4e3a \\(n \\times m\\) \uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nm)\\) \u3002

        <1><2><3><4><5><6><7><8><9><10><11><12>

        \u56fe 14-16 \u00a0 \u6700\u5c0f\u8def\u5f84\u548c\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#4","title":"4. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u6bcf\u4e2a\u683c\u5b50\u53ea\u4e0e\u5176\u5de6\u8fb9\u548c\u4e0a\u8fb9\u7684\u683c\u5b50\u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u53ea\u7528\u4e00\u4e2a\u5355\u884c\u6570\u7ec4\u6765\u5b9e\u73b0 \\(dp\\) \u8868\u3002

        \u8bf7\u6ce8\u610f\uff0c\u56e0\u4e3a\u6570\u7ec4 dp \u53ea\u80fd\u8868\u793a\u4e00\u884c\u7684\u72b6\u6001\uff0c\u6240\u4ee5\u6211\u4eec\u65e0\u6cd5\u63d0\u524d\u521d\u59cb\u5316\u9996\u5217\u72b6\u6001\uff0c\u800c\u662f\u5728\u904d\u5386\u6bcf\u884c\u65f6\u66f4\u65b0\u5b83\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dp_comp(grid: list[list[int]]) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(grid), len(grid[0])\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * m\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j in range(1, m):\ndp[j] = dp[j - 1] + grid[0][j]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in range(1, n):\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in range(1, m):\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\nreturn dp[m - 1]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(vector<vector<int>> &grid) {\nint n = grid.size(), m = grid[0].size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(int[][] grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[m];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint MinPathSumDPComp(int[][] grid) {\nint n = grid.Length, m = grid[0].Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[m];\ndp[0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = Math.Min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDPComp(grid [][]int) int {\nn, m := len(grid), len(grid[0])\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, m)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j := 1; j < m; j++ {\ndp[j] = dp[j-1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i < n; i++ {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j := 1; j < m; j++ {\ndp[j] = int(math.Min(float64(dp[j-1]), float64(dp[j]))) + grid[i][j]\n}\n}\nreturn dp[m-1]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDPComp(grid: [[Int]]) -> Int {\nlet n = grid.count\nlet m = grid[0].count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: m)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j in stride(from: 1, to: m, by: 1) {\ndp[j] = dp[j - 1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in stride(from: 1, to: n, by: 1) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in stride(from: 1, to: m, by: 1) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n}\n}\nreturn dp[m - 1]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDPComp(grid) {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = new Array(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (let j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDPComp(grid: Array<Array<number>>): number {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = new Array(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (let j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(List<List<int>> grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(m, 0);\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn min_path_sum_dp_comp(grid: &Vec<Vec<i32>>) -> i32 {\nlet (n, m) = (grid.len(), grid[0].len());\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; m];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor j in 1..m {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in 1..n {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in 1..m {\ndp[j] = std::cmp::min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\ndp[m - 1]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(int grid[MAX_SIZE][MAX_SIZE], int n, int m) {\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(m, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = myMin(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nint res = dp[m - 1];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn minPathSumDPComp(comptime grid: anytype) i32 {\ncomptime var n = grid.len;\ncomptime var m = grid[0].len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** m;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (1..m) |j| {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (1..n) |i| {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\nfor (1..m) |j| {\ndp[j] = @min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        "},{"location":"chapter_dynamic_programming/edit_distance_problem/","title":"14.6 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898","text":"

        \u7f16\u8f91\u8ddd\u79bb\uff0c\u4e5f\u79f0 Levenshtein \u8ddd\u79bb\uff0c\u6307\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u4e92\u76f8\u8f6c\u6362\u7684\u6700\u5c11\u4fee\u6539\u6b21\u6570\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4fe1\u606f\u68c0\u7d22\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u5ea6\u91cf\u4e24\u4e2a\u5e8f\u5217\u7684\u76f8\u4f3c\u5ea6\u3002

        Question

        \u8f93\u5165\u4e24\u4e2a\u5b57\u7b26\u4e32 \\(s\\) \u548c \\(t\\) \uff0c\u8fd4\u56de\u5c06 \\(s\\) \u8f6c\u6362\u4e3a \\(t\\) \u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002

        \u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fdb\u884c\u4e09\u79cd\u7f16\u8f91\u64cd\u4f5c\uff1a\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u3001\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3001\u5c06\u5b57\u7b26\u66ff\u6362\u4e3a\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002

        \u5982\u56fe 14-27 \u6240\u793a\uff0c\u5c06 kitten \u8f6c\u6362\u4e3a sitting \u9700\u8981\u7f16\u8f91 3 \u6b65\uff0c\u5305\u62ec 2 \u6b21\u66ff\u6362\u64cd\u4f5c\u4e0e 1 \u6b21\u6dfb\u52a0\u64cd\u4f5c\uff1b\u5c06 hello \u8f6c\u6362\u4e3a algo \u9700\u8981 3 \u6b65\uff0c\u5305\u62ec 2 \u6b21\u66ff\u6362\u64cd\u4f5c\u548c 1 \u6b21\u5220\u9664\u64cd\u4f5c\u3002

        \u56fe 14-27 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u793a\u4f8b\u6570\u636e

        \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u53ef\u4ee5\u5f88\u81ea\u7136\u5730\u7528\u51b3\u7b56\u6811\u6a21\u578b\u6765\u89e3\u91ca\u3002\u5b57\u7b26\u4e32\u5bf9\u5e94\u6811\u8282\u70b9\uff0c\u4e00\u8f6e\u51b3\u7b56\uff08\u4e00\u6b21\u7f16\u8f91\u64cd\u4f5c\uff09\u5bf9\u5e94\u6811\u7684\u4e00\u6761\u8fb9\u3002

        \u5982\u56fe 14-28 \u6240\u793a\uff0c\u5728\u4e0d\u9650\u5236\u64cd\u4f5c\u7684\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u6d3e\u751f\u51fa\u8bb8\u591a\u6761\u8fb9\uff0c\u6bcf\u6761\u8fb9\u5bf9\u5e94\u4e00\u79cd\u64cd\u4f5c\uff0c\u8fd9\u610f\u5473\u7740\u4ece hello \u8f6c\u6362\u5230 algo \u6709\u8bb8\u591a\u79cd\u53ef\u80fd\u7684\u8def\u5f84\u3002

        \u4ece\u51b3\u7b56\u6811\u7684\u89d2\u5ea6\u770b\uff0c\u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u8282\u70b9 hello \u548c\u8282\u70b9 algo \u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002

        \u56fe 14-28 \u00a0 \u57fa\u4e8e\u51b3\u7b56\u6811\u6a21\u578b\u8868\u793a\u7f16\u8f91\u8ddd\u79bb\u95ee\u9898

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u6bcf\u4e00\u8f6e\u7684\u51b3\u7b56\u662f\u5bf9\u5b57\u7b26\u4e32 \\(s\\) \u8fdb\u884c\u4e00\u6b21\u7f16\u8f91\u64cd\u4f5c\u3002

        \u6211\u4eec\u5e0c\u671b\u5728\u7f16\u8f91\u64cd\u4f5c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u95ee\u9898\u7684\u89c4\u6a21\u9010\u6e10\u7f29\u5c0f\uff0c\u8fd9\u6837\u624d\u80fd\u6784\u5efa\u5b50\u95ee\u9898\u3002\u8bbe\u5b57\u7b26\u4e32 \\(s\\) \u548c \\(t\\) \u7684\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\) \u548c \\(m\\) \uff0c\u6211\u4eec\u5148\u8003\u8651\u4e24\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u5b57\u7b26 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u3002

        • \u82e5 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u76f8\u540c\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u8fc7\u5b83\u4eec\uff0c\u76f4\u63a5\u8003\u8651 \\(s[n-2]\\) \u548c \\(t[m-2]\\) \u3002
        • \u82e5 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u4e0d\u540c\uff0c\u6211\u4eec\u9700\u8981\u5bf9 \\(s\\) \u8fdb\u884c\u4e00\u6b21\u7f16\u8f91\uff08\u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\uff09\uff0c\u4f7f\u5f97\u4e24\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u5b57\u7b26\u76f8\u540c\uff0c\u4ece\u800c\u53ef\u4ee5\u8df3\u8fc7\u5b83\u4eec\uff0c\u8003\u8651\u89c4\u6a21\u66f4\u5c0f\u7684\u95ee\u9898\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5728\u5b57\u7b26\u4e32 \\(s\\) \u4e2d\u8fdb\u884c\u7684\u6bcf\u4e00\u8f6e\u51b3\u7b56\uff08\u7f16\u8f91\u64cd\u4f5c\uff09\uff0c\u90fd\u4f1a\u4f7f\u5f97 \\(s\\) \u548c \\(t\\) \u4e2d\u5269\u4f59\u7684\u5f85\u5339\u914d\u5b57\u7b26\u53d1\u751f\u53d8\u5316\u3002\u56e0\u6b64\uff0c\u72b6\u6001\u4e3a\u5f53\u524d\u5728 \\(s\\) \u548c \\(t\\) \u4e2d\u8003\u8651\u7684\u7b2c \\(i\\) \u548c\u7b2c \\(j\\) \u4e2a\u5b57\u7b26\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\uff1a\u5c06 \\(s\\) \u7684\u524d \\(i\\) \u4e2a\u5b57\u7b26\u66f4\u6539\u4e3a \\(t\\) \u7684\u524d \\(j\\) \u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002

        \u81f3\u6b64\uff0c\u5f97\u5230\u4e00\u4e2a\u5c3a\u5bf8\u4e3a \\((i+1) \\times (j+1)\\) \u7684\u4e8c\u7ef4 \\(dp\\) \u8868\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u8003\u8651\u5b50\u95ee\u9898 \\(dp[i, j]\\) \uff0c\u5176\u5bf9\u5e94\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5c3e\u90e8\u5b57\u7b26\u4e3a \\(s[i-1]\\) \u548c \\(t[j-1]\\) \uff0c\u53ef\u6839\u636e\u4e0d\u540c\u7f16\u8f91\u64cd\u4f5c\u5206\u4e3a\u56fe 14-29 \u6240\u793a\u7684\u4e09\u79cd\u60c5\u51b5\u3002

        1. \u5728 \\(s[i-1]\\) \u4e4b\u540e\u6dfb\u52a0 \\(t[j-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i, j-1]\\) \u3002
        2. \u5220\u9664 \\(s[i-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i-1, j]\\) \u3002
        3. \u5c06 \\(s[i-1]\\) \u66ff\u6362\u4e3a \\(t[j-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i-1, j-1]\\) \u3002

        \u56fe 14-29 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u72b6\u6001\u8f6c\u79fb

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u53ef\u5f97\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\\(dp[i, j]\\) \u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(dp[i, j-1]\\)\u3001\\(dp[i-1, j]\\)\u3001\\(dp[i-1, j-1]\\) \u4e09\u8005\u4e2d\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\uff0c\u518d\u52a0\u4e0a\u672c\u6b21\u7684\u7f16\u8f91\u6b65\u6570 \\(1\\) \u3002\u5bf9\u5e94\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, j] = \\min(dp[i, j-1], dp[i-1, j], dp[i-1, j-1]) + 1 \\]

        \u8bf7\u6ce8\u610f\uff0c\u5f53 \\(s[i-1]\\) \u548c \\(t[j-1]\\) \u76f8\u540c\u65f6\uff0c\u65e0\u987b\u7f16\u8f91\u5f53\u524d\u5b57\u7b26\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, j] = dp[i-1, j-1] \\]

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u4e24\u5b57\u7b26\u4e32\u90fd\u4e3a\u7a7a\u65f6\uff0c\u7f16\u8f91\u6b65\u6570\u4e3a \\(0\\) \uff0c\u5373 \\(dp[0, 0] = 0\\) \u3002\u5f53 \\(s\\) \u4e3a\u7a7a\u4f46 \\(t\\) \u4e0d\u4e3a\u7a7a\u65f6\uff0c\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(t\\) \u7684\u957f\u5ea6\uff0c\u5373\u9996\u884c \\(dp[0, j] = j\\) \u3002\u5f53 \\(s\\) \u4e0d\u4e3a\u7a7a\u4f46 \\(t\\) \u4e3a\u7a7a\u65f6\uff0c\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(s\\) \u7684\u957f\u5ea6\uff0c\u5373\u9996\u5217 \\(dp[i, 0] = i\\) \u3002

        \u89c2\u5bdf\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u89e3 \\(dp[i, j]\\) \u4f9d\u8d56\u5de6\u65b9\u3001\u4e0a\u65b9\u3001\u5de6\u4e0a\u65b9\u7684\u89e3\uff0c\u56e0\u6b64\u901a\u8fc7\u4e24\u5c42\u5faa\u73af\u6b63\u5e8f\u904d\u5386\u6574\u4e2a \\(dp\\) \u8868\u5373\u53ef\u3002

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig edit_distance.py
        def edit_distance_dp(s: str, t: str) -> int:\n\"\"\"\u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(s), len(t)\ndp = [[0] * (m + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in range(1, n + 1):\ndp[i][0] = i\nfor j in range(1, m + 1):\ndp[0][j] = j\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n + 1):\nfor j in range(1, m + 1):\nif s[i - 1] == t[j - 1]:\n# \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1]\nelse:\n# \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1\nreturn dp[n][m]\n
        edit_distance.cpp
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(string s, string t) {\nint n = s.length(), m = t.length();\nvector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.java
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\nint n = s.length(), m = t.length();\nint[][] dp = new int[n + 1][m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s.charAt(i - 1) == t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.cs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDP(string s, string t) {\nint n = s.Length, m = t.Length;\nint[,] dp = new int[n + 1, m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i, 0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0, j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i, j] = dp[i - 1, j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i, j] = Math.Min(Math.Min(dp[i, j - 1], dp[i - 1, j]), dp[i - 1, j - 1]) + 1;\n}\n}\n}\nreturn dp[n, m];\n}\n
        edit_distance.go
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s string, t string) int {\nn := len(s)\nm := len(t)\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, m+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i := 1; i <= n; i++ {\ndp[i][0] = i\n}\nfor j := 1; j <= m; j++ {\ndp[0][j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor j := 1; j <= m; j++ {\nif s[i-1] == t[j-1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i-1][j-1]\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = MinInt(MinInt(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1]) + 1\n}\n}\n}\nreturn dp[n][m]\n}\n
        edit_distance.swift
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s: String, t: String) -> Int {\nlet n = s.utf8CString.count\nlet m = t.utf8CString.count\nvar dp = Array(repeating: Array(repeating: 0, count: m + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in stride(from: 1, through: n, by: 1) {\ndp[i][0] = i\n}\nfor j in stride(from: 1, through: m, by: 1) {\ndp[0][j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, through: n, by: 1) {\nfor j in stride(from: 1, through: m, by: 1) {\nif s.utf8CString[i - 1] == t.utf8CString[j - 1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1]\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1\n}\n}\n}\nreturn dp[n][m]\n}\n
        edit_distance.js
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s, t) {\nconst n = s.length,\nm = t.length;\nconst dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (let j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let j = 1; j <= m; j++) {\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] =\nMath.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.ts
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s: string, t: string): number {\nconst n = s.length,\nm = t.length;\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: m + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (let j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let j = 1; j <= m; j++) {\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] =\nMath.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.dart
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\nint n = s.length, m = t.length;\nList<List<int>> dp = List.generate(n + 1, (_) => List.filled(m + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.rs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfn edit_distance_dp(s: &str, t: &str) -> i32 {\nlet (n, m) = (s.len(), t.len());\nlet mut dp = vec![vec![0; m + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in 1..= n {\ndp[i][0] = i as i32;\n}\nfor j in 1..m {\ndp[0][j] = j as i32;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..=n {\nfor j in 1..=m {\nif s.chars().nth(i - 1) == t.chars().nth(j - 1) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = std::cmp::min(std::cmp::min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\ndp[n][m]\n}\n
        edit_distance.c
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(char *s, char *t, int n, int m) {\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(m + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = myMin(myMin(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nint res = dp[n][m];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        edit_distance.zig
        // \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212\nfn editDistanceDP(comptime s: []const u8, comptime t: []const u8) i32 {\ncomptime var n = s.len;\ncomptime var m = t.len;\nvar dp = [_][m + 1]i32{[_]i32{0} ** (m + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (1..n + 1) |i| {\ndp[i][0] = @intCast(i);\n}\nfor (1..m + 1) |j| {\ndp[0][j] = @intCast(j);\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n + 1) |i| {\nfor (1..m + 1) |j| {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = @min(@min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n

        \u5982\u56fe 14-30 \u6240\u793a\uff0c\u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u7684\u72b6\u6001\u8f6c\u79fb\u8fc7\u7a0b\u4e0e\u80cc\u5305\u95ee\u9898\u975e\u5e38\u7c7b\u4f3c\uff0c\u90fd\u53ef\u4ee5\u770b\u4f5c\u586b\u5199\u4e00\u4e2a\u4e8c\u7ef4\u7f51\u683c\u7684\u8fc7\u7a0b\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14><15>

        \u56fe 14-30 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#3","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e \\(dp[i,j]\\) \u662f\u7531\u4e0a\u65b9 \\(dp[i-1, j]\\)\u3001\u5de6\u65b9 \\(dp[i, j-1]\\)\u3001\u5de6\u4e0a\u65b9 \\(dp[i-1, j-1]\\) \u8f6c\u79fb\u800c\u6765\u7684\uff0c\u800c\u6b63\u5e8f\u904d\u5386\u4f1a\u4e22\u5931\u5de6\u4e0a\u65b9 \\(dp[i-1, j-1]\\) \uff0c\u5012\u5e8f\u904d\u5386\u65e0\u6cd5\u63d0\u524d\u6784\u5efa \\(dp[i, j-1]\\) \uff0c\u56e0\u6b64\u4e24\u79cd\u904d\u5386\u987a\u5e8f\u90fd\u4e0d\u53ef\u53d6\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf leftup \u6765\u6682\u5b58\u5de6\u4e0a\u65b9\u7684\u89e3 \\(dp[i-1, j-1]\\) \uff0c\u4ece\u800c\u53ea\u9700\u8003\u8651\u5de6\u65b9\u548c\u4e0a\u65b9\u7684\u89e3\u3002\u6b64\u65f6\u7684\u60c5\u51b5\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u76f8\u540c\uff0c\u53ef\u4f7f\u7528\u6b63\u5e8f\u904d\u5386\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig edit_distance.py
        def edit_distance_dp_comp(s: str, t: str) -> int:\n\"\"\"\u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(s), len(t)\ndp = [0] * (m + 1)\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in range(1, m + 1):\ndp[j] = j\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in range(1, n + 1):\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nleftup = dp[0]  # \u6682\u5b58 dp[i-1, j-1]\ndp[0] += 1\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in range(1, m + 1):\ntemp = dp[j]\nif s[i - 1] == t[j - 1]:\n# \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup\nelse:\n# \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(dp[j - 1], dp[j], leftup) + 1\nleftup = temp  # \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\nreturn dp[m]\n
        edit_distance.cpp
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(string s, string t) {\nint n = s.length(), m = t.length();\nvector<int> dp(m + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.java
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(String s, String t) {\nint n = s.length(), m = t.length();\nint[] dp = new int[m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s.charAt(i - 1) == t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(Math.min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.cs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDPComp(string s, string t) {\nint n = s.Length, m = t.Length;\nint[] dp = new int[m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.Min(Math.Min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.go
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDPComp(s string, t string) int {\nn := len(s)\nm := len(t)\ndp := make([]int, m+1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j := 1; j <= m; j++ {\ndp[j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i := 1; i <= n; i++ {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nleftUp := dp[0] // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j := 1; j <= m; j++ {\ntemp := dp[j]\nif s[i-1] == t[j-1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftUp\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = MinInt(MinInt(dp[j-1], dp[j]), leftUp) + 1\n}\nleftUp = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m]\n}\n
        edit_distance.swift
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDPComp(s: String, t: String) -> Int {\nlet n = s.utf8CString.count\nlet m = t.utf8CString.count\nvar dp = Array(repeating: 0, count: m + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in stride(from: 1, through: m, by: 1) {\ndp[j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in stride(from: 1, through: n, by: 1) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nvar leftup = dp[0] // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in stride(from: 1, through: m, by: 1) {\nlet temp = dp[j]\nif s.utf8CString[i - 1] == t.utf8CString[j - 1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1\n}\nleftup = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m]\n}\n
        edit_distance.js
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDPComp(s, t) {\nconst n = s.length,\nm = t.length;\nconst dp = new Array(m + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j <= m; j++) {\nconst temp = dp[j];\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.ts
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDPComp(s: string, t: string): number {\nconst n = s.length,\nm = t.length;\nconst dp = new Array(m + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j <= m; j++) {\nconst temp = dp[j];\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.dart
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(String s, String t) {\nint n = s.length, m = t.length;\nList<int> dp = List.filled(m + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.rs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn edit_distance_dp_comp(s: &str, t: &str) -> i32 {\nlet (n, m) = (s.len(), t.len());\nlet mut dp = vec![0; m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in 1..m {\ndp[j] = j as i32;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in 1..=n {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet mut leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i as i32;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in 1..=m {\nlet temp = dp[j];\nif s.chars().nth(i - 1) == t.chars().nth(j - 1) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = std::cmp::min(std::cmp::min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\ndp[m]\n}\n
        edit_distance.c
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(char *s, char *t, int n, int m) {\nint *dp = calloc(m + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = myMin(myMin(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nint res = dp[m];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        edit_distance.zig
        // \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn editDistanceDPComp(comptime s: []const u8, comptime t: []const u8) i32 {\ncomptime var n = s.len;\ncomptime var m = t.len;\nvar dp = [_]i32{0} ** (m + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (1..m + 1) |j| {\ndp[j] = @intCast(j);\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (1..n + 1) |i| {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nvar leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = @intCast(i);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (1..m + 1) |j| {\nvar temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = @min(@min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/","title":"14.1 \u00a0 \u521d\u63a2\u52a8\u6001\u89c4\u5212","text":"

        \u300c\u52a8\u6001\u89c4\u5212 dynamic programming\u300d\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u7b97\u6cd5\u8303\u5f0f\uff0c\u5b83\u5c06\u4e00\u4e2a\u95ee\u9898\u5206\u89e3\u4e3a\u4e00\u7cfb\u5217\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u5e76\u901a\u8fc7\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\u6765\u907f\u514d\u91cd\u590d\u8ba1\u7b97\uff0c\u4ece\u800c\u5927\u5e45\u63d0\u5347\u65f6\u95f4\u6548\u7387\u3002

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u4ece\u4e00\u4e2a\u7ecf\u5178\u4f8b\u9898\u5165\u624b\uff0c\u5148\u7ed9\u51fa\u5b83\u7684\u66b4\u529b\u56de\u6eaf\u89e3\u6cd5\uff0c\u89c2\u5bdf\u5176\u4e2d\u5305\u542b\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u518d\u9010\u6b65\u5bfc\u51fa\u66f4\u9ad8\u6548\u7684\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u3002

        \u722c\u697c\u68af

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5982\u56fe 14-1 \u6240\u793a\uff0c\u5bf9\u4e8e\u4e00\u4e2a \\(3\\) \u9636\u697c\u68af\uff0c\u5171\u6709 \\(3\\) \u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002

        \u56fe 14-1 \u00a0 \u722c\u5230\u7b2c 3 \u9636\u7684\u65b9\u6848\u6570\u91cf

        \u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u65b9\u6848\u6570\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u901a\u8fc7\u56de\u6eaf\u6765\u7a77\u4e3e\u6240\u6709\u53ef\u80fd\u6027\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c06\u722c\u697c\u68af\u60f3\u8c61\u4e3a\u4e00\u4e2a\u591a\u8f6e\u9009\u62e9\u7684\u8fc7\u7a0b\uff1a\u4ece\u5730\u9762\u51fa\u53d1\uff0c\u6bcf\u8f6e\u9009\u62e9\u4e0a \\(1\\) \u9636\u6216 \\(2\\) \u9636\uff0c\u6bcf\u5f53\u5230\u8fbe\u697c\u68af\u9876\u90e8\u65f6\u5c31\u5c06\u65b9\u6848\u6570\u91cf\u52a0 \\(1\\) \uff0c\u5f53\u8d8a\u8fc7\u697c\u68af\u9876\u90e8\u65f6\u5c31\u5c06\u5176\u526a\u679d\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_backtrack.py
        def backtrack(choices: list[int], state: int, n: int, res: list[int]) -> int:\n\"\"\"\u56de\u6eaf\"\"\"\n# \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n:\nres[0] += 1\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res)\n# \u56de\u9000\ndef climbing_stairs_backtrack(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u56de\u6eaf\"\"\"\nchoices = [1, 2]  # \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nstate = 0  # \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nres = [0]  # \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res)\nreturn res[0]\n
        climbing_stairs_backtrack.cpp
        /* \u56de\u6eaf */\nvoid backtrack(vector<int> &choices, int state, int n, vector<int> &res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (auto &choice : choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nvector<int> choices = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0;                // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvector<int> res = {0};        // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.java
        /* \u56de\u6eaf */\nvoid backtrack(List<Integer> choices, int state, int n, List<Integer> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Integer choice : choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nList<Integer> choices = Arrays.asList(1, 2); // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<Integer> res = new ArrayList<>();\nres.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.cs
        /* \u56de\u6eaf */\nvoid Backtrack(List<int> choices, int state, int n, List<int> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (int choice in choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nBacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint ClimbingStairsBacktrack(int n) {\nList<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<int> res = [0]; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nBacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.go
        /* \u56de\u6eaf */\nfunc backtrack(choices []int, state, n int, res []int) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n {\nres[0] = res[0] + 1\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state+choice > n {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state+choice, n, res)\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n int) int {\n// \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nchoices := []int{1, 2}\n// \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nstate := 0\nres := make([]int, 1)\n// \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nres[0] = 0\nbacktrack(choices, state, n, res)\nreturn res[0]\n}\n
        climbing_stairs_backtrack.swift
        /* \u56de\u6eaf */\nfunc backtrack(choices: [Int], state: Int, n: Int, res: inout [Int]) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n {\nres[0] += 1\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n {\ncontinue\n}\nbacktrack(choices: choices, state: state + choice, n: n, res: &res)\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n: Int) -> Int {\nlet choices = [1, 2] // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nlet state = 0 // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvar res: [Int] = []\nres.append(0) // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices: choices, state: state, n: n, res: &res)\nreturn res[0]\n}\n
        climbing_stairs_backtrack.js
        /* \u56de\u6eaf */\nfunction backtrack(choices, state, n, res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state === n) res.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n) {\nconst choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nconst state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nconst res = new Map();\nres.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.ts
        /* \u56de\u6eaf */\nfunction backtrack(\nchoices: number[],\nstate: number,\nn: number,\nres: Map<0, any>\n): void {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state === n) res.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n: number): number {\nconst choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nconst state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nconst res = new Map();\nres.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.dart
        /* \u56de\u6eaf */\nvoid backtrack(List<int> choices, int state, int n, List<int> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n) {\nres[0]++;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int choice in choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nList<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<int> res = [];\nres.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.rs
        /* \u56de\u6eaf */\nfn backtrack(choices: &[i32], state: i32, n: i32, res: &mut [i32]) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n { res[0] = res[0] + 1; }\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor &choice in choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n { continue; }\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfn climbing_stairs_backtrack(n: usize) -> i32 {\nlet choices = vec![ 1, 2 ]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nlet state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nlet mut res = Vec::new();\nres.push(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(&choices, state, n as i32, &mut res);\nres[0]\n}\n
        climbing_stairs_backtrack.c
        /* \u56de\u6eaf */\nvoid backtrack(int *choices, int state, int n, int *res, int len) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < len; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res, len);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nint choices[2] = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0;           // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nint *res = (int *)malloc(sizeof(int));\n*res = 0; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nint len = sizeof(choices) / sizeof(int);\nbacktrack(choices, state, n, res, len);\nint result = *res;\nfree(res);\nreturn result;\n}\n
        climbing_stairs_backtrack.zig
        // \u56de\u6eaf\nfn backtrack(choices: []i32, state: i32, n: i32, res: std.ArrayList(i32)) void {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n) {\nres.items[0] = res.items[0] + 1;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (choices) |choice| {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n// \u722c\u697c\u68af\uff1a\u56de\u6eaf\nfn climbingStairsBacktrack(n: usize) !i32 {\nvar choices = [_]i32{ 1, 2 }; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nvar state: i32 = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvar res = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer res.deinit();\ntry res.append(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(&choices, state, @intCast(n), res);\nreturn res.items[0];\n}\n
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1411","title":"14.1.1 \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u5e76\u4e0d\u663e\u5f0f\u5730\u5bf9\u95ee\u9898\u8fdb\u884c\u62c6\u89e3\uff0c\u800c\u662f\u5c06\u6c42\u89e3\u95ee\u9898\u770b\u4f5c\u4e00\u7cfb\u5217\u51b3\u7b56\u6b65\u9aa4\uff0c\u901a\u8fc7\u8bd5\u63a2\u548c\u526a\u679d\uff0c\u641c\u7d22\u6240\u6709\u53ef\u80fd\u7684\u89e3\u3002

        \u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u4ece\u95ee\u9898\u5206\u89e3\u7684\u89d2\u5ea6\u5206\u6790\u8fd9\u9053\u9898\u3002\u8bbe\u722c\u5230\u7b2c \\(i\\) \u9636\u5171\u6709 \\(dp[i]\\) \u79cd\u65b9\u6848\uff0c\u90a3\u4e48 \\(dp[i]\\) \u5c31\u662f\u539f\u95ee\u9898\uff0c\u5176\u5b50\u95ee\u9898\u5305\u62ec\uff1a

        \\[ dp[i-1], dp[i-2], \\dots, dp[2], dp[1] \\]

        \u7531\u4e8e\u6bcf\u8f6e\u53ea\u80fd\u4e0a \\(1\\) \u9636\u6216 \\(2\\) \u9636\uff0c\u56e0\u6b64\u5f53\u6211\u4eec\u7ad9\u5728\u7b2c \\(i\\) \u9636\u697c\u68af\u4e0a\u65f6\uff0c\u4e0a\u4e00\u8f6e\u53ea\u53ef\u80fd\u7ad9\u5728\u7b2c \\(i - 1\\) \u9636\u6216\u7b2c \\(i - 2\\) \u9636\u4e0a\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u53ea\u80fd\u4ece\u7b2c \\(i -1\\) \u9636\u6216\u7b2c \\(i - 2\\) \u9636\u8fc8\u5411\u7b2c \\(i\\) \u9636\u3002

        \u7531\u6b64\u4fbf\u53ef\u5f97\u51fa\u4e00\u4e2a\u91cd\u8981\u63a8\u8bba\uff1a\u722c\u5230\u7b2c \\(i - 1\\) \u9636\u7684\u65b9\u6848\u6570\u52a0\u4e0a\u722c\u5230\u7b2c \\(i - 2\\) \u9636\u7684\u65b9\u6848\u6570\u5c31\u7b49\u4e8e\u722c\u5230\u7b2c \\(i\\) \u9636\u7684\u65b9\u6848\u6570\u3002\u516c\u5f0f\u5982\u4e0b\uff1a

        \\[ dp[i] = dp[i-1] + dp[i-2] \\]

        \u8fd9\u610f\u5473\u7740\u5728\u722c\u697c\u68af\u95ee\u9898\u4e2d\uff0c\u5404\u4e2a\u5b50\u95ee\u9898\u4e4b\u95f4\u5b58\u5728\u9012\u63a8\u5173\u7cfb\uff0c\u539f\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u7531\u5b50\u95ee\u9898\u7684\u89e3\u6784\u5efa\u5f97\u6765\u3002\u56fe 14-2 \u5c55\u793a\u4e86\u8be5\u9012\u63a8\u5173\u7cfb\u3002

        \u56fe 14-2 \u00a0 \u65b9\u6848\u6570\u91cf\u9012\u63a8\u5173\u7cfb

        \u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9012\u63a8\u516c\u5f0f\u5f97\u5230\u66b4\u529b\u641c\u7d22\u89e3\u6cd5\u3002\u4ee5 \\(dp[n]\\) \u4e3a\u8d77\u59cb\u70b9\uff0c\u9012\u5f52\u5730\u5c06\u4e00\u4e2a\u8f83\u5927\u95ee\u9898\u62c6\u89e3\u4e3a\u4e24\u4e2a\u8f83\u5c0f\u95ee\u9898\u7684\u548c\uff0c\u76f4\u81f3\u5230\u8fbe\u6700\u5c0f\u5b50\u95ee\u9898 \\(dp[1]\\) \u548c \\(dp[2]\\) \u65f6\u8fd4\u56de\u3002\u5176\u4e2d\uff0c\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u662f\u5df2\u77e5\u7684\uff0c\u5373 \\(dp[1] = 1\\)\u3001\\(dp[2] = 2\\) \uff0c\u8868\u793a\u722c\u5230\u7b2c \\(1\\)\u3001\\(2\\) \u9636\u5206\u522b\u6709 \\(1\\)\u3001\\(2\\) \u79cd\u65b9\u6848\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5b83\u548c\u6807\u51c6\u56de\u6eaf\u4ee3\u7801\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff0c\u4f46\u66f4\u52a0\u7b80\u6d01\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dfs.py
        def dfs(i: int) -> int:\n\"\"\"\u641c\u7d22\"\"\"\n# \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 or i == 2:\nreturn i\n# dp[i] = dp[i-1] + dp[i-2]\ncount = dfs(i - 1) + dfs(i - 2)\nreturn count\ndef climbing_stairs_dfs(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u641c\u7d22\"\"\"\nreturn dfs(n)\n
        climbing_stairs_dfs.cpp
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.java
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.cs
        /* \u641c\u7d22 */\nint DFS(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = DFS(i - 1) + DFS(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint ClimbingStairsDFS(int n) {\nreturn DFS(n);\n}\n
        climbing_stairs_dfs.go
        /* \u641c\u7d22 */\nfunc dfs(i int) int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// dp[i] = dp[i-1] + dp[i-2]\ncount := dfs(i-1) + dfs(i-2)\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n int) int {\nreturn dfs(n)\n}\n
        climbing_stairs_dfs.swift
        /* \u641c\u7d22 */\nfunc dfs(i: Int) -> Int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i: i - 1) + dfs(i: i - 2)\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n: Int) -> Int {\ndfs(i: n)\n}\n
        climbing_stairs_dfs.js
        /* \u641c\u7d22 */\nfunction dfs(i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.ts
        /* \u641c\u7d22 */\nfunction dfs(i: number): number {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n: number): number {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.dart
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.rs
        /* \u641c\u7d22 */\nfn dfs(i: usize) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 { return i as i32; }\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i - 1) + dfs(i - 2);\ncount\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfn climbing_stairs_dfs(n: usize) -> i32 {\ndfs(n) }\n
        climbing_stairs_dfs.c
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.zig
        // \u641c\u7d22\nfn dfs(i: usize) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 or i == 2) {\nreturn @intCast(i);\n}\n// dp[i] = dp[i-1] + dp[i-2]\nvar count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n// \u722c\u697c\u68af\uff1a\u641c\u7d22\nfn climbingStairsDFS(comptime n: usize) i32 {\nreturn dfs(n);\n}\n

        \u56fe 14-3 \u5c55\u793a\u4e86\u66b4\u529b\u641c\u7d22\u5f62\u6210\u7684\u9012\u5f52\u6811\u3002\u5bf9\u4e8e\u95ee\u9898 \\(dp[n]\\) \uff0c\u5176\u9012\u5f52\u6811\u7684\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002\u6307\u6570\u9636\u5c5e\u4e8e\u7206\u70b8\u5f0f\u589e\u957f\uff0c\u5982\u679c\u6211\u4eec\u8f93\u5165\u4e00\u4e2a\u6bd4\u8f83\u5927\u7684 \\(n\\) \uff0c\u5219\u4f1a\u9677\u5165\u6f2b\u957f\u7684\u7b49\u5f85\u4e4b\u4e2d\u3002

        \u56fe 14-3 \u00a0 \u722c\u697c\u68af\u5bf9\u5e94\u9012\u5f52\u6811

        \u89c2\u5bdf\u56fe 14-3 \uff0c\u6307\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u201c\u91cd\u53e0\u5b50\u95ee\u9898\u201d\u5bfc\u81f4\u7684\u3002\u4f8b\u5982 \\(dp[9]\\) \u88ab\u5206\u89e3\u4e3a \\(dp[8]\\) \u548c \\(dp[7]\\) \uff0c\\(dp[8]\\) \u88ab\u5206\u89e3\u4e3a \\(dp[7]\\) \u548c \\(dp[6]\\) \uff0c\u4e24\u8005\u90fd\u5305\u542b\u5b50\u95ee\u9898 \\(dp[7]\\) \u3002

        \u4ee5\u6b64\u7c7b\u63a8\uff0c\u5b50\u95ee\u9898\u4e2d\u5305\u542b\u66f4\u5c0f\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u5b50\u5b50\u5b59\u5b59\u65e0\u7a77\u5c3d\u4e5f\u3002\u7edd\u5927\u90e8\u5206\u8ba1\u7b97\u8d44\u6e90\u90fd\u6d6a\u8d39\u5728\u8fd9\u4e9b\u91cd\u53e0\u7684\u95ee\u9898\u4e0a\u3002

        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1412","title":"14.1.2 \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u4e3a\u4e86\u63d0\u5347\u7b97\u6cd5\u6548\u7387\uff0c\u6211\u4eec\u5e0c\u671b\u6240\u6709\u7684\u91cd\u53e0\u5b50\u95ee\u9898\u90fd\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4 mem \u6765\u8bb0\u5f55\u6bcf\u4e2a\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5e76\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u5c06\u91cd\u53e0\u5b50\u95ee\u9898\u526a\u679d\u3002

        1. \u5f53\u9996\u6b21\u8ba1\u7b97 \\(dp[i]\\) \u65f6\uff0c\u6211\u4eec\u5c06\u5176\u8bb0\u5f55\u81f3 mem[i] \uff0c\u4ee5\u4fbf\u4e4b\u540e\u4f7f\u7528\u3002
        2. \u5f53\u518d\u6b21\u9700\u8981\u8ba1\u7b97 \\(dp[i]\\) \u65f6\uff0c\u6211\u4eec\u4fbf\u53ef\u76f4\u63a5\u4ece mem[i] \u4e2d\u83b7\u53d6\u7ed3\u679c\uff0c\u4ece\u800c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u8be5\u5b50\u95ee\u9898\u3002

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dfs_mem.py
        def dfs(i: int, mem: list[int]) -> int:\n\"\"\"\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 or i == 2:\nreturn i\n# \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1:\nreturn mem[i]\n# dp[i] = dp[i-1] + dp[i-2]\ncount = dfs(i - 1, mem) + dfs(i - 2, mem)\n# \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\ndef climbing_stairs_dfs_mem(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nmem = [-1] * (n + 1)\nreturn dfs(n, mem)\n
        climbing_stairs_dfs_mem.cpp
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, vector<int> &mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvector<int> mem(n + 1, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.java
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, int[] mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint[] mem = new int[n + 1];\nArrays.fill(mem, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.cs
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint DFS(int i, int[] mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = DFS(i - 1, mem) + DFS(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint ClimbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint[] mem = new int[n + 1];\nArray.Fill(mem, -1);\nreturn DFS(n, mem);\n}\n
        climbing_stairs_dfs_mem.go
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc dfsMem(i int, mem []int) int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 {\nreturn mem[i]\n}\n// dp[i] = dp[i-1] + dp[i-2]\ncount := dfsMem(i-1, mem) + dfsMem(i-2, mem)\n// \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc climbingStairsDFSMem(n int) int {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nmem := make([]int, n+1)\nfor i := range mem {\nmem[i] = -1\n}\nreturn dfsMem(n, mem)\n}\n
        climbing_stairs_dfs_mem.swift
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc dfs(i: Int, mem: inout [Int]) -> Int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 {\nreturn mem[i]\n}\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i: i - 1, mem: &mem) + dfs(i: i - 2, mem: &mem)\n// \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc climbingStairsDFSMem(n: Int) -> Int {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvar mem = Array(repeating: -1, count: n + 1)\nreturn dfs(i: n, mem: &mem)\n}\n
        climbing_stairs_dfs_mem.js
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction dfs(i, mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction climbingStairsDFSMem(n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nconst mem = new Array(n + 1).fill(-1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.ts
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction dfs(i: number, mem: number[]): number {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction climbingStairsDFSMem(n: number): number {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nconst mem = new Array(n + 1).fill(-1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.dart
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, List<int> mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nList<int> mem = List.filled(n + 1, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.rs
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn dfs(i: usize, mem: &mut [i32]) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 { return i as i32; }\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 { return mem[i]; }\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\ncount\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn climbing_stairs_dfs_mem(n: usize) -> i32 {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nlet mut mem = vec![-1; n + 1];\ndfs(n, &mut mem)\n}\n
        climbing_stairs_dfs_mem.c
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, int *mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint *mem = (int *)malloc((n + 1) * sizeof(int));\nfor (int i = 0; i <= n; i++) {\nmem[i] = -1;\n}\nint result = dfs(n, mem);\nfree(mem);\nreturn result;\n}\n
        climbing_stairs_dfs_mem.zig
        // \u8bb0\u5fc6\u5316\u641c\u7d22\nfn dfs(i: usize, mem: []i32) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 or i == 2) {\nreturn @intCast(i);\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) {\nreturn mem[i];\n}\n// dp[i] = dp[i-1] + dp[i-2]\nvar count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n// \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn climbingStairsDFSMem(comptime n: usize) i32 {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvar mem = [_]i32{ -1 } ** (n + 1);\nreturn dfs(n, &mem);\n}\n

        \u89c2\u5bdf\u56fe 14-4 \uff0c\u7ecf\u8fc7\u8bb0\u5fc6\u5316\u5904\u7406\u540e\uff0c\u6240\u6709\u91cd\u53e0\u5b50\u95ee\u9898\u90fd\u53ea\u9700\u8ba1\u7b97\u4e00\u6b21\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(n)\\) \uff0c\u8fd9\u662f\u4e00\u4e2a\u5de8\u5927\u7684\u98de\u8dc3\u3002

        \u56fe 14-4 \u00a0 \u8bb0\u5fc6\u5316\u641c\u7d22\u5bf9\u5e94\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1413","title":"14.1.3 \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u8bb0\u5fc6\u5316\u641c\u7d22\u662f\u4e00\u79cd\u201c\u4ece\u9876\u81f3\u5e95\u201d\u7684\u65b9\u6cd5\uff1a\u6211\u4eec\u4ece\u539f\u95ee\u9898\uff08\u6839\u8282\u70b9\uff09\u5f00\u59cb\uff0c\u9012\u5f52\u5730\u5c06\u8f83\u5927\u5b50\u95ee\u9898\u5206\u89e3\u4e3a\u8f83\u5c0f\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u89e3\u5df2\u77e5\u7684\u6700\u5c0f\u5b50\u95ee\u9898\uff08\u53f6\u8282\u70b9\uff09\u3002\u4e4b\u540e\uff0c\u901a\u8fc7\u56de\u6eaf\u9010\u5c42\u6536\u96c6\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u6784\u5efa\u51fa\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u4e0e\u4e4b\u76f8\u53cd\uff0c\u52a8\u6001\u89c4\u5212\u662f\u4e00\u79cd\u201c\u4ece\u5e95\u81f3\u9876\u201d\u7684\u65b9\u6cd5\uff1a\u4ece\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u5f00\u59cb\uff0c\u8fed\u4ee3\u5730\u6784\u5efa\u66f4\u5927\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u76f4\u81f3\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u7531\u4e8e\u52a8\u6001\u89c4\u5212\u4e0d\u5305\u542b\u56de\u6eaf\u8fc7\u7a0b\uff0c\u56e0\u6b64\u53ea\u9700\u4f7f\u7528\u5faa\u73af\u8fed\u4ee3\u5b9e\u73b0\uff0c\u65e0\u987b\u4f7f\u7528\u9012\u5f52\u3002\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u4e00\u4e2a\u6570\u7ec4 dp \u6765\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5b83\u8d77\u5230\u4e86\u4e0e\u8bb0\u5fc6\u5316\u641c\u7d22\u4e2d\u6570\u7ec4 mem \u76f8\u540c\u7684\u8bb0\u5f55\u4f5c\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dp.py
        def climbing_stairs_dp(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn n\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [0] * (n + 1)\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1], dp[2] = 1, 2\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i] = dp[i - 1] + dp[i - 2]\nreturn dp[n]\n
        climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<int> dp(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.java
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.go
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n int) int {\nif n == 1 || n == 2 {\nreturn n\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1\ndp[2] = 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i] = dp[i-1] + dp[i-2]\n}\nreturn dp[n]\n}\n
        climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn n\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: 0, count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1\ndp[2] = 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i] = dp[i - 1] + dp[i - 2]\n}\nreturn dp[n]\n}\n
        climbing_stairs_dp.js
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n) {\nif (n === 1 || n === 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1).fill(-1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n: number): number {\nif (n === 1 || n === 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1).fill(-1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<int> dp = List.filled(n + 1, 0);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_dp(n: usize) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif n == 1 || n == 2 { return n as i32; }\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![-1; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\ndp[n]\n}\n
        climbing_stairs_dp.c
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint *dp = (int *)malloc((n + 1) * sizeof(int));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nint result = dp[n];\nfree(dp);\nreturn result;\n}\n
        climbing_stairs_dp.zig
        // \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\nfn climbingStairsDP(comptime n: usize) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (n == 1 or n == 2) {\nreturn @intCast(n);\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_]i32{-1} ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n

        \u56fe 14-5 \u6a21\u62df\u4e86\u4ee5\u4e0a\u4ee3\u7801\u7684\u6267\u884c\u8fc7\u7a0b\u3002

        \u56fe 14-5 \u00a0 \u722c\u697c\u68af\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u4e0e\u56de\u6eaf\u7b97\u6cd5\u4e00\u6837\uff0c\u52a8\u6001\u89c4\u5212\u4e5f\u4f7f\u7528\u201c\u72b6\u6001\u201d\u6982\u5ff5\u6765\u8868\u793a\u95ee\u9898\u6c42\u89e3\u7684\u7279\u5b9a\u9636\u6bb5\uff0c\u6bcf\u4e2a\u72b6\u6001\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5b50\u95ee\u9898\u4ee5\u53ca\u76f8\u5e94\u7684\u5c40\u90e8\u6700\u4f18\u89e3\u3002\u4f8b\u5982\uff0c\u722c\u697c\u68af\u95ee\u9898\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u5f53\u524d\u6240\u5728\u697c\u68af\u9636\u6570 \\(i\\) \u3002

        \u6839\u636e\u4ee5\u4e0a\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u52a8\u6001\u89c4\u5212\u7684\u5e38\u7528\u672f\u8bed\u3002

        • \u5c06\u6570\u7ec4 dp \u79f0\u4e3a\u300c\\(dp\\) \u8868\u300d\uff0c\\(dp[i]\\) \u8868\u793a\u72b6\u6001 \\(i\\) \u5bf9\u5e94\u5b50\u95ee\u9898\u7684\u89e3\u3002
        • \u5c06\u6700\u5c0f\u5b50\u95ee\u9898\u5bf9\u5e94\u7684\u72b6\u6001\uff08\u7b2c \\(1\\) \u9636\u548c\u7b2c \\(2\\) \u9636\u697c\u68af\uff09\u79f0\u4e3a\u300c\u521d\u59cb\u72b6\u6001\u300d\u3002
        • \u5c06\u9012\u63a8\u516c\u5f0f \\(dp[i] = dp[i-1] + dp[i-2]\\) \u79f0\u4e3a\u300c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u300d\u3002
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1414","title":"14.1.4 \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7ec6\u5fc3\u7684\u8bfb\u8005\u53ef\u80fd\u53d1\u73b0\u4e86\uff0c\u7531\u4e8e \\(dp[i]\\) \u53ea\u4e0e \\(dp[i-1]\\) \u548c \\(dp[i-2]\\) \u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u987b\u4f7f\u7528\u4e00\u4e2a\u6570\u7ec4 dp \u6765\u5b58\u50a8\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u800c\u53ea\u9700\u4e24\u4e2a\u53d8\u91cf\u6eda\u52a8\u524d\u8fdb\u5373\u53ef\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dp.py
        def climbing_stairs_dp_comp(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn n\na, b = 1, 2\nfor _ in range(3, n + 1):\na, b = b, a + b\nreturn b\n
        climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.java
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.go
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDPComp(n int) int {\nif n == 1 || n == 2 {\nreturn n\n}\na, b := 1, 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\na, b = b, a+b\n}\nreturn b\n}\n
        climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDPComp(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn n\n}\nvar a = 1\nvar b = 2\nfor _ in stride(from: 3, through: n, by: 1) {\n(a, b) = (b, a + b)\n}\nreturn b\n}\n
        climbing_stairs_dp.js
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n) {\nif (n === 1 || n === 2) return n;\nlet a = 1,\nb = 2;\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n: number): number {\nif (n === 1 || n === 2) return n;\nlet a = 1,\nb = 2;\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2) return n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_dp_comp(n: usize) -> i32 {\nif n == 1 || n == 2 { return n as i32; }\nlet (mut a, mut b) = (1, 2);\nfor _ in 3..=n {\nlet tmp = b;\nb = a + b;\na = tmp;\n}\nb\n}\n
        climbing_stairs_dp.c
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.zig
        // \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn climbingStairsDPComp(comptime n: usize) i32 {\nif (n == 1 or n == 2) {\nreturn @intCast(n);\n}\nvar a: i32 = 1;\nvar b: i32 = 2;\nfor (3..n + 1) |_| {\nvar tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u7531\u4e8e\u7701\u53bb\u4e86\u6570\u7ec4 dp \u5360\u7528\u7684\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \u3002

        \u5728\u52a8\u6001\u89c4\u5212\u95ee\u9898\u4e2d\uff0c\u5f53\u524d\u72b6\u6001\u5f80\u5f80\u4ec5\u4e0e\u524d\u9762\u6709\u9650\u4e2a\u72b6\u6001\u6709\u5173\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u53ea\u4fdd\u7559\u5fc5\u8981\u7684\u72b6\u6001\uff0c\u901a\u8fc7\u201c\u964d\u7ef4\u201d\u6765\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u3002\u8fd9\u79cd\u7a7a\u95f4\u4f18\u5316\u6280\u5de7\u88ab\u79f0\u4e3a\u201c\u6eda\u52a8\u53d8\u91cf\u201d\u6216\u201c\u6eda\u52a8\u6570\u7ec4\u201d\u3002

        "},{"location":"chapter_dynamic_programming/knapsack_problem/","title":"14.4 \u00a0 0-1 \u80cc\u5305\u95ee\u9898","text":"

        \u80cc\u5305\u95ee\u9898\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u52a8\u6001\u89c4\u5212\u5165\u95e8\u9898\u76ee\uff0c\u662f\u52a8\u6001\u89c4\u5212\u4e2d\u6700\u5e38\u89c1\u7684\u95ee\u9898\u5f62\u5f0f\u3002\u5176\u5177\u6709\u5f88\u591a\u53d8\u79cd\uff0c\u4f8b\u5982 0-1 \u80cc\u5305\u95ee\u9898\u3001\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u3001\u591a\u91cd\u80cc\u5305\u95ee\u9898\u7b49\u3002

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5148\u6765\u6c42\u89e3\u6700\u5e38\u89c1\u7684 0-1 \u80cc\u5305\u95ee\u9898\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ea\u80fd\u9009\u62e9\u4e00\u6b21\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002

        \u89c2\u5bdf\u56fe 14-17 \uff0c\u7531\u4e8e\u7269\u54c1\u7f16\u53f7 \\(i\\) \u4ece \\(1\\) \u5f00\u59cb\u8ba1\u6570\uff0c\u6570\u7ec4\u7d22\u5f15\u4ece \\(0\\) \u5f00\u59cb\u8ba1\u6570\uff0c\u56e0\u6b64\u7269\u54c1 \\(i\\) \u5bf9\u5e94\u91cd\u91cf \\(wgt[i-1]\\) \u548c\u4ef7\u503c \\(val[i-1]\\) \u3002

        \u56fe 14-17 \u00a0 0-1 \u80cc\u5305\u7684\u793a\u4f8b\u6570\u636e

        \u6211\u4eec\u53ef\u4ee5\u5c06 0-1 \u80cc\u5305\u95ee\u9898\u770b\u4f5c\u4e00\u4e2a\u7531 \\(n\\) \u8f6e\u51b3\u7b56\u7ec4\u6210\u7684\u8fc7\u7a0b\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u7269\u4f53\u90fd\u6709\u4e0d\u653e\u5165\u548c\u653e\u5165\u4e24\u79cd\u51b3\u7b56\uff0c\u56e0\u6b64\u8be5\u95ee\u9898\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\u3002

        \u8be5\u95ee\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u201c\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u201d\uff0c\u56e0\u6b64\u8f83\u5927\u6982\u7387\u662f\u4e00\u4e2a\u52a8\u6001\u89c4\u5212\u95ee\u9898\u3002

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u5bf9\u4e8e\u6bcf\u4e2a\u7269\u54c1\u6765\u8bf4\uff0c\u4e0d\u653e\u5165\u80cc\u5305\uff0c\u80cc\u5305\u5bb9\u91cf\u4e0d\u53d8\uff1b\u653e\u5165\u80cc\u5305\uff0c\u80cc\u5305\u5bb9\u91cf\u51cf\u5c0f\u3002\u7531\u6b64\u53ef\u5f97\u72b6\u6001\u5b9a\u4e49\uff1a\u5f53\u524d\u7269\u54c1\u7f16\u53f7 \\(i\\) \u548c\u5269\u4f59\u80cc\u5305\u5bb9\u91cf \\(c\\) \uff0c\u8bb0\u4e3a \\([i, c]\\) \u3002

        \u72b6\u6001 \\([i, c]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u524d \\(i\\) \u4e2a\u7269\u54c1\u5728\u5269\u4f59\u5bb9\u91cf\u4e3a \\(c\\) \u7684\u80cc\u5305\u4e2d\u7684\u6700\u5927\u4ef7\u503c\uff0c\u8bb0\u4e3a \\(dp[i, c]\\) \u3002

        \u5f85\u6c42\u89e3\u7684\u662f \\(dp[n, cap]\\) \uff0c\u56e0\u6b64\u9700\u8981\u4e00\u4e2a\u5c3a\u5bf8\u4e3a \\((n+1) \\times (cap+1)\\) \u7684\u4e8c\u7ef4 \\(dp\\) \u8868\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u5f53\u6211\u4eec\u505a\u51fa\u7269\u54c1 \\(i\\) \u7684\u51b3\u7b56\u540e\uff0c\u5269\u4f59\u7684\u662f\u524d \\(i-1\\) \u4e2a\u7269\u54c1\u7684\u51b3\u7b56\uff0c\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\u3002

        • \u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u80cc\u5305\u5bb9\u91cf\u4e0d\u53d8\uff0c\u72b6\u6001\u53d8\u5316\u4e3a \\([i-1, c]\\) \u3002
        • \u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u80cc\u5305\u5bb9\u91cf\u51cf\u5c11 \\(wgt[i-1]\\) \uff0c\u4ef7\u503c\u589e\u52a0 \\(val[i-1]\\) \uff0c\u72b6\u6001\u53d8\u5316\u4e3a \\([i-1, c-wgt[i-1]]\\) \u3002

        \u4e0a\u8ff0\u5206\u6790\u5411\u6211\u4eec\u63ed\u793a\u4e86\u672c\u9898\u7684\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u6700\u5927\u4ef7\u503c \\(dp[i, c]\\) \u7b49\u4e8e\u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \u548c\u653e\u5165\u7269\u54c1 \\(i\\) \u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\u3002\u7531\u6b64\u53ef\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a

        \\[ dp[i, c] = \\max(dp[i-1, c], dp[i-1, c - wgt[i-1]] + val[i-1]) \\]

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u82e5\u5f53\u524d\u7269\u54c1\u91cd\u91cf \\(wgt[i - 1]\\) \u8d85\u51fa\u5269\u4f59\u80cc\u5305\u5bb9\u91cf \\(c\\) \uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\u3002

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u65e0\u7269\u54c1\u6216\u65e0\u5269\u4f59\u80cc\u5305\u5bb9\u91cf\u65f6\u6700\u5927\u4ef7\u503c\u4e3a \\(0\\) \uff0c\u5373\u9996\u5217 \\(dp[i, 0]\\) \u548c\u9996\u884c \\(dp[0, c]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        \u5f53\u524d\u72b6\u6001 \\([i, c]\\) \u4ece\u4e0a\u65b9\u7684\u72b6\u6001 \\([i-1, c]\\) \u548c\u5de6\u4e0a\u65b9\u7684\u72b6\u6001 \\([i-1, c-wgt[i-1]]\\) \u8f6c\u79fb\u800c\u6765\uff0c\u56e0\u6b64\u901a\u8fc7\u4e24\u5c42\u5faa\u73af\u6b63\u5e8f\u904d\u5386\u6574\u4e2a \\(dp\\) \u8868\u5373\u53ef\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u6309\u987a\u5e8f\u5b9e\u73b0\u66b4\u529b\u641c\u7d22\u3001\u8bb0\u5fc6\u5316\u641c\u7d22\u3001\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u3002

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#1","title":"1. \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u641c\u7d22\u4ee3\u7801\u5305\u542b\u4ee5\u4e0b\u8981\u7d20\u3002

        • \u9012\u5f52\u53c2\u6570\uff1a\u72b6\u6001 \\([i, c]\\) \u3002
        • \u8fd4\u56de\u503c\uff1a\u5b50\u95ee\u9898\u7684\u89e3 \\(dp[i, c]\\) \u3002
        • \u7ec8\u6b62\u6761\u4ef6\uff1a\u5f53\u7269\u54c1\u7f16\u53f7\u8d8a\u754c \\(i = 0\\) \u6216\u80cc\u5305\u5269\u4f59\u5bb9\u91cf\u4e3a \\(0\\) \u65f6\uff0c\u7ec8\u6b62\u9012\u5f52\u5e76\u8fd4\u56de\u4ef7\u503c \\(0\\) \u3002
        • \u526a\u679d\uff1a\u82e5\u5f53\u524d\u7269\u54c1\u91cd\u91cf\u8d85\u51fa\u80cc\u5305\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dfs(wgt: list[int], val: list[int], i: int, c: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22\"\"\"\n# \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 or c == 0:\nreturn 0\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c:\nreturn knapsack_dfs(wgt, val, i - 1, c)\n# \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno = knapsack_dfs(wgt, val, i - 1, c)\nyes = knapsack_dfs(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1]\n# \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes)\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(vector<int> &wgt, vector<int> &val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes);\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(int[] wgt, int[] val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint KnapsackDFS(int[] weight, int[] val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (weight[i - 1] > c) {\nreturn KnapsackDFS(weight, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = KnapsackDFS(weight, val, i - 1, c);\nint yes = KnapsackDFS(weight, val, i - 1, c - weight[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.Max(no, yes);\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc knapsackDFS(wgt, val []int, i, c int) int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i-1] > c {\nreturn knapsackDFS(wgt, val, i-1, c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno := knapsackDFS(wgt, val, i-1, c)\nyes := knapsackDFS(wgt, val, i-1, c-wgt[i-1]) + val[i-1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn int(math.Max(float64(no), float64(yes)))\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc knapsackDFS(wgt: [Int], val: [Int], i: Int, c: Int) -> Int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c {\nreturn knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\nlet yes = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c - wgt[i - 1]) + val[i - 1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes)\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(wgt, val, i, c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFS(wgt, val, i - 1, c);\nconst yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(\nwgt: Array<number>,\nval: Array<number>,\ni: number,\nc: number\n): number {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFS(wgt, val, i - 1, c);\nconst yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(List<int> wgt, List<int> val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes);\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfn knapsack_dfs(wgt: &[i32], val: &[i32], i: usize, c: usize) -> i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c as i32 {\nreturn knapsack_dfs(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsack_dfs(wgt, val, i - 1, c);\nlet yes = knapsack_dfs(wgt, val, i - 1, c - wgt[i - 1] as usize) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nstd::cmp::max(no, yes)\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(int wgt[], int val[], int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn myMax(no, yes);\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22\nfn knapsackDFS(wgt: []i32, val: []i32, i: usize, c: usize) i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 or c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nvar no = knapsackDFS(wgt, val, i - 1, c);\nvar yes = knapsackDFS(wgt, val, i - 1, c - @as(usize, @intCast(wgt[i - 1]))) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn @max(no, yes);\n}\n

        \u5982\u56fe 14-18 \u6240\u793a\uff0c\u7531\u4e8e\u6bcf\u4e2a\u7269\u54c1\u90fd\u4f1a\u4ea7\u751f\u4e0d\u9009\u548c\u9009\u4e24\u6761\u641c\u7d22\u5206\u652f\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002

        \u89c2\u5bdf\u9012\u5f52\u6811\uff0c\u5bb9\u6613\u53d1\u73b0\u5176\u4e2d\u5b58\u5728\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u4f8b\u5982 \\(dp[1, 10]\\) \u7b49\u3002\u800c\u5f53\u7269\u54c1\u8f83\u591a\u3001\u80cc\u5305\u5bb9\u91cf\u8f83\u5927\uff0c\u5c24\u5176\u662f\u76f8\u540c\u91cd\u91cf\u7684\u7269\u54c1\u8f83\u591a\u65f6\uff0c\u91cd\u53e0\u5b50\u95ee\u9898\u7684\u6570\u91cf\u5c06\u4f1a\u5927\u5e45\u589e\u591a\u3002

        \u56fe 14-18 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u66b4\u529b\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#2","title":"2. \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u4e3a\u4e86\u4fdd\u8bc1\u91cd\u53e0\u5b50\u95ee\u9898\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\uff0c\u6211\u4eec\u501f\u52a9\u8bb0\u5fc6\u5217\u8868 mem \u6765\u8bb0\u5f55\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5176\u4e2d mem[i][c] \u5bf9\u5e94 \\(dp[i, c]\\) \u3002

        \u5f15\u5165\u8bb0\u5fc6\u5316\u4e4b\u540e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u5b50\u95ee\u9898\u6570\u91cf\uff0c\u4e5f\u5c31\u662f \\(O(n \\times cap)\\) \u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dfs_mem(\nwgt: list[int], val: list[int], mem: list[list[int]], i: int, c: int\n) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 or c == 0:\nreturn 0\n# \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1:\nreturn mem[i][c]\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c:\nreturn knapsack_dfs_mem(wgt, val, mem, i - 1, c)\n# \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno = knapsack_dfs_mem(wgt, val, mem, i - 1, c)\nyes = knapsack_dfs_mem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1]\n# \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes)\nreturn mem[i][c]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(vector<int> &wgt, vector<int> &val, vector<vector<int>> &mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(int[] wgt, int[] val, int[][] mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint KnapsackDFSMem(int[] weight, int[] val, int[][] mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (weight[i - 1] > c) {\nreturn KnapsackDFSMem(weight, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = KnapsackDFSMem(weight, val, mem, i - 1, c);\nint yes = KnapsackDFSMem(weight, val, mem, i - 1, c - weight[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.Max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc knapsackDFSMem(wgt, val []int, mem [][]int, i, c int) int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c]\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i-1] > c {\nreturn knapsackDFSMem(wgt, val, mem, i-1, c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno := knapsackDFSMem(wgt, val, mem, i-1, c)\nyes := knapsackDFSMem(wgt, val, mem, i-1, c-wgt[i-1]) + val[i-1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = int(math.Max(float64(no), float64(yes)))\nreturn mem[i][c]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc knapsackDFSMem(wgt: [Int], val: [Int], mem: inout [[Int]], i: Int, c: Int) -> Int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c]\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c {\nreturn knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\nlet yes = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c - wgt[i - 1]) + val[i - 1]\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes)\nreturn mem[i][c]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(wgt, val, mem, i, c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] !== -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nconst yes =\nknapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(\nwgt: Array<number>,\nval: Array<number>,\nmem: Array<Array<number>>,\ni: number,\nc: number\n): number {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] !== -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nconst yes =\nknapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(\nList<int> wgt,\nList<int> val,\nList<List<int>> mem,\nint i,\nint c,\n) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn knapsack_dfs_mem(wgt: &[i32], val: &[i32], mem: &mut Vec<Vec<i32>>, i: usize, c: usize) -> i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c as i32 {\nreturn knapsack_dfs_mem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsack_dfs_mem(wgt, val, mem, i - 1, c);\nlet yes = knapsack_dfs_mem(wgt, val, mem, i - 1, c - wgt[i - 1] as usize) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = std::cmp::max(no, yes);\nmem[i][c]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(int wgt[], int val[], int memCols, int **mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = myMax(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn knapsackDFSMem(wgt: []i32, val: []i32, mem: anytype, i: usize, c: usize) i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 or c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nvar no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nvar yes = knapsackDFSMem(wgt, val, mem, i - 1, c - @as(usize, @intCast(wgt[i - 1]))) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = @max(no, yes);\nreturn mem[i][c];\n}\n

        \u56fe 14-19 \u5c55\u793a\u4e86\u5728\u8bb0\u5fc6\u5316\u641c\u7d22\u4e2d\u88ab\u526a\u6389\u7684\u641c\u7d22\u5206\u652f\u3002

        \u56fe 14-19 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u8bb0\u5fc6\u5316\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#3","title":"3. \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u52a8\u6001\u89c4\u5212\u5b9e\u8d28\u4e0a\u5c31\u662f\u5728\u72b6\u6001\u8f6c\u79fb\u4e2d\u586b\u5145 \\(dp\\) \u8868\u7684\u8fc7\u7a0b\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (cap + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\nreturn dp[n][cap]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint KnapsackDP(int[] weight, int[] val, int cap) {\nint n = weight.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (weight[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i, c] = dp[i - 1, c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i, c] = Math.Max(dp[i - 1, c - weight[i - 1]] + val[i - 1], dp[i - 1, c]);\n}\n}\n}\nreturn dp[n, cap];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, cap+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i-1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i-1][c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[n][cap]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[n][cap]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(n + 1)\n.fill(0)\n.map(() => Array(cap + 1).fill(0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i - 1][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i - 1][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfn knapsack_dp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; cap + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = std::cmp::max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[n][cap]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(cap + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = myMax(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[n][cap];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\nfn knapsackDP(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = @max(dp[i - 1][c], dp[i - 1][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n

        \u5982\u56fe 14-20 \u6240\u793a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u90fd\u7531\u6570\u7ec4 dp \u5927\u5c0f\u51b3\u5b9a\uff0c\u5373 \\(O(n \\times cap)\\) \u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14>

        \u56fe 14-20 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#4","title":"4. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u6bcf\u4e2a\u72b6\u6001\u90fd\u53ea\u4e0e\u5176\u4e0a\u4e00\u884c\u7684\u72b6\u6001\u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u6570\u7ec4\u6eda\u52a8\u524d\u8fdb\uff0c\u5c06\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n^2)\\) \u964d\u81f3 \\(O(n)\\) \u3002

        \u8fdb\u4e00\u6b65\u601d\u8003\uff0c\u6211\u4eec\u80fd\u5426\u4ec5\u7528\u4e00\u4e2a\u6570\u7ec4\u5b9e\u73b0\u7a7a\u95f4\u4f18\u5316\u5462\uff1f\u89c2\u5bdf\u53ef\u77e5\uff0c\u6bcf\u4e2a\u72b6\u6001\u90fd\u662f\u7531\u6b63\u4e0a\u65b9\u6216\u5de6\u4e0a\u65b9\u7684\u683c\u5b50\u8f6c\u79fb\u8fc7\u6765\u7684\u3002\u5047\u8bbe\u53ea\u6709\u4e00\u4e2a\u6570\u7ec4\uff0c\u5f53\u5f00\u59cb\u904d\u5386\u7b2c \\(i\\) \u884c\u65f6\uff0c\u8be5\u6570\u7ec4\u5b58\u50a8\u7684\u4ecd\u7136\u662f\u7b2c \\(i-1\\) \u884c\u7684\u72b6\u6001\u3002

        • \u5982\u679c\u91c7\u53d6\u6b63\u5e8f\u904d\u5386\uff0c\u90a3\u4e48\u904d\u5386\u5230 \\(dp[i, j]\\) \u65f6\uff0c\u5de6\u4e0a\u65b9 \\(dp[i-1, 1]\\) ~ \\(dp[i-1, j-1]\\) \u503c\u53ef\u80fd\u5df2\u7ecf\u88ab\u8986\u76d6\uff0c\u6b64\u65f6\u5c31\u65e0\u6cd5\u5f97\u5230\u6b63\u786e\u7684\u72b6\u6001\u8f6c\u79fb\u7ed3\u679c\u3002
        • \u5982\u679c\u91c7\u53d6\u5012\u5e8f\u904d\u5386\uff0c\u5219\u4e0d\u4f1a\u53d1\u751f\u8986\u76d6\u95ee\u9898\uff0c\u72b6\u6001\u8f6c\u79fb\u53ef\u4ee5\u6b63\u786e\u8fdb\u884c\u3002

        \u56fe 14-21 \u5c55\u793a\u4e86\u5728\u5355\u4e2a\u6570\u7ec4\u4e0b\u4ece\u7b2c \\(i = 1\\) \u884c\u8f6c\u6362\u81f3\u7b2c \\(i = 2\\) \u884c\u7684\u8fc7\u7a0b\u3002\u8bf7\u601d\u8003\u6b63\u5e8f\u904d\u5386\u548c\u5012\u5e8f\u904d\u5386\u7684\u533a\u522b\u3002

        <1><2><3><4><5><6>

        \u56fe 14-21 \u00a0 0-1 \u80cc\u5305\u7684\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u4ec5\u9700\u5c06\u6570\u7ec4 dp \u7684\u7b2c\u4e00\u7ef4 \\(i\\) \u76f4\u63a5\u5220\u9664\uff0c\u5e76\u4e14\u628a\u5185\u5faa\u73af\u66f4\u6539\u4e3a\u5012\u5e8f\u904d\u5386\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dp_comp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (cap + 1)\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u5012\u5e8f\u904d\u5386\nfor c in range(cap, 0, -1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\nreturn dp[cap]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint KnapsackDPComp(int[] weight, int[] val, int cap) {\nint n = weight.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c > 0; c--) {\nif (weight[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.Max(dp[c], dp[c - weight[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDPComp(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, cap+1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor c := cap; c >= 1; c-- {\nif wgt[i-1] <= c {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[cap]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDPComp(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: cap + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\n// \u5012\u5e8f\u904d\u5386\nfor c in stride(from: cap, through: 1, by: -1) {\nif wgt[i - 1] <= c {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[cap]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(cap + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (let c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(cap + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (let c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn knapsack_dp_comp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\n// \u5012\u5e8f\u904d\u5386\nfor c in (1..=cap).rev() {\nif wgt[i - 1] <= c as i32 {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[cap]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(cap + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[cap];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn knapsackDPComp(wgt: []i32, val: []i32, comptime cap: usize) i32 {\nvar n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (cap + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\n// \u5012\u5e8f\u904d\u5386\nvar c = cap;\nwhile (c > 0) : (c -= 1) {\nif (wgt[i - 1] < c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        "},{"location":"chapter_dynamic_programming/summary/","title":"14.7 \u00a0 \u5c0f\u7ed3","text":"
        • \u52a8\u6001\u89c4\u5212\u5bf9\u95ee\u9898\u8fdb\u884c\u5206\u89e3\uff0c\u5e76\u901a\u8fc7\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\u6765\u89c4\u907f\u91cd\u590d\u8ba1\u7b97\uff0c\u63d0\u9ad8 \u8ba1\u7b97\u6548\u7387\u3002
        • \u4e0d\u8003\u8651\u65f6\u95f4\u7684\u524d\u63d0\u4e0b\uff0c\u6240\u6709\u52a8\u6001\u89c4\u5212\u95ee\u9898\u90fd\u53ef\u4ee5\u7528\u56de\u6eaf\uff08\u66b4\u529b\u641c\u7d22\uff09\u8fdb\u884c\u6c42\u89e3\uff0c\u4f46\u9012\u5f52\u6811\u4e2d\u5b58\u5728\u5927\u91cf\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u6548\u7387\u6781\u4f4e\u3002\u901a\u8fc7\u5f15\u5165\u8bb0\u5fc6\u5316\u5217\u8868\uff0c\u53ef\u4ee5\u5b58\u50a8\u6240\u6709\u8ba1\u7b97\u8fc7\u7684\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u4ece\u800c\u4fdd\u8bc1\u91cd\u53e0\u5b50\u95ee\u9898\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002
        • \u8bb0\u5fc6\u5316\u9012\u5f52\u662f\u4e00\u79cd\u4ece\u9876\u81f3\u5e95\u7684\u9012\u5f52\u5f0f\u89e3\u6cd5\uff0c\u800c\u4e0e\u4e4b\u5bf9\u5e94\u7684\u52a8\u6001\u89c4\u5212\u662f\u4e00\u79cd\u4ece\u5e95\u81f3\u9876\u7684\u9012\u63a8\u5f0f\u89e3\u6cd5\uff0c\u5176\u5982\u540c\u201c\u586b\u5199\u8868\u683c\u201d\u4e00\u6837\u3002\u7531\u4e8e\u5f53\u524d\u72b6\u6001\u4ec5\u4f9d\u8d56\u67d0\u4e9b\u5c40\u90e8\u72b6\u6001\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u6d88\u9664 \\(dp\\) \u8868\u7684\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u4ece\u800c\u964d\u4f4e\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u901a\u7528\u7684\u7b97\u6cd5\u601d\u8def\uff0c\u5728\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u3001\u56de\u6eaf\u4e2d\u5177\u6709\u4e0d\u540c\u7684\u6027\u8d28\u3002
        • \u52a8\u6001\u89c4\u5212\u95ee\u9898\u6709\u4e09\u5927\u7279\u6027\uff1a\u91cd\u53e0\u5b50\u95ee\u9898\u3001\u6700\u4f18\u5b50\u7ed3\u6784\u3001\u65e0\u540e\u6548\u6027\u3002
        • \u5982\u679c\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u53ef\u4ee5\u4ece\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6784\u5efa\u5f97\u6765\uff0c\u5219\u5b83\u5c31\u5177\u6709\u6700\u4f18\u5b50\u7ed3\u6784\u3002
        • \u65e0\u540e\u6548\u6027\u6307\u5bf9\u4e8e\u4e00\u4e2a\u72b6\u6001\uff0c\u5176\u672a\u6765\u53d1\u5c55\u53ea\u4e0e\u8be5\u72b6\u6001\u6709\u5173\uff0c\u800c\u4e0e\u8fc7\u53bb\u7ecf\u5386\u7684\u6240\u6709\u72b6\u6001\u65e0\u5173\u3002\u8bb8\u591a\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u4e0d\u5177\u6709\u65e0\u540e\u6548\u6027\uff0c\u65e0\u6cd5\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u5feb\u901f\u6c42\u89e3\u3002

        \u80cc\u5305\u95ee\u9898

        • \u80cc\u5305\u95ee\u9898\u662f\u6700\u5178\u578b\u7684\u52a8\u6001\u89c4\u5212\u95ee\u9898\u4e4b\u4e00\uff0c\u5177\u6709 0-1 \u80cc\u5305\u3001\u5b8c\u5168\u80cc\u5305\u3001\u591a\u91cd\u80cc\u5305\u7b49\u53d8\u79cd\u3002
        • 0-1 \u80cc\u5305\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u524d \\(i\\) \u4e2a\u7269\u54c1\u5728\u5269\u4f59\u5bb9\u91cf\u4e3a \\(c\\) \u7684\u80cc\u5305\u4e2d\u7684\u6700\u5927\u4ef7\u503c\u3002\u6839\u636e\u4e0d\u653e\u5165\u80cc\u5305\u548c\u653e\u5165\u80cc\u5305\u4e24\u79cd\u51b3\u7b56\uff0c\u53ef\u5f97\u5230\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5e76\u6784\u5efa\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u5728\u7a7a\u95f4\u4f18\u5316\u4e2d\uff0c\u7531\u4e8e\u6bcf\u4e2a\u72b6\u6001\u4f9d\u8d56\u6b63\u4e0a\u65b9\u548c\u5de6\u4e0a\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u9700\u8981\u5012\u5e8f\u904d\u5386\u5217\u8868\uff0c\u907f\u514d\u5de6\u4e0a\u65b9\u72b6\u6001\u88ab\u8986\u76d6\u3002
        • \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u6bcf\u79cd\u7269\u54c1\u7684\u9009\u53d6\u6570\u91cf\u65e0\u9650\u5236\uff0c\u56e0\u6b64\u9009\u62e9\u653e\u5165\u7269\u54c1\u7684\u72b6\u6001\u8f6c\u79fb\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u4e0d\u540c\u3002\u7531\u4e8e\u72b6\u6001\u4f9d\u8d56\u6b63\u4e0a\u65b9\u548c\u6b63\u5de6\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u5728\u7a7a\u95f4\u4f18\u5316\u4e2d\u5e94\u5f53\u6b63\u5e8f\u904d\u5386\u3002
        • \u96f6\u94b1\u5151\u6362\u95ee\u9898\u662f\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u4e00\u4e2a\u53d8\u79cd\u3002\u5b83\u4ece\u6c42\u201c\u6700\u5927\u201d\u4ef7\u503c\u53d8\u4e3a\u6c42\u201c\u6700\u5c0f\u201d\u786c\u5e01\u6570\u91cf\uff0c\u56e0\u6b64\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(\\max()\\) \u5e94\u6539\u4e3a \\(\\min()\\) \u3002\u4ece\u8ffd\u6c42\u201c\u4e0d\u8d85\u8fc7\u201d\u80cc\u5305\u5bb9\u91cf\u5230\u8ffd\u6c42\u201c\u6070\u597d\u201d\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u4f7f\u7528 \\(amt + 1\\) \u6765\u8868\u793a\u201c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u201d\u7684\u65e0\u6548\u89e3\u3002
        • \u96f6\u94b1\u5151\u6362 II \u95ee\u9898\u4ece\u6c42\u201c\u6700\u5c11\u786c\u5e01\u6570\u91cf\u201d\u6539\u4e3a\u6c42\u201c\u786c\u5e01\u7ec4\u5408\u6570\u91cf\u201d\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u76f8\u5e94\u5730\u4ece \\(\\min()\\) \u6539\u4e3a\u6c42\u548c\u8fd0\u7b97\u7b26\u3002

        \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898

        • \u7f16\u8f91\u8ddd\u79bb\uff08Levenshtein \u8ddd\u79bb\uff09\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\uff0c\u5176\u5b9a\u4e49\u4e3a\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\uff0c\u7f16\u8f91\u64cd\u4f5c\u5305\u62ec\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66ff\u6362\u3002
        • \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u5c06 \\(s\\) \u7684\u524d \\(i\\) \u4e2a\u5b57\u7b26\u66f4\u6539\u4e3a \\(t\\) \u7684\u524d \\(j\\) \u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002\u5f53 \\(s[i] \\ne t[j]\\) \u65f6\uff0c\u5177\u6709\u4e09\u79cd\u51b3\u7b56\uff1a\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66ff\u6362\uff0c\u5b83\u4eec\u90fd\u6709\u76f8\u5e94\u7684\u5269\u4f59\u5b50\u95ee\u9898\u3002\u636e\u6b64\u4fbf\u53ef\u4ee5\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\u4e0e\u6784\u5efa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u800c\u5f53 \\(s[i] = t[j]\\) \u65f6\uff0c\u65e0\u987b\u7f16\u8f91\u5f53\u524d\u5b57\u7b26\u3002
        • \u5728\u7f16\u8f91\u8ddd\u79bb\u4e2d\uff0c\u72b6\u6001\u4f9d\u8d56\u5176\u6b63\u4e0a\u65b9\u3001\u6b63\u5de6\u65b9\u3001\u5de6\u4e0a\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u7a7a\u95f4\u4f18\u5316\u540e\u6b63\u5e8f\u6216\u5012\u5e8f\u904d\u5386\u90fd\u65e0\u6cd5\u6b63\u786e\u5730\u8fdb\u884c\u72b6\u6001\u8f6c\u79fb\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5229\u7528\u4e00\u4e2a\u53d8\u91cf\u6682\u5b58\u5de6\u4e0a\u65b9\u72b6\u6001\uff0c\u4ece\u800c\u8f6c\u5316\u5230\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7b49\u4ef7\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u5728\u7a7a\u95f4\u4f18\u5316\u540e\u8fdb\u884c\u6b63\u5e8f\u904d\u5386\u3002
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/","title":"14.5 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898","text":"

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5148\u6c42\u89e3\u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u80cc\u5305\u95ee\u9898\uff1a\u5b8c\u5168\u80cc\u5305\uff0c\u518d\u4e86\u89e3\u5b83\u7684\u4e00\u79cd\u7279\u4f8b\uff1a\u96f6\u94b1\u5151\u6362\u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1451","title":"14.5.1 \u00a0 \u5b8c\u5168\u80cc\u5305","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002\u793a\u4f8b\u5982\u56fe 14-22 \u6240\u793a\u3002

        \u56fe 14-22 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u548c 0-1 \u80cc\u5305\u95ee\u9898\u975e\u5e38\u76f8\u4f3c\uff0c\u533a\u522b\u4ec5\u5728\u4e8e\u4e0d\u9650\u5236\u7269\u54c1\u7684\u9009\u62e9\u6b21\u6570\u3002

        • \u5728 0-1 \u80cc\u5305\u95ee\u9898\u4e2d\uff0c\u6bcf\u79cd\u7269\u54c1\u53ea\u6709\u4e00\u4e2a\uff0c\u56e0\u6b64\u5c06\u7269\u54c1 \\(i\\) \u653e\u5165\u80cc\u5305\u540e\uff0c\u53ea\u80fd\u4ece\u524d \\(i-1\\) \u4e2a\u7269\u54c1\u4e2d\u9009\u62e9\u3002
        • \u5728\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u4e2d\uff0c\u6bcf\u79cd\u7269\u54c1\u7684\u6570\u91cf\u662f\u65e0\u9650\u7684\uff0c\u56e0\u6b64\u5c06\u7269\u54c1 \\(i\\) \u653e\u5165\u80cc\u5305\u540e\uff0c\u4ecd\u53ef\u4ee5\u4ece\u524d \\(i\\) \u4e2a\u7269\u54c1\u4e2d\u9009\u62e9\u3002

        \u5728\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u89c4\u5b9a\u4e0b\uff0c\u72b6\u6001 \\([i, c]\\) \u7684\u53d8\u5316\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\u3002

        • \u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u76f8\u540c\uff0c\u8f6c\u79fb\u81f3 \\([i-1, c]\\) \u3002
        • \u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u4e0d\u540c\uff0c\u8f6c\u79fb\u81f3 \\([i, c-wgt[i-1]]\\) \u3002

        \u4ece\u800c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u53d8\u4e3a\uff1a

        \\[ dp[i, c] = \\max(dp[i-1, c], dp[i, c - wgt[i-1]] + val[i-1]) \\]"},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5bf9\u6bd4\u4e24\u9053\u9898\u76ee\u7684\u4ee3\u7801\uff0c\u72b6\u6001\u8f6c\u79fb\u4e2d\u6709\u4e00\u5904\u4ece \\(i-1\\) \u53d8\u4e3a \\(i\\) \uff0c\u5176\u4f59\u5b8c\u5168\u4e00\u81f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig unbounded_knapsack.py
        def unbounded_knapsack_dp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (cap + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\nreturn dp[n][cap]\n
        unbounded_knapsack.cpp
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.java
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.cs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint UnboundedKnapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i, c] = dp[i - 1, c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i, c] = Math.Max(dp[i - 1, c], dp[i, c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n, cap];\n}\n
        unbounded_knapsack.go
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDP(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, cap+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i-1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i][c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[n][cap]\n}\n
        unbounded_knapsack.swift
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDP(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[n][cap]\n}\n
        unbounded_knapsack.js
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.ts
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.dart
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.rs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfn unbounded_knapsack_dp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; cap + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = std::cmp::max(dp[i - 1][c], dp[i][c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.c
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(cap + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = myMax(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[n][cap];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        unbounded_knapsack.zig
        // \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\nfn unboundedKnapsackDP(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = @max(dp[i - 1][c], dp[i][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u5f53\u524d\u72b6\u6001\u662f\u4ece\u5de6\u8fb9\u548c\u4e0a\u8fb9\u7684\u72b6\u6001\u8f6c\u79fb\u800c\u6765\u7684\uff0c\u56e0\u6b64\u7a7a\u95f4\u4f18\u5316\u540e\u5e94\u8be5\u5bf9 \\(dp\\) \u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u8fdb\u884c\u6b63\u5e8f\u904d\u5386\u3002

        \u8fd9\u4e2a\u904d\u5386\u987a\u5e8f\u4e0e 0-1 \u80cc\u5305\u6b63\u597d\u76f8\u53cd\u3002\u8bf7\u501f\u52a9\u56fe 14-23 \u6765\u7406\u89e3\u4e24\u8005\u7684\u533a\u522b\u3002

        <1><2><3><4><5><6>

        \u56fe 14-23 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u5728\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u4ee3\u7801\u5b9e\u73b0\u6bd4\u8f83\u7b80\u5355\uff0c\u4ec5\u9700\u5c06\u6570\u7ec4 dp \u7684\u7b2c\u4e00\u7ef4\u5220\u9664\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig unbounded_knapsack.py
        def unbounded_knapsack_dp_comp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (cap + 1)\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\nreturn dp[cap]\n
        unbounded_knapsack.cpp
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.java
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.cs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint UnboundedKnapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.Max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.go
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDPComp(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, cap+1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[cap]\n}\n
        unbounded_knapsack.swift
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDPComp(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: cap + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[cap]\n}\n
        unbounded_knapsack.js
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: cap + 1 }, () => 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.ts
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: cap + 1 }, () => 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.dart
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.rs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn unbounded_knapsack_dp_comp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[cap]\n}\n
        unbounded_knapsack.c
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(cap + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[cap];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        unbounded_knapsack.zig
        // \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn unboundedKnapsackDPComp(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (cap + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1452","title":"14.5.2 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898","text":"

        \u80cc\u5305\u95ee\u9898\u662f\u4e00\u5927\u7c7b\u52a8\u6001\u89c4\u5212\u95ee\u9898\u7684\u4ee3\u8868\uff0c\u5176\u62e5\u6709\u5f88\u591a\u53d8\u79cd\uff0c\u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u80fd\u591f\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002\u793a\u4f8b\u5982\u56fe 14-24 \u6240\u793a\u3002

        \u56fe 14-24 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1_1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u96f6\u94b1\u5151\u6362\u53ef\u4ee5\u770b\u4f5c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\uff0c\u4e24\u8005\u5177\u6709\u4ee5\u4e0b\u8054\u7cfb\u4e0e\u4e0d\u540c\u70b9\u3002

        • \u4e24\u9053\u9898\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\uff0c\u201c\u7269\u54c1\u201d\u5bf9\u5e94\u201c\u786c\u5e01\u201d\u3001\u201c\u7269\u54c1\u91cd\u91cf\u201d\u5bf9\u5e94\u201c\u786c\u5e01\u9762\u503c\u201d\u3001\u201c\u80cc\u5305\u5bb9\u91cf\u201d\u5bf9\u5e94\u201c\u76ee\u6807\u91d1\u989d\u201d\u3002
        • \u4f18\u5316\u76ee\u6807\u76f8\u53cd\uff0c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u662f\u8981\u6700\u5927\u5316\u7269\u54c1\u4ef7\u503c\uff0c\u96f6\u94b1\u5151\u6362\u95ee\u9898\u662f\u8981\u6700\u5c0f\u5316\u786c\u5e01\u6570\u91cf\u3002
        • \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u662f\u6c42\u201c\u4e0d\u8d85\u8fc7\u201d\u80cc\u5305\u5bb9\u91cf\u4e0b\u7684\u89e3\uff0c\u96f6\u94b1\u5151\u6362\u662f\u6c42\u201c\u6070\u597d\u201d\u51d1\u5230\u76ee\u6807\u91d1\u989d\u7684\u89e3\u3002

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u72b6\u6001 \\([i, a]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u524d \\(i\\) \u79cd\u786c\u5e01\u80fd\u591f\u51d1\u51fa\u91d1\u989d \\(a\\) \u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\uff0c\u8bb0\u4e3a \\(dp[i, a]\\) \u3002

        \u4e8c\u7ef4 \\(dp\\) \u8868\u7684\u5c3a\u5bf8\u4e3a \\((n+1) \\times (amt+1)\\) \u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u672c\u9898\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u5b58\u5728\u4ee5\u4e0b\u4e24\u70b9\u5dee\u5f02\u3002

        • \u672c\u9898\u8981\u6c42\u6700\u5c0f\u503c\uff0c\u56e0\u6b64\u9700\u5c06\u8fd0\u7b97\u7b26 \\(\\max()\\) \u66f4\u6539\u4e3a \\(\\min()\\) \u3002
        • \u4f18\u5316\u4e3b\u4f53\u662f\u786c\u5e01\u6570\u91cf\u800c\u975e\u5546\u54c1\u4ef7\u503c\uff0c\u56e0\u6b64\u5728\u9009\u4e2d\u786c\u5e01\u65f6\u6267\u884c \\(+1\\) \u5373\u53ef\u3002
        \\[ dp[i, a] = \\min(dp[i-1, a], dp[i, a - coins[i-1]] + 1) \\]

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u76ee\u6807\u91d1\u989d\u4e3a \\(0\\) \u65f6\uff0c\u51d1\u51fa\u5b83\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u4e3a \\(0\\) \uff0c\u5373\u9996\u5217\u6240\u6709 \\(dp[i, 0]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        \u5f53\u65e0\u786c\u5e01\u65f6\uff0c\u65e0\u6cd5\u51d1\u51fa\u4efb\u610f \\(> 0\\) \u7684\u76ee\u6807\u91d1\u989d\uff0c\u5373\u662f\u65e0\u6548\u89e3\u3002\u4e3a\u4f7f\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(\\min()\\) \u51fd\u6570\u80fd\u591f\u8bc6\u522b\u5e76\u8fc7\u6ee4\u65e0\u6548\u89e3\uff0c\u6211\u4eec\u8003\u8651\u4f7f\u7528 \\(+ \\infty\\) \u6765\u8868\u793a\u5b83\u4eec\uff0c\u5373\u4ee4\u9996\u884c\u6240\u6709 \\(dp[0, a]\\) \u90fd\u7b49\u4e8e \\(+ \\infty\\) \u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u5e76\u672a\u63d0\u4f9b \\(+ \\infty\\) \u53d8\u91cf\uff0c\u53ea\u80fd\u4f7f\u7528\u6574\u578b int \u7684\u6700\u5927\u503c\u6765\u4ee3\u66ff\u3002\u800c\u8fd9\u53c8\u4f1a\u5bfc\u81f4\u5927\u6570\u8d8a\u754c\uff1a\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(+ 1\\) \u64cd\u4f5c\u53ef\u80fd\u53d1\u751f\u6ea2\u51fa\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u91c7\u7528\u6570\u5b57 \\(amt + 1\\) \u6765\u8868\u793a\u65e0\u6548\u89e3\uff0c\u56e0\u4e3a\u51d1\u51fa \\(amt\\) \u7684\u786c\u5e01\u6570\u91cf\u6700\u591a\u4e3a \\(amt\\) \u3002\u6700\u540e\u8fd4\u56de\u524d\uff0c\u5224\u65ad \\(dp[n, amt]\\) \u662f\u5426\u7b49\u4e8e \\(amt + 1\\) \uff0c\u82e5\u662f\u5219\u8fd4\u56de \\(-1\\) \uff0c\u4ee3\u8868\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change.py
        def coin_change_dp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\nMAX = amt + 1\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (amt + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in range(1, amt + 1):\ndp[0][a] = MAX\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n + 1):\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\nreturn dp[n][amt] if dp[n][amt] != MAX else -1\n
        coin_change.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(vector<int> &coins, int amt) {\nint n = coins.size();\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(int[] coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][amt + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint CoinChangeDP(int[] coins, int amt) {\nint n = coins.Length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, amt + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0, a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i, a] = dp[i - 1, a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i, a] = Math.Min(dp[i - 1, a], dp[i, a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n, amt] != MAX ? dp[n, amt] : -1;\n}\n
        coin_change.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins []int, amt int) int {\nn := len(coins)\nmax := amt + 1\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, amt+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a := 1; a <= amt; a++ {\ndp[0][a] = max\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i-1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = int(math.Min(float64(dp[i-1][a]), float64(dp[i][a-coins[i-1]]+1)))\n}\n}\n}\nif dp[n][amt] != max {\nreturn dp[n][amt]\n}\nreturn -1\n}\n
        coin_change.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\nlet MAX = amt + 1\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in stride(from: 1, through: amt, by: 1) {\ndp[0][a] = MAX\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1\n}\n
        coin_change.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDP(coins, amt) {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] !== MAX ? dp[n][amt] : -1;\n}\n
        coin_change.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDP(coins: Array<number>, amt: number): number {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] !== MAX ? dp[n][amt] : -1;\n}\n
        coin_change.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(List<int> coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfn coin_change_dp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\nlet max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; amt + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in 1..= amt {\ndp[0][a] = max;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = std::cmp::min(dp[i - 1][a], dp[i][a - coins[i - 1] as usize] + 1);\n}\n}\n}\nif dp[n][amt] != max { return dp[n][amt] as i32; } else { -1 }\n}\n
        coin_change.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(amt + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = myMin(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nint res = dp[n][amt] != MAX ? dp[n][amt] : -1;\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        coin_change.zig
        // \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeDP(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\ncomptime var max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (1..amt + 1) |a| {\ndp[0][a] = max;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = @min(dp[i - 1][a], dp[i][a - @as(usize, @intCast(coins[i - 1]))] + 1);\n}\n}\n}\nif (dp[n][amt] != max) {\nreturn @intCast(dp[n][amt]);\n} else {\nreturn -1;\n}\n}\n

        \u56fe 14-25 \u5c55\u793a\u4e86\u96f6\u94b1\u5151\u6362\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b\uff0c\u548c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u975e\u5e38\u76f8\u4f3c\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14><15>

        \u56fe 14-25 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3_1","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u96f6\u94b1\u5151\u6362\u7684\u7a7a\u95f4\u4f18\u5316\u7684\u5904\u7406\u65b9\u5f0f\u548c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u4e00\u81f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change.py
        def coin_change_dp_comp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\nMAX = amt + 1\n# \u521d\u59cb\u5316 dp \u8868\ndp = [MAX] * (amt + 1)\ndp[0] = 0\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\nreturn dp[amt] if dp[amt] != MAX else -1\n
        coin_change.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(vector<int> &coins, int amt) {\nint n = coins.size();\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(amt + 1, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(int[] coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\nArrays.fill(dp, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint CoinChangeDPComp(int[] coins, int amt) {\nint n = coins.Length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\nArray.Fill(dp, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.Min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDPComp(coins []int, amt int) int {\nn := len(coins)\nmax := amt + 1\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, amt+1)\nfor i := 1; i <= amt; i++ {\ndp[i] = max\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = int(math.Min(float64(dp[a]), float64(dp[a-coins[i-1]]+1)))\n}\n}\n}\nif dp[amt] != max {\nreturn dp[amt]\n}\nreturn -1\n}\n
        coin_change.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDPComp(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\nlet MAX = amt + 1\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: MAX, count: amt + 1)\ndp[0] = 0\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1\n}\n
        coin_change.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDPComp(coins, amt) {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] !== MAX ? dp[amt] : -1;\n}\n
        coin_change.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDPComp(coins: Array<number>, amt: number): number {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] !== MAX ? dp[amt] : -1;\n}\n
        coin_change.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(List<int> coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(amt + 1, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn coin_change_dp_comp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\nlet max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; amt + 1];\ndp.fill(max);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = std::cmp::min(dp[a], dp[a - coins[i - 1] as usize] + 1);\n}\n}\n}\nif dp[amt] != max { return dp[amt] as i32; } else { -1 }\n}\n
        coin_change.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(amt + 1, sizeof(int));\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = myMin(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nint res = dp[amt] != MAX ? dp[amt] : -1;\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        coin_change.zig
        // \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn coinChangeDPComp(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\ncomptime var max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (amt + 1);\n@memset(&dp, max);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = @min(dp[a], dp[a - @as(usize, @intCast(coins[i - 1]))] + 1);\n}\n}\n}\nif (dp[amt] != max) {\nreturn @intCast(dp[amt]);\n} else {\nreturn -1;\n}\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1453-ii","title":"14.5.3 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898 II","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u786c\u5e01\u7ec4\u5408\u6570\u91cf\u3002\u793a\u4f8b\u5982\u56fe 14-26 \u6240\u793a\u3002

        \u56fe 14-26 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898 II \u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1_2","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u76f8\u6bd4\u4e8e\u4e0a\u4e00\u9898\uff0c\u672c\u9898\u76ee\u6807\u662f\u6c42\u7ec4\u5408\u6570\u91cf\uff0c\u56e0\u6b64\u5b50\u95ee\u9898\u53d8\u4e3a\uff1a\u524d \\(i\\) \u79cd\u786c\u5e01\u80fd\u591f\u51d1\u51fa\u91d1\u989d \\(a\\) \u7684\u7ec4\u5408\u6570\u91cf\u3002\u800c \\(dp\\) \u8868\u4ecd\u7136\u662f\u5c3a\u5bf8\u4e3a \\((n+1) \\times (amt + 1)\\) \u7684\u4e8c\u7ef4\u77e9\u9635\u3002

        \u5f53\u524d\u72b6\u6001\u7684\u7ec4\u5408\u6570\u91cf\u7b49\u4e8e\u4e0d\u9009\u5f53\u524d\u786c\u5e01\u4e0e\u9009\u5f53\u524d\u786c\u5e01\u8fd9\u4e24\u79cd\u51b3\u7b56\u7684\u7ec4\u5408\u6570\u91cf\u4e4b\u548c\u3002\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, a] = dp[i-1, a] + dp[i, a - coins[i-1]] \\]

        \u5f53\u76ee\u6807\u91d1\u989d\u4e3a \\(0\\) \u65f6\uff0c\u65e0\u987b\u9009\u62e9\u4efb\u4f55\u786c\u5e01\u5373\u53ef\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u5e94\u5c06\u9996\u5217\u6240\u6709 \\(dp[i, 0]\\) \u90fd\u521d\u59cb\u5316\u4e3a \\(1\\) \u3002\u5f53\u65e0\u786c\u5e01\u65f6\uff0c\u65e0\u6cd5\u51d1\u51fa\u4efb\u4f55 \\(>0\\) \u7684\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u9996\u884c\u6240\u6709 \\(dp[0, a]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2_2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_ii.py
        def coin_change_ii_dp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (amt + 1) for _ in range(n + 1)]\n# \u521d\u59cb\u5316\u9996\u5217\nfor i in range(n + 1):\ndp[i][0] = 1\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\nreturn dp[n][amt]\n
        coin_change_ii.cpp
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(vector<int> &coins, int amt) {\nint n = coins.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.java
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(int[] coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][amt + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.cs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint CoinChangeIIDP(int[] coins, int amt) {\nint n = coins.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, amt + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i, 0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i, a] = dp[i - 1, a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i, a] = dp[i - 1, a] + dp[i, a - coins[i - 1]];\n}\n}\n}\nreturn dp[n, amt];\n}\n
        coin_change_ii.go
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDP(coins []int, amt int) int {\nn := len(coins)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, amt+1)\n}\n// \u521d\u59cb\u5316\u9996\u5217\nfor i := 0; i <= n; i++ {\ndp[i][0] = 1\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i-1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i-1][a] + dp[i][a-coins[i-1]]\n}\n}\n}\nreturn dp[n][amt]\n}\n
        coin_change_ii.swift
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDP(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n// \u521d\u59cb\u5316\u9996\u5217\nfor i in stride(from: 0, through: n, by: 1) {\ndp[i][0] = 1\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n}\n}\n}\nreturn dp[n][amt]\n}\n
        coin_change_ii.js
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins, amt) {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (let i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.ts
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins: Array<number>, amt: number): number {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (let i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.dart
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(List<int> coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.rs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfn coin_change_ii_dp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; amt + 1]; n + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor i in 0..= n {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1] as usize];\n}\n}\n}\ndp[n][amt]\n}\n
        coin_change_ii.c
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(amt + 1, sizeof(int));\n}\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nint res = dp[n][amt];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        coin_change_ii.zig
        // \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeIIDP(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (0..n + 1) |i| {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = dp[i - 1][a] + dp[i][a - @as(usize, @intCast(coins[i - 1]))];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3_2","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7a7a\u95f4\u4f18\u5316\u5904\u7406\u65b9\u5f0f\u76f8\u540c\uff0c\u5220\u9664\u786c\u5e01\u7ef4\u5ea6\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_ii.py
        def coin_change_ii_dp_comp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (amt + 1)\ndp[0] = 1\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]]\nreturn dp[amt]\n
        coin_change_ii.cpp
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(vector<int> &coins, int amt) {\nint n = coins.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(amt + 1, 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.java
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(int[] coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.cs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint CoinChangeIIDPComp(int[] coins, int amt) {\nint n = coins.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.go
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDPComp(coins []int, amt int) int {\nn := len(coins)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, amt+1)\ndp[0] = 1\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a-coins[i-1]]\n}\n}\n}\nreturn dp[amt]\n}\n
        coin_change_ii.swift
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDPComp(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: amt + 1)\ndp[0] = 1\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]]\n}\n}\n}\nreturn dp[amt]\n}\n
        coin_change_ii.js
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDPComp(coins, amt) {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.ts
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDPComp(coins: Array<number>, amt: number): number {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.dart
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(List<int> coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(amt + 1, 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.rs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn coin_change_ii_dp_comp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = dp[a] + dp[a - coins[i - 1] as usize];\n}\n}\n}\ndp[amt]\n}\n
        coin_change_ii.c
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(amt + 1, sizeof(int));\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nint res = dp[amt];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        coin_change_ii.zig
        // \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn coinChangeIIDPComp(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (amt + 1);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = dp[a] + dp[a - @as(usize, @intCast(coins[i - 1]))];\n}\n}\n}\nreturn dp[amt];\n}\n
        "},{"location":"chapter_graph/","title":"\u7b2c 9 \u7ae0 \u00a0 \u56fe","text":"

        Abstract

        \u5728\u751f\u547d\u65c5\u9014\u4e2d\uff0c\u6211\u4eec\u5c31\u50cf\u662f\u4e00\u4e2a\u4e2a\u8282\u70b9\uff0c\u88ab\u65e0\u6570\u770b\u4e0d\u89c1\u7684\u8fb9\u76f8\u8fde\u3002

        \u6bcf\u4e00\u6b21\u7684\u76f8\u8bc6\u4e0e\u76f8\u79bb\uff0c\u90fd\u5728\u8fd9\u5f20\u5de8\u5927\u7684\u7f51\u7edc\u56fe\u4e2d\u7559\u4e0b\u72ec\u7279\u7684\u5370\u8bb0\u3002

        "},{"location":"chapter_graph/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 9.1 \u00a0 \u56fe
        • 9.2 \u00a0 \u56fe\u57fa\u7840\u64cd\u4f5c
        • 9.3 \u00a0 \u56fe\u7684\u904d\u5386
        • 9.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_graph/graph/","title":"9.1 \u00a0 \u56fe","text":"

        \u300c\u56fe graph\u300d\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u7531\u300c\u9876\u70b9 vertex\u300d\u548c\u300c\u8fb9 edge\u300d\u7ec4\u6210\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u56fe \\(G\\) \u62bd\u8c61\u5730\u8868\u793a\u4e3a\u4e00\u7ec4\u9876\u70b9 \\(V\\) \u548c\u4e00\u7ec4\u8fb9 \\(E\\) \u7684\u96c6\u5408\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u4e00\u4e2a\u5305\u542b 5 \u4e2a\u9876\u70b9\u548c 7 \u6761\u8fb9\u7684\u56fe\u3002

        \\[ \\begin{aligned} V & = \\{ 1, 2, 3, 4, 5 \\} \\newline E & = \\{ (1,2), (1,3), (1,5), (2,3), (2,4), (2,5), (4,5) \\} \\newline G & = \\{ V, E \\} \\newline \\end{aligned} \\]

        \u5982\u679c\u5c06\u9876\u70b9\u770b\u4f5c\u8282\u70b9\uff0c\u5c06\u8fb9\u770b\u4f5c\u8fde\u63a5\u5404\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u56fe\u770b\u4f5c\u4e00\u79cd\u4ece\u94fe\u8868\u62d3\u5c55\u800c\u6765\u7684\u6570\u636e\u7ed3\u6784\u3002\u5982\u56fe 9-1 \u6240\u793a\uff0c\u76f8\u8f83\u4e8e\u7ebf\u6027\u5173\u7cfb\uff08\u94fe\u8868\uff09\u548c\u5206\u6cbb\u5173\u7cfb\uff08\u6811\uff09\uff0c\u7f51\u7edc\u5173\u7cfb\uff08\u56fe\uff09\u7684\u81ea\u7531\u5ea6\u66f4\u9ad8\uff0c\u56e0\u800c\u66f4\u4e3a\u590d\u6742\u3002

        \u56fe 9-1 \u00a0 \u94fe\u8868\u3001\u6811\u3001\u56fe\u4e4b\u95f4\u7684\u5173\u7cfb

        "},{"location":"chapter_graph/graph/#911","title":"9.1.1 \u00a0 \u56fe\u5e38\u89c1\u7c7b\u578b\u4e0e\u672f\u8bed","text":"

        \u6839\u636e\u8fb9\u662f\u5426\u5177\u6709\u65b9\u5411\uff0c\u53ef\u5206\u4e3a\u300c\u65e0\u5411\u56fe undirected graph\u300d\u548c\u300c\u6709\u5411\u56fe directed graph\u300d\uff0c\u5982\u56fe 9-2 \u6240\u793a\u3002

        • \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u8fb9\u8868\u793a\u4e24\u9876\u70b9\u4e4b\u95f4\u7684\u201c\u53cc\u5411\u201d\u8fde\u63a5\u5173\u7cfb\uff0c\u4f8b\u5982\u5fae\u4fe1\u6216 QQ \u4e2d\u7684\u201c\u597d\u53cb\u5173\u7cfb\u201d\u3002
        • \u5728\u6709\u5411\u56fe\u4e2d\uff0c\u8fb9\u5177\u6709\u65b9\u5411\u6027\uff0c\u5373 \\(A \\rightarrow B\\) \u548c \\(A \\leftarrow B\\) \u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u4f8b\u5982\u5fae\u535a\u6216\u6296\u97f3\u4e0a\u7684\u201c\u5173\u6ce8\u201d\u4e0e\u201c\u88ab\u5173\u6ce8\u201d\u5173\u7cfb\u3002

        \u56fe 9-2 \u00a0 \u6709\u5411\u56fe\u4e0e\u65e0\u5411\u56fe

        \u6839\u636e\u6240\u6709\u9876\u70b9\u662f\u5426\u8fde\u901a\uff0c\u53ef\u5206\u4e3a\u300c\u8fde\u901a\u56fe connected graph\u300d\u548c\u300c\u975e\u8fde\u901a\u56fe disconnected graph\u300d\uff0c\u5982\u56fe 9-3 \u6240\u793a\u3002

        • \u5bf9\u4e8e\u8fde\u901a\u56fe\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u53ef\u4ee5\u5230\u8fbe\u5176\u4f59\u4efb\u610f\u9876\u70b9\u3002
        • \u5bf9\u4e8e\u975e\u8fde\u901a\u56fe\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u9876\u70b9\u65e0\u6cd5\u5230\u8fbe\u3002

        \u56fe 9-3 \u00a0 \u8fde\u901a\u56fe\u4e0e\u975e\u8fde\u901a\u56fe

        \u6211\u4eec\u8fd8\u53ef\u4ee5\u4e3a\u8fb9\u6dfb\u52a0\u201c\u6743\u91cd\u201d\u53d8\u91cf\uff0c\u4ece\u800c\u5f97\u5230\u5982\u56fe 9-4 \u6240\u793a\u7684\u300c\u6709\u6743\u56fe weighted graph\u300d\u3002\u4f8b\u5982\u5728\u201c\u738b\u8005\u8363\u8000\u201d\u7b49\u624b\u6e38\u4e2d\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e\u5171\u540c\u6e38\u620f\u65f6\u95f4\u6765\u8ba1\u7b97\u73a9\u5bb6\u4e4b\u95f4\u7684\u201c\u4eb2\u5bc6\u5ea6\u201d\uff0c\u8fd9\u79cd\u4eb2\u5bc6\u5ea6\u7f51\u7edc\u5c31\u53ef\u4ee5\u7528\u6709\u6743\u56fe\u6765\u8868\u793a\u3002

        \u56fe 9-4 \u00a0 \u6709\u6743\u56fe\u4e0e\u65e0\u6743\u56fe

        \u56fe\u6570\u636e\u7ed3\u6784\u5305\u542b\u4ee5\u4e0b\u5e38\u7528\u672f\u8bed\u3002

        • \u300c\u90bb\u63a5 adjacency\u300d\uff1a\u5f53\u4e24\u9876\u70b9\u4e4b\u95f4\u5b58\u5728\u8fb9\u76f8\u8fde\u65f6\uff0c\u79f0\u8fd9\u4e24\u9876\u70b9\u201c\u90bb\u63a5\u201d\u3002\u5728\u56fe 9-4 \u4e2d\uff0c\u9876\u70b9 1 \u7684\u90bb\u63a5\u9876\u70b9\u4e3a\u9876\u70b9 2\u30013\u30015\u3002
        • \u300c\u8def\u5f84 path\u300d\uff1a\u4ece\u9876\u70b9 A \u5230\u9876\u70b9 B \u7ecf\u8fc7\u7684\u8fb9\u6784\u6210\u7684\u5e8f\u5217\u88ab\u79f0\u4e3a\u4ece A \u5230 B \u7684\u201c\u8def\u5f84\u201d\u3002\u5728\u56fe 9-4 \u4e2d\uff0c\u8fb9\u5e8f\u5217 1-5-2-4 \u662f\u9876\u70b9 1 \u5230\u9876\u70b9 4 \u7684\u4e00\u6761\u8def\u5f84\u3002
        • \u300c\u5ea6 degree\u300d\uff1a\u4e00\u4e2a\u9876\u70b9\u62e5\u6709\u7684\u8fb9\u6570\u3002\u5bf9\u4e8e\u6709\u5411\u56fe\uff0c\u300c\u5165\u5ea6 in-degree\u300d\u8868\u793a\u6709\u591a\u5c11\u6761\u8fb9\u6307\u5411\u8be5\u9876\u70b9\uff0c\u300c\u51fa\u5ea6 out-degree\u300d\u8868\u793a\u6709\u591a\u5c11\u6761\u8fb9\u4ece\u8be5\u9876\u70b9\u6307\u51fa\u3002
        "},{"location":"chapter_graph/graph/#912","title":"9.1.2 \u00a0 \u56fe\u7684\u8868\u793a","text":"

        \u56fe\u7684\u5e38\u7528\u8868\u793a\u65b9\u5f0f\u5305\u62ec\u201c\u90bb\u63a5\u77e9\u9635\u201d\u548c\u201c\u90bb\u63a5\u8868\u201d\u3002\u4ee5\u4e0b\u4f7f\u7528\u65e0\u5411\u56fe\u8fdb\u884c\u4e3e\u4f8b\u3002

        "},{"location":"chapter_graph/graph/#1","title":"1. \u00a0 \u90bb\u63a5\u77e9\u9635","text":"

        \u8bbe\u56fe\u7684\u9876\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u300c\u90bb\u63a5\u77e9\u9635 adjacency matrix\u300d\u4f7f\u7528\u4e00\u4e2a \\(n \\times n\\) \u5927\u5c0f\u7684\u77e9\u9635\u6765\u8868\u793a\u56fe\uff0c\u6bcf\u4e00\u884c\uff08\u5217\uff09\u4ee3\u8868\u4e00\u4e2a\u9876\u70b9\uff0c\u77e9\u9635\u5143\u7d20\u4ee3\u8868\u8fb9\uff0c\u7528 \\(1\\) \u6216 \\(0\\) \u8868\u793a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u8fb9\u3002

        \u5982\u56fe 9-5 \u6240\u793a\uff0c\u8bbe\u90bb\u63a5\u77e9\u9635\u4e3a \\(M\\)\u3001\u9876\u70b9\u5217\u8868\u4e3a \\(V\\) \uff0c\u90a3\u4e48\u77e9\u9635\u5143\u7d20 \\(M[i, j] = 1\\) \u8868\u793a\u9876\u70b9 \\(V[i]\\) \u5230\u9876\u70b9 \\(V[j]\\) \u4e4b\u95f4\u5b58\u5728\u8fb9\uff0c\u53cd\u4e4b \\(M[i, j] = 0\\) \u8868\u793a\u4e24\u9876\u70b9\u4e4b\u95f4\u65e0\u8fb9\u3002

        \u56fe 9-5 \u00a0 \u56fe\u7684\u90bb\u63a5\u77e9\u9635\u8868\u793a

        \u90bb\u63a5\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u9876\u70b9\u4e0d\u80fd\u4e0e\u81ea\u8eab\u76f8\u8fde\uff0c\u56e0\u6b64\u90bb\u63a5\u77e9\u9635\u4e3b\u5bf9\u89d2\u7ebf\u5143\u7d20\u6ca1\u6709\u610f\u4e49\u3002
        • \u5bf9\u4e8e\u65e0\u5411\u56fe\uff0c\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u7b49\u4ef7\uff0c\u6b64\u65f6\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\u3002
        • \u5c06\u90bb\u63a5\u77e9\u9635\u7684\u5143\u7d20\u4ece \\(1\\) \u548c \\(0\\) \u66ff\u6362\u4e3a\u6743\u91cd\uff0c\u5219\u53ef\u8868\u793a\u6709\u6743\u56fe\u3002

        \u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u8868\u793a\u56fe\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u77e9\u9635\u5143\u7d20\u4ee5\u83b7\u53d6\u8fb9\uff0c\u56e0\u6b64\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u7684\u6548\u7387\u5f88\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(1)\\) \u3002\u7136\u800c\uff0c\u77e9\u9635\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u5185\u5b58\u5360\u7528\u8f83\u591a\u3002

        "},{"location":"chapter_graph/graph/#2","title":"2. \u00a0 \u90bb\u63a5\u8868","text":"

        \u300c\u90bb\u63a5\u8868 adjacency list\u300d\u4f7f\u7528 \\(n\\) \u4e2a\u94fe\u8868\u6765\u8868\u793a\u56fe\uff0c\u94fe\u8868\u8282\u70b9\u8868\u793a\u9876\u70b9\u3002\u7b2c \\(i\\) \u4e2a\u94fe\u8868\u5bf9\u5e94\u9876\u70b9 \\(i\\) \uff0c\u5176\u4e2d\u5b58\u50a8\u4e86\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff08\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u9876\u70b9\uff09\u3002\u56fe 9-6 \u5c55\u793a\u4e86\u4e00\u4e2a\u4f7f\u7528\u90bb\u63a5\u8868\u5b58\u50a8\u7684\u56fe\u7684\u793a\u4f8b\u3002

        \u56fe 9-6 \u00a0 \u56fe\u7684\u90bb\u63a5\u8868\u8868\u793a

        \u90bb\u63a5\u8868\u4ec5\u5b58\u50a8\u5b9e\u9645\u5b58\u5728\u7684\u8fb9\uff0c\u800c\u8fb9\u7684\u603b\u6570\u901a\u5e38\u8fdc\u5c0f\u4e8e \\(n^2\\) \uff0c\u56e0\u6b64\u5b83\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\u3002\u7136\u800c\uff0c\u5728\u90bb\u63a5\u8868\u4e2d\u9700\u8981\u901a\u8fc7\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u8fb9\uff0c\u56e0\u6b64\u5176\u65f6\u95f4\u6548\u7387\u4e0d\u5982\u90bb\u63a5\u77e9\u9635\u3002

        \u89c2\u5bdf\u56fe 9-6 \uff0c\u90bb\u63a5\u8868\u7ed3\u6784\u4e0e\u54c8\u5e0c\u8868\u4e2d\u7684\u201c\u94fe\u5f0f\u5730\u5740\u201d\u975e\u5e38\u76f8\u4f3c\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u53ef\u4ee5\u91c7\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\u6765\u4f18\u5316\u6548\u7387\u3002\u6bd4\u5982\u5f53\u94fe\u8868\u8f83\u957f\u65f6\uff0c\u53ef\u4ee5\u5c06\u94fe\u8868\u8f6c\u5316\u4e3a AVL \u6811\u6216\u7ea2\u9ed1\u6811\uff0c\u4ece\u800c\u5c06\u65f6\u95f4\u6548\u7387\u4ece \\(O(n)\\) \u4f18\u5316\u81f3 \\(O(\\log n)\\) \uff1b\u8fd8\u53ef\u4ee5\u628a\u94fe\u8868\u8f6c\u6362\u4e3a\u54c8\u5e0c\u8868\uff0c\u4ece\u800c\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u81f3 \\(O(1)\\) \u3002

        "},{"location":"chapter_graph/graph/#913","title":"9.1.3 \u00a0 \u56fe\u5e38\u89c1\u5e94\u7528","text":"

        \u5982\u8868 9-1 \u6240\u793a\uff0c\u8bb8\u591a\u73b0\u5b9e\u7cfb\u7edf\u53ef\u4ee5\u7528\u56fe\u6765\u5efa\u6a21\uff0c\u76f8\u5e94\u7684\u95ee\u9898\u4e5f\u53ef\u4ee5\u7ea6\u5316\u4e3a\u56fe\u8ba1\u7b97\u95ee\u9898\u3002

        \u8868 9-1 \u00a0 \u73b0\u5b9e\u751f\u6d3b\u4e2d\u5e38\u89c1\u7684\u56fe

        \u9876\u70b9 \u8fb9 \u56fe\u8ba1\u7b97\u95ee\u9898 \u793e\u4ea4\u7f51\u7edc \u7528\u6237 \u597d\u53cb\u5173\u7cfb \u6f5c\u5728\u597d\u53cb\u63a8\u8350 \u5730\u94c1\u7ebf\u8def \u7ad9\u70b9 \u7ad9\u70b9\u95f4\u7684\u8fde\u901a\u6027 \u6700\u77ed\u8def\u7ebf\u63a8\u8350 \u592a\u9633\u7cfb \u661f\u4f53 \u661f\u4f53\u95f4\u7684\u4e07\u6709\u5f15\u529b\u4f5c\u7528 \u884c\u661f\u8f68\u9053\u8ba1\u7b97"},{"location":"chapter_graph/graph_operations/","title":"9.2 \u00a0 \u56fe\u57fa\u7840\u64cd\u4f5c","text":"

        \u56fe\u7684\u57fa\u7840\u64cd\u4f5c\u53ef\u5206\u4e3a\u5bf9\u201c\u8fb9\u201d\u7684\u64cd\u4f5c\u548c\u5bf9\u201c\u9876\u70b9\u201d\u7684\u64cd\u4f5c\u3002\u5728\u201c\u90bb\u63a5\u77e9\u9635\u201d\u548c\u201c\u90bb\u63a5\u8868\u201d\u4e24\u79cd\u8868\u793a\u65b9\u6cd5\u4e0b\uff0c\u5b9e\u73b0\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002

        "},{"location":"chapter_graph/graph_operations/#921","title":"9.2.1 \u00a0 \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u7684\u5b9e\u73b0","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u9876\u70b9\u6570\u91cf\u4e3a \\(n\\) \u7684\u65e0\u5411\u56fe\uff0c\u5219\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u65b9\u5f0f\u5982\u56fe 9-7 \u6240\u793a\u3002

        • \u6dfb\u52a0\u6216\u5220\u9664\u8fb9\uff1a\u76f4\u63a5\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u4fee\u6539\u6307\u5b9a\u7684\u8fb9\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u800c\u7531\u4e8e\u662f\u65e0\u5411\u56fe\uff0c\u56e0\u6b64\u9700\u8981\u540c\u65f6\u66f4\u65b0\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u6dfb\u52a0\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u77e9\u9635\u7684\u5c3e\u90e8\u6dfb\u52a0\u4e00\u884c\u4e00\u5217\uff0c\u5e76\u5168\u90e8\u586b \\(0\\) \u5373\u53ef\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u4e00\u884c\u4e00\u5217\u3002\u5f53\u5220\u9664\u9996\u884c\u9996\u5217\u65f6\u8fbe\u5230\u6700\u5dee\u60c5\u51b5\uff0c\u9700\u8981\u5c06 \\((n-1)^2\\) \u4e2a\u5143\u7d20\u201c\u5411\u5de6\u4e0a\u79fb\u52a8\u201d\uff0c\u4ece\u800c\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u521d\u59cb\u5316\uff1a\u4f20\u5165 \\(n\\) \u4e2a\u9876\u70b9\uff0c\u521d\u59cb\u5316\u957f\u5ea6\u4e3a \\(n\\) \u7684\u9876\u70b9\u5217\u8868 vertices \uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\uff1b\u521d\u59cb\u5316 \\(n \\times n\\) \u5927\u5c0f\u7684\u90bb\u63a5\u77e9\u9635 adjMat \uff0c\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        \u521d\u59cb\u5316\u90bb\u63a5\u77e9\u9635\u6dfb\u52a0\u8fb9\u5220\u9664\u8fb9\u6dfb\u52a0\u9876\u70b9\u5220\u9664\u9876\u70b9

        \u56fe 9-7 \u00a0 \u90bb\u63a5\u77e9\u9635\u7684\u521d\u59cb\u5316\u3001\u589e\u5220\u8fb9\u3001\u589e\u5220\u9876\u70b9

        \u4ee5\u4e0b\u662f\u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u8868\u793a\u56fe\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_adjacency_matrix.py
        class GraphAdjMat:\n\"\"\"\u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\"\"\"\ndef __init__(self, vertices: list[int], edges: list[list[int]]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nself.vertices: list[int] = []\n# \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\nself.adj_mat: list[list[int]] = []\n# \u6dfb\u52a0\u9876\u70b9\nfor val in vertices:\nself.add_vertex(val)\n# \u6dfb\u52a0\u8fb9\n# \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor e in edges:\nself.add_edge(e[0], e[1])\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\nreturn len(self.vertices)\ndef add_vertex(self, val: int):\n\"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\nn = self.size()\n# \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nself.vertices.append(val)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nnew_row = [0] * n\nself.adj_mat.append(new_row)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor row in self.adj_mat:\nrow.append(0)\ndef remove_vertex(self, index: int):\n\"\"\"\u5220\u9664\u9876\u70b9\"\"\"\nif index >= self.size():\nraise IndexError()\n# \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nself.vertices.pop(index)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nself.adj_mat.pop(index)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor row in self.adj_mat:\nrow.pop(index)\ndef add_edge(self, i: int, j: int):\n\"\"\"\u6dfb\u52a0\u8fb9\"\"\"\n# \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n# \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\nraise IndexError()\n# \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nself.adj_mat[i][j] = 1\nself.adj_mat[j][i] = 1\ndef remove_edge(self, i: int, j: int):\n\"\"\"\u5220\u9664\u8fb9\"\"\"\n# \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n# \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\nraise IndexError()\nself.adj_mat[i][j] = 0\nself.adj_mat[j][i] = 0\ndef print(self):\n\"\"\"\u6253\u5370\u90bb\u63a5\u77e9\u9635\"\"\"\nprint(\"\u9876\u70b9\u5217\u8868 =\", self.vertices)\nprint(\"\u90bb\u63a5\u77e9\u9635 =\")\nprint_matrix(self.adj_mat)\n
        graph_adjacency_matrix.cpp
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvector<int> vertices;       // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nvector<vector<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjMat(const vector<int> &vertices, const vector<vector<int>> &edges) {\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val : vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const vector<int> &edge : edges) {\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() const {\nreturn vertices.size();\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.push_back(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nadjMat.emplace_back(vector<int>(n, 0));\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (vector<int> &row : adjMat) {\nrow.push_back(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(int index) {\nif (index >= size()) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.erase(vertices.begin() + index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.erase(adjMat.begin() + index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (vector<int> &row : adjMat) {\nrow.erase(row.begin() + index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid print() {\ncout << \"\u9876\u70b9\u5217\u8868 = \";\nprintVector(vertices);\ncout << \"\u90bb\u63a5\u77e9\u9635 =\" << endl;\nprintVectorMatrix(adjMat);\n}\n};\n
        graph_adjacency_matrix.java
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<Integer> vertices; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<Integer>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\npublic GraphAdjMat(int[] vertices, int[][] edges) {\nthis.vertices = new ArrayList<>();\nthis.adjMat = new ArrayList<>();\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val : vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (int[] e : edges) {\naddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic int size() {\nreturn vertices.size();\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<Integer> newRow = new ArrayList<>(n);\nfor (int j = 0; j < n; j++) {\nnewRow.add(0);\n}\nadjMat.add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (List<Integer> row : adjMat) {\nrow.add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void removeVertex(int index) {\nif (index >= size())\nthrow new IndexOutOfBoundsException();\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (List<Integer> row : adjMat) {\nrow.remove(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\nthrow new IndexOutOfBoundsException();\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat.get(i).set(j, 1);\nadjMat.get(j).set(i, 1);\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\nthrow new IndexOutOfBoundsException();\nadjMat.get(i).set(j, 0);\nadjMat.get(j).set(i, 0);\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npublic void print() {\nSystem.out.print(\"\u9876\u70b9\u5217\u8868 = \");\nSystem.out.println(vertices);\nSystem.out.println(\"\u90bb\u63a5\u77e9\u9635 =\");\nPrintUtil.printMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.cs
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<int> vertices;     // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\npublic GraphAdjMat(int[] vertices, int[][] edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nforeach (int val in vertices) {\nAddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nforeach (int[] e in edges) {\nAddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint Size() {\nreturn vertices.Count;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void AddVertex(int val) {\nint n = Size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.Add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<int> newRow = new(n);\nfor (int j = 0; j < n; j++) {\nnewRow.Add(0);\n}\nadjMat.Add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nforeach (List<int> row in adjMat) {\nrow.Add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void RemoveVertex(int index) {\nif (index >= Size())\nthrow new IndexOutOfRangeException();\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.RemoveAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.RemoveAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nforeach (List<int> row in adjMat) {\nrow.RemoveAt(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void AddEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\nthrow new IndexOutOfRangeException();\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void RemoveEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\nthrow new IndexOutOfRangeException();\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npublic void Print() {\nConsole.Write(\"\u9876\u70b9\u5217\u8868 = \");\nPrintUtil.PrintList(vertices);\nConsole.WriteLine(\"\u90bb\u63a5\u77e9\u9635 =\");\nPrintUtil.PrintMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.go
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntype graphAdjMat struct {\n// \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nvertices []int\n// \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat [][]int\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {\n// \u6dfb\u52a0\u9876\u70b9\nn := len(vertices)\nadjMat := make([][]int, n)\nfor i := range adjMat {\nadjMat[i] = make([]int, n)\n}\n// \u521d\u59cb\u5316\u56fe\ng := &graphAdjMat{\nvertices: vertices,\nadjMat:   adjMat,\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor i := range edges {\ng.addEdge(edges[i][0], edges[i][1])\n}\nreturn g\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjMat) size() int {\nreturn len(g.vertices)\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjMat) addVertex(val int) {\nn := g.size()\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\ng.vertices = append(g.vertices, val)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nnewRow := make([]int, n)\ng.adjMat = append(g.adjMat, newRow)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor i := range g.adjMat {\ng.adjMat[i] = append(g.adjMat[i], 0)\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjMat) removeVertex(index int) {\nif index >= g.size() {\nreturn\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\ng.vertices = append(g.vertices[:index], g.vertices[index+1:]...)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\ng.adjMat = append(g.adjMat[:index], g.adjMat[index+1:]...)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor i := range g.adjMat {\ng.adjMat[i] = append(g.adjMat[i][:index], g.adjMat[i][index+1:]...)\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc (g *graphAdjMat) addEdge(i, j int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\nfmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\ng.adjMat[i][j] = 1\ng.adjMat[j][i] = 1\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc (g *graphAdjMat) removeEdge(i, j int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\nfmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n}\ng.adjMat[i][j] = 0\ng.adjMat[j][i] = 0\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc (g *graphAdjMat) print() {\nfmt.Printf(\"\\t\u9876\u70b9\u5217\u8868 = %v\\n\", g.vertices)\nfmt.Printf(\"\\t\u90bb\u63a5\u77e9\u9635 = \\n\")\nfor i := range g.adjMat {\nfmt.Printf(\"\\t\\t\\t%v\\n\", g.adjMat[i])\n}\n}\n
        graph_adjacency_matrix.swift
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nprivate var vertices: [Int] // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nprivate var adjMat: [[Int]] // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(vertices: [Int], edges: [[Int]]) {\nself.vertices = []\nadjMat = []\n// \u6dfb\u52a0\u9876\u70b9\nfor val in vertices {\naddVertex(val: val)\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor e in edges {\naddEdge(i: e[0], j: e[1])\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc size() -> Int {\nvertices.count\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc addVertex(val: Int) {\nlet n = size()\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.append(val)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nlet newRow = Array(repeating: 0, count: n)\nadjMat.append(newRow)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor i in adjMat.indices {\nadjMat[i].append(0)\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc removeVertex(index: Int) {\nif index >= size() {\nfatalError(\"\u8d8a\u754c\")\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.remove(at: index)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.remove(at: index)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor i in adjMat.indices {\nadjMat[i].remove(at: index)\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc addEdge(i: Int, j: Int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= size() || j >= size() || i == j {\nfatalError(\"\u8d8a\u754c\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1\nadjMat[j][i] = 1\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc removeEdge(i: Int, j: Int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= size() || j >= size() || i == j {\nfatalError(\"\u8d8a\u754c\")\n}\nadjMat[i][j] = 0\nadjMat[j][i] = 0\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc print() {\nSwift.print(\"\u9876\u70b9\u5217\u8868 = \", terminator: \"\")\nSwift.print(vertices)\nSwift.print(\"\u90bb\u63a5\u77e9\u9635 =\")\nPrintUtil.printMatrix(matrix: adjMat)\n}\n}\n
        graph_adjacency_matrix.js
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvertices; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\nconstructor(vertices, edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (const val of vertices) {\nthis.addVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const e of edges) {\nthis.addEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize() {\nreturn this.vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(val) {\nconst n = this.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nthis.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nconst newRow = [];\nfor (let j = 0; j < n; j++) {\nnewRow.push(0);\n}\nthis.adjMat.push(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (const row of this.adjMat) {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(index) {\nif (index >= this.size()) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nthis.vertices.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nthis.adjMat.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (const row of this.adjMat) {\nrow.splice(index, 1);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\naddEdge(i, j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) === (j, i)\nthis.adjMat[i][j] = 1;\nthis.adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nremoveEdge(i, j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\nthis.adjMat[i][j] = 0;\nthis.adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nprint() {\nconsole.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\nconsole.log('\u90bb\u63a5\u77e9\u9635 =', this.adjMat);\n}\n}\n
        graph_adjacency_matrix.ts
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvertices: number[]; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat: number[][]; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\nconstructor(vertices: number[], edges: number[][]) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (const val of vertices) {\nthis.addVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const e of edges) {\nthis.addEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(val: number): void {\nconst n: number = this.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nthis.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nconst newRow: number[] = [];\nfor (let j: number = 0; j < n; j++) {\nnewRow.push(0);\n}\nthis.adjMat.push(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (const row of this.adjMat) {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(index: number): void {\nif (index >= this.size()) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nthis.vertices.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nthis.adjMat.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (const row of this.adjMat) {\nrow.splice(index, 1);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\naddEdge(i: number, j: number): void {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) === (j, i)\nthis.adjMat[i][j] = 1;\nthis.adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nremoveEdge(i: number, j: number): void {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\nthis.adjMat[i][j] = 0;\nthis.adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nprint(): void {\nconsole.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\nconsole.log('\u90bb\u63a5\u77e9\u9635 =', this.adjMat);\n}\n}\n
        graph_adjacency_matrix.dart
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<int> vertices = []; // \u9876\u70b9\u5143\u7d20\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<int>> adjMat = []; //\u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjMat(List<int> vertices, List<List<int>> edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val in vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (List<int> e in edges) {\naddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<int> newRow = List.filled(n, 0, growable: true);\nadjMat.add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (List<int> row in adjMat) {\nrow.add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(int index) {\nif (index >= size()) {\nthrow IndexError;\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.removeAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.removeAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (List<int> row in adjMat) {\nrow.removeAt(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow IndexError;\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow IndexError;\n}\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printAdjMat() {\nprint(\"\u9876\u70b9\u5217\u8868 = $vertices\");\nprint(\"\u90bb\u63a5\u77e9\u9635 = \");\nprintMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.rs
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\u578b */\npub struct GraphAdjMat {\n// \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\npub vertices: Vec<i32>,\n// \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\npub adj_mat: Vec<Vec<i32>>,\n}\nimpl GraphAdjMat {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(vertices: Vec<i32>, edges: Vec<[usize; 2]>) -> Self {\nlet mut graph = GraphAdjMat {\nvertices: vec![],\nadj_mat: vec![],\n};\n// \u6dfb\u52a0\u9876\u70b9\nfor val in vertices {\ngraph.add_vertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor edge in edges {\ngraph.add_edge(edge[0], edge[1])\n}\ngraph\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npub fn size(&self) -> usize {\nself.vertices.len()\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npub fn add_vertex(&mut self, val: i32) {\nlet n = self.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nself.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nself.adj_mat.push(vec![0; n]);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor row in &mut self.adj_mat {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npub fn remove_vertex(&mut self, index: usize) {\nif index >= self.size() {\npanic!(\"index error\")\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nself.vertices.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nself.adj_mat.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor row in &mut self.adj_mat {\nrow.remove(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\npub fn add_edge(&mut self, i: usize, j: usize) {\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i >= self.size() || j >= self.size() || i == j {\npanic!(\"index error\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nself.adj_mat[i][j] = 1;\nself.adj_mat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npub fn remove_edge(&mut self, i: usize, j: usize) {\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i >= self.size() || j >= self.size() || i == j {\npanic!(\"index error\")\n}\nself.adj_mat[i][j] = 0;\nself.adj_mat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npub fn print(&self) {\nprintln!(\"\u9876\u70b9\u5217\u8868 = {:?}\", self.vertices);\nprintln!(\"\u90bb\u63a5\u77e9\u9635 =\");\nprintln!(\"[\");\nfor row in &self.adj_mat {\nprintln!(\"  {:?},\", row);\n}\nprintln!(\"]\")\n}\n}\n
        graph_adjacency_matrix.c
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7ed3\u6784\u4f53 */\ntypedef struct {\nint vertices[MAX_SIZE];\nint adjMat[MAX_SIZE][MAX_SIZE];\nint size;\n} GraphAdjMat;\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjMat *newGraphAdjMat() {\nGraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));\ngraph->size = 0;\nfor (int i = 0; i < MAX_SIZE; i++) {\nfor (int j = 0; j < MAX_SIZE; j++) {\ngraph->adjMat[i][j] = 0;\n}\n}\nreturn graph;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjMat(GraphAdjMat *graph) {\nfree(graph);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjMat *graph, int val) {\nif (graph->size == MAX_SIZE) {\nfprintf(stderr, \"\u56fe\u7684\u9876\u70b9\u6570\u91cf\u5df2\u8fbe\u6700\u5927\u503c\\n\");\nreturn;\n}\n// \u6dfb\u52a0\u7b2c n \u4e2a\u9876\u70b9\uff0c\u5e76\u5c06\u7b2c n \u884c\u548c\u5217\u7f6e\u96f6\nint n = graph->size;\ngraph->vertices[n] = val;\nfor (int i = 0; i <= n; i++) {\ngraph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n}\ngraph->size++;\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\nif (index < 0 || index >= graph->size) {\nfprintf(stderr, \"\u9876\u70b9\u7d22\u5f15\u8d8a\u754c\\n\");\nreturn;\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nfor (int i = index; i < graph->size - 1; i++) {\ngraph->vertices[i] = graph->vertices[i + 1];\n}\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nfor (int i = index; i < graph->size - 1; i++) {\nfor (int j = 0; j < graph->size; j++) {\ngraph->adjMat[i][j] = graph->adjMat[i + 1][j];\n}\n}\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (int i = 0; i < graph->size; i++) {\nfor (int j = index; j < graph->size - 1; j++) {\ngraph->adjMat[i][j] = graph->adjMat[i][j + 1];\n}\n}\ngraph->size--;\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(GraphAdjMat *graph, int i, int j) {\nif (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\nfprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\nreturn;\n}\ngraph->adjMat[i][j] = 1;\ngraph->adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(GraphAdjMat *graph, int i, int j) {\nif (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\nfprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\nreturn;\n}\ngraph->adjMat[i][j] = 0;\ngraph->adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printGraphAdjMat(GraphAdjMat *graph) {\nprintf(\"\u9876\u70b9\u5217\u8868 = \");\nprintArray(graph->vertices, graph->size);\nprintf(\"\u90bb\u63a5\u77e9\u9635 =\\n\");\nfor (int i = 0; i < graph->size; i++) {\nprintArray(graph->adjMat[i], graph->size);\n}\n}\n
        graph_adjacency_matrix.zig
        [class]{GraphAdjMat}-[func]{}\n
        "},{"location":"chapter_graph/graph_operations/#922","title":"9.2.2 \u00a0 \u57fa\u4e8e\u90bb\u63a5\u8868\u7684\u5b9e\u73b0","text":"

        \u8bbe\u65e0\u5411\u56fe\u7684\u9876\u70b9\u603b\u6570\u4e3a \\(n\\)\u3001\u8fb9\u603b\u6570\u4e3a \\(m\\) \uff0c\u5219\u53ef\u6839\u636e\u56fe 9-8 \u6240\u793a\u7684\u65b9\u6cd5\u5b9e\u73b0\u5404\u79cd\u64cd\u4f5c\u3002

        • \u6dfb\u52a0\u8fb9\uff1a\u5728\u9876\u70b9\u5bf9\u5e94\u94fe\u8868\u7684\u672b\u5c3e\u6dfb\u52a0\u8fb9\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u56e0\u4e3a\u662f\u65e0\u5411\u56fe\uff0c\u6240\u4ee5\u9700\u8981\u540c\u65f6\u6dfb\u52a0\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u5220\u9664\u8fb9\uff1a\u5728\u9876\u70b9\u5bf9\u5e94\u94fe\u8868\u4e2d\u67e5\u627e\u5e76\u5220\u9664\u6307\u5b9a\u8fb9\uff0c\u4f7f\u7528 \\(O(m)\\) \u65f6\u95f4\u3002\u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u9700\u8981\u540c\u65f6\u5220\u9664\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u6dfb\u52a0\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u94fe\u8868\uff0c\u5e76\u5c06\u65b0\u589e\u9876\u70b9\u4f5c\u4e3a\u94fe\u8868\u5934\u8282\u70b9\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u9876\u70b9\uff1a\u9700\u904d\u5386\u6574\u4e2a\u90bb\u63a5\u8868\uff0c\u5220\u9664\u5305\u542b\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u8fb9\uff0c\u4f7f\u7528 \\(O(n + m)\\) \u65f6\u95f4\u3002
        • \u521d\u59cb\u5316\uff1a\u5728\u90bb\u63a5\u8868\u4e2d\u521b\u5efa \\(n\\) \u4e2a\u9876\u70b9\u548c \\(2m\\) \u6761\u8fb9\uff0c\u4f7f\u7528 \\(O(n + m)\\) \u65f6\u95f4\u3002
        \u521d\u59cb\u5316\u90bb\u63a5\u8868\u6dfb\u52a0\u8fb9\u5220\u9664\u8fb9\u6dfb\u52a0\u9876\u70b9\u5220\u9664\u9876\u70b9

        \u56fe 9-8 \u00a0 \u90bb\u63a5\u8868\u7684\u521d\u59cb\u5316\u3001\u589e\u5220\u8fb9\u3001\u589e\u5220\u9876\u70b9

        \u4ee5\u4e0b\u662f\u90bb\u63a5\u8868\u7684\u4ee3\u7801\u5b9e\u73b0\u3002\u5bf9\u6bd4\u56fe 9-8 \uff0c\u5b9e\u9645\u4ee3\u7801\u6709\u4ee5\u4e0b\u4e0d\u540c\u3002

        • \u4e3a\u4e86\u65b9\u4fbf\u6dfb\u52a0\u4e0e\u5220\u9664\u9876\u70b9\uff0c\u4ee5\u53ca\u7b80\u5316\u4ee3\u7801\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u6765\u4ee3\u66ff\u94fe\u8868\u3002
        • \u4f7f\u7528\u54c8\u5e0c\u8868\u6765\u5b58\u50a8\u90bb\u63a5\u8868\uff0ckey \u4e3a\u9876\u70b9\u5b9e\u4f8b\uff0cvalue \u4e3a\u8be5\u9876\u70b9\u7684\u90bb\u63a5\u9876\u70b9\u5217\u8868\uff08\u94fe\u8868\uff09\u3002

        \u53e6\u5916\uff0c\u6211\u4eec\u5728\u90bb\u63a5\u8868\u4e2d\u4f7f\u7528 Vertex \u7c7b\u6765\u8868\u793a\u9876\u70b9\uff0c\u8fd9\u6837\u505a\u7684\u539f\u56e0\u662f\uff1a\u5982\u679c\u4e0e\u90bb\u63a5\u77e9\u9635\u4e00\u6837\uff0c\u7528\u5217\u8868\u7d22\u5f15\u6765\u533a\u5206\u4e0d\u540c\u9876\u70b9\uff0c\u90a3\u4e48\u5047\u8bbe\u8981\u5220\u9664\u7d22\u5f15\u4e3a \\(i\\) \u7684\u9876\u70b9\uff0c\u5219\u9700\u904d\u5386\u6574\u4e2a\u90bb\u63a5\u8868\uff0c\u5c06\u6240\u6709\u5927\u4e8e \\(i\\) \u7684\u7d22\u5f15\u5168\u90e8\u51cf \\(1\\) \uff0c\u6548\u7387\u5f88\u4f4e\u3002\u800c\u5982\u679c\u6bcf\u4e2a\u9876\u70b9\u90fd\u662f\u552f\u4e00\u7684 Vertex \u5b9e\u4f8b\uff0c\u5220\u9664\u67d0\u4e00\u9876\u70b9\u4e4b\u540e\u5c31\u65e0\u987b\u6539\u52a8\u5176\u4ed6\u9876\u70b9\u4e86\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_adjacency_list.py
        class GraphAdjList:\n\"\"\"\u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\"\"\"\ndef __init__(self, edges: list[list[Vertex]]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nself.adj_list = dict[Vertex, list[Vertex]]()\n# \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges:\nself.add_vertex(edge[0])\nself.add_vertex(edge[1])\nself.add_edge(edge[0], edge[1])\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\nreturn len(self.adj_list)\ndef add_edge(self, vet1: Vertex, vet2: Vertex):\n\"\"\"\u6dfb\u52a0\u8fb9\"\"\"\nif vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\nraise ValueError()\n# \u6dfb\u52a0\u8fb9 vet1 - vet2\nself.adj_list[vet1].append(vet2)\nself.adj_list[vet2].append(vet1)\ndef remove_edge(self, vet1: Vertex, vet2: Vertex):\n\"\"\"\u5220\u9664\u8fb9\"\"\"\nif vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\nraise ValueError()\n# \u5220\u9664\u8fb9 vet1 - vet2\nself.adj_list[vet1].remove(vet2)\nself.adj_list[vet2].remove(vet1)\ndef add_vertex(self, vet: Vertex):\n\"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\nif vet in self.adj_list:\nreturn\n# \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nself.adj_list[vet] = []\ndef remove_vertex(self, vet: Vertex):\n\"\"\"\u5220\u9664\u9876\u70b9\"\"\"\nif vet not in self.adj_list:\nraise ValueError()\n# \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nself.adj_list.pop(vet)\n# \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor vertex in self.adj_list:\nif vet in self.adj_list[vertex]:\nself.adj_list[vertex].remove(vet)\ndef print(self):\n\"\"\"\u6253\u5370\u90bb\u63a5\u8868\"\"\"\nprint(\"\u90bb\u63a5\u8868 =\")\nfor vertex in self.adj_list:\ntmp = [v.val for v in self.adj_list[vertex]]\nprint(f\"{vertex.val}: {tmp},\")\n
        graph_adjacency_list.cpp
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\npublic:\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nunordered_map<Vertex *, vector<Vertex *>> adjList;\n/* \u5728 vector \u4e2d\u5220\u9664\u6307\u5b9a\u8282\u70b9 */\nvoid remove(vector<Vertex *> &vec, Vertex *vet) {\nfor (int i = 0; i < vec.size(); i++) {\nif (vec[i] == vet) {\nvec.erase(vec.begin() + i);\nbreak;\n}\n}\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjList(const vector<vector<Vertex *>> &edges) {\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const vector<Vertex *> &edge : edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn adjList.size();\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(Vertex *vet1, Vertex *vet2) {\nif (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1].push_back(vet2);\nadjList[vet2].push_back(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(Vertex *vet1, Vertex *vet2) {\nif (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u5220\u9664\u8fb9 vet1 - vet2\nremove(adjList[vet1], vet2);\nremove(adjList[vet2], vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(Vertex *vet) {\nif (adjList.count(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = vector<Vertex *>();\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(Vertex *vet) {\nif (!adjList.count(vet))\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.erase(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (auto &adj : adjList) {\nremove(adj.second, vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nvoid print() {\ncout << \"\u90bb\u63a5\u8868 =\" << endl;\nfor (auto &adj : adjList) {\nconst auto &key = adj.first;\nconst auto &vec = adj.second;\ncout << key->val << \": \";\nprintVector(vetsToVals(vec));\n}\n}\n};\n
        graph_adjacency_list.java
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nMap<Vertex, List<Vertex>> adjList;\n/* \u6784\u9020\u65b9\u6cd5 */\npublic GraphAdjList(Vertex[][] edges) {\nthis.adjList = new HashMap<>();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (Vertex[] edge : edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic int size() {\nreturn adjList.size();\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic void addEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\nthrow new IllegalArgumentException();\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList.get(vet1).add(vet2);\nadjList.get(vet2).add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\npublic void removeEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\nthrow new IllegalArgumentException();\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList.get(vet1).remove(vet2);\nadjList.get(vet2).remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void addVertex(Vertex vet) {\nif (adjList.containsKey(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList.put(vet, new ArrayList<>());\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void removeVertex(Vertex vet) {\nif (!adjList.containsKey(vet))\nthrow new IllegalArgumentException();\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (List<Vertex> list : adjList.values()) {\nlist.remove(vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic void print() {\nSystem.out.println(\"\u90bb\u63a5\u8868 =\");\nfor (Map.Entry<Vertex, List<Vertex>> pair : adjList.entrySet()) {\nList<Integer> tmp = new ArrayList<>();\nfor (Vertex vertex : pair.getValue())\ntmp.add(vertex.val);\nSystem.out.println(pair.getKey().val + \": \" + tmp + \",\");\n}\n}\n}\n
        graph_adjacency_list.cs
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npublic Dictionary<Vertex, List<Vertex>> adjList;\n/* \u6784\u9020\u51fd\u6570 */\npublic GraphAdjList(Vertex[][] edges) {\nadjList = [];\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nforeach (Vertex[] edge in edges) {\nAddVertex(edge[0]);\nAddVertex(edge[1]);\nAddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint Size() {\nreturn adjList.Count;\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic void AddEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\nthrow new InvalidOperationException();\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1].Add(vet2);\nadjList[vet2].Add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\npublic void RemoveEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\nthrow new InvalidOperationException();\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1].Remove(vet2);\nadjList[vet2].Remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void AddVertex(Vertex vet) {\nif (adjList.ContainsKey(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList.Add(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void RemoveVertex(Vertex vet) {\nif (!adjList.ContainsKey(vet))\nthrow new InvalidOperationException();\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.Remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nforeach (List<Vertex> list in adjList.Values) {\nlist.Remove(vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic void Print() {\nConsole.WriteLine(\"\u90bb\u63a5\u8868 =\");\nforeach (KeyValuePair<Vertex, List<Vertex>> pair in adjList) {\nList<int> tmp = [];\nforeach (Vertex vertex in pair.Value)\ntmp.Add(vertex.val);\nConsole.WriteLine(pair.Key.val + \": [\" + string.Join(\", \", tmp) + \"],\");\n}\n}\n}\n
        graph_adjacency_list.go
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntype graphAdjList struct {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList map[Vertex][]Vertex\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjList(edges [][]Vertex) *graphAdjList {\ng := &graphAdjList{\nadjList: make(map[Vertex][]Vertex),\n}\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor _, edge := range edges {\ng.addVertex(edge[0])\ng.addVertex(edge[1])\ng.addEdge(edge[0], edge[1])\n}\nreturn g\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjList) size() int {\nreturn len(g.adjList)\n}\n/* \u6dfb\u52a0\u8fb9 */\nfunc (g *graphAdjList) addEdge(vet1 Vertex, vet2 Vertex) {\n_, ok1 := g.adjList[vet1]\n_, ok2 := g.adjList[vet2]\nif !ok1 || !ok2 || vet1 == vet2 {\npanic(\"error\")\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2, \u6dfb\u52a0\u533f\u540d struct{},\ng.adjList[vet1] = append(g.adjList[vet1], vet2)\ng.adjList[vet2] = append(g.adjList[vet2], vet1)\n}\n/* \u5220\u9664\u8fb9 */\nfunc (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) {\n_, ok1 := g.adjList[vet1]\n_, ok2 := g.adjList[vet2]\nif !ok1 || !ok2 || vet1 == vet2 {\npanic(\"error\")\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\ng.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2)\ng.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1)\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjList) addVertex(vet Vertex) {\n_, ok := g.adjList[vet]\nif ok {\nreturn\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\ng.adjList[vet] = make([]Vertex, 0)\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjList) removeVertex(vet Vertex) {\n_, ok := g.adjList[vet]\nif !ok {\npanic(\"error\")\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\ndelete(g.adjList, vet)\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor v, list := range g.adjList {\ng.adjList[v] = DeleteSliceElms(list, vet)\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nfunc (g *graphAdjList) print() {\nvar builder strings.Builder\nfmt.Printf(\"\u90bb\u63a5\u8868 = \\n\")\nfor k, v := range g.adjList {\nbuilder.WriteString(\"\\t\\t\" + strconv.Itoa(k.Val) + \": \")\nfor _, vet := range v {\nbuilder.WriteString(strconv.Itoa(vet.Val) + \" \")\n}\nfmt.Println(builder.String())\nbuilder.Reset()\n}\n}\n
        graph_adjacency_list.swift
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npublic private(set) var adjList: [Vertex: [Vertex]]\n/* \u6784\u9020\u65b9\u6cd5 */\npublic init(edges: [[Vertex]]) {\nadjList = [:]\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges {\naddVertex(vet: edge[0])\naddVertex(vet: edge[1])\naddEdge(vet1: edge[0], vet2: edge[1])\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic func size() -> Int {\nadjList.count\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic func addEdge(vet1: Vertex, vet2: Vertex) {\nif adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1]?.append(vet2)\nadjList[vet2]?.append(vet1)\n}\n/* \u5220\u9664\u8fb9 */\npublic func removeEdge(vet1: Vertex, vet2: Vertex) {\nif adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1]?.removeAll(where: { $0 == vet2 })\nadjList[vet2]?.removeAll(where: { $0 == vet1 })\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic func addVertex(vet: Vertex) {\nif adjList[vet] != nil {\nreturn\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = []\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic func removeVertex(vet: Vertex) {\nif adjList[vet] == nil {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.removeValue(forKey: vet)\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor key in adjList.keys {\nadjList[key]?.removeAll(where: { $0 == vet })\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic func print() {\nSwift.print(\"\u90bb\u63a5\u8868 =\")\nfor pair in adjList {\nvar tmp: [Int] = []\nfor vertex in pair.value {\ntmp.append(vertex.val)\n}\nSwift.print(\"\\(pair.key.val): \\(tmp),\")\n}\n}\n}\n
        graph_adjacency_list.js
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(edges) {\nthis.adjList = new Map();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const edge of edges) {\nthis.addVertex(edge[0]);\nthis.addVertex(edge[1]);\nthis.addEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize() {\nreturn this.adjList.size;\n}\n/* \u6dfb\u52a0\u8fb9 */\naddEdge(vet1, vet2) {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).push(vet2);\nthis.adjList.get(vet2).push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nremoveEdge(vet1, vet2) {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\nthis.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(vet) {\nif (this.adjList.has(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nthis.adjList.set(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(vet) {\nif (!this.adjList.has(vet)) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nthis.adjList.delete(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (const set of this.adjList.values()) {\nconst index = set.indexOf(vet);\nif (index > -1) {\nset.splice(index, 1);\n}\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nprint() {\nconsole.log('\u90bb\u63a5\u8868 =');\nfor (const [key, value] of this.adjList) {\nconst tmp = [];\nfor (const vertex of value) {\ntmp.push(vertex.val);\n}\nconsole.log(key.val + ': ' + tmp.join());\n}\n}\n}\n
        graph_adjacency_list.ts
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList: Map<Vertex, Vertex[]>;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(edges: Vertex[][]) {\nthis.adjList = new Map();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const edge of edges) {\nthis.addVertex(edge[0]);\nthis.addVertex(edge[1]);\nthis.addEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.adjList.size;\n}\n/* \u6dfb\u52a0\u8fb9 */\naddEdge(vet1: Vertex, vet2: Vertex): void {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).push(vet2);\nthis.adjList.get(vet2).push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nremoveEdge(vet1: Vertex, vet2: Vertex): void {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\nthis.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(vet: Vertex): void {\nif (this.adjList.has(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nthis.adjList.set(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(vet: Vertex): void {\nif (!this.adjList.has(vet)) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nthis.adjList.delete(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (const set of this.adjList.values()) {\nconst index: number = set.indexOf(vet);\nif (index > -1) {\nset.splice(index, 1);\n}\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nprint(): void {\nconsole.log('\u90bb\u63a5\u8868 =');\nfor (const [key, value] of this.adjList.entries()) {\nconst tmp = [];\nfor (const vertex of value) {\ntmp.push(vertex.val);\n}\nconsole.log(key.val + ': ' + tmp.join());\n}\n}\n}\n
        graph_adjacency_list.dart
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nMap<Vertex, List<Vertex>> adjList = {};\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjList(List<List<Vertex>> edges) {\nfor (List<Vertex> edge in edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn adjList.length;\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) ||\n!adjList.containsKey(vet2) ||\nvet1 == vet2) {\nthrow ArgumentError;\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1]!.add(vet2);\nadjList[vet2]!.add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) ||\n!adjList.containsKey(vet2) ||\nvet1 == vet2) {\nthrow ArgumentError;\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1]!.remove(vet2);\nadjList[vet2]!.remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(Vertex vet) {\nif (adjList.containsKey(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = [];\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(Vertex vet) {\nif (!adjList.containsKey(vet)) {\nthrow ArgumentError;\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nadjList.forEach((key, value) {\nvalue.remove(vet);\n});\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nvoid printAdjList() {\nprint(\"\u90bb\u63a5\u8868 =\");\nadjList.forEach((key, value) {\nList<int> tmp = [];\nfor (Vertex vertex in value) {\ntmp.add(vertex.val);\n}\nprint(\"${key.val}: $tmp,\");\n});\n}\n}\n
        graph_adjacency_list.rs
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\u578b */\npub struct GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npub adj_list: HashMap<Vertex, Vec<Vertex>>,\n}\nimpl GraphAdjList {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(edges: Vec<[Vertex; 2]>) -> Self {\nlet mut graph = GraphAdjList {\nadj_list: HashMap::new(),\n};\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges {\ngraph.add_vertex(edge[0]);\ngraph.add_vertex(edge[1]);\ngraph.add_edge(edge[0], edge[1]);\n}\ngraph\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n#[allow(unused)]\npub fn size(&self) -> usize {\nself.adj_list.len()\n}\n/* \u6dfb\u52a0\u8fb9 */\npub fn add_edge(&mut self, vet1: Vertex, vet2: Vertex) {\nif !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n{\npanic!(\"value error\");\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nself.adj_list.get_mut(&vet1).unwrap().push(vet2);\nself.adj_list.get_mut(&vet2).unwrap().push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\n#[allow(unused)]\npub fn remove_edge(&mut self, vet1: Vertex, vet2: Vertex) {\nif !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n{\npanic!(\"value error\");\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nself.adj_list\n.get_mut(&vet1)\n.unwrap()\n.retain(|&vet| vet != vet2);\nself.adj_list\n.get_mut(&vet2)\n.unwrap()\n.retain(|&vet| vet != vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npub fn add_vertex(&mut self, vet: Vertex) {\nif self.adj_list.contains_key(&vet) {\nreturn;\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nself.adj_list.insert(vet, vec![]);\n}\n/* \u5220\u9664\u9876\u70b9 */\n#[allow(unused)]\npub fn remove_vertex(&mut self, vet: Vertex) {\nif !self.adj_list.contains_key(&vet) {\npanic!(\"value error\");\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nself.adj_list.remove(&vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor list in self.adj_list.values_mut() {\nlist.retain(|&v| v != vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npub fn print(&self) {\nprintln!(\"\u90bb\u63a5\u8868 =\");\nfor (vertex, list) in &self.adj_list {\nlet list = list.iter().map(|vertex| vertex.val).collect::<Vec<i32>>();\nprintln!(\"{}: {:?},\", vertex.val, list);\n}\n}\n}\n
        graph_adjacency_list.c
        /* \u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct AdjListNode {\nVertex *vertex;           // \u9876\u70b9\nstruct AdjListNode *next; // \u540e\u7ee7\u8282\u70b9\n} AdjListNode;\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\nfor (int i = 0; i < graph->size; i++) {\nif (graph->heads[i]->vertex == vet) {\nreturn graph->heads[i];\n}\n}\nreturn NULL;\n}\n/* \u6dfb\u52a0\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid addEdgeHelper(AdjListNode *head, Vertex *vet) {\nAdjListNode *node = (AdjListNode *)malloc(sizeof(AdjListNode));\nnode->vertex = vet;\n// \u5934\u63d2\u6cd5\nnode->next = head->next;\nhead->next = node;\n}\n/* \u5220\u9664\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid removeEdgeHelper(AdjListNode *head, Vertex *vet) {\nAdjListNode *pre = head;\nAdjListNode *cur = head->next;\n// \u5728\u94fe\u8868\u4e2d\u641c\u7d22 vet \u5bf9\u5e94\u8282\u70b9\nwhile (cur != NULL && cur->vertex != vet) {\npre = cur;\ncur = cur->next;\n}\nif (cur == NULL)\nreturn;\n// \u5c06 vet \u5bf9\u5e94\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\npre->next = cur->next;\n// \u91ca\u653e\u5185\u5b58\nfree(cur);\n}\n/* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntypedef struct {\nAdjListNode *heads[MAX_SIZE]; // \u8282\u70b9\u6570\u7ec4\nint size;                     // \u8282\u70b9\u6570\u91cf\n} GraphAdjList;\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjList *newGraphAdjList() {\nGraphAdjList *graph = (GraphAdjList *)malloc(sizeof(GraphAdjList));\nif (!graph) {\nreturn NULL;\n}\ngraph->size = 0;\nfor (int i = 0; i < MAX_SIZE; i++) {\ngraph->heads[i] = NULL;\n}\nreturn graph;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjList(GraphAdjList *graph) {\nfor (int i = 0; i < graph->size; i++) {\nAdjListNode *cur = graph->heads[i];\nwhile (cur != NULL) {\nAdjListNode *next = cur->next;\nif (cur != graph->heads[i]) {\nfree(cur);\n}\ncur = next;\n}\nfree(graph->heads[i]->vertex);\nfree(graph->heads[i]);\n}\nfree(graph);\n}\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\nfor (int i = 0; i < graph->size; i++) {\nif (graph->heads[i]->vertex == vet) {\nreturn graph->heads[i];\n}\n}\nreturn NULL;\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\nAdjListNode *head1 = findNode(graph, vet1);\nAdjListNode *head2 = findNode(graph, vet2);\nassert(head1 != NULL && head2 != NULL && head1 != head2);\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\naddEdgeHelper(head1, vet2);\naddEdgeHelper(head2, vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\nAdjListNode *head1 = findNode(graph, vet1);\nAdjListNode *head2 = findNode(graph, vet2);\nassert(head1 != NULL && head2 != NULL);\n// \u5220\u9664\u8fb9 vet1 - vet2\nremoveEdgeHelper(head1, head2->vertex);\nremoveEdgeHelper(head2, head1->vertex);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjList *graph, Vertex *vet) {\nassert(graph != NULL && graph->size < MAX_SIZE);\nAdjListNode *head = (AdjListNode *)malloc(sizeof(AdjListNode));\nhead->vertex = vet;\nhead->next = NULL;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\ngraph->heads[graph->size++] = head;\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjList *graph, Vertex *vet) {\nAdjListNode *node = findNode(graph, vet);\nassert(node != NULL);\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nAdjListNode *cur = node, *pre = NULL;\nwhile (cur) {\npre = cur;\ncur = cur->next;\nfree(pre);\n}\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (int i = 0; i < graph->size; i++) {\ncur = graph->heads[i];\npre = NULL;\nwhile (cur) {\npre = cur;\ncur = cur->next;\nif (cur && cur->vertex == vet) {\npre->next = cur->next;\nfree(cur);\nbreak;\n}\n}\n}\n// \u5c06\u8be5\u9876\u70b9\u4e4b\u540e\u7684\u9876\u70b9\u5411\u524d\u79fb\u52a8\uff0c\u4ee5\u586b\u8865\u7a7a\u7f3a\nint i;\nfor (i = 0; i < graph->size; i++) {\nif (graph->heads[i] == node)\nbreak;\n}\nfor (int j = i; j < graph->size - 1; j++) {\ngraph->heads[j] = graph->heads[j + 1];\n}\ngraph->size--;\nfree(vet);\n}\n
        graph_adjacency_list.zig
        [class]{GraphAdjList}-[func]{}\n
        "},{"location":"chapter_graph/graph_operations/#923","title":"9.2.3 \u00a0 \u6548\u7387\u5bf9\u6bd4","text":"

        \u8bbe\u56fe\u4e2d\u5171\u6709 \\(n\\) \u4e2a\u9876\u70b9\u548c \\(m\\) \u6761\u8fb9\uff0c\u8868 9-2 \u5bf9\u6bd4\u4e86\u90bb\u63a5\u77e9\u9635\u548c\u90bb\u63a5\u8868\u7684\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u3002

        \u8868 9-2 \u00a0 \u90bb\u63a5\u77e9\u9635\u4e0e\u90bb\u63a5\u8868\u5bf9\u6bd4

        \u90bb\u63a5\u77e9\u9635 \u90bb\u63a5\u8868\uff08\u94fe\u8868\uff09 \u90bb\u63a5\u8868\uff08\u54c8\u5e0c\u8868\uff09 \u5224\u65ad\u662f\u5426\u90bb\u63a5 \\(O(1)\\) \\(O(m)\\) \\(O(1)\\) \u6dfb\u52a0\u8fb9 \\(O(1)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u8fb9 \\(O(1)\\) \\(O(m)\\) \\(O(1)\\) \u6dfb\u52a0\u9876\u70b9 \\(O(n)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u9876\u70b9 \\(O(n^2)\\) \\(O(n + m)\\) \\(O(n)\\) \u5185\u5b58\u7a7a\u95f4\u5360\u7528 \\(O(n^2)\\) \\(O(n + m)\\) \\(O(n + m)\\)

        \u89c2\u5bdf\u8868 9-2 \uff0c\u4f3c\u4e4e\u90bb\u63a5\u8868\uff08\u54c8\u5e0c\u8868\uff09\u7684\u65f6\u95f4\u6548\u7387\u4e0e\u7a7a\u95f4\u6548\u7387\u6700\u4f18\u3002\u4f46\u5b9e\u9645\u4e0a\uff0c\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u64cd\u4f5c\u8fb9\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u53ea\u9700\u4e00\u6b21\u6570\u7ec4\u8bbf\u95ee\u6216\u8d4b\u503c\u64cd\u4f5c\u5373\u53ef\u3002\u7efc\u5408\u6765\u770b\uff0c\u90bb\u63a5\u77e9\u9635\u4f53\u73b0\u4e86\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u7684\u539f\u5219\uff0c\u800c\u90bb\u63a5\u8868\u4f53\u73b0\u4e86\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u7684\u539f\u5219\u3002

        "},{"location":"chapter_graph/graph_traversal/","title":"9.3 \u00a0 \u56fe\u7684\u904d\u5386","text":"

        \u6811\u4ee3\u8868\u7684\u662f\u201c\u4e00\u5bf9\u591a\u201d\u7684\u5173\u7cfb\uff0c\u800c\u56fe\u5219\u5177\u6709\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\uff0c\u53ef\u4ee5\u8868\u793a\u4efb\u610f\u7684\u201c\u591a\u5bf9\u591a\u201d\u5173\u7cfb\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u6811\u770b\u4f5c\u56fe\u7684\u4e00\u79cd\u7279\u4f8b\u3002\u663e\u7136\uff0c\u6811\u7684\u904d\u5386\u64cd\u4f5c\u4e5f\u662f\u56fe\u7684\u904d\u5386\u64cd\u4f5c\u7684\u4e00\u79cd\u7279\u4f8b\u3002

        \u56fe\u548c\u6811\u90fd\u9700\u8981\u5e94\u7528\u641c\u7d22\u7b97\u6cd5\u6765\u5b9e\u73b0\u904d\u5386\u64cd\u4f5c\u3002\u56fe\u7684\u904d\u5386\u65b9\u5f0f\u53ef\u5206\u4e3a\u4e24\u79cd\uff1a\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal\u300d\u3002\u5b83\u4eec\u4e5f\u5e38\u88ab\u79f0\u4e3a\u300c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search\u300d\uff0c\u7b80\u79f0 BFS \u548c DFS \u3002

        "},{"location":"chapter_graph/graph_traversal/#931","title":"9.3.1 \u00a0 \u5e7f\u5ea6\u4f18\u5148\u904d\u5386","text":"

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u7531\u8fd1\u53ca\u8fdc\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u51fa\u53d1\uff0c\u59cb\u7ec8\u4f18\u5148\u8bbf\u95ee\u8ddd\u79bb\u6700\u8fd1\u7684\u9876\u70b9\uff0c\u5e76\u4e00\u5c42\u5c42\u5411\u5916\u6269\u5f20\u3002\u5982\u56fe 9-9 \u6240\u793a\uff0c\u4ece\u5de6\u4e0a\u89d2\u9876\u70b9\u51fa\u53d1\uff0c\u9996\u5148\u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff0c\u7136\u540e\u904d\u5386\u4e0b\u4e00\u4e2a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u6240\u6709\u9876\u70b9\u8bbf\u95ee\u5b8c\u6bd5\u3002

        \u56fe 9-9 \u00a0 \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386

        "},{"location":"chapter_graph/graph_traversal/#1","title":"1. \u00a0 \u7b97\u6cd5\u5b9e\u73b0","text":"

        BFS \u901a\u5e38\u501f\u52a9\u961f\u5217\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002\u961f\u5217\u5177\u6709\u201c\u5148\u5165\u5148\u51fa\u201d\u7684\u6027\u8d28\uff0c\u8fd9\u4e0e BFS \u7684\u201c\u7531\u8fd1\u53ca\u8fdc\u201d\u7684\u601d\u60f3\u5f02\u66f2\u540c\u5de5\u3002

        1. \u5c06\u904d\u5386\u8d77\u59cb\u9876\u70b9 startVet \u52a0\u5165\u961f\u5217\uff0c\u5e76\u5f00\u542f\u5faa\u73af\u3002
        2. \u5728\u5faa\u73af\u7684\u6bcf\u8f6e\u8fed\u4ee3\u4e2d\uff0c\u5f39\u51fa\u961f\u9996\u9876\u70b9\u5e76\u8bb0\u5f55\u8bbf\u95ee\uff0c\u7136\u540e\u5c06\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\u52a0\u5165\u5230\u961f\u5217\u5c3e\u90e8\u3002
        3. \u5faa\u73af\u6b65\u9aa4 2. \uff0c\u76f4\u5230\u6240\u6709\u9876\u70b9\u88ab\u8bbf\u95ee\u5b8c\u6bd5\u540e\u7ed3\u675f\u3002

        \u4e3a\u4e86\u9632\u6b62\u91cd\u590d\u904d\u5386\u9876\u70b9\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 visited \u6765\u8bb0\u5f55\u54ea\u4e9b\u8282\u70b9\u5df2\u88ab\u8bbf\u95ee\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_bfs.py
        def graph_bfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n\"\"\"\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS\"\"\"\n# \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n# \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres = []\n# \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited = set[Vertex]([start_vet])\n# \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nque = deque[Vertex]([start_vet])\n# \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile len(que) > 0:\nvet = que.popleft()  # \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n# \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adj_vet in graph.adj_list[vet]:\nif adj_vet in visited:\ncontinue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.append(adj_vet)  # \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adj_vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n# \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n
        graph_bfs.cpp
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvector<Vertex *> graphBFS(GraphAdjList &graph, Vertex *startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvector<Vertex *> res;\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nunordered_set<Vertex *> visited = {startVet};\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nqueue<Vertex *> que;\nque.push(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!que.empty()) {\nVertex *vet = que.front();\nque.pop();          // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push_back(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (auto adjVet : graph.adjList[vet]) {\nif (visited.count(adjVet))\ncontinue;            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.push(adjVet);        // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.emplace(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.java
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> graphBFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = new ArrayList<>();\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = new HashSet<>();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = new LinkedList<>();\nque.offer(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!que.isEmpty()) {\nVertex vet = que.poll(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.add(vet);            // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet : graph.adjList.get(vet)) {\nif (visited.contains(adjVet))\ncontinue;        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.offer(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.cs
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> GraphBFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nHashSet<Vertex> visited = [startVet];\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = new();\nque.Enqueue(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.Count > 0) {\nVertex vet = que.Dequeue(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.Add(vet);               // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nforeach (Vertex adjVet in graph.adjList[vet]) {\nif (visited.Contains(adjVet)) {\ncontinue;          // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.Enqueue(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.Add(adjVet);   // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.go
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphBFS(g *graphAdjList, startVet Vertex) []Vertex {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres := make([]Vertex, 0)\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited := make(map[Vertex]struct{})\nvisited[startVet] = struct{}{}\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS, \u4f7f\u7528\u5207\u7247\u6a21\u62df\u961f\u5217\nqueue := make([]Vertex, 0)\nqueue = append(queue, startVet)\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nfor len(queue) > 0 {\n// \u961f\u9996\u9876\u70b9\u51fa\u961f\nvet := queue[0]\nqueue = queue[1:]\n// \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nres = append(res, vet)\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor _, adjVet := range g.adjList[vet] {\n_, isExist := visited[adjVet]\n// \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nif !isExist {\nqueue = append(queue, adjVet)\nvisited[adjVet] = struct{}{}\n}\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_bfs.swift
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphBFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvar res: [Vertex] = []\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvar visited: Set<Vertex> = [startVet]\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nvar que: [Vertex] = [startVet]\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile !que.isEmpty {\nlet vet = que.removeFirst() // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adjList[vet] ?? [] {\nif visited.contains(adjVet) {\ncontinue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.append(adjVet) // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.insert(adjVet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_bfs.js
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphBFS(graph, startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited = new Set();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nconst que = [startVet];\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.length) {\nconst vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet) ?? []) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.ts
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphBFS(graph: GraphAdjList, startVet: Vertex): Vertex[] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res: Vertex[] = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited: Set<Vertex> = new Set();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nconst que = [startVet];\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.length) {\nconst vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet) ?? []) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.dart
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\nList<Vertex> graphBFS(GraphAdjList graph, Vertex startVet) {\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = {};\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = Queue();\nque.add(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.isNotEmpty) {\nVertex vet = que.removeFirst(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet in graph.adjList[vet]!) {\nif (visited.contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.add(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.rs
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfn graph_bfs(graph: GraphAdjList, start_vet: Vertex) -> Vec<Vertex> {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nlet mut res = vec![];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nlet mut visited = HashSet::new();\nvisited.insert(start_vet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nlet mut que = VecDeque::new();\nque.push_back(start_vet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile !que.is_empty() {\nlet vet = que.pop_front().unwrap(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nif let Some(adj_vets) = graph.adj_list.get(&vet) {\nfor &adj_vet in adj_vets {\nif visited.contains(&adj_vet) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push_back(adj_vet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.insert(adj_vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nres\n}\n
        graph_bfs.c
        /* \u8282\u70b9\u961f\u5217\u7ed3\u6784\u4f53 */\ntypedef struct {\nVertex *vertices[MAX_SIZE];\nint front, rear, size;\n} Queue;\n/* \u6784\u9020\u51fd\u6570 */\nQueue *newQueue() {\nQueue *q = (Queue *)malloc(sizeof(Queue));\nq->front = q->rear = q->size = 0;\nreturn q;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nint isEmpty(Queue *q) {\nreturn q->size == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid enqueue(Queue *q, Vertex *vet) {\nq->vertices[q->rear] = vet;\nq->rear = (q->rear + 1) % MAX_SIZE;\nq->size++;\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nVertex *dequeue(Queue *q) {\nVertex *vet = q->vertices[q->front];\nq->front = (q->front + 1) % MAX_SIZE;\nq->size--;\nreturn vet;\n}\n/* \u68c0\u67e5\u9876\u70b9\u662f\u5426\u5df2\u88ab\u8bbf\u95ee */\nint isVisited(Vertex **visited, int size, Vertex *vet) {\n// \u904d\u5386\u67e5\u627e\u8282\u70b9\uff0c\u4f7f\u7528 O(n) \u65f6\u95f4\nfor (int i = 0; i < size; i++) {\nif (visited[i] == vet)\nreturn 1;\n}\nreturn 0;\n}\n/* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvoid graphBFS(GraphAdjList *graph, Vertex *startVet, Vertex **res, int *resSize, Vertex **visited, int *visitedSize) {\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue *queue = newQueue();\nenqueue(queue, startVet);\nvisited[(*visitedSize)++] = startVet;\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!isEmpty(queue)) {\nVertex *vet = dequeue(queue); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres[(*resSize)++] = vet;      // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nAdjListNode *node = findNode(graph, vet);\nwhile (node != NULL) {\n// \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nif (!isVisited(visited, *visitedSize, node->vertex)) {\nenqueue(queue, node->vertex);             // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited[(*visitedSize)++] = node->vertex; // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\nnode = node->next;\n}\n}\n// \u91ca\u653e\u5185\u5b58\nfree(queue);\n}\n
        graph_bfs.zig
        [class]{}-[func]{graphBFS}\n

        \u4ee3\u7801\u76f8\u5bf9\u62bd\u8c61\uff0c\u5efa\u8bae\u5bf9\u7167\u56fe 9-10 \u6765\u52a0\u6df1\u7406\u89e3\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 9-10 \u00a0 \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u6b65\u9aa4

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5e8f\u5217\u662f\u5426\u552f\u4e00\uff1f

        \u4e0d\u552f\u4e00\u3002\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u53ea\u8981\u6c42\u6309\u201c\u7531\u8fd1\u53ca\u8fdc\u201d\u7684\u987a\u5e8f\u904d\u5386\uff0c\u800c\u591a\u4e2a\u76f8\u540c\u8ddd\u79bb\u7684\u9876\u70b9\u7684\u904d\u5386\u987a\u5e8f\u5141\u8bb8\u88ab\u4efb\u610f\u6253\u4e71\u3002\u4ee5\u56fe 9-10 \u4e3a\u4f8b\uff0c\u9876\u70b9 \\(1\\)\u3001\\(3\\) \u7684\u8bbf\u95ee\u987a\u5e8f\u53ef\u4ee5\u4ea4\u6362\uff0c\u9876\u70b9 \\(2\\)\u3001\\(4\\)\u3001\\(6\\) \u7684\u8bbf\u95ee\u987a\u5e8f\u4e5f\u53ef\u4ee5\u4efb\u610f\u4ea4\u6362\u3002

        "},{"location":"chapter_graph/graph_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u6240\u6709\u9876\u70b9\u90fd\u4f1a\u5165\u961f\u5e76\u51fa\u961f\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(|V|)\\) \u65f6\u95f4\uff1b\u5728\u904d\u5386\u90bb\u63a5\u9876\u70b9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7531\u4e8e\u662f\u65e0\u5411\u56fe\uff0c\u56e0\u6b64\u6240\u6709\u8fb9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(2\\) \u6b21\uff0c\u4f7f\u7528 \\(O(2|E|)\\) \u65f6\u95f4\uff1b\u603b\u4f53\u4f7f\u7528 \\(O(|V| + |E|)\\) \u65f6\u95f4\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6\uff1a\u5217\u8868 res \uff0c\u54c8\u5e0c\u8868 visited \uff0c\u961f\u5217 que \u4e2d\u7684\u9876\u70b9\u6570\u91cf\u6700\u591a\u4e3a \\(|V|\\) \uff0c\u4f7f\u7528 \\(O(|V|)\\) \u7a7a\u95f4\u3002

        "},{"location":"chapter_graph/graph_traversal/#932","title":"9.3.2 \u00a0 \u6df1\u5ea6\u4f18\u5148\u904d\u5386","text":"

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u4f18\u5148\u8d70\u5230\u5e95\u3001\u65e0\u8def\u53ef\u8d70\u518d\u56de\u5934\u7684\u904d\u5386\u65b9\u5f0f\u3002\u5982\u56fe 9-11 \u6240\u793a\uff0c\u4ece\u5de6\u4e0a\u89d2\u9876\u70b9\u51fa\u53d1\uff0c\u8bbf\u95ee\u5f53\u524d\u9876\u70b9\u7684\u67d0\u4e2a\u90bb\u63a5\u9876\u70b9\uff0c\u76f4\u5230\u8d70\u5230\u5c3d\u5934\u65f6\u8fd4\u56de\uff0c\u518d\u7ee7\u7eed\u8d70\u5230\u5c3d\u5934\u5e76\u8fd4\u56de\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u6240\u6709\u9876\u70b9\u904d\u5386\u5b8c\u6210\u3002

        \u56fe 9-11 \u00a0 \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386

        "},{"location":"chapter_graph/graph_traversal/#1_1","title":"1. \u00a0 \u7b97\u6cd5\u5b9e\u73b0","text":"

        \u8fd9\u79cd\u201c\u8d70\u5230\u5c3d\u5934\u518d\u8fd4\u56de\u201d\u7684\u7b97\u6cd5\u8303\u5f0f\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u6765\u5b9e\u73b0\u3002\u4e0e\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7c7b\u4f3c\uff0c\u5728\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u4e2d\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 visited \u6765\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u8bbf\u95ee\u9876\u70b9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_dfs.py
        def dfs(graph: GraphAdjList, visited: set[Vertex], res: list[Vertex], vet: Vertex):\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570\"\"\"\nres.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n# \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adj_list[vet]:\nif adjVet in visited:\ncontinue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n# \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet)\ndef graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS\"\"\"\n# \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n# \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres = []\n# \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited = set[Vertex]()\ndfs(graph, visited, res, start_vet)\nreturn res\n
        graph_dfs.cpp
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList &graph, unordered_set<Vertex *> &visited, vector<Vertex *> &res, Vertex *vet) {\nres.push_back(vet);   // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.emplace(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex *adjVet : graph.adjList[vet]) {\nif (visited.count(adjVet))\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvector<Vertex *> graphDFS(GraphAdjList &graph, Vertex *startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvector<Vertex *> res;\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nunordered_set<Vertex *> visited;\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.java
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList graph, Set<Vertex> visited, List<Vertex> res, Vertex vet) {\nres.add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet : graph.adjList.get(vet)) {\nif (visited.contains(adjVet))\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = new ArrayList<>();\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = new HashSet<>();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.cs
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid DFS(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {\nres.Add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.Add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nforeach (Vertex adjVet in graph.adjList[vet]) {\nif (visited.Contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9                             \n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\nDFS(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> GraphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nHashSet<Vertex> visited = [];\nDFS(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.go
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunc dfs(g *graphAdjList, visited map[Vertex]struct{}, res *[]Vertex, vet Vertex) {\n// append \u64cd\u4f5c\u4f1a\u8fd4\u56de\u65b0\u7684\u7684\u5f15\u7528\uff0c\u5fc5\u987b\u8ba9\u539f\u5f15\u7528\u91cd\u65b0\u8d4b\u503c\u4e3a\u65b0slice\u7684\u5f15\u7528\n*res = append(*res, vet)\nvisited[vet] = struct{}{}\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor _, adjVet := range g.adjList[vet] {\n_, isExist := visited[adjVet]\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\nif !isExist {\ndfs(g, visited, res, adjVet)\n}\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphDFS(g *graphAdjList, startVet Vertex) []Vertex {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres := make([]Vertex, 0)\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited := make(map[Vertex]struct{})\ndfs(g, visited, &res, startVet)\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_dfs.swift
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunc dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {\nres.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.insert(vet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adjList[vet] ?? [] {\nif visited.contains(adjVet) {\ncontinue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph: graph, visited: &visited, res: &res, vet: adjVet)\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphDFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvar res: [Vertex] = []\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvar visited: Set<Vertex> = []\ndfs(graph: graph, visited: &visited, res: &res, vet: startVet)\nreturn res\n}\n
        graph_dfs.js
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction dfs(graph, visited, res, vet) {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet)) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphDFS(graph, startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited = new Set();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.ts
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunction dfs(\ngraph: GraphAdjList,\nvisited: Set<Vertex>,\nres: Vertex[],\nvet: Vertex\n): void {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet)) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphDFS(graph: GraphAdjList, startVet: Vertex): Vertex[] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res: Vertex[] = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited: Set<Vertex> = new Set();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.dart
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(\nGraphAdjList graph,\nSet<Vertex> visited,\nList<Vertex> res,\nVertex vet,\n) {\nres.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet in graph.adjList[vet]!) {\nif (visited.contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = {};\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.rs
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfn dfs(graph: &GraphAdjList, visited: &mut HashSet<Vertex>, res: &mut Vec<Vertex>, vet: Vertex) {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.insert(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nif let Some(adj_vets) = graph.adj_list.get(&vet) {\nfor &adj_vet in adj_vets {\nif visited.contains(&adj_vet) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adj_vet);\n}\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfn graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> Vec<Vertex> {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nlet mut res = vec![];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nlet mut visited = HashSet::new();\ndfs(&graph, &mut visited, &mut res, start_vet);\nres\n}\n
        graph_dfs.c
        /* \u68c0\u67e5\u9876\u70b9\u662f\u5426\u5df2\u88ab\u8bbf\u95ee */\nint isVisited(Vertex **res, int size, Vertex *vet) {\n// \u904d\u5386\u67e5\u627e\u8282\u70b9\uff0c\u4f7f\u7528 O(n) \u65f6\u95f4\nfor (int i = 0; i < size; i++) {\nif (res[i] == vet) {\nreturn 1;\n}\n}\nreturn 0;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList *graph, Vertex **res, int *resSize, Vertex *vet) {\n// \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nres[(*resSize)++] = vet;\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nAdjListNode *node = findNode(graph, vet);\nwhile (node != NULL) {\n// \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nif (!isVisited(res, *resSize, node->vertex)) {\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, res, resSize, node->vertex);\n}\nnode = node->next;\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvoid graphDFS(GraphAdjList *graph, Vertex *startVet, Vertex **res, int *resSize) {\ndfs(graph, res, resSize, startVet);\n}\n
        graph_dfs.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{graphDFS}\n

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u7b97\u6cd5\u6d41\u7a0b\u5982\u56fe 9-12 \u6240\u793a\u3002

        • \u76f4\u865a\u7ebf\u4ee3\u8868\u5411\u4e0b\u9012\u63a8\uff0c\u8868\u793a\u5f00\u542f\u4e86\u4e00\u4e2a\u65b0\u7684\u9012\u5f52\u65b9\u6cd5\u6765\u8bbf\u95ee\u65b0\u9876\u70b9\u3002
        • \u66f2\u865a\u7ebf\u4ee3\u8868\u5411\u4e0a\u56de\u6eaf\uff0c\u8868\u793a\u6b64\u9012\u5f52\u65b9\u6cd5\u5df2\u7ecf\u8fd4\u56de\uff0c\u56de\u6eaf\u5230\u4e86\u5f00\u542f\u6b64\u65b9\u6cd5\u7684\u4f4d\u7f6e\u3002

        \u4e3a\u4e86\u52a0\u6df1\u7406\u89e3\uff0c\u5efa\u8bae\u5c06\u56fe 9-12 \u4e0e\u4ee3\u7801\u7ed3\u5408\u8d77\u6765\uff0c\u5728\u8111\u4e2d\u6a21\u62df\uff08\u6216\u8005\u7528\u7b14\u753b\u4e0b\u6765\uff09\u6574\u4e2a DFS \u8fc7\u7a0b\uff0c\u5305\u62ec\u6bcf\u4e2a\u9012\u5f52\u65b9\u6cd5\u4f55\u65f6\u5f00\u542f\u3001\u4f55\u65f6\u8fd4\u56de\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 9-12 \u00a0 \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u6b65\u9aa4

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5e8f\u5217\u662f\u5426\u552f\u4e00\uff1f

        \u4e0e\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7c7b\u4f3c\uff0c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u5e8f\u5217\u7684\u987a\u5e8f\u4e5f\u4e0d\u662f\u552f\u4e00\u7684\u3002\u7ed9\u5b9a\u67d0\u9876\u70b9\uff0c\u5148\u5f80\u54ea\u4e2a\u65b9\u5411\u63a2\u7d22\u90fd\u53ef\u4ee5\uff0c\u5373\u90bb\u63a5\u9876\u70b9\u7684\u987a\u5e8f\u53ef\u4ee5\u4efb\u610f\u6253\u4e71\uff0c\u90fd\u662f\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u3002

        \u4ee5\u6811\u7684\u904d\u5386\u4e3a\u4f8b\uff0c\u201c\u6839 \\(\\rightarrow\\) \u5de6 \\(\\rightarrow\\) \u53f3\u201d\u201c\u5de6 \\(\\rightarrow\\) \u6839 \\(\\rightarrow\\) \u53f3\u201d\u201c\u5de6 \\(\\rightarrow\\) \u53f3 \\(\\rightarrow\\) \u6839\u201d\u5206\u522b\u5bf9\u5e94\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\uff0c\u5b83\u4eec\u5c55\u793a\u4e86\u4e09\u79cd\u904d\u5386\u4f18\u5148\u7ea7\uff0c\u7136\u800c\u8fd9\u4e09\u8005\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u3002

        "},{"location":"chapter_graph/graph_traversal/#2_1","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u6240\u6709\u9876\u70b9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(1\\) \u6b21\uff0c\u4f7f\u7528 \\(O(|V|)\\) \u65f6\u95f4\uff1b\u6240\u6709\u8fb9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(2\\) \u6b21\uff0c\u4f7f\u7528 \\(O(2|E|)\\) \u65f6\u95f4\uff1b\u603b\u4f53\u4f7f\u7528 \\(O(|V| + |E|)\\) \u65f6\u95f4\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6\uff1a\u5217\u8868 res \uff0c\u54c8\u5e0c\u8868 visited \u9876\u70b9\u6570\u91cf\u6700\u591a\u4e3a \\(|V|\\) \uff0c\u9012\u5f52\u6df1\u5ea6\u6700\u5927\u4e3a \\(|V|\\) \uff0c\u56e0\u6b64\u4f7f\u7528 \\(O(|V|)\\) \u7a7a\u95f4\u3002

        "},{"location":"chapter_graph/summary/","title":"9.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_graph/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u56fe\u7531\u9876\u70b9\u548c\u8fb9\u7ec4\u6210\uff0c\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u7ec4\u9876\u70b9\u548c\u4e00\u7ec4\u8fb9\u6784\u6210\u7684\u96c6\u5408\u3002
        • \u76f8\u8f83\u4e8e\u7ebf\u6027\u5173\u7cfb\uff08\u94fe\u8868\uff09\u548c\u5206\u6cbb\u5173\u7cfb\uff08\u6811\uff09\uff0c\u7f51\u7edc\u5173\u7cfb\uff08\u56fe\uff09\u5177\u6709\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\uff0c\u56e0\u800c\u66f4\u4e3a\u590d\u6742\u3002
        • \u6709\u5411\u56fe\u7684\u8fb9\u5177\u6709\u65b9\u5411\u6027\uff0c\u8fde\u901a\u56fe\u4e2d\u7684\u4efb\u610f\u9876\u70b9\u5747\u53ef\u8fbe\uff0c\u6709\u6743\u56fe\u7684\u6bcf\u6761\u8fb9\u90fd\u5305\u542b\u6743\u91cd\u53d8\u91cf\u3002
        • \u90bb\u63a5\u77e9\u9635\u5229\u7528\u77e9\u9635\u6765\u8868\u793a\u56fe\uff0c\u6bcf\u4e00\u884c\uff08\u5217\uff09\u4ee3\u8868\u4e00\u4e2a\u9876\u70b9\uff0c\u77e9\u9635\u5143\u7d20\u4ee3\u8868\u8fb9\uff0c\u7528 \\(1\\) \u6216 \\(0\\) \u8868\u793a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u6709\u8fb9\u6216\u65e0\u8fb9\u3002\u90bb\u63a5\u77e9\u9635\u5728\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u4e0a\u6548\u7387\u5f88\u9ad8\uff0c\u4f46\u7a7a\u95f4\u5360\u7528\u8f83\u591a\u3002
        • \u90bb\u63a5\u8868\u4f7f\u7528\u591a\u4e2a\u94fe\u8868\u6765\u8868\u793a\u56fe\uff0c\u7b2c \\(i\\) \u4e2a\u94fe\u8868\u5bf9\u5e94\u9876\u70b9 \\(i\\) \uff0c\u5176\u4e2d\u5b58\u50a8\u4e86\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\u3002\u90bb\u63a5\u8868\u76f8\u5bf9\u4e8e\u90bb\u63a5\u77e9\u9635\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\uff0c\u4f46\u7531\u4e8e\u9700\u8981\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u8fb9\uff0c\u56e0\u6b64\u65f6\u95f4\u6548\u7387\u8f83\u4f4e\u3002
        • \u5f53\u90bb\u63a5\u8868\u4e2d\u7684\u94fe\u8868\u8fc7\u957f\u65f6\uff0c\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u6216\u54c8\u5e0c\u8868\uff0c\u4ece\u800c\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002
        • \u4ece\u7b97\u6cd5\u601d\u60f3\u7684\u89d2\u5ea6\u5206\u6790\uff0c\u90bb\u63a5\u77e9\u9635\u4f53\u73b0\u4e86\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\uff0c\u90bb\u63a5\u8868\u4f53\u73b0\u4e86\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u3002
        • \u56fe\u53ef\u7528\u4e8e\u5efa\u6a21\u5404\u7c7b\u73b0\u5b9e\u7cfb\u7edf\uff0c\u5982\u793e\u4ea4\u7f51\u7edc\u3001\u5730\u94c1\u7ebf\u8def\u7b49\u3002
        • \u6811\u662f\u56fe\u7684\u4e00\u79cd\u7279\u4f8b\uff0c\u6811\u7684\u904d\u5386\u4e5f\u662f\u56fe\u7684\u904d\u5386\u7684\u4e00\u79cd\u7279\u4f8b\u3002
        • \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u7531\u8fd1\u53ca\u8fdc\u3001\u5c42\u5c42\u6269\u5f20\u7684\u641c\u7d22\u65b9\u5f0f\uff0c\u901a\u5e38\u501f\u52a9\u961f\u5217\u5b9e\u73b0\u3002
        • \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u4f18\u5148\u8d70\u5230\u5e95\u3001\u65e0\u8def\u53ef\u8d70\u65f6\u518d\u56de\u6eaf\u7684\u641c\u7d22\u65b9\u5f0f\uff0c\u5e38\u57fa\u4e8e\u9012\u5f52\u6765\u5b9e\u73b0\u3002
        "},{"location":"chapter_graph/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u8def\u5f84\u7684\u5b9a\u4e49\u662f\u9876\u70b9\u5e8f\u5217\u8fd8\u662f\u8fb9\u5e8f\u5217\uff1f

        \u7ef4\u57fa\u767e\u79d1\u4e0a\u4e0d\u540c\u8bed\u8a00\u7248\u672c\u7684\u5b9a\u4e49\u4e0d\u4e00\u81f4\uff1a\u82f1\u6587\u7248\u662f\u201c\u8def\u5f84\u662f\u4e00\u4e2a\u8fb9\u5e8f\u5217\u201d\uff0c\u800c\u4e2d\u6587\u7248\u662f\u201c\u8def\u5f84\u662f\u4e00\u4e2a\u9876\u70b9\u5e8f\u5217\u201d\u3002\u4ee5\u4e0b\u662f\u82f1\u6587\u7248\u539f\u6587\uff1aIn graph theory, a path in a graph is a finite or infinite sequence of edges which joins a sequence of vertices. \u5728\u672c\u6587\u4e2d\uff0c\u8def\u5f84\u88ab\u89c6\u4e3a\u4e00\u4e2a\u8fb9\u5e8f\u5217\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u9876\u70b9\u5e8f\u5217\u3002\u8fd9\u662f\u56e0\u4e3a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u591a\u6761\u8fb9\u8fde\u63a5\uff0c\u6b64\u65f6\u6bcf\u6761\u8fb9\u90fd\u5bf9\u5e94\u4e00\u6761\u8def\u5f84\u3002

        \u975e\u8fde\u901a\u56fe\u4e2d\u662f\u5426\u4f1a\u6709\u65e0\u6cd5\u904d\u5386\u5230\u7684\u70b9\uff1f

        \u5728\u975e\u8fde\u901a\u56fe\u4e2d\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u9876\u70b9\u65e0\u6cd5\u5230\u8fbe\u3002\u904d\u5386\u975e\u8fde\u901a\u56fe\u9700\u8981\u8bbe\u7f6e\u591a\u4e2a\u8d77\u70b9\uff0c\u4ee5\u904d\u5386\u5230\u56fe\u7684\u6240\u6709\u8fde\u901a\u5206\u91cf\u3002

        \u5728\u90bb\u63a5\u8868\u4e2d\uff0c\u201c\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u6240\u6709\u9876\u70b9\u201d\u7684\u9876\u70b9\u987a\u5e8f\u662f\u5426\u6709\u8981\u6c42\uff1f

        \u53ef\u4ee5\u662f\u4efb\u610f\u987a\u5e8f\u3002\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u6309\u7167\u6307\u5b9a\u89c4\u5219\u6765\u6392\u5e8f\uff0c\u6bd4\u5982\u6309\u7167\u9876\u70b9\u6dfb\u52a0\u7684\u6b21\u5e8f\uff0c\u6216\u8005\u6309\u7167\u9876\u70b9\u503c\u5927\u5c0f\u7684\u987a\u5e8f\u7b49\uff0c\u8fd9\u6837\u6709\u52a9\u4e8e\u5feb\u901f\u67e5\u627e\u201c\u5e26\u6709\u67d0\u79cd\u6781\u503c\u201d\u7684\u9876\u70b9\u3002

        "},{"location":"chapter_greedy/","title":"\u7b2c 15 \u7ae0 \u00a0 \u8d2a\u5fc3","text":"

        Abstract

        \u5411\u65e5\u8475\u671d\u7740\u592a\u9633\u8f6c\u52a8\uff0c\u65f6\u523b\u8ffd\u6c42\u81ea\u8eab\u6210\u957f\u7684\u6700\u5927\u53ef\u80fd\u3002

        \u8d2a\u5fc3\u7b56\u7565\u5728\u4e00\u8f6e\u8f6e\u7684\u7b80\u5355\u9009\u62e9\u4e2d\uff0c\u9010\u6b65\u5bfc\u5411\u6700\u4f73\u7b54\u6848\u3002

        "},{"location":"chapter_greedy/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 15.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5
        • 15.2 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898
        • 15.3 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898
        • 15.4 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898
        • 15.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_greedy/fractional_knapsack_problem/","title":"15.2 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ea\u80fd\u9009\u62e9\u4e00\u6b21\uff0c\u4f46\u53ef\u4ee5\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\uff0c\u4ef7\u503c\u6839\u636e\u9009\u62e9\u7684\u91cd\u91cf\u6bd4\u4f8b\u8ba1\u7b97\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80cc\u5305\u4e2d\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002\u793a\u4f8b\u5982\u56fe 15-3 \u6240\u793a\u3002

        \u56fe 15-3 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        \u5206\u6570\u80cc\u5305\u95ee\u9898\u548c 0-1 \u80cc\u5305\u95ee\u9898\u6574\u4f53\u4e0a\u975e\u5e38\u76f8\u4f3c\uff0c\u72b6\u6001\u5305\u542b\u5f53\u524d\u7269\u54c1 \\(i\\) \u548c\u5bb9\u91cf \\(c\\) \uff0c\u76ee\u6807\u662f\u6c42\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u7684\u6700\u5927\u4ef7\u503c\u3002

        \u4e0d\u540c\u70b9\u5728\u4e8e\uff0c\u672c\u9898\u5141\u8bb8\u53ea\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\u3002\u5982\u56fe 15-4 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u7269\u54c1\u4efb\u610f\u5730\u8fdb\u884c\u5207\u5206\uff0c\u5e76\u6309\u7167\u91cd\u91cf\u6bd4\u4f8b\u6765\u8ba1\u7b97\u76f8\u5e94\u4ef7\u503c\u3002

        1. \u5bf9\u4e8e\u7269\u54c1 \\(i\\) \uff0c\u5b83\u5728\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u4ef7\u503c\u4e3a \\(val[i-1] / wgt[i-1]\\) \uff0c\u7b80\u79f0\u5355\u4f4d\u4ef7\u503c\u3002
        2. \u5047\u8bbe\u653e\u5165\u4e00\u90e8\u5206\u7269\u54c1 \\(i\\) \uff0c\u91cd\u91cf\u4e3a \\(w\\) \uff0c\u5219\u80cc\u5305\u589e\u52a0\u7684\u4ef7\u503c\u4e3a \\(w \\times val[i-1] / wgt[i-1]\\) \u3002

        \u56fe 15-4 \u00a0 \u7269\u54c1\u5728\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u4ef7\u503c

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u6700\u5927\u5316\u80cc\u5305\u5185\u7269\u54c1\u603b\u4ef7\u503c\uff0c\u672c\u8d28\u4e0a\u662f\u6700\u5927\u5316\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u7269\u54c1\u4ef7\u503c\u3002\u7531\u6b64\u4fbf\u53ef\u63a8\u7406\u51fa\u56fe 15-5 \u6240\u793a\u7684\u8d2a\u5fc3\u7b56\u7565\u3002

        1. \u5c06\u7269\u54c1\u6309\u7167\u5355\u4f4d\u4ef7\u503c\u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\u3002
        2. \u904d\u5386\u6240\u6709\u7269\u54c1\uff0c\u6bcf\u8f6e\u8d2a\u5fc3\u5730\u9009\u62e9\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\u7684\u7269\u54c1\u3002
        3. \u82e5\u5269\u4f59\u80cc\u5305\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u4f7f\u7528\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u586b\u6ee1\u80cc\u5305\u3002

        \u56fe 15-5 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u8d2a\u5fc3\u7b56\u7565

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u6211\u4eec\u5efa\u7acb\u4e86\u4e00\u4e2a\u7269\u54c1\u7c7b Item \uff0c\u4ee5\u4fbf\u5c06\u7269\u54c1\u6309\u7167\u5355\u4f4d\u4ef7\u503c\u8fdb\u884c\u6392\u5e8f\u3002\u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u5f53\u80cc\u5305\u5df2\u6ee1\u65f6\u8df3\u51fa\u5e76\u8fd4\u56de\u89e3\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig fractional_knapsack.py
        class Item:\n\"\"\"\u7269\u54c1\"\"\"\ndef __init__(self, w: int, v: int):\nself.w = w  # \u7269\u54c1\u91cd\u91cf\nself.v = v  # \u7269\u54c1\u4ef7\u503c\ndef fractional_knapsack(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3\"\"\"\n# \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nitems = [Item(w, v) for w, v in zip(wgt, val)]\n# \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort(key=lambda item: item.v / item.w, reverse=True)\n# \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nres = 0\nfor item in items:\nif item.w <= cap:\n# \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v\ncap -= item.w\nelse:\n# \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap\n# \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\nreturn res\n
        fractional_knapsack.cpp
        /* \u7269\u54c1 */\nclass Item {\npublic:\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\nItem(int w, int v) : w(w), v(v) {\n}\n};\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(vector<int> &wgt, vector<int> &val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nvector<Item> items;\nfor (int i = 0; i < wgt.size(); i++) {\nitems.push_back(Item(wgt[i], val[i]));\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nsort(items.begin(), items.end(), [](Item &a, Item &b) { return (double)a.v / a.w > (double)b.v / b.w; });\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (auto &item : items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double)item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.java
        /* \u7269\u54c1 */\nclass Item {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\npublic Item(int w, int v) {\nthis.w = w;\nthis.v = v;\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(int[] wgt, int[] val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem[] items = new Item[wgt.length];\nfor (int i = 0; i < wgt.length; i++) {\nitems[i] = new Item(wgt[i], val[i]);\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nArrays.sort(items, Comparator.comparingDouble(item -> -((double) item.v / item.w)));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (Item item : items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double) item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.cs
        /* \u7269\u54c1 */\nclass Item(int w, int v) {\npublic int w = w; // \u7269\u54c1\u91cd\u91cf\npublic int v = v; // \u7269\u54c1\u4ef7\u503c\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble FractionalKnapsack(int[] wgt, int[] val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem[] items = new Item[wgt.Length];\nfor (int i = 0; i < wgt.Length; i++) {\nitems[i] = new Item(wgt[i], val[i]);\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nArray.Sort(items, (x, y) => (y.v / y.w).CompareTo(x.v / x.w));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nforeach (Item item in items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double)item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.go
        /* \u7269\u54c1 */\ntype Item struct {\nw int // \u7269\u54c1\u91cd\u91cf\nv int // \u7269\u54c1\u4ef7\u503c\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunc fractionalKnapsack(wgt []int, val []int, cap int) float64 {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nitems := make([]Item, len(wgt))\nfor i := 0; i < len(wgt); i++ {\nitems[i] = Item{wgt[i], val[i]}\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nsort.Slice(items, func(i, j int) bool {\nreturn float64(items[i].v)/float64(items[i].w) > float64(items[j].v)/float64(items[j].w)\n})\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nres := 0.0\nfor _, item := range items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += float64(item.v)\ncap -= item.w\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += float64(item.v) / float64(item.w) * float64(cap)\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\nreturn res\n}\n
        fractional_knapsack.swift
        /* \u7269\u54c1 */\nclass Item {\nvar w: Int // \u7269\u54c1\u91cd\u91cf\nvar v: Int // \u7269\u54c1\u4ef7\u503c\ninit(w: Int, v: Int) {\nself.w = w\nself.v = v\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunc fractionalKnapsack(wgt: [Int], val: [Int], cap: Int) -> Double {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nvar items = zip(wgt, val).map { Item(w: $0, v: $1) }\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort(by: { -(Double($0.v) / Double($0.w)) < -(Double($1.v) / Double($1.w)) })\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nvar res = 0.0\nvar cap = cap\nfor item in items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += Double(item.v)\ncap -= item.w\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += Double(item.v) / Double(item.w) * Double(cap)\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\nreturn res\n}\n
        fractional_knapsack.js
        /* \u7269\u54c1 */\nclass Item {\nconstructor(w, v) {\nthis.w = w; // \u7269\u54c1\u91cd\u91cf\nthis.v = v; // \u7269\u54c1\u4ef7\u503c\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunction fractionalKnapsack(wgt, val, cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nconst items = wgt.map((w, i) => new Item(w, val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => b.v / b.w - a.v / a.w);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet res = 0;\nfor (const item of items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.ts
        /* \u7269\u54c1 */\nclass Item {\nw: number; // \u7269\u54c1\u91cd\u91cf\nv: number; // \u7269\u54c1\u4ef7\u503c\nconstructor(w: number, v: number) {\nthis.w = w;\nthis.v = v;\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunction fractionalKnapsack(wgt: number[], val: number[], cap: number): number {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nconst items: Item[] = wgt.map((w, i) => new Item(w, val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => b.v / b.w - a.v / a.w);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet res = 0;\nfor (const item of items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.dart
        /* \u7269\u54c1 */\nclass Item {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\nItem(this.w, this.v);\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(List<int> wgt, List<int> val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nList<Item> items = List.generate(wgt.length, (i) => Item(wgt[i], val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => (b.v / b.w).compareTo(a.v / a.w));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (Item item in items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.rs
        /* \u7269\u54c1 */\nstruct Item {\nw: i32, // \u7269\u54c1\u91cd\u91cf\nv: i32, // \u7269\u54c1\u4ef7\u503c\n}\nimpl Item {\nfn new(w: i32, v: i32) -> Self {\nSelf { w, v }\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfn fractional_knapsack(wgt: &[i32], val: &[i32], mut cap: i32) -> f64 {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nlet mut items = wgt\n.iter()\n.zip(val.iter())\n.map(|(&w, &v)| Item::new(w, v))\n.collect::<Vec<Item>>();\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort_by(|a, b| {\n(b.v as f64 / b.w as f64)\n.partial_cmp(&(a.v as f64 / a.w as f64))\n.unwrap()\n});\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet mut res = 0.0;\nfor item in &items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v as f64;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += item.v as f64 / item.w as f64 * cap as f64;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nres\n}\n
        fractional_knapsack.c
        /* \u7269\u54c1 */\ntypedef struct {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\n} Item;\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfloat fractionalKnapsack(int wgt[], int val[], int itemCount, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem *items = malloc(sizeof(Item) * itemCount);\nfor (int i = 0; i < itemCount; i++) {\nitems[i] = (Item){.w = wgt[i], .v = val[i]};\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nqsort(items, (size_t)itemCount, sizeof(Item), sortByValueDensity);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nfloat res = 0.0;\nfor (int i = 0; i < itemCount; i++) {\nif (items[i].w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += items[i].v;\ncap -= items[i].w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (float)cap / items[i].w * items[i].v;\ncap = 0;\nbreak;\n}\n}\nfree(items);\nreturn res;\n}\n
        fractional_knapsack.zig
        [class]{Item}-[func]{}\n[class]{}-[func]{fractionalKnapsack}\n

        \u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u904d\u5386\u6574\u4e2a\u7269\u54c1\u5217\u8868\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u7269\u54c1\u6570\u91cf\u3002

        \u7531\u4e8e\u521d\u59cb\u5316\u4e86\u4e00\u4e2a Item \u5bf9\u8c61\u5217\u8868\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u91c7\u7528\u53cd\u8bc1\u6cd5\u3002\u5047\u8bbe\u7269\u54c1 \\(x\\) \u662f\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\u7684\u7269\u54c1\uff0c\u4f7f\u7528\u67d0\u7b97\u6cd5\u6c42\u5f97\u6700\u5927\u4ef7\u503c\u4e3a res \uff0c\u4f46\u8be5\u89e3\u4e2d\u4e0d\u5305\u542b\u7269\u54c1 \\(x\\) \u3002

        \u73b0\u5728\u4ece\u80cc\u5305\u4e2d\u62ff\u51fa\u5355\u4f4d\u91cd\u91cf\u7684\u4efb\u610f\u7269\u54c1\uff0c\u5e76\u66ff\u6362\u4e3a\u5355\u4f4d\u91cd\u91cf\u7684\u7269\u54c1 \\(x\\) \u3002\u7531\u4e8e\u7269\u54c1 \\(x\\) \u7684\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\uff0c\u56e0\u6b64\u66ff\u6362\u540e\u7684\u603b\u4ef7\u503c\u4e00\u5b9a\u5927\u4e8e res \u3002\u8fd9\u4e0e res \u662f\u6700\u4f18\u89e3\u77db\u76fe\uff0c\u8bf4\u660e\u6700\u4f18\u89e3\u4e2d\u5fc5\u987b\u5305\u542b\u7269\u54c1 \\(x\\) \u3002

        \u5bf9\u4e8e\u8be5\u89e3\u4e2d\u7684\u5176\u4ed6\u7269\u54c1\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u6784\u5efa\u51fa\u4e0a\u8ff0\u77db\u76fe\u3002\u603b\u800c\u8a00\u4e4b\uff0c\u5355\u4f4d\u4ef7\u503c\u66f4\u5927\u7684\u7269\u54c1\u603b\u662f\u66f4\u4f18\u9009\u62e9\uff0c\u8fd9\u8bf4\u660e\u8d2a\u5fc3\u7b56\u7565\u662f\u6709\u6548\u7684\u3002

        \u5982\u56fe 15-6 \u6240\u793a\uff0c\u5982\u679c\u5c06\u7269\u54c1\u91cd\u91cf\u548c\u7269\u54c1\u5355\u4f4d\u4ef7\u503c\u5206\u522b\u770b\u4f5c\u4e00\u5f20\u4e8c\u7ef4\u56fe\u8868\u7684\u6a2a\u8f74\u548c\u7eb5\u8f74\uff0c\u5219\u5206\u6570\u80cc\u5305\u95ee\u9898\u53ef\u8f6c\u5316\u4e3a\u201c\u6c42\u5728\u6709\u9650\u6a2a\u8f74\u533a\u95f4\u4e0b\u7684\u6700\u5927\u56f4\u6210\u9762\u79ef\u201d\u3002\u8fd9\u4e2a\u7c7b\u6bd4\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4ece\u51e0\u4f55\u89d2\u5ea6\u7406\u89e3\u8d2a\u5fc3\u7b56\u7565\u7684\u6709\u6548\u6027\u3002

        \u56fe 15-6 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u51e0\u4f55\u8868\u793a

        "},{"location":"chapter_greedy/greedy_algorithm/","title":"15.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5","text":"

        \u300c\u8d2a\u5fc3\u7b97\u6cd5 greedy algorithm\u300d\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u89e3\u51b3\u4f18\u5316\u95ee\u9898\u7684\u7b97\u6cd5\uff0c\u5176\u57fa\u672c\u601d\u60f3\u662f\u5728\u95ee\u9898\u7684\u6bcf\u4e2a\u51b3\u7b56\u9636\u6bb5\uff0c\u90fd\u9009\u62e9\u5f53\u524d\u770b\u8d77\u6765\u6700\u4f18\u7684\u9009\u62e9\uff0c\u5373\u8d2a\u5fc3\u5730\u505a\u51fa\u5c40\u90e8\u6700\u4f18\u7684\u51b3\u7b56\uff0c\u4ee5\u671f\u83b7\u5f97\u5168\u5c40\u6700\u4f18\u89e3\u3002\u8d2a\u5fc3\u7b97\u6cd5\u7b80\u6d01\u4e14\u9ad8\u6548\uff0c\u5728\u8bb8\u591a\u5b9e\u9645\u95ee\u9898\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002

        \u8d2a\u5fc3\u7b97\u6cd5\u548c\u52a8\u6001\u89c4\u5212\u90fd\u5e38\u7528\u4e8e\u89e3\u51b3\u4f18\u5316\u95ee\u9898\u3002\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u76f8\u4f3c\u4e4b\u5904\uff0c\u6bd4\u5982\u90fd\u4f9d\u8d56\u6700\u4f18\u5b50\u7ed3\u6784\u6027\u8d28\uff0c\u4f46\u5de5\u4f5c\u539f\u7406\u4e0d\u540c\u3002

        • \u52a8\u6001\u89c4\u5212\u4f1a\u6839\u636e\u4e4b\u524d\u9636\u6bb5\u7684\u6240\u6709\u51b3\u7b56\u6765\u8003\u8651\u5f53\u524d\u51b3\u7b56\uff0c\u5e76\u4f7f\u7528\u8fc7\u53bb\u5b50\u95ee\u9898\u7684\u89e3\u6765\u6784\u5efa\u5f53\u524d\u5b50\u95ee\u9898\u7684\u89e3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4f1a\u8003\u8651\u8fc7\u53bb\u7684\u51b3\u7b56\uff0c\u800c\u662f\u4e00\u8def\u5411\u524d\u5730\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u4e0d\u65ad\u7f29\u5c0f\u95ee\u9898\u8303\u56f4\uff0c\u76f4\u81f3\u95ee\u9898\u88ab\u89e3\u51b3\u3002

        \u6211\u4eec\u5148\u901a\u8fc7\u4f8b\u9898\u201c\u96f6\u94b1\u5151\u6362\u201d\u4e86\u89e3\u8d2a\u5fc3\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u3002\u8fd9\u9053\u9898\u5df2\u7ecf\u5728\u201c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u201d\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u76f8\u4fe1\u4f60\u5bf9\u5b83\u5e76\u4e0d\u964c\u751f\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u80fd\u591f\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u5219\u8fd4\u56de \\(-1\\) \u3002

        \u672c\u9898\u91c7\u53d6\u7684\u8d2a\u5fc3\u7b56\u7565\u5982\u56fe 15-1 \u6240\u793a\u3002\u7ed9\u5b9a\u76ee\u6807\u91d1\u989d\uff0c\u6211\u4eec\u8d2a\u5fc3\u5730\u9009\u62e9\u4e0d\u5927\u4e8e\u4e14\u6700\u63a5\u8fd1\u5b83\u7684\u786c\u5e01\uff0c\u4e0d\u65ad\u5faa\u73af\u8be5\u6b65\u9aa4\uff0c\u76f4\u81f3\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u4e3a\u6b62\u3002

        \u56fe 15-1 \u00a0 \u96f6\u94b1\u5151\u6362\u7684\u8d2a\u5fc3\u7b56\u7565

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002\u4f60\u53ef\u80fd\u4f1a\u4e0d\u7531\u5730\u53d1\u51fa\u611f\u53f9\uff1aSo clean \uff01\u8d2a\u5fc3\u7b97\u6cd5\u4ec5\u7528\u7ea6\u5341\u884c\u4ee3\u7801\u5c31\u89e3\u51b3\u4e86\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_greedy.py
        def coin_change_greedy(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3\"\"\"\n# \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\ni = len(coins) - 1\ncount = 0\n# \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0:\n# \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 and coins[i] > amt:\ni -= 1\n# \u9009\u62e9 coins[i]\namt -= coins[i]\ncount += 1\n# \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn count if amt == 0 else -1\n
        coin_change_greedy.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(vector<int> &coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.size() - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(int[] coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint CoinChangeGreedy(int[] coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.Length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunc coinChangeGreedy(coins []int, amt int) int {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\ni := len(coins) - 1\ncount := 0\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nfor amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nfor i > 0 && coins[i] > amt {\ni--\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i]\ncount++\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nif amt != 0 {\nreturn -1\n}\nreturn count\n}\n
        coin_change_greedy.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunc coinChangeGreedy(coins: [Int], amt: Int) -> Int {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nvar i = coins.count - 1\nvar count = 0\nvar amt = amt\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 && coins[i] > amt {\ni -= 1\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i]\ncount += 1\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1\n}\n
        coin_change_greedy.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunction coinChangeGreedy(coins, amt) {\n// \u5047\u8bbe coins \u6570\u7ec4\u6709\u5e8f\nlet i = coins.length - 1;\nlet count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt === 0 ? count : -1;\n}\n
        coin_change_greedy.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunction coinChangeGreedy(coins: number[], amt: number): number {\n// \u5047\u8bbe coins \u6570\u7ec4\u6709\u5e8f\nlet i = coins.length - 1;\nlet count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt === 0 ? count : -1;\n}\n
        coin_change_greedy.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(List<int> coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfn coin_change_greedy(coins: &[i32], mut amt: i32) -> i32 {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nlet mut i = coins.len() - 1;\nlet mut count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 && coins[i] > amt {\ni -= 1;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount += 1;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nif amt == 0 {\ncount\n} else {\n-1\n}\n}\n
        coin_change_greedy.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(int *coins, int size, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = size - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.zig
        [class]{}-[func]{coinChangeGreedy}\n
        "},{"location":"chapter_greedy/greedy_algorithm/#1511","title":"15.1.1 \u00a0 \u8d2a\u5fc3\u7684\u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4ec5\u64cd\u4f5c\u76f4\u63a5\u3001\u5b9e\u73b0\u7b80\u5355\uff0c\u800c\u4e14\u901a\u5e38\u6548\u7387\u4e5f\u5f88\u9ad8\u3002\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u8bb0\u786c\u5e01\u6700\u5c0f\u9762\u503c\u4e3a \\(\\min(coins)\\) \uff0c\u5219\u8d2a\u5fc3\u9009\u62e9\u6700\u591a\u5faa\u73af \\(amt / \\min(coins)\\) \u6b21\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(amt / \\min(coins))\\) \u3002\u8fd9\u6bd4\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\times amt)\\) \u63d0\u5347\u4e86\u4e00\u4e2a\u6570\u91cf\u7ea7\u3002

        \u7136\u800c\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u786c\u5e01\u9762\u503c\u7ec4\u5408\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u5e76\u4e0d\u80fd\u627e\u5230\u6700\u4f18\u89e3\u3002\u56fe 15-2 \u7ed9\u51fa\u4e86\u4e24\u4e2a\u793a\u4f8b\u3002

        • \u6b63\u4f8b \\(coins = [1, 5, 10, 20, 50, 100]\\)\uff1a\u5728\u8be5\u786c\u5e01\u7ec4\u5408\u4e0b\uff0c\u7ed9\u5b9a\u4efb\u610f \\(amt\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u90fd\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3\u3002
        • \u53cd\u4f8b \\(coins = [1, 20, 50]\\)\uff1a\u5047\u8bbe \\(amt = 60\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ea\u80fd\u627e\u5230 \\(50 + 1 \\times 10\\) \u7684\u5151\u6362\u7ec4\u5408\uff0c\u5171\u8ba1 \\(11\\) \u679a\u786c\u5e01\uff0c\u4f46\u52a8\u6001\u89c4\u5212\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3 \\(20 + 20 + 20\\) \uff0c\u4ec5\u9700 \\(3\\) \u679a\u786c\u5e01\u3002
        • \u53cd\u4f8b \\(coins = [1, 49, 50]\\)\uff1a\u5047\u8bbe \\(amt = 98\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ea\u80fd\u627e\u5230 \\(50 + 1 \\times 48\\) \u7684\u5151\u6362\u7ec4\u5408\uff0c\u5171\u8ba1 \\(49\\) \u679a\u786c\u5e01\uff0c\u4f46\u52a8\u6001\u89c4\u5212\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3 \\(49 + 49\\) \uff0c\u4ec5\u9700 \\(2\\) \u679a\u786c\u5e01\u3002

        \u56fe 15-2 \u00a0 \u8d2a\u5fc3\u65e0\u6cd5\u627e\u51fa\u6700\u4f18\u89e3\u7684\u793a\u4f8b

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u65e0\u6cd5\u4fdd\u8bc1\u627e\u5230\u5168\u5c40\u6700\u4f18\u89e3\uff0c\u5e76\u4e14\u6709\u53ef\u80fd\u627e\u5230\u975e\u5e38\u5dee\u7684\u89e3\u3002\u5b83\u66f4\u9002\u5408\u7528\u52a8\u6001\u89c4\u5212\u89e3\u51b3\u3002

        \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u9002\u7528\u60c5\u51b5\u5206\u4ee5\u4e0b\u4e24\u79cd\u3002

        1. \u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1a\u8d2a\u5fc3\u7b97\u6cd5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5f80\u5f80\u662f\u6700\u4f18\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u5f80\u5f80\u6bd4\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u66f4\u9ad8\u6548\u3002
        2. \u53ef\u4ee5\u627e\u5230\u8fd1\u4f3c\u6700\u4f18\u89e3\uff1a\u8d2a\u5fc3\u7b97\u6cd5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e5f\u662f\u53ef\u7528\u7684\u3002\u5bf9\u4e8e\u5f88\u591a\u590d\u6742\u95ee\u9898\u6765\u8bf4\uff0c\u5bfb\u627e\u5168\u5c40\u6700\u4f18\u89e3\u975e\u5e38\u56f0\u96be\uff0c\u80fd\u4ee5\u8f83\u9ad8\u6548\u7387\u627e\u5230\u6b21\u4f18\u89e3\u4e5f\u662f\u975e\u5e38\u4e0d\u9519\u7684\u3002
        "},{"location":"chapter_greedy/greedy_algorithm/#1512","title":"15.1.2 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\u7279\u6027","text":"

        \u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u4ec0\u4e48\u6837\u7684\u95ee\u9898\u9002\u5408\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u5462\uff1f\u6216\u8005\u8bf4\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1f

        \u76f8\u8f83\u4e8e\u52a8\u6001\u89c4\u5212\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u4f7f\u7528\u6761\u4ef6\u66f4\u52a0\u82db\u523b\uff0c\u5176\u4e3b\u8981\u5173\u6ce8\u95ee\u9898\u7684\u4e24\u4e2a\u6027\u8d28\u3002

        • \u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\uff1a\u53ea\u6709\u5f53\u5c40\u90e8\u6700\u4f18\u9009\u62e9\u59cb\u7ec8\u53ef\u4ee5\u5bfc\u81f4\u5168\u5c40\u6700\u4f18\u89e3\u65f6\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u624d\u80fd\u4fdd\u8bc1\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u5305\u542b\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u3002

        \u6700\u4f18\u5b50\u7ed3\u6784\u5df2\u7ecf\u5728\u201c\u52a8\u6001\u89c4\u5212\u201d\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4e00\u4e9b\u95ee\u9898\u7684\u6700\u4f18\u5b50\u7ed3\u6784\u5e76\u4e0d\u660e\u663e\uff0c\u4f46\u4ecd\u7136\u53ef\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u89e3\u51b3\u3002

        \u6211\u4eec\u4e3b\u8981\u63a2\u7a76\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u7684\u5224\u65ad\u65b9\u6cd5\u3002\u867d\u7136\u5b83\u7684\u63cf\u8ff0\u770b\u4e0a\u53bb\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u5b9e\u9645\u4e0a\u5bf9\u4e8e\u8bb8\u591a\u95ee\u9898\uff0c\u8bc1\u660e\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u5e76\u975e\u6613\u4e8b\u3002

        \u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff0c\u6211\u4eec\u867d\u7136\u80fd\u591f\u5bb9\u6613\u5730\u4e3e\u51fa\u53cd\u4f8b\uff0c\u5bf9\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u8fdb\u884c\u8bc1\u4f2a\uff0c\u4f46\u8bc1\u5b9e\u7684\u96be\u5ea6\u8f83\u5927\u3002\u5982\u679c\u95ee\uff1a\u6ee1\u8db3\u4ec0\u4e48\u6761\u4ef6\u7684\u786c\u5e01\u7ec4\u5408\u53ef\u4ee5\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\uff1f\u6211\u4eec\u5f80\u5f80\u53ea\u80fd\u51ed\u501f\u76f4\u89c9\u6216\u4e3e\u4f8b\u5b50\u6765\u7ed9\u51fa\u4e00\u4e2a\u6a21\u68f1\u4e24\u53ef\u7684\u7b54\u6848\uff0c\u800c\u96be\u4ee5\u7ed9\u51fa\u4e25\u8c28\u7684\u6570\u5b66\u8bc1\u660e\u3002

        Quote

        \u6709\u4e00\u7bc7\u8bba\u6587\u7ed9\u51fa\u4e86\u4e00\u4e2a \\(O(n^3)\\) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7b97\u6cd5\uff0c\u7528\u4e8e\u5224\u65ad\u4e00\u4e2a\u786c\u5e01\u7ec4\u5408\u80fd\u5426\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u627e\u51fa\u4efb\u610f\u91d1\u989d\u7684\u6700\u4f18\u89e3\u3002

        Pearson, David. A polynomial-time algorithm for the change-making problem. Operations Research Letters 33.3 (2005): 231-234.

        "},{"location":"chapter_greedy/greedy_algorithm/#1513","title":"15.1.3 \u00a0 \u8d2a\u5fc3\u89e3\u9898\u6b65\u9aa4","text":"

        \u8d2a\u5fc3\u95ee\u9898\u7684\u89e3\u51b3\u6d41\u7a0b\u5927\u4f53\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e09\u6b65\u3002

        1. \u95ee\u9898\u5206\u6790\uff1a\u68b3\u7406\u4e0e\u7406\u89e3\u95ee\u9898\u7279\u6027\uff0c\u5305\u62ec\u72b6\u6001\u5b9a\u4e49\u3001\u4f18\u5316\u76ee\u6807\u548c\u7ea6\u675f\u6761\u4ef6\u7b49\u3002\u8fd9\u4e00\u6b65\u5728\u56de\u6eaf\u548c\u52a8\u6001\u89c4\u5212\u4e2d\u90fd\u6709\u6d89\u53ca\u3002
        2. \u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\uff1a\u786e\u5b9a\u5982\u4f55\u5728\u6bcf\u4e00\u6b65\u4e2d\u505a\u51fa\u8d2a\u5fc3\u9009\u62e9\u3002\u8fd9\u4e2a\u7b56\u7565\u80fd\u591f\u5728\u6bcf\u4e00\u6b65\u51cf\u5c0f\u95ee\u9898\u7684\u89c4\u6a21\uff0c\u5e76\u6700\u7ec8\u89e3\u51b3\u6574\u4e2a\u95ee\u9898\u3002
        3. \u6b63\u786e\u6027\u8bc1\u660e\uff1a\u901a\u5e38\u9700\u8981\u8bc1\u660e\u95ee\u9898\u5177\u6709\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u3002\u8fd9\u4e2a\u6b65\u9aa4\u53ef\u80fd\u9700\u8981\u7528\u5230\u6570\u5b66\u8bc1\u660e\uff0c\u4f8b\u5982\u5f52\u7eb3\u6cd5\u6216\u53cd\u8bc1\u6cd5\u7b49\u3002

        \u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u662f\u6c42\u89e3\u95ee\u9898\u7684\u6838\u5fc3\u6b65\u9aa4\uff0c\u4f46\u5b9e\u65bd\u8d77\u6765\u53ef\u80fd\u5e76\u4e0d\u5bb9\u6613\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u4e0d\u540c\u95ee\u9898\u7684\u8d2a\u5fc3\u7b56\u7565\u7684\u5dee\u5f02\u8f83\u5927\u3002\u5bf9\u4e8e\u8bb8\u591a\u95ee\u9898\u6765\u8bf4\uff0c\u8d2a\u5fc3\u7b56\u7565\u6bd4\u8f83\u6d45\u663e\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e9b\u5927\u6982\u7684\u601d\u8003\u4e0e\u5c1d\u8bd5\u5c31\u80fd\u5f97\u51fa\u3002\u800c\u5bf9\u4e8e\u4e00\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u8d2a\u5fc3\u7b56\u7565\u53ef\u80fd\u975e\u5e38\u9690\u853d\uff0c\u8fd9\u79cd\u60c5\u51b5\u5c31\u975e\u5e38\u8003\u9a8c\u4e2a\u4eba\u7684\u89e3\u9898\u7ecf\u9a8c\u4e0e\u7b97\u6cd5\u80fd\u529b\u4e86\u3002
        • \u67d0\u4e9b\u8d2a\u5fc3\u7b56\u7565\u5177\u6709\u8f83\u5f3a\u7684\u8ff7\u60d1\u6027\u3002\u5f53\u6211\u4eec\u6ee1\u6000\u4fe1\u5fc3\u8bbe\u8ba1\u597d\u8d2a\u5fc3\u7b56\u7565\uff0c\u5199\u51fa\u89e3\u9898\u4ee3\u7801\u5e76\u63d0\u4ea4\u8fd0\u884c\uff0c\u5f88\u53ef\u80fd\u53d1\u73b0\u90e8\u5206\u6d4b\u8bd5\u6837\u4f8b\u65e0\u6cd5\u901a\u8fc7\u3002\u8fd9\u662f\u56e0\u4e3a\u8bbe\u8ba1\u7684\u8d2a\u5fc3\u7b56\u7565\u53ea\u662f\u201c\u90e8\u5206\u6b63\u786e\u201d\u7684\uff0c\u4e0a\u6587\u4ecb\u7ecd\u7684\u96f6\u94b1\u5151\u6362\u5c31\u662f\u4e00\u4e2a\u5178\u578b\u6848\u4f8b\u3002

        \u4e3a\u4e86\u4fdd\u8bc1\u6b63\u786e\u6027\uff0c\u6211\u4eec\u5e94\u8be5\u5bf9\u8d2a\u5fc3\u7b56\u7565\u8fdb\u884c\u4e25\u8c28\u7684\u6570\u5b66\u8bc1\u660e\uff0c\u901a\u5e38\u9700\u8981\u7528\u5230\u53cd\u8bc1\u6cd5\u6216\u6570\u5b66\u5f52\u7eb3\u6cd5\u3002

        \u7136\u800c\uff0c\u6b63\u786e\u6027\u8bc1\u660e\u4e5f\u5f88\u53ef\u80fd\u4e0d\u662f\u4e00\u4ef6\u6613\u4e8b\u3002\u5982\u82e5\u6ca1\u6709\u5934\u7eea\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9009\u62e9\u9762\u5411\u6d4b\u8bd5\u7528\u4f8b\u8fdb\u884c\u4ee3\u7801\u8c03\u8bd5\uff0c\u4e00\u6b65\u6b65\u4fee\u6539\u4e0e\u9a8c\u8bc1\u8d2a\u5fc3\u7b56\u7565\u3002

        "},{"location":"chapter_greedy/greedy_algorithm/#1514","title":"15.1.4 \u00a0 \u8d2a\u5fc3\u5178\u578b\u4f8b\u9898","text":"

        \u8d2a\u5fc3\u7b97\u6cd5\u5e38\u5e38\u5e94\u7528\u5728\u6ee1\u8db3\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u4f18\u5316\u95ee\u9898\u4e2d\uff0c\u4ee5\u4e0b\u5217\u4e3e\u4e86\u4e00\u4e9b\u5178\u578b\u7684\u8d2a\u5fc3\u7b97\u6cd5\u95ee\u9898\u3002

        • \u786c\u5e01\u627e\u96f6\u95ee\u9898\uff1a\u5728\u67d0\u4e9b\u786c\u5e01\u7ec4\u5408\u4e0b\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u603b\u662f\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u533a\u95f4\u8c03\u5ea6\u95ee\u9898\uff1a\u5047\u8bbe\u4f60\u6709\u4e00\u4e9b\u4efb\u52a1\uff0c\u6bcf\u4e2a\u4efb\u52a1\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8fdb\u884c\uff0c\u4f60\u7684\u76ee\u6807\u662f\u5b8c\u6210\u5c3d\u53ef\u80fd\u591a\u7684\u4efb\u52a1\u3002\u5982\u679c\u6bcf\u6b21\u90fd\u9009\u62e9\u7ed3\u675f\u65f6\u95f4\u6700\u65e9\u7684\u4efb\u52a1\uff0c\u90a3\u4e48\u8d2a\u5fc3\u7b97\u6cd5\u5c31\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u5206\u6570\u80cc\u5305\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u7269\u54c1\u548c\u4e00\u4e2a\u8f7d\u91cd\u91cf\uff0c\u4f60\u7684\u76ee\u6807\u662f\u9009\u62e9\u4e00\u7ec4\u7269\u54c1\uff0c\u4f7f\u5f97\u603b\u91cd\u91cf\u4e0d\u8d85\u8fc7\u8f7d\u91cd\u91cf\uff0c\u4e14\u603b\u4ef7\u503c\u6700\u5927\u3002\u5982\u679c\u6bcf\u6b21\u90fd\u9009\u62e9\u6027\u4ef7\u6bd4\u6700\u9ad8\uff08\u4ef7\u503c / \u91cd\u91cf\uff09\u7684\u7269\u54c1\uff0c\u90a3\u4e48\u8d2a\u5fc3\u7b97\u6cd5\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u80a1\u7968\u4e70\u5356\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u80a1\u7968\u7684\u5386\u53f2\u4ef7\u683c\uff0c\u4f60\u53ef\u4ee5\u8fdb\u884c\u591a\u6b21\u4e70\u5356\uff0c\u4f46\u5982\u679c\u4f60\u5df2\u7ecf\u6301\u6709\u80a1\u7968\uff0c\u90a3\u4e48\u5728\u5356\u51fa\u4e4b\u524d\u4e0d\u80fd\u518d\u4e70\uff0c\u76ee\u6807\u662f\u83b7\u53d6\u6700\u5927\u5229\u6da6\u3002
        • \u970d\u592b\u66fc\u7f16\u7801\uff1a\u970d\u592b\u66fc\u7f16\u7801\u662f\u4e00\u79cd\u7528\u4e8e\u65e0\u635f\u6570\u636e\u538b\u7f29\u7684\u8d2a\u5fc3\u7b97\u6cd5\u3002\u901a\u8fc7\u6784\u5efa\u970d\u592b\u66fc\u6811\uff0c\u6bcf\u6b21\u9009\u62e9\u51fa\u73b0\u9891\u7387\u6700\u4f4e\u7684\u4e24\u4e2a\u8282\u70b9\u5408\u5e76\uff0c\u6700\u540e\u5f97\u5230\u7684\u970d\u592b\u66fc\u6811\u7684\u5e26\u6743\u8def\u5f84\u957f\u5ea6\uff08\u7f16\u7801\u957f\u5ea6\uff09\u6700\u5c0f\u3002
        • Dijkstra \u7b97\u6cd5\uff1a\u5b83\u662f\u4e00\u79cd\u89e3\u51b3\u7ed9\u5b9a\u6e90\u9876\u70b9\u5230\u5176\u4f59\u5404\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u95ee\u9898\u7684\u8d2a\u5fc3\u7b97\u6cd5\u3002
        "},{"location":"chapter_greedy/max_capacity_problem/","title":"15.3 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6570\u7ec4 \\(ht\\) \uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e00\u4e2a\u5782\u76f4\u9694\u677f\u7684\u9ad8\u5ea6\u3002\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u9694\u677f\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u7a7a\u95f4\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u5bb9\u5668\u3002

        \u5bb9\u5668\u7684\u5bb9\u91cf\u7b49\u4e8e\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u7684\u4e58\u79ef\uff08\u9762\u79ef\uff09\uff0c\u5176\u4e2d\u9ad8\u5ea6\u7531\u8f83\u77ed\u7684\u9694\u677f\u51b3\u5b9a\uff0c\u5bbd\u5ea6\u662f\u4e24\u4e2a\u9694\u677f\u7684\u6570\u7ec4\u7d22\u5f15\u4e4b\u5dee\u3002

        \u8bf7\u5728\u6570\u7ec4\u4e2d\u9009\u62e9\u4e24\u4e2a\u9694\u677f\uff0c\u4f7f\u5f97\u7ec4\u6210\u7684\u5bb9\u5668\u7684\u5bb9\u91cf\u6700\u5927\uff0c\u8fd4\u56de\u6700\u5927\u5bb9\u91cf\u3002\u793a\u4f8b\u5982\u56fe 15-7 \u6240\u793a\u3002

        \u56fe 15-7 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        \u5bb9\u5668\u7531\u4efb\u610f\u4e24\u4e2a\u9694\u677f\u56f4\u6210\uff0c\u56e0\u6b64\u672c\u9898\u7684\u72b6\u6001\u4e3a\u4e24\u4e2a\u9694\u677f\u7684\u7d22\u5f15\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u6839\u636e\u9898\u610f\uff0c\u5bb9\u91cf\u7b49\u4e8e\u9ad8\u5ea6\u4e58\u4ee5\u5bbd\u5ea6\uff0c\u5176\u4e2d\u9ad8\u5ea6\u7531\u77ed\u677f\u51b3\u5b9a\uff0c\u5bbd\u5ea6\u662f\u4e24\u9694\u677f\u7684\u6570\u7ec4\u7d22\u5f15\u4e4b\u5dee\u3002\u8bbe\u5bb9\u91cf\u4e3a \\(cap[i, j]\\) \uff0c\u5219\u53ef\u5f97\u8ba1\u7b97\u516c\u5f0f\uff1a

        \\[ cap[i, j] = \\min(ht[i], ht[j]) \\times (j - i) \\]

        \u8bbe\u6570\u7ec4\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u4e24\u4e2a\u9694\u677f\u7684\u7ec4\u5408\u6570\u91cf\uff08\u72b6\u6001\u603b\u6570\uff09\u4e3a \\(C_n^2 = \\frac{n(n - 1)}{2}\\) \u4e2a\u3002\u6700\u76f4\u63a5\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u7a77\u4e3e\u6240\u6709\u72b6\u6001\uff0c\u4ece\u800c\u6c42\u5f97\u6700\u5927\u5bb9\u91cf\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_greedy/max_capacity_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u8fd9\u9053\u9898\u8fd8\u6709\u66f4\u9ad8\u6548\u7387\u7684\u89e3\u6cd5\u3002\u5982\u56fe 15-8 \u6240\u793a\uff0c\u73b0\u9009\u53d6\u4e00\u4e2a\u72b6\u6001 \\([i, j]\\) \uff0c\u5176\u6ee1\u8db3\u7d22\u5f15 \\(i < j\\) \u4e14\u9ad8\u5ea6 \\(ht[i] < ht[j]\\) \uff0c\u5373 \\(i\\) \u4e3a\u77ed\u677f\u3001\\(j\\) \u4e3a\u957f\u677f\u3002

        \u56fe 15-8 \u00a0 \u521d\u59cb\u72b6\u6001

        \u5982\u56fe 15-9 \u6240\u793a\uff0c\u82e5\u6b64\u65f6\u5c06\u957f\u677f \\(j\\) \u5411\u77ed\u677f \\(i\\) \u9760\u8fd1\uff0c\u5219\u5bb9\u91cf\u4e00\u5b9a\u53d8\u5c0f\u3002

        \u8fd9\u662f\u56e0\u4e3a\u5728\u79fb\u52a8\u957f\u677f \\(j\\) \u540e\uff0c\u5bbd\u5ea6 \\(j-i\\) \u80af\u5b9a\u53d8\u5c0f\uff1b\u800c\u9ad8\u5ea6\u7531\u77ed\u677f\u51b3\u5b9a\uff0c\u56e0\u6b64\u9ad8\u5ea6\u53ea\u53ef\u80fd\u4e0d\u53d8\uff08 \\(i\\) \u4ecd\u4e3a\u77ed\u677f\uff09\u6216\u53d8\u5c0f\uff08\u79fb\u52a8\u540e\u7684 \\(j\\) \u6210\u4e3a\u77ed\u677f\uff09\u3002

        \u56fe 15-9 \u00a0 \u5411\u5185\u79fb\u52a8\u957f\u677f\u540e\u7684\u72b6\u6001

        \u53cd\u5411\u601d\u8003\uff0c\u6211\u4eec\u53ea\u6709\u5411\u5185\u6536\u7f29\u77ed\u677f \\(i\\) \uff0c\u624d\u6709\u53ef\u80fd\u4f7f\u5bb9\u91cf\u53d8\u5927\u3002\u56e0\u4e3a\u867d\u7136\u5bbd\u5ea6\u4e00\u5b9a\u53d8\u5c0f\uff0c\u4f46\u9ad8\u5ea6\u53ef\u80fd\u4f1a\u53d8\u5927\uff08\u79fb\u52a8\u540e\u7684\u77ed\u677f \\(i\\) \u53ef\u80fd\u4f1a\u53d8\u957f\uff09\u3002\u4f8b\u5982\u5728\u56fe 15-10 \u4e2d\uff0c\u79fb\u52a8\u77ed\u677f\u540e\u9762\u79ef\u53d8\u5927\u3002

        \u56fe 15-10 \u00a0 \u5411\u5185\u79fb\u52a8\u77ed\u677f\u540e\u7684\u72b6\u6001

        \u7531\u6b64\u4fbf\u53ef\u63a8\u51fa\u672c\u9898\u7684\u8d2a\u5fc3\u7b56\u7565\uff1a\u521d\u59cb\u5316\u4e24\u6307\u9488\u5206\u5217\u5bb9\u5668\u4e24\u7aef\uff0c\u6bcf\u8f6e\u5411\u5185\u6536\u7f29\u77ed\u677f\u5bf9\u5e94\u7684\u6307\u9488\uff0c\u76f4\u81f3\u4e24\u6307\u9488\u76f8\u9047\u3002

        \u56fe 15-11 \u5c55\u793a\u4e86\u8d2a\u5fc3\u7b56\u7565\u7684\u6267\u884c\u8fc7\u7a0b\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5206\u5217\u4e0e\u6570\u7ec4\u4e24\u7aef\u3002
        2. \u8ba1\u7b97\u5f53\u524d\u72b6\u6001\u7684\u5bb9\u91cf \\(cap[i, j]\\) \uff0c\u5e76\u66f4\u65b0\u6700\u5927\u5bb9\u91cf\u3002
        3. \u6bd4\u8f83\u677f \\(i\\) \u548c \u677f \\(j\\) \u7684\u9ad8\u5ea6\uff0c\u5e76\u5c06\u77ed\u677f\u5411\u5185\u79fb\u52a8\u4e00\u683c\u3002
        4. \u5faa\u73af\u6267\u884c\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\uff0c\u76f4\u81f3 \\(i\\) \u548c \\(j\\) \u76f8\u9047\u65f6\u7ed3\u675f\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 15-11 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u7684\u8d2a\u5fc3\u8fc7\u7a0b

        "},{"location":"chapter_greedy/max_capacity_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4ee3\u7801\u5faa\u73af\u6700\u591a \\(n\\) \u8f6e\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u53d8\u91cf \\(i\\)\u3001\\(j\\)\u3001\\(res\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig max_capacity.py
        def max_capacity(ht: list[int]) -> int:\n\"\"\"\u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3\"\"\"\n# \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\ni, j = 0, len(ht) - 1\n# \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nres = 0\n# \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j:\n# \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\ncap = min(ht[i], ht[j]) * (j - i)\nres = max(res, cap)\n# \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j]:\ni += 1\nelse:\nj -= 1\nreturn res\n
        max_capacity.cpp
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(vector<int> &ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.size() - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = min(ht[i], ht[j]) * (j - i);\nres = max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.java
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int[] ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.cs
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint MaxCapacity(int[] ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.Length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = Math.Min(ht[i], ht[j]) * (j - i);\nres = Math.Max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.go
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht []int) int {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\ni, j := 0, len(ht)-1\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nres := 0\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nfor i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\ncapacity := int(math.Min(float64(ht[i]), float64(ht[j]))) * (j - i)\nres = int(math.Max(float64(res), float64(capacity)))\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni++\n} else {\nj--\n}\n}\nreturn res\n}\n
        max_capacity.swift
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht: [Int]) -> Int {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nvar i = 0, j = ht.count - 1\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nvar res = 0\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nlet cap = min(ht[i], ht[j]) * (j - i)\nres = max(res, cap)\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni += 1\n} else {\nj -= 1\n}\n}\nreturn res\n}\n
        max_capacity.js
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet i = 0,\nj = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nconst cap = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni += 1;\n} else {\nj -= 1;\n}\n}\nreturn res;\n}\n
        max_capacity.ts
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht: number[]): number {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet i = 0,\nj = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nconst cap: number = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni += 1;\n} else {\nj -= 1;\n}\n}\nreturn res;\n}\n
        max_capacity.dart
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(List<int> ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = min(ht[i], ht[j]) * (j - i);\nres = max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.rs
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfn max_capacity(ht: &[i32]) -> i32 {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet mut i = 0;\nlet mut j = ht.len() - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet mut res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nlet cap = std::cmp::min(ht[i], ht[j]) * (j - i) as i32;\nres = std::cmp::max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni += 1;\n} else {\nj -= 1;\n}\n}\nres\n}\n
        max_capacity.c
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int ht[], int htLength) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0;\nint j = htLength - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint capacity = myMin(ht[i], ht[j]) * (j - i);\nres = myMax(res, capacity);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.zig
        [class]{}-[func]{maxCapacity}\n
        "},{"location":"chapter_greedy/max_capacity_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u4e4b\u6240\u4ee5\u8d2a\u5fc3\u6bd4\u7a77\u4e3e\u66f4\u5feb\uff0c\u662f\u56e0\u4e3a\u6bcf\u8f6e\u7684\u8d2a\u5fc3\u9009\u62e9\u90fd\u4f1a\u201c\u8df3\u8fc7\u201d\u4e00\u4e9b\u72b6\u6001\u3002

        \u6bd4\u5982\u5728\u72b6\u6001 \\(cap[i, j]\\) \u4e0b\uff0c\\(i\\) \u4e3a\u77ed\u677f\u3001\\(j\\) \u4e3a\u957f\u677f\u3002\u82e5\u8d2a\u5fc3\u5730\u5c06\u77ed\u677f \\(i\\) \u5411\u5185\u79fb\u52a8\u4e00\u683c\uff0c\u4f1a\u5bfc\u81f4\u56fe 15-12 \u6240\u793a\u7684\u72b6\u6001\u88ab\u201c\u8df3\u8fc7\u201d\u3002\u8fd9\u610f\u5473\u7740\u4e4b\u540e\u65e0\u6cd5\u9a8c\u8bc1\u8fd9\u4e9b\u72b6\u6001\u7684\u5bb9\u91cf\u5927\u5c0f\u3002

        \\[ cap[i, i+1], cap[i, i+2], \\dots, cap[i, j-2], cap[i, j-1] \\]

        \u56fe 15-12 \u00a0 \u79fb\u52a8\u77ed\u677f\u5bfc\u81f4\u88ab\u8df3\u8fc7\u7684\u72b6\u6001

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u8fd9\u4e9b\u88ab\u8df3\u8fc7\u7684\u72b6\u6001\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u957f\u677f \\(j\\) \u5411\u5185\u79fb\u52a8\u7684\u6240\u6709\u72b6\u6001\u3002\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u8bc1\u660e\u5185\u79fb\u957f\u677f\u4e00\u5b9a\u4f1a\u5bfc\u81f4\u5bb9\u91cf\u53d8\u5c0f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u88ab\u8df3\u8fc7\u7684\u72b6\u6001\u90fd\u4e0d\u53ef\u80fd\u662f\u6700\u4f18\u89e3\uff0c\u8df3\u8fc7\u5b83\u4eec\u4e0d\u4f1a\u5bfc\u81f4\u9519\u8fc7\u6700\u4f18\u89e3\u3002

        \u4ee5\u4e0a\u5206\u6790\u8bf4\u660e\uff0c\u79fb\u52a8\u77ed\u677f\u7684\u64cd\u4f5c\u662f\u201c\u5b89\u5168\u201d\u7684\uff0c\u8d2a\u5fc3\u7b56\u7565\u662f\u6709\u6548\u7684\u3002

        "},{"location":"chapter_greedy/max_product_cutting_problem/","title":"15.4 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 \\(n\\) \uff0c\u5c06\u5176\u5207\u5206\u4e3a\u81f3\u5c11\u4e24\u4e2a\u6b63\u6574\u6570\u7684\u548c\uff0c\u6c42\u5207\u5206\u540e\u6240\u6709\u6574\u6570\u7684\u4e58\u79ef\u6700\u5927\u662f\u591a\u5c11\uff0c\u5982\u56fe 15-13 \u6240\u793a\u3002

        \u56fe 15-13 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u7684\u95ee\u9898\u5b9a\u4e49

        \u5047\u8bbe\u6211\u4eec\u5c06 \\(n\\) \u5207\u5206\u4e3a \\(m\\) \u4e2a\u6574\u6570\u56e0\u5b50\uff0c\u5176\u4e2d\u7b2c \\(i\\) \u4e2a\u56e0\u5b50\u8bb0\u4e3a \\(n_i\\) \uff0c\u5373

        \\[ n = \\sum_{i=1}^{m}n_i \\]

        \u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u5f97\u6240\u6709\u6574\u6570\u56e0\u5b50\u7684\u6700\u5927\u4e58\u79ef\uff0c\u5373

        \\[ \\max(\\prod_{i=1}^{m}n_i) \\]

        \u6211\u4eec\u9700\u8981\u601d\u8003\u7684\u662f\uff1a\u5207\u5206\u6570\u91cf \\(m\\) \u5e94\u8be5\u591a\u5927\uff0c\u6bcf\u4e2a \\(n_i\\) \u5e94\u8be5\u662f\u591a\u5c11\uff1f

        "},{"location":"chapter_greedy/max_product_cutting_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u6839\u636e\u7ecf\u9a8c\uff0c\u4e24\u4e2a\u6574\u6570\u7684\u4e58\u79ef\u5f80\u5f80\u6bd4\u5b83\u4eec\u7684\u52a0\u548c\u66f4\u5927\u3002\u5047\u8bbe\u4ece \\(n\\) \u4e2d\u5206\u51fa\u4e00\u4e2a\u56e0\u5b50 \\(2\\) \uff0c\u5219\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a \\(2(n-2)\\) \u3002\u6211\u4eec\u5c06\u8be5\u4e58\u79ef\u4e0e \\(n\\) \u4f5c\u6bd4\u8f83\uff1a

        \\[ \\begin{aligned} 2(n-2) & \\geq n \\newline 2n - n - 4 & \\geq 0 \\newline n & \\geq 4 \\end{aligned} \\]

        \u5982\u56fe 15-14 \u6240\u793a\uff0c\u5f53 \\(n \\geq 4\\) \u65f6\uff0c\u5207\u5206\u51fa\u4e00\u4e2a \\(2\\) \u540e\u4e58\u79ef\u4f1a\u53d8\u5927\uff0c\u8fd9\u8bf4\u660e\u5927\u4e8e\u7b49\u4e8e \\(4\\) \u7684\u6574\u6570\u90fd\u5e94\u8be5\u88ab\u5207\u5206\u3002

        \u8d2a\u5fc3\u7b56\u7565\u4e00\uff1a\u5982\u679c\u5207\u5206\u65b9\u6848\u4e2d\u5305\u542b \\(\\geq 4\\) \u7684\u56e0\u5b50\uff0c\u90a3\u4e48\u5b83\u5c31\u5e94\u8be5\u88ab\u7ee7\u7eed\u5207\u5206\u3002\u6700\u7ec8\u7684\u5207\u5206\u65b9\u6848\u53ea\u5e94\u51fa\u73b0 \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u8fd9\u4e09\u79cd\u56e0\u5b50\u3002

        \u56fe 15-14 \u00a0 \u5207\u5206\u5bfc\u81f4\u4e58\u79ef\u53d8\u5927

        \u63a5\u4e0b\u6765\u601d\u8003\u54ea\u4e2a\u56e0\u5b50\u662f\u6700\u4f18\u7684\u3002\u5728 \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u8fd9\u4e09\u4e2a\u56e0\u5b50\u4e2d\uff0c\u663e\u7136 \\(1\\) \u662f\u6700\u5dee\u7684\uff0c\u56e0\u4e3a \\(1 \\times (n-1) < n\\) \u6052\u6210\u7acb\uff0c\u5373\u5207\u5206\u51fa \\(1\\) \u53cd\u800c\u4f1a\u5bfc\u81f4\u4e58\u79ef\u51cf\u5c0f\u3002

        \u5982\u56fe 15-15 \u6240\u793a\uff0c\u5f53 \\(n = 6\\) \u65f6\uff0c\u6709 \\(3 \\times 3 > 2 \\times 2 \\times 2\\) \u3002\u8fd9\u610f\u5473\u7740\u5207\u5206\u51fa \\(3\\) \u6bd4\u5207\u5206\u51fa \\(2\\) \u66f4\u4f18\u3002

        \u8d2a\u5fc3\u7b56\u7565\u4e8c\uff1a\u5728\u5207\u5206\u65b9\u6848\u4e2d\uff0c\u6700\u591a\u53ea\u5e94\u5b58\u5728\u4e24\u4e2a \\(2\\) \u3002\u56e0\u4e3a\u4e09\u4e2a \\(2\\) \u603b\u662f\u53ef\u4ee5\u66ff\u6362\u4e3a\u4e24\u4e2a \\(3\\) \uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002

        \u56fe 15-15 \u00a0 \u6700\u4f18\u5207\u5206\u56e0\u5b50

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u53ef\u63a8\u7406\u51fa\u4ee5\u4e0b\u8d2a\u5fc3\u7b56\u7565\u3002

        1. \u8f93\u5165\u6574\u6570 \\(n\\) \uff0c\u4ece\u5176\u4e0d\u65ad\u5730\u5207\u5206\u51fa\u56e0\u5b50 \\(3\\) \uff0c\u76f4\u81f3\u4f59\u6570\u4e3a \\(0\\)\u3001\\(1\\)\u3001\\(2\\) \u3002
        2. \u5f53\u4f59\u6570\u4e3a \\(0\\) \u65f6\uff0c\u4ee3\u8868 \\(n\\) \u662f \\(3\\) \u7684\u500d\u6570\uff0c\u56e0\u6b64\u4e0d\u505a\u4efb\u4f55\u5904\u7406\u3002
        3. \u5f53\u4f59\u6570\u4e3a \\(2\\) \u65f6\uff0c\u4e0d\u7ee7\u7eed\u5212\u5206\uff0c\u4fdd\u7559\u4e4b\u3002
        4. \u5f53\u4f59\u6570\u4e3a \\(1\\) \u65f6\uff0c\u7531\u4e8e \\(2 \\times 2 > 1 \\times 3\\) \uff0c\u56e0\u6b64\u5e94\u5c06\u6700\u540e\u4e00\u4e2a \\(3\\) \u66ff\u6362\u4e3a \\(2\\) \u3002
        "},{"location":"chapter_greedy/max_product_cutting_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5982\u56fe 15-16 \u6240\u793a\uff0c\u6211\u4eec\u65e0\u987b\u901a\u8fc7\u5faa\u73af\u6765\u5207\u5206\u6574\u6570\uff0c\u800c\u53ef\u4ee5\u5229\u7528\u5411\u4e0b\u6574\u9664\u8fd0\u7b97\u5f97\u5230 \\(3\\) \u7684\u4e2a\u6570 \\(a\\) \uff0c\u7528\u53d6\u6a21\u8fd0\u7b97\u5f97\u5230\u4f59\u6570 \\(b\\) \uff0c\u6b64\u65f6\u6709\uff1a

        \\[ n = 3 a + b \\]

        \u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e \\(n \\leq 3\\) \u7684\u8fb9\u754c\u60c5\u51b5\uff0c\u5fc5\u987b\u62c6\u5206\u51fa\u4e00\u4e2a \\(1\\) \uff0c\u4e58\u79ef\u4e3a \\(1 \\times (n - 1)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig max_product_cutting.py
        def max_product_cutting(n: int) -> int:\n\"\"\"\u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3\"\"\"\n# \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3:\nreturn 1 * (n - 1)\n# \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\na, b = n // 3, n % 3\nif b == 1:\n# \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn int(math.pow(3, a - 1)) * 2 * 2\nif b == 2:\n# \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.pow(3, a)) * 2\n# \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.pow(3, a))\n
        max_product_cutting.cpp
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int)pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)pow(3, a);\n}\n
        max_product_cutting.java
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int) Math.pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int) Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int) Math.pow(3, a);\n}\n
        max_product_cutting.cs
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint MaxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int)Math.Pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)Math.Pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)Math.Pow(3, a);\n}\n
        max_product_cutting.go
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunc maxProductCutting(n int) int {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1)\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\na := n / 3\nb := n % 3\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn int(math.Pow(3, float64(a-1))) * 2 * 2\n}\nif b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.Pow(3, float64(a))) * 2\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.Pow(3, float64(a)))\n}\n
        max_product_cutting.swift
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunc maxProductCutting(n: Int) -> Int {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1)\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = n / 3\nlet b = n % 3\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn pow(3, a - 1) * 2 * 2\n}\nif b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a) * 2\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a)\n}\n
        max_product_cutting.js
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunction maxProductCutting(n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = Math.floor(n / 3);\nlet b = n % 3;\nif (b === 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn Math.pow(3, a - 1) * 2 * 2;\n}\nif (b === 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a);\n}\n
        max_product_cutting.ts
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunction maxProductCutting(n: number): number {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a: number = Math.floor(n / 3);\nlet b: number = n % 3;\nif (b === 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn Math.pow(3, a - 1) * 2 * 2;\n}\nif (b === 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a);\n}\n
        max_product_cutting.dart
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n ~/ 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (pow(3, a - 1) * 2 * 2).toInt();\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (pow(3, a) * 2).toInt();\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a).toInt();\n}\n
        max_product_cutting.rs
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfn max_product_cutting(n: i32) -> i32 {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = n / 3;\nlet b = n % 3;\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n3_i32.pow(a as u32 - 1) * 2 * 2\n} else if b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n3_i32.pow(a as u32) * 2\n} else {\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n3_i32.pow(a as u32)\n}\n}\n
        max_product_cutting.c
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a);\n}\n
        max_product_cutting.zig
        [class]{}-[func]{maxProductCutting}\n

        \u56fe 15-16 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u7684\u8ba1\u7b97\u65b9\u6cd5

        \u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u5e42\u8fd0\u7b97\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002\u4ee5 Python \u4e3a\u4f8b\uff0c\u5e38\u7528\u7684\u5e42\u8ba1\u7b97\u51fd\u6570\u6709\u4e09\u79cd\u3002

        • \u8fd0\u7b97\u7b26 ** \u548c\u51fd\u6570 pow() \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log\u2061 a)\\) \u3002
        • \u51fd\u6570 math.pow() \u5185\u90e8\u8c03\u7528 C \u8bed\u8a00\u5e93\u7684 pow() \u51fd\u6570\uff0c\u5176\u6267\u884c\u6d6e\u70b9\u53d6\u5e42\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        \u53d8\u91cf \\(a\\) \u548c \\(b\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        "},{"location":"chapter_greedy/max_product_cutting_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u4f7f\u7528\u53cd\u8bc1\u6cd5\uff0c\u53ea\u5206\u6790 \\(n \\geq 3\\) \u7684\u60c5\u51b5\u3002

        1. \u6240\u6709\u56e0\u5b50 \\(\\leq 3\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5b58\u5728 \\(\\geq 4\\) \u7684\u56e0\u5b50 \\(x\\) \uff0c\u90a3\u4e48\u4e00\u5b9a\u53ef\u4ee5\u5c06\u5176\u7ee7\u7eed\u5212\u5206\u4e3a \\(2(x-2)\\) \uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        2. \u5207\u5206\u65b9\u6848\u4e0d\u5305\u542b \\(1\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5b58\u5728\u4e00\u4e2a\u56e0\u5b50 \\(1\\) \uff0c\u90a3\u4e48\u5b83\u4e00\u5b9a\u53ef\u4ee5\u5408\u5e76\u5165\u53e6\u5916\u4e00\u4e2a\u56e0\u5b50\u4e2d\uff0c\u4ee5\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        3. \u5207\u5206\u65b9\u6848\u6700\u591a\u5305\u542b\u4e24\u4e2a \\(2\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5305\u542b\u4e09\u4e2a \\(2\\) \uff0c\u90a3\u4e48\u4e00\u5b9a\u53ef\u4ee5\u66ff\u6362\u4e3a\u4e24\u4e2a \\(3\\) \uff0c\u4e58\u79ef\u66f4\u5927\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        "},{"location":"chapter_greedy/summary/","title":"15.5 \u00a0 \u5c0f\u7ed3","text":"
        • \u8d2a\u5fc3\u7b97\u6cd5\u901a\u5e38\u7528\u4e8e\u89e3\u51b3\u6700\u4f18\u5316\u95ee\u9898\uff0c\u5176\u539f\u7406\u662f\u5728\u6bcf\u4e2a\u51b3\u7b56\u9636\u6bb5\u90fd\u505a\u51fa\u5c40\u90e8\u6700\u4f18\u7684\u51b3\u7b56\uff0c\u4ee5\u671f\u83b7\u5f97\u5168\u5c40\u6700\u4f18\u89e3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4f1a\u8fed\u4ee3\u5730\u505a\u51fa\u4e00\u4e2a\u53c8\u4e00\u4e2a\u7684\u8d2a\u5fc3\u9009\u62e9\uff0c\u6bcf\u8f6e\u90fd\u5c06\u95ee\u9898\u8f6c\u5316\u6210\u4e00\u4e2a\u89c4\u6a21\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u5230\u95ee\u9898\u88ab\u89e3\u51b3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4ec5\u5b9e\u73b0\u7b80\u5355\uff0c\u8fd8\u5177\u6709\u5f88\u9ad8\u7684\u89e3\u9898\u6548\u7387\u3002\u76f8\u6bd4\u4e8e\u52a8\u6001\u89c4\u5212\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u66f4\u4f4e\u3002
        • \u5728\u96f6\u94b1\u5151\u6362\u95ee\u9898\u4e2d\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u786c\u5e01\u7ec4\u5408\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1b\u5bf9\u4e8e\u53e6\u5916\u4e00\u4e9b\u786c\u5e01\u7ec4\u5408\u5219\u4e0d\u7136\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ef\u80fd\u627e\u5230\u5f88\u5dee\u7684\u89e3\u3002
        • \u9002\u5408\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u7684\u95ee\u9898\u5177\u6709\u4e24\u5927\u6027\u8d28\uff1a\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u3002\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u4ee3\u8868\u8d2a\u5fc3\u7b56\u7565\u7684\u6709\u6548\u6027\u3002
        • \u5bf9\u4e8e\u67d0\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u7684\u8bc1\u660e\u5e76\u4e0d\u7b80\u5355\u3002\u76f8\u5bf9\u6765\u8bf4\uff0c\u8bc1\u4f2a\u66f4\u52a0\u5bb9\u6613\uff0c\u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\u3002
        • \u6c42\u89e3\u8d2a\u5fc3\u95ee\u9898\u4e3b\u8981\u5206\u4e3a\u4e09\u6b65\uff1a\u95ee\u9898\u5206\u6790\u3001\u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u3001\u6b63\u786e\u6027\u8bc1\u660e\u3002\u5176\u4e2d\uff0c\u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u662f\u6838\u5fc3\u6b65\u9aa4\uff0c\u6b63\u786e\u6027\u8bc1\u660e\u5f80\u5f80\u662f\u96be\u70b9\u3002
        • \u5206\u6570\u80cc\u5305\u95ee\u9898\u5728 0-1 \u80cc\u5305\u7684\u57fa\u7840\u4e0a\uff0c\u5141\u8bb8\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u53ef\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u3002\u8d2a\u5fc3\u7b56\u7565\u7684\u6b63\u786e\u6027\u53ef\u4ee5\u4f7f\u7528\u53cd\u8bc1\u6cd5\u6765\u8bc1\u660e\u3002
        • \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u53ef\u4f7f\u7528\u7a77\u4e3e\u6cd5\u6c42\u89e3\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002\u901a\u8fc7\u8bbe\u8ba1\u8d2a\u5fc3\u7b56\u7565\uff0c\u6bcf\u8f6e\u5411\u5185\u79fb\u52a8\u77ed\u677f\uff0c\u53ef\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(n)\\) \u3002
        • \u5728\u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898\u4e2d\uff0c\u6211\u4eec\u5148\u540e\u63a8\u7406\u51fa\u4e24\u4e2a\u8d2a\u5fc3\u7b56\u7565\uff1a\\(\\geq 4\\) \u7684\u6574\u6570\u90fd\u5e94\u8be5\u7ee7\u7eed\u5207\u5206\u3001\u6700\u4f18\u5207\u5206\u56e0\u5b50\u4e3a \\(3\\) \u3002\u4ee3\u7801\u4e2d\u5305\u542b\u5e42\u8fd0\u7b97\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u5e42\u8fd0\u7b97\u5b9e\u73b0\u65b9\u6cd5\uff0c\u901a\u5e38\u4e3a \\(O(1)\\) \u6216 \\(O(\\log n)\\) \u3002
        "},{"location":"chapter_hashing/","title":"\u7b2c 6 \u7ae0 \u00a0 \u54c8\u5e0c\u8868","text":"

        Abstract

        \u5728\u8ba1\u7b97\u673a\u4e16\u754c\u4e2d\uff0c\u54c8\u5e0c\u8868\u5982\u540c\u4e00\u4f4d\u806a\u6167\u7684\u56fe\u4e66\u7ba1\u7406\u5458\u3002

        \u4ed6\u77e5\u9053\u5982\u4f55\u8ba1\u7b97\u7d22\u4e66\u53f7\uff0c\u4ece\u800c\u53ef\u4ee5\u5feb\u901f\u627e\u5230\u76ee\u6807\u56fe\u4e66\u3002

        "},{"location":"chapter_hashing/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 6.1 \u00a0 \u54c8\u5e0c\u8868
        • 6.2 \u00a0 \u54c8\u5e0c\u51b2\u7a81
        • 6.3 \u00a0 \u54c8\u5e0c\u7b97\u6cd5
        • 6.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_hashing/hash_algorithm/","title":"6.3 \u00a0 \u54c8\u5e0c\u7b97\u6cd5","text":"

        \u524d\u4e24\u8282\u4ecb\u7ecd\u4e86\u54c8\u5e0c\u8868\u7684\u5de5\u4f5c\u539f\u7406\u548c\u54c8\u5e0c\u51b2\u7a81\u7684\u5904\u7406\u65b9\u6cd5\u3002\u7136\u800c\u65e0\u8bba\u662f\u5f00\u653e\u5bfb\u5740\u8fd8\u662f\u94fe\u5f0f\u5730\u5740\uff0c\u5b83\u4eec\u53ea\u80fd\u4fdd\u8bc1\u54c8\u5e0c\u8868\u53ef\u4ee5\u5728\u53d1\u751f\u51b2\u7a81\u65f6\u6b63\u5e38\u5de5\u4f5c\uff0c\u800c\u65e0\u6cd5\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u7684\u53d1\u751f\u3002

        \u5982\u679c\u54c8\u5e0c\u51b2\u7a81\u8fc7\u4e8e\u9891\u7e41\uff0c\u54c8\u5e0c\u8868\u7684\u6027\u80fd\u5219\u4f1a\u6025\u5267\u52a3\u5316\u3002\u5982\u56fe 6-8 \u6240\u793a\uff0c\u5bf9\u4e8e\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\uff0c\u7406\u60f3\u60c5\u51b5\u4e0b\u952e\u503c\u5bf9\u5747\u5300\u5206\u5e03\u5728\u5404\u4e2a\u6876\u4e2d\uff0c\u8fbe\u5230\u6700\u4f73\u67e5\u8be2\u6548\u7387\uff1b\u6700\u5dee\u60c5\u51b5\u4e0b\u6240\u6709\u952e\u503c\u5bf9\u90fd\u5b58\u50a8\u5230\u540c\u4e00\u4e2a\u6876\u4e2d\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u9000\u5316\u81f3 \\(O(n)\\) \u3002

        \u56fe 6-8 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u7684\u6700\u4f73\u60c5\u51b5\u4e0e\u6700\u5dee\u60c5\u51b5

        \u952e\u503c\u5bf9\u7684\u5206\u5e03\u60c5\u51b5\u7531\u54c8\u5e0c\u51fd\u6570\u51b3\u5b9a\u3002\u56de\u5fc6\u54c8\u5e0c\u51fd\u6570\u7684\u8ba1\u7b97\u6b65\u9aa4\uff0c\u5148\u8ba1\u7b97\u54c8\u5e0c\u503c\uff0c\u518d\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21\uff1a

        index = hash(key) % capacity\n

        \u89c2\u5bdf\u4ee5\u4e0a\u516c\u5f0f\uff0c\u5f53\u54c8\u5e0c\u8868\u5bb9\u91cf capacity \u56fa\u5b9a\u65f6\uff0c\u54c8\u5e0c\u7b97\u6cd5 hash() \u51b3\u5b9a\u4e86\u8f93\u51fa\u503c\uff0c\u8fdb\u800c\u51b3\u5b9a\u4e86\u952e\u503c\u5bf9\u5728\u54c8\u5e0c\u8868\u4e2d\u7684\u5206\u5e03\u60c5\u51b5\u3002

        \u8fd9\u610f\u5473\u7740\uff0c\u4e3a\u4e86\u964d\u4f4e\u54c8\u5e0c\u51b2\u7a81\u7684\u53d1\u751f\u6982\u7387\uff0c\u6211\u4eec\u5e94\u5f53\u5c06\u6ce8\u610f\u529b\u96c6\u4e2d\u5728\u54c8\u5e0c\u7b97\u6cd5 hash() \u7684\u8bbe\u8ba1\u4e0a\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#631","title":"6.3.1 \u00a0 \u54c8\u5e0c\u7b97\u6cd5\u7684\u76ee\u6807","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u201c\u65e2\u5feb\u53c8\u7a33\u201d\u7684\u54c8\u5e0c\u8868\u6570\u636e\u7ed3\u6784\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5e94\u5177\u5907\u4ee5\u4e0b\u7279\u70b9\u3002

        • \u786e\u5b9a\u6027\uff1a\u5bf9\u4e8e\u76f8\u540c\u7684\u8f93\u5165\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5e94\u59cb\u7ec8\u4ea7\u751f\u76f8\u540c\u7684\u8f93\u51fa\u3002\u8fd9\u6837\u624d\u80fd\u786e\u4fdd\u54c8\u5e0c\u8868\u662f\u53ef\u9760\u7684\u3002
        • \u6548\u7387\u9ad8\uff1a\u8ba1\u7b97\u54c8\u5e0c\u503c\u7684\u8fc7\u7a0b\u5e94\u8be5\u8db3\u591f\u5feb\u3002\u8ba1\u7b97\u5f00\u9500\u8d8a\u5c0f\uff0c\u54c8\u5e0c\u8868\u7684\u5b9e\u7528\u6027\u8d8a\u9ad8\u3002
        • \u5747\u5300\u5206\u5e03\uff1a\u54c8\u5e0c\u7b97\u6cd5\u5e94\u4f7f\u5f97\u952e\u503c\u5bf9\u5747\u5300\u5206\u5e03\u5728\u54c8\u5e0c\u8868\u4e2d\u3002\u5206\u5e03\u8d8a\u5747\u5300\uff0c\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\u3002

        \u5b9e\u9645\u4e0a\uff0c\u54c8\u5e0c\u7b97\u6cd5\u9664\u4e86\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u54c8\u5e0c\u8868\uff0c\u8fd8\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5176\u4ed6\u9886\u57df\u4e2d\u3002

        • \u5bc6\u7801\u5b58\u50a8\uff1a\u4e3a\u4e86\u4fdd\u62a4\u7528\u6237\u5bc6\u7801\u7684\u5b89\u5168\uff0c\u7cfb\u7edf\u901a\u5e38\u4e0d\u4f1a\u76f4\u63a5\u5b58\u50a8\u7528\u6237\u7684\u660e\u6587\u5bc6\u7801\uff0c\u800c\u662f\u5b58\u50a8\u5bc6\u7801\u7684\u54c8\u5e0c\u503c\u3002\u5f53\u7528\u6237\u8f93\u5165\u5bc6\u7801\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5bf9\u8f93\u5165\u7684\u5bc6\u7801\u8ba1\u7b97\u54c8\u5e0c\u503c\uff0c\u7136\u540e\u4e0e\u5b58\u50a8\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u8005\u5339\u914d\uff0c\u90a3\u4e48\u5bc6\u7801\u5c31\u88ab\u89c6\u4e3a\u6b63\u786e\u3002
        • \u6570\u636e\u5b8c\u6574\u6027\u68c0\u67e5\uff1a\u6570\u636e\u53d1\u9001\u65b9\u53ef\u4ee5\u8ba1\u7b97\u6570\u636e\u7684\u54c8\u5e0c\u503c\u5e76\u5c06\u5176\u4e00\u540c\u53d1\u9001\uff1b\u63a5\u6536\u65b9\u53ef\u4ee5\u91cd\u65b0\u8ba1\u7b97\u63a5\u6536\u5230\u7684\u6570\u636e\u7684\u54c8\u5e0c\u503c\uff0c\u5e76\u4e0e\u63a5\u6536\u5230\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u8005\u5339\u914d\uff0c\u90a3\u4e48\u6570\u636e\u5c31\u88ab\u89c6\u4e3a\u5b8c\u6574\u3002

        \u5bf9\u4e8e\u5bc6\u7801\u5b66\u7684\u76f8\u5173\u5e94\u7528\uff0c\u4e3a\u4e86\u9632\u6b62\u4ece\u54c8\u5e0c\u503c\u63a8\u5bfc\u51fa\u539f\u59cb\u5bc6\u7801\u7b49\u9006\u5411\u5de5\u7a0b\uff0c\u54c8\u5e0c\u7b97\u6cd5\u9700\u8981\u5177\u5907\u66f4\u9ad8\u7b49\u7ea7\u7684\u5b89\u5168\u7279\u6027\u3002

        • \u5355\u5411\u6027\uff1a\u65e0\u6cd5\u901a\u8fc7\u54c8\u5e0c\u503c\u53cd\u63a8\u51fa\u5173\u4e8e\u8f93\u5165\u6570\u636e\u7684\u4efb\u4f55\u4fe1\u606f\u3002
        • \u6297\u78b0\u649e\u6027\uff1a\u5e94\u5f53\u6781\u96be\u627e\u5230\u4e24\u4e2a\u4e0d\u540c\u7684\u8f93\u5165\uff0c\u4f7f\u5f97\u5b83\u4eec\u7684\u54c8\u5e0c\u503c\u76f8\u540c\u3002
        • \u96ea\u5d29\u6548\u5e94\uff1a\u8f93\u5165\u7684\u5fae\u5c0f\u53d8\u5316\u5e94\u5f53\u5bfc\u81f4\u8f93\u51fa\u7684\u663e\u8457\u4e14\u4e0d\u53ef\u9884\u6d4b\u7684\u53d8\u5316\u3002

        \u8bf7\u6ce8\u610f\uff0c\u201c\u5747\u5300\u5206\u5e03\u201d\u4e0e\u201c\u6297\u78b0\u649e\u6027\u201d\u662f\u4e24\u4e2a\u72ec\u7acb\u7684\u6982\u5ff5\uff0c\u6ee1\u8db3\u5747\u5300\u5206\u5e03\u4e0d\u4e00\u5b9a\u6ee1\u8db3\u6297\u78b0\u649e\u6027\u3002\u4f8b\u5982\uff0c\u5728\u968f\u673a\u8f93\u5165 key \u4e0b\uff0c\u54c8\u5e0c\u51fd\u6570 key % 100 \u53ef\u4ee5\u4ea7\u751f\u5747\u5300\u5206\u5e03\u7684\u8f93\u51fa\u3002\u7136\u800c\u8be5\u54c8\u5e0c\u7b97\u6cd5\u8fc7\u4e8e\u7b80\u5355\uff0c\u6240\u6709\u540e\u4e24\u4f4d\u76f8\u7b49\u7684 key \u7684\u8f93\u51fa\u90fd\u76f8\u540c\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u4ece\u54c8\u5e0c\u503c\u53cd\u63a8\u51fa\u53ef\u7528\u7684 key \uff0c\u4ece\u800c\u7834\u89e3\u5bc6\u7801\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#632","title":"6.3.2 \u00a0 \u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1","text":"

        \u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1\u662f\u4e00\u4e2a\u9700\u8981\u8003\u8651\u8bb8\u591a\u56e0\u7d20\u7684\u590d\u6742\u95ee\u9898\u3002\u7136\u800c\u5bf9\u4e8e\u67d0\u4e9b\u8981\u6c42\u4e0d\u9ad8\u7684\u573a\u666f\uff0c\u6211\u4eec\u4e5f\u80fd\u8bbe\u8ba1\u4e00\u4e9b\u7b80\u5355\u7684\u54c8\u5e0c\u7b97\u6cd5\u3002

        • \u52a0\u6cd5\u54c8\u5e0c\uff1a\u5bf9\u8f93\u5165\u7684\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u8fdb\u884c\u76f8\u52a0\uff0c\u5c06\u5f97\u5230\u7684\u603b\u548c\u4f5c\u4e3a\u54c8\u5e0c\u503c\u3002
        • \u4e58\u6cd5\u54c8\u5e0c\uff1a\u5229\u7528\u4e58\u6cd5\u7684\u4e0d\u76f8\u5173\u6027\uff0c\u6bcf\u8f6e\u4e58\u4ee5\u4e00\u4e2a\u5e38\u6570\uff0c\u5c06\u5404\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u7d2f\u79ef\u5230\u54c8\u5e0c\u503c\u4e2d\u3002
        • \u5f02\u6216\u54c8\u5e0c\uff1a\u5c06\u8f93\u5165\u6570\u636e\u7684\u6bcf\u4e2a\u5143\u7d20\u901a\u8fc7\u5f02\u6216\u64cd\u4f5c\u7d2f\u79ef\u5230\u4e00\u4e2a\u54c8\u5e0c\u503c\u4e2d\u3002
        • \u65cb\u8f6c\u54c8\u5e0c\uff1a\u5c06\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u7d2f\u79ef\u5230\u4e00\u4e2a\u54c8\u5e0c\u503c\u4e2d\uff0c\u6bcf\u6b21\u7d2f\u79ef\u4e4b\u524d\u90fd\u4f1a\u5bf9\u54c8\u5e0c\u503c\u8fdb\u884c\u65cb\u8f6c\u64cd\u4f5c\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig simple_hash.py
        def add_hash(key: str) -> int:\n\"\"\"\u52a0\u6cd5\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash += ord(c)\nreturn hash % modulus\ndef mul_hash(key: str) -> int:\n\"\"\"\u4e58\u6cd5\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash = 31 * hash + ord(c)\nreturn hash % modulus\ndef xor_hash(key: str) -> int:\n\"\"\"\u5f02\u6216\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash ^= ord(c)\nreturn hash % modulus\ndef rot_hash(key: str) -> int:\n\"\"\"\u65cb\u8f6c\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash = (hash << 4) ^ (hash >> 28) ^ ord(c)\nreturn hash % modulus\n
        simple_hash.cpp
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = (hash + (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = (31 * hash + (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(string key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash ^= (int)c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.java
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = (hash + (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = (31 * hash + (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash ^= (int) c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n
        simple_hash.cs
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint AddHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = (hash + c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint MulHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = (31 * hash + c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint XorHash(string key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash ^= c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint RotHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.go
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = (hash + int64(b)) % modulus\n}\nreturn int(hash)\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = (31*hash + int64(b)) % modulus\n}\nreturn int(hash)\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key string) int {\nhash := 0\nmodulus := 1000000007\nfor _, b := range []byte(key) {\nfmt.Println(int(b))\nhash ^= int(b)\nhash = (31*hash + int(b)) % modulus\n}\nreturn hash & modulus\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ int64(b)) % modulus\n}\nreturn int(hash)\n}\n
        simple_hash.swift
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = (hash + Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = (31 * hash + Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash ^= Int(scalar.value)\n}\n}\nreturn hash & MODULUS\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = ((hash << 4) ^ (hash >> 28) ^ Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n
        simple_hash.js
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash ^= c.charCodeAt(0);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.ts
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash ^= c.charCodeAt(0);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.dart
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = (hash + key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = (31 * hash + key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash ^= key.codeUnitAt(i);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = ((hash << 4) ^ (hash >> 28) ^ key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.rs
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfn add_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = (hash + c as i64) % MODULUS;\n}\nhash as i32\n} /* \u4e58\u6cd5\u54c8\u5e0c */\nfn mul_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = (31 * hash + c as i64) % MODULUS;\n}\nhash as i32\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfn xor_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash ^= c as i64;\n}\n(hash & MODULUS) as i32\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfn rot_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = ((hash << 4) ^ (hash >> 28) ^ c as i64) % MODULUS;\n}\nhash as i32\n}\n
        simple_hash.c
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = (hash + (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = (31 * hash + (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(char *key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash ^= (unsigned char)key[i];\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.zig
        [class]{}-[func]{addHash}\n[class]{}-[func]{mulHash}\n[class]{}-[func]{xorHash}\n[class]{}-[func]{rotHash}\n

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u6bcf\u79cd\u54c8\u5e0c\u7b97\u6cd5\u7684\u6700\u540e\u4e00\u6b65\u90fd\u662f\u5bf9\u5927\u8d28\u6570 \\(1000000007\\) \u53d6\u6a21\uff0c\u4ee5\u786e\u4fdd\u54c8\u5e0c\u503c\u5728\u5408\u9002\u7684\u8303\u56f4\u5185\u3002\u503c\u5f97\u601d\u8003\u7684\u662f\uff0c\u4e3a\u4ec0\u4e48\u8981\u5f3a\u8c03\u5bf9\u8d28\u6570\u53d6\u6a21\uff0c\u6216\u8005\u8bf4\u5bf9\u5408\u6570\u53d6\u6a21\u7684\u5f0a\u7aef\u662f\u4ec0\u4e48\uff1f\u8fd9\u662f\u4e00\u4e2a\u6709\u8da3\u7684\u95ee\u9898\u3002

        \u5148\u629b\u51fa\u7ed3\u8bba\uff1a\u4f7f\u7528\u5927\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u53ef\u4ee5\u6700\u5927\u5316\u5730\u4fdd\u8bc1\u54c8\u5e0c\u503c\u7684\u5747\u5300\u5206\u5e03\u3002\u56e0\u4e3a\u8d28\u6570\u4e0d\u4e0e\u5176\u4ed6\u6570\u5b57\u5b58\u5728\u516c\u7ea6\u6570\uff0c\u53ef\u4ee5\u51cf\u5c11\u56e0\u53d6\u6a21\u64cd\u4f5c\u800c\u4ea7\u751f\u7684\u5468\u671f\u6027\u6a21\u5f0f\uff0c\u4ece\u800c\u907f\u514d\u54c8\u5e0c\u51b2\u7a81\u3002

        \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u6211\u4eec\u9009\u62e9\u5408\u6570 \\(9\\) \u4f5c\u4e3a\u6a21\u6570\uff0c\u5b83\u53ef\u4ee5\u88ab \\(3\\) \u6574\u9664\uff0c\u90a3\u4e48\u6240\u6709\u53ef\u4ee5\u88ab \\(3\\) \u6574\u9664\u7684 key \u90fd\u4f1a\u88ab\u6620\u5c04\u5230 \\(0\\)\u3001\\(3\\)\u3001\\(6\\) \u8fd9\u4e09\u4e2a\u54c8\u5e0c\u503c\u3002

        \\[ \\begin{aligned} \\text{modulus} & = 9 \\newline \\text{key} & = \\{ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, \\dots \\} \\newline \\text{hash} & = \\{ 0, 3, 6, 0, 3, 6, 0, 3, 6, 0, 3, 6,\\dots \\} \\end{aligned} \\]

        \u5982\u679c\u8f93\u5165 key \u6070\u597d\u6ee1\u8db3\u8fd9\u79cd\u7b49\u5dee\u6570\u5217\u7684\u6570\u636e\u5206\u5e03\uff0c\u90a3\u4e48\u54c8\u5e0c\u503c\u5c31\u4f1a\u51fa\u73b0\u805a\u5806\uff0c\u4ece\u800c\u52a0\u91cd\u54c8\u5e0c\u51b2\u7a81\u3002\u73b0\u5728\uff0c\u5047\u8bbe\u5c06 modulus \u66ff\u6362\u4e3a\u8d28\u6570 \\(13\\) \uff0c\u7531\u4e8e key \u548c modulus \u4e4b\u95f4\u4e0d\u5b58\u5728\u516c\u7ea6\u6570\uff0c\u56e0\u6b64\u8f93\u51fa\u7684\u54c8\u5e0c\u503c\u7684\u5747\u5300\u6027\u4f1a\u660e\u663e\u63d0\u5347\u3002

        \\[ \\begin{aligned} \\text{modulus} & = 13 \\newline \\text{key} & = \\{ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, \\dots \\} \\newline \\text{hash} & = \\{ 0, 3, 6, 9, 12, 2, 5, 8, 11, 1, 4, 7, \\dots \\} \\end{aligned} \\]

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5982\u679c\u80fd\u591f\u4fdd\u8bc1 key \u662f\u968f\u673a\u5747\u5300\u5206\u5e03\u7684\uff0c\u90a3\u4e48\u9009\u62e9\u8d28\u6570\u6216\u8005\u5408\u6570\u4f5c\u4e3a\u6a21\u6570\u90fd\u53ef\u4ee5\uff0c\u5b83\u4eec\u90fd\u80fd\u8f93\u51fa\u5747\u5300\u5206\u5e03\u7684\u54c8\u5e0c\u503c\u3002\u800c\u5f53 key \u7684\u5206\u5e03\u5b58\u5728\u67d0\u79cd\u5468\u671f\u6027\u65f6\uff0c\u5bf9\u5408\u6570\u53d6\u6a21\u66f4\u5bb9\u6613\u51fa\u73b0\u805a\u96c6\u73b0\u8c61\u3002

        \u603b\u800c\u8a00\u4e4b\uff0c\u6211\u4eec\u901a\u5e38\u9009\u53d6\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u5e76\u4e14\u8fd9\u4e2a\u8d28\u6570\u6700\u597d\u8db3\u591f\u5927\uff0c\u4ee5\u5c3d\u53ef\u80fd\u6d88\u9664\u5468\u671f\u6027\u6a21\u5f0f\uff0c\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u7a33\u5065\u6027\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#633","title":"6.3.3 \u00a0 \u5e38\u89c1\u54c8\u5e0c\u7b97\u6cd5","text":"

        \u4e0d\u96be\u53d1\u73b0\uff0c\u4ee5\u4e0a\u4ecb\u7ecd\u7684\u7b80\u5355\u54c8\u5e0c\u7b97\u6cd5\u90fd\u6bd4\u8f83\u201c\u8106\u5f31\u201d\uff0c\u8fdc\u8fdc\u6ca1\u6709\u8fbe\u5230\u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1\u76ee\u6807\u3002\u4f8b\u5982\uff0c\u7531\u4e8e\u52a0\u6cd5\u548c\u5f02\u6216\u6ee1\u8db3\u4ea4\u6362\u5f8b\uff0c\u56e0\u6b64\u52a0\u6cd5\u54c8\u5e0c\u548c\u5f02\u6216\u54c8\u5e0c\u65e0\u6cd5\u533a\u5206\u5185\u5bb9\u76f8\u540c\u4f46\u987a\u5e8f\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u8fd9\u53ef\u80fd\u4f1a\u52a0\u5267\u54c8\u5e0c\u51b2\u7a81\uff0c\u5e76\u5f15\u8d77\u4e00\u4e9b\u5b89\u5168\u95ee\u9898\u3002

        \u5728\u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u7528\u4e00\u4e9b\u6807\u51c6\u54c8\u5e0c\u7b97\u6cd5\uff0c\u4f8b\u5982 MD5\u3001SHA-1\u3001SHA-2\u3001SHA-3 \u7b49\u3002\u5b83\u4eec\u53ef\u4ee5\u5c06\u4efb\u610f\u957f\u5ea6\u7684\u8f93\u5165\u6570\u636e\u6620\u5c04\u5230\u6052\u5b9a\u957f\u5ea6\u7684\u54c8\u5e0c\u503c\u3002

        \u8fd1\u4e00\u4e2a\u4e16\u7eaa\u4ee5\u6765\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5904\u5728\u4e0d\u65ad\u5347\u7ea7\u4e0e\u4f18\u5316\u7684\u8fc7\u7a0b\u4e2d\u3002\u4e00\u90e8\u5206\u7814\u7a76\u4eba\u5458\u52aa\u529b\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u6027\u80fd\uff0c\u53e6\u4e00\u90e8\u5206\u7814\u7a76\u4eba\u5458\u548c\u9ed1\u5ba2\u5219\u81f4\u529b\u4e8e\u5bfb\u627e\u54c8\u5e0c\u7b97\u6cd5\u7684\u5b89\u5168\u6027\u95ee\u9898\u3002\u8868 6-2 \u5c55\u793a\u4e86\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5\u3002

        • MD5 \u548c SHA-1 \u5df2\u591a\u6b21\u88ab\u6210\u529f\u653b\u51fb\uff0c\u56e0\u6b64\u5b83\u4eec\u88ab\u5404\u7c7b\u5b89\u5168\u5e94\u7528\u5f03\u7528\u3002
        • SHA-2 \u7cfb\u5217\u4e2d\u7684 SHA-256 \u662f\u6700\u5b89\u5168\u7684\u54c8\u5e0c\u7b97\u6cd5\u4e4b\u4e00\uff0c\u4ecd\u672a\u51fa\u73b0\u6210\u529f\u7684\u653b\u51fb\u6848\u4f8b\uff0c\u56e0\u6b64\u5e38\u7528\u5728\u5404\u7c7b\u5b89\u5168\u5e94\u7528\u4e0e\u534f\u8bae\u4e2d\u3002
        • SHA-3 \u76f8\u8f83 SHA-2 \u7684\u5b9e\u73b0\u5f00\u9500\u66f4\u4f4e\u3001\u8ba1\u7b97\u6548\u7387\u66f4\u9ad8\uff0c\u4f46\u76ee\u524d\u4f7f\u7528\u8986\u76d6\u5ea6\u4e0d\u5982 SHA-2 \u7cfb\u5217\u3002

        \u8868 6-2 \u00a0 \u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5

        MD5 SHA-1 SHA-2 SHA-3 \u63a8\u51fa\u65f6\u95f4 1992 1995 2002 2008 \u8f93\u51fa\u957f\u5ea6 128 bits 160 bits 256/512 bits 224/256/384/512 bits \u54c8\u5e0c\u51b2\u7a81 \u8f83\u591a \u8f83\u591a \u5f88\u5c11 \u5f88\u5c11 \u5b89\u5168\u7b49\u7ea7 \u4f4e\uff0c\u5df2\u88ab\u6210\u529f\u653b\u51fb \u4f4e\uff0c\u5df2\u88ab\u6210\u529f\u653b\u51fb \u9ad8 \u9ad8 \u5e94\u7528 \u5df2\u88ab\u5f03\u7528\uff0c\u4ecd\u7528\u4e8e\u6570\u636e\u5b8c\u6574\u6027\u68c0\u67e5 \u5df2\u88ab\u5f03\u7528 \u52a0\u5bc6\u8d27\u5e01\u4ea4\u6613\u9a8c\u8bc1\u3001\u6570\u5b57\u7b7e\u540d\u7b49 \u53ef\u7528\u4e8e\u66ff\u4ee3 SHA-2"},{"location":"chapter_hashing/hash_algorithm/#634","title":"6.3.4 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u54c8\u5e0c\u503c","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u54c8\u5e0c\u8868\u7684 key \u53ef\u4ee5\u662f\u6574\u6570\u3001\u5c0f\u6570\u6216\u5b57\u7b26\u4e32\u7b49\u6570\u636e\u7c7b\u578b\u3002\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u4e3a\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u5185\u7f6e\u7684\u54c8\u5e0c\u7b97\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u54c8\u5e0c\u8868\u4e2d\u7684\u6876\u7d22\u5f15\u3002\u4ee5 Python \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u8c03\u7528 hash() \u51fd\u6570\u6765\u8ba1\u7b97\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u54c8\u5e0c\u503c\u3002

        • \u6574\u6570\u548c\u5e03\u5c14\u91cf\u7684\u54c8\u5e0c\u503c\u5c31\u662f\u5176\u672c\u8eab\u3002
        • \u6d6e\u70b9\u6570\u548c\u5b57\u7b26\u4e32\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\u8f83\u4e3a\u590d\u6742\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u8bf7\u81ea\u884c\u5b66\u4e60\u3002
        • \u5143\u7ec4\u7684\u54c8\u5e0c\u503c\u662f\u5bf9\u5176\u4e2d\u6bcf\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u54c8\u5e0c\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u54c8\u5e0c\u503c\u7ec4\u5408\u8d77\u6765\uff0c\u5f97\u5230\u5355\u4e00\u7684\u54c8\u5e0c\u503c\u3002
        • \u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u57fa\u4e8e\u5176\u5185\u5b58\u5730\u5740\u751f\u6210\u3002\u901a\u8fc7\u91cd\u5199\u5bf9\u8c61\u7684\u54c8\u5e0c\u65b9\u6cd5\uff0c\u53ef\u5b9e\u73b0\u57fa\u4e8e\u5185\u5bb9\u751f\u6210\u54c8\u5e0c\u503c\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u7684\u5185\u7f6e\u54c8\u5e0c\u503c\u8ba1\u7b97\u51fd\u6570\u7684\u5b9a\u4e49\u548c\u65b9\u6cd5\u4e0d\u540c\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig built_in_hash.py
        num = 3\nhash_num = hash(num)\n# \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nbol = True\nhash_bol = hash(bol)\n# \u5e03\u5c14\u91cf True \u7684\u54c8\u5e0c\u503c\u4e3a 1\ndec = 3.14159\nhash_dec = hash(dec)\n# \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 326484311674566659\nstr = \"Hello \u7b97\u6cd5\"\nhash_str = hash(str)\n# \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 4617003410720528961\ntup = (12836, \"\u5c0f\u54c8\")\nhash_tup = hash(tup)\n# \u5143\u7ec4 (12836, '\u5c0f\u54c8') \u7684\u54c8\u5e0c\u503c\u4e3a 1029005403108185979\nobj = ListNode(0)\nhash_obj = hash(obj)\n# \u8282\u70b9\u5bf9\u8c61 <ListNode object at 0x1058fd810> \u7684\u54c8\u5e0c\u503c\u4e3a 274267521\n
        built_in_hash.cpp
        int num = 3;\nsize_t hashNum = hash<int>()(num);\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nbool bol = true;\nsize_t hashBol = hash<bool>()(bol);\n// \u5e03\u5c14\u91cf 1 \u7684\u54c8\u5e0c\u503c\u4e3a 1\ndouble dec = 3.14159;\nsize_t hashDec = hash<double>()(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 4614256650576692846\nstring str = \"Hello \u7b97\u6cd5\";\nsize_t hashStr = hash<string>()(str);\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 15466937326284535026\n// \u5728 C++ \u4e2d\uff0c\u5185\u7f6e std:hash() \u4ec5\u63d0\u4f9b\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\n// \u6570\u7ec4\u3001\u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\u9700\u8981\u81ea\u884c\u5b9e\u73b0\n
        built_in_hash.java
        int num = 3;\nint hashNum = Integer.hashCode(num);\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nboolean bol = true;\nint hashBol = Boolean.hashCode(bol);\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\ndouble dec = 3.14159;\nint hashDec = Double.hashCode(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -727081396\nObject[] arr = { 12836, \"\u5c0f\u54c8\" };\nint hashTup = Arrays.hashCode(arr);\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 1151158\nListNode obj = new ListNode(0);\nint hashObj = obj.hashCode();\n// \u8282\u70b9\u5bf9\u8c61 utils.ListNode@7dc5e7b4 \u7684\u54c8\u5e0c\u503c\u4e3a 2110121908\n
        built_in_hash.cs
        int num = 3;\nint hashNum = num.GetHashCode();\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3;\nbool bol = true;\nint hashBol = bol.GetHashCode();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1;\ndouble dec = 3.14159;\nint hashDec = dec.GetHashCode();\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729;\nstring str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.GetHashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -586107568;\nobject[] arr = [12836, \"\u5c0f\u54c8\"];\nint hashTup = arr.GetHashCode();\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 42931033;\nListNode obj = new(0);\nint hashObj = obj.GetHashCode();\n// \u8282\u70b9\u5bf9\u8c61 0 \u7684\u54c8\u5e0c\u503c\u4e3a 39053774;\n
        built_in_hash.go
        // Go \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.swift
        let num = 3\nlet hashNum = num.hashValue\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 9047044699613009734\nlet bol = true\nlet hashBol = bol.hashValue\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a -4431640247352757451\nlet dec = 3.14159\nlet hashDec = dec.hashValue\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -2465384235396674631\nlet str = \"Hello \u7b97\u6cd5\"\nlet hashStr = str.hashValue\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -7850626797806988787\nlet arr = [AnyHashable(12836), AnyHashable(\"\u5c0f\u54c8\")]\nlet hashTup = arr.hashValue\n// \u6570\u7ec4 [AnyHashable(12836), AnyHashable(\"\u5c0f\u54c8\")] \u7684\u54c8\u5e0c\u503c\u4e3a -2308633508154532996\nlet obj = ListNode(x: 0)\nlet hashObj = obj.hashValue\n// \u8282\u70b9\u5bf9\u8c61 utils.ListNode \u7684\u54c8\u5e0c\u503c\u4e3a -2434780518035996159\n
        built_in_hash.js
        // JavaScript \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.ts
        // TypeScript \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.dart
        int num = 3;\nint hashNum = num.hashCode;\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 34803\nbool bol = true;\nint hashBol = bol.hashCode;\n// \u5e03\u5c14\u503c true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\ndouble dec = 3.14159;\nint hashDec = dec.hashCode;\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2570631074981783\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode;\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 468167534\nList arr = [12836, \"\u5c0f\u54c8\"];\nint hashArr = arr.hashCode;\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 976512528\nListNode obj = new ListNode(0);\nint hashObj = obj.hashCode;\n// \u8282\u70b9\u5bf9\u8c61 Instance of 'ListNode' \u7684\u54c8\u5e0c\u503c\u4e3a 1033450432\n
        built_in_hash.rs
        use std::collections::hash_map::DefaultHasher;\nuse std::hash::{Hash, Hasher};\nlet num = 3;\nlet mut num_hasher = DefaultHasher::new();\nnum.hash(&mut num_hasher);\nlet hash_num = num_hasher.finish();\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 568126464209439262\nlet bol = true;\nlet mut bol_hasher = DefaultHasher::new();\nbol.hash(&mut bol_hasher);\nlet hash_bol = bol_hasher.finish();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 4952851536318644461\nlet dec: f32 = 3.14159;\nlet mut dec_hasher = DefaultHasher::new();\ndec.to_bits().hash(&mut dec_hasher);\nlet hash_dec = dec_hasher.finish();\nprintln!(\"\u5c0f\u6570 {} \u7684\u54c8\u5e0c\u503c\u4e3a {}\", dec, hash_dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2566941990314602357\nlet str = \"Hello \u7b97\u6cd5\";\nlet mut str_hasher = DefaultHasher::new();\nstr.hash(&mut str_hasher);\nlet hash_str = str_hasher.finish();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 16092673739211250988\nlet arr = (&12836, &\"\u5c0f\u54c8\");\nlet mut tup_hasher = DefaultHasher::new();\narr.hash(&mut tup_hasher);\nlet hash_tup = tup_hasher.finish();\n// \u5143\u7ec4 (12836, \"\u5c0f\u54c8\") \u7684\u54c8\u5e0c\u503c\u4e3a 1885128010422702749\nlet node = ListNode::new(42);\nlet mut hasher = DefaultHasher::new();\nnode.borrow().val.hash(&mut hasher);\nlet hash = hasher.finish();\n// \u8282\u70b9\u5bf9\u8c61 RefCell { value: ListNode { val: 42, next: None } } \u7684\u54c8\u5e0c\u503c\u4e3a15387811073369036852\n
        built_in_hash.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.zig
        \n

        \u5728\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u53ea\u6709\u4e0d\u53ef\u53d8\u5bf9\u8c61\u624d\u53ef\u4f5c\u4e3a\u54c8\u5e0c\u8868\u7684 key \u3002\u5047\u5982\u6211\u4eec\u5c06\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u4f5c\u4e3a key \uff0c\u5f53\u5217\u8868\u7684\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5b83\u7684\u54c8\u5e0c\u503c\u4e5f\u968f\u4e4b\u6539\u53d8\uff0c\u6211\u4eec\u5c31\u65e0\u6cd5\u5728\u54c8\u5e0c\u8868\u4e2d\u67e5\u8be2\u5230\u539f\u5148\u7684 value \u4e86\u3002

        \u867d\u7136\u81ea\u5b9a\u4e49\u5bf9\u8c61\uff08\u6bd4\u5982\u94fe\u8868\u8282\u70b9\uff09\u7684\u6210\u5458\u53d8\u91cf\u662f\u53ef\u53d8\u7684\uff0c\u4f46\u5b83\u662f\u53ef\u54c8\u5e0c\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u901a\u5e38\u662f\u57fa\u4e8e\u5185\u5b58\u5730\u5740\u751f\u6210\u7684\uff0c\u5373\u4f7f\u5bf9\u8c61\u7684\u5185\u5bb9\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u4f46\u5b83\u7684\u5185\u5b58\u5730\u5740\u4e0d\u53d8\uff0c\u54c8\u5e0c\u503c\u4ecd\u7136\u662f\u4e0d\u53d8\u7684\u3002

        \u7ec6\u5fc3\u7684\u4f60\u53ef\u80fd\u53d1\u73b0\u5728\u4e0d\u540c\u63a7\u5236\u53f0\u4e2d\u8fd0\u884c\u7a0b\u5e8f\u65f6\uff0c\u8f93\u51fa\u7684\u54c8\u5e0c\u503c\u662f\u4e0d\u540c\u7684\u3002\u8fd9\u662f\u56e0\u4e3a Python \u89e3\u91ca\u5668\u5728\u6bcf\u6b21\u542f\u52a8\u65f6\uff0c\u90fd\u4f1a\u4e3a\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570\u52a0\u5165\u4e00\u4e2a\u968f\u673a\u7684\u76d0\uff08Salt\uff09\u503c\u3002\u8fd9\u79cd\u505a\u6cd5\u53ef\u4ee5\u6709\u6548\u9632\u6b62 HashDoS \u653b\u51fb\uff0c\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u5b89\u5168\u6027\u3002

        "},{"location":"chapter_hashing/hash_collision/","title":"6.2 \u00a0 \u54c8\u5e0c\u51b2\u7a81","text":"

        \u4e0a\u4e00\u8282\u63d0\u5230\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u54c8\u5e0c\u51fd\u6570\u7684\u8f93\u5165\u7a7a\u95f4\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\uff0c\u56e0\u6b64\u7406\u8bba\u4e0a\u54c8\u5e0c\u51b2\u7a81\u662f\u4e0d\u53ef\u907f\u514d\u7684\u3002\u6bd4\u5982\uff0c\u8f93\u5165\u7a7a\u95f4\u4e3a\u5168\u4f53\u6574\u6570\uff0c\u8f93\u51fa\u7a7a\u95f4\u4e3a\u6570\u7ec4\u5bb9\u91cf\u5927\u5c0f\uff0c\u5219\u5fc5\u7136\u6709\u591a\u4e2a\u6574\u6570\u6620\u5c04\u81f3\u540c\u4e00\u6876\u7d22\u5f15\u3002

        \u54c8\u5e0c\u51b2\u7a81\u4f1a\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u9519\u8bef\uff0c\u4e25\u91cd\u5f71\u54cd\u54c8\u5e0c\u8868\u7684\u53ef\u7528\u6027\u3002\u4e3a\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u6bcf\u5f53\u9047\u5230\u54c8\u5e0c\u51b2\u7a81\u5c31\u8fdb\u884c\u54c8\u5e0c\u8868\u6269\u5bb9\uff0c\u76f4\u81f3\u51b2\u7a81\u6d88\u5931\u4e3a\u6b62\u3002\u6b64\u65b9\u6cd5\u7b80\u5355\u7c97\u66b4\u4e14\u6709\u6548\uff0c\u4f46\u6548\u7387\u592a\u4f4e\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u6269\u5bb9\u9700\u8981\u8fdb\u884c\u5927\u91cf\u7684\u6570\u636e\u642c\u8fd0\u4e0e\u54c8\u5e0c\u503c\u8ba1\u7b97\u3002\u4e3a\u4e86\u63d0\u5347\u6548\u7387\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\u3002

        1. \u6539\u826f\u54c8\u5e0c\u8868\u6570\u636e\u7ed3\u6784\uff0c\u4f7f\u5f97\u54c8\u5e0c\u8868\u53ef\u4ee5\u5728\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81\u65f6\u6b63\u5e38\u5de5\u4f5c\u3002
        2. \u4ec5\u5728\u5fc5\u8981\u65f6\uff0c\u5373\u5f53\u54c8\u5e0c\u51b2\u7a81\u6bd4\u8f83\u4e25\u91cd\u65f6\uff0c\u624d\u6267\u884c\u6269\u5bb9\u64cd\u4f5c\u3002

        \u54c8\u5e0c\u8868\u7684\u7ed3\u6784\u6539\u826f\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u201c\u94fe\u5f0f\u5730\u5740\u201d\u548c\u201c\u5f00\u653e\u5bfb\u5740\u201d\u3002

        "},{"location":"chapter_hashing/hash_collision/#621","title":"6.2.1 \u00a0 \u94fe\u5f0f\u5730\u5740","text":"

        \u5728\u539f\u59cb\u54c8\u5e0c\u8868\u4e2d\uff0c\u6bcf\u4e2a\u6876\u4ec5\u80fd\u5b58\u50a8\u4e00\u4e2a\u952e\u503c\u5bf9\u3002\u300c\u94fe\u5f0f\u5730\u5740 separate chaining\u300d\u5c06\u5355\u4e2a\u5143\u7d20\u8f6c\u6362\u4e3a\u94fe\u8868\uff0c\u5c06\u952e\u503c\u5bf9\u4f5c\u4e3a\u94fe\u8868\u8282\u70b9\uff0c\u5c06\u6240\u6709\u53d1\u751f\u51b2\u7a81\u7684\u952e\u503c\u5bf9\u90fd\u5b58\u50a8\u5728\u540c\u4e00\u94fe\u8868\u4e2d\u3002\u56fe 6-5 \u5c55\u793a\u4e86\u4e00\u4e2a\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\u7684\u4f8b\u5b50\u3002

        \u56fe 6-5 \u00a0 \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868

        \u57fa\u4e8e\u94fe\u5f0f\u5730\u5740\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\u7684\u64cd\u4f5c\u65b9\u6cd5\u53d1\u751f\u4e86\u4ee5\u4e0b\u53d8\u5316\u3002

        • \u67e5\u8be2\u5143\u7d20\uff1a\u8f93\u5165 key \uff0c\u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u5f97\u5230\u6876\u7d22\u5f15\uff0c\u5373\u53ef\u8bbf\u95ee\u94fe\u8868\u5934\u8282\u70b9\uff0c\u7136\u540e\u904d\u5386\u94fe\u8868\u5e76\u5bf9\u6bd4 key \u4ee5\u67e5\u627e\u76ee\u6807\u952e\u503c\u5bf9\u3002
        • \u6dfb\u52a0\u5143\u7d20\uff1a\u9996\u5148\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u8bbf\u95ee\u94fe\u8868\u5934\u8282\u70b9\uff0c\u7136\u540e\u5c06\u8282\u70b9\uff08\u952e\u503c\u5bf9\uff09\u6dfb\u52a0\u5230\u94fe\u8868\u4e2d\u3002
        • \u5220\u9664\u5143\u7d20\uff1a\u6839\u636e\u54c8\u5e0c\u51fd\u6570\u7684\u7ed3\u679c\u8bbf\u95ee\u94fe\u8868\u5934\u90e8\uff0c\u63a5\u7740\u904d\u5386\u94fe\u8868\u4ee5\u67e5\u627e\u76ee\u6807\u8282\u70b9\u5e76\u5c06\u5176\u5220\u9664\u3002

        \u94fe\u5f0f\u5730\u5740\u5b58\u5728\u4ee5\u4e0b\u5c40\u9650\u6027\u3002

        • \u5360\u7528\u7a7a\u95f4\u589e\u5927\uff0c\u94fe\u8868\u5305\u542b\u8282\u70b9\u6307\u9488\uff0c\u5b83\u76f8\u6bd4\u6570\u7ec4\u66f4\u52a0\u8017\u8d39\u5185\u5b58\u7a7a\u95f4\u3002
        • \u67e5\u8be2\u6548\u7387\u964d\u4f4e\uff0c\u56e0\u4e3a\u9700\u8981\u7ebf\u6027\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u5bf9\u5e94\u5143\u7d20\u3002

        \u4ee5\u4e0b\u4ee3\u7801\u7ed9\u51fa\u4e86\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\u7684\u7b80\u5355\u5b9e\u73b0\uff0c\u9700\u8981\u6ce8\u610f\u4e24\u70b9\u3002

        • \u4f7f\u7528\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u4ee3\u66ff\u94fe\u8868\uff0c\u4ece\u800c\u7b80\u5316\u4ee3\u7801\u3002\u5728\u8fd9\u79cd\u8bbe\u5b9a\u4e0b\uff0c\u54c8\u5e0c\u8868\uff08\u6570\u7ec4\uff09\u5305\u542b\u591a\u4e2a\u6876\uff0c\u6bcf\u4e2a\u6876\u90fd\u662f\u4e00\u4e2a\u5217\u8868\u3002
        • \u4ee5\u4e0b\u5b9e\u73b0\u5305\u542b\u54c8\u5e0c\u8868\u6269\u5bb9\u65b9\u6cd5\u3002\u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7 \\(\\frac{2}{3}\\) \u65f6\uff0c\u6211\u4eec\u5c06\u54c8\u5e0c\u8868\u6269\u5bb9\u81f3\u539f\u5148\u7684 \\(2\\) \u500d\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map_chaining.py
        class HashMapChaining:\n\"\"\"\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\nself.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\nself.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nself.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\nself.buckets = [[] for _ in range(self.capacity)]  # \u6876\u6570\u7ec4\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nreturn key % self.capacity\ndef load_factor(self) -> float:\n\"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\nreturn self.size / self.capacity\ndef get(self, key: int) -> str | None:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket:\nif pair.key == key:\nreturn pair.val\n# \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nreturn None\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n# \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres:\nself.extend()\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket:\nif pair.key == key:\npair.val = val\nreturn\n# \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\npair = Pair(key, val)\nbucket.append(pair)\nself.size += 1\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor pair in bucket:\nif pair.key == key:\nbucket.remove(pair)\nself.size -= 1\nbreak\ndef extend(self):\n\"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n# \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nbuckets = self.buckets\n# \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio\nself.buckets = [[] for _ in range(self.capacity)]\nself.size = 0\n# \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in buckets:\nfor pair in bucket:\nself.put(pair.key, pair.val)\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor bucket in self.buckets:\nres = []\nfor pair in bucket:\nres.append(str(pair.key) + \" -> \" + pair.val)\nprint(res)\n
        hash_map_chaining.cpp
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nprivate:\nint size;                       // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;                   // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres;               // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;                // \u6269\u5bb9\u500d\u6570\nvector<vector<Pair *>> buckets; // \u6876\u6570\u7ec4\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) {\nbuckets.resize(capacity);\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~HashMapChaining() {\nfor (auto &bucket : buckets) {\nfor (Pair *pair : bucket) {\n// \u91ca\u653e\u5185\u5b58\ndelete pair;\n}\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double)size / (double)capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\nint index = hashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair *pair : buckets[index]) {\nif (pair->key == key) {\nreturn pair->val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair *pair : buckets[index]) {\nif (pair->key == key) {\npair->val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nbuckets[index].push_back(new Pair(key, val));\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nauto &bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (int i = 0; i < bucket.size(); i++) {\nif (bucket[i]->key == key) {\nPair *tmp = bucket[i];\nbucket.erase(bucket.begin() + i); // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\ndelete tmp;                       // \u91ca\u653e\u5185\u5b58\nsize--;\nreturn;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nvector<vector<Pair *>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets.clear();\nbuckets.resize(capacity);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (auto &bucket : bucketsTmp) {\nfor (Pair *pair : bucket) {\nput(pair->key, pair->val);\n// \u91ca\u653e\u5185\u5b58\ndelete pair;\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (auto &bucket : buckets) {\ncout << \"[\";\nfor (Pair *pair : bucket) {\ncout << pair->key << \" -> \" << pair->val << \", \";\n}\ncout << \"]\\n\";\n}\n}\n};\n
        hash_map_chaining.java
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio; // \u6269\u5bb9\u500d\u6570\nList<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = new ArrayList<>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.add(new ArrayList<>());\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double) size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString get(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair pair : bucket) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair pair : bucket) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nPair pair = new Pair(key, val);\nbucket.add(pair);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (Pair pair : bucket) {\nif (pair.key == key) {\nbucket.remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new ArrayList<>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.add(new ArrayList<>());\n}\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (List<Pair> bucket : bucketsTmp) {\nfor (Pair pair : bucket) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (List<Pair> bucket : buckets) {\nList<String> res = new ArrayList<>();\nfor (Pair pair : bucket) {\nres.add(pair.key + \" -> \" + pair.val);\n}\nSystem.out.println(res);\n}\n}\n}\n
        hash_map_chaining.cs
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio; // \u6269\u5bb9\u500d\u6570\nList<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = new List<List<Pair>>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.Add([]);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble LoadFactor() {\nreturn (double)size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nforeach (Pair pair in buckets[index]) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (LoadFactor() > loadThres) {\nExtend();\n}\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nforeach (Pair pair in buckets[index]) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nbuckets[index].Add(new Pair(key, val));\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nforeach (Pair pair in buckets[index].ToList()) {\nif (pair.key == key) {\nbuckets[index].Remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid Extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new List<List<Pair>>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.Add([]);\n}\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nforeach (List<Pair> bucket in bucketsTmp) {\nforeach (Pair pair in bucket) {\nPut(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (List<Pair> bucket in buckets) {\nList<string> res = [];\nforeach (Pair pair in bucket) {\nres.Add(pair.key + \" -> \" + pair.val);\n}\nforeach (string kv in res) {\nConsole.WriteLine(kv);\n}\n}\n}\n}\n
        hash_map_chaining.go
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntype hashMapChaining struct {\nsize        int      // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity    int      // \u54c8\u5e0c\u8868\u5bb9\u91cf\nloadThres   float64  // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextendRatio int      // \u6269\u5bb9\u500d\u6570\nbuckets     [][]pair // \u6876\u6570\u7ec4\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapChaining() *hashMapChaining {\nbuckets := make([][]pair, 4)\nfor i := 0; i < 4; i++ {\nbuckets[i] = make([]pair, 0)\n}\nreturn &hashMapChaining{\nsize:        0,\ncapacity:    4,\nloadThres:   2.0 / 3.0,\nextendRatio: 2,\nbuckets:     buckets,\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapChaining) hashFunc(key int) int {\nreturn key % m.capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapChaining) loadFactor() float64 {\nreturn float64(m.size / m.capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapChaining) get(key int) string {\nidx := m.hashFunc(key)\nbucket := m.buckets[idx]\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor _, p := range bucket {\nif p.key == key {\nreturn p.val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\"\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (m *hashMapChaining) put(key int, val string) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif m.loadFactor() > m.loadThres {\nm.extend()\n}\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor _, p := range m.buckets[idx] {\nif p.key == key {\np.val = val\nreturn\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\np := pair{\nkey: key,\nval: val,\n}\nm.buckets[idx] = append(m.buckets[idx], p)\nm.size += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapChaining) remove(key int) {\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor i, p := range m.buckets[idx] {\nif p.key == key {\n// \u5207\u7247\u5220\u9664\nm.buckets[idx] = append(m.buckets[idx][:i], m.buckets[idx][i+1:]...)\nm.size -= 1\nbreak\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\ntmpBuckets := make([][]pair, len(m.buckets))\nfor i := 0; i < len(m.buckets); i++ {\ntmpBuckets[i] = make([]pair, len(m.buckets[i]))\ncopy(tmpBuckets[i], m.buckets[i])\n}\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nm.capacity *= m.extendRatio\nm.buckets = make([][]pair, m.capacity)\nfor i := 0; i < m.capacity; i++ {\nm.buckets[i] = make([]pair, 0)\n}\nm.size = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor _, bucket := range tmpBuckets {\nfor _, p := range bucket {\nm.put(p.key, p.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) print() {\nvar builder strings.Builder\nfor _, bucket := range m.buckets {\nbuilder.WriteString(\"[\")\nfor _, p := range bucket {\nbuilder.WriteString(strconv.Itoa(p.key) + \" -> \" + p.val + \" \")\n}\nbuilder.WriteString(\"]\")\nfmt.Println(builder.String())\nbuilder.Reset()\n}\n}\n
        hash_map_chaining.swift
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nvar size: Int // \u952e\u503c\u5bf9\u6570\u91cf\nvar capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\nvar loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nvar extendRatio: Int // \u6269\u5bb9\u500d\u6570\nvar buckets: [[Pair]] // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\nsize = 0\ncapacity = 4\nloadThres = 2.0 / 3.0\nextendRatio = 2\nbuckets = Array(repeating: [], count: capacity)\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc hashFunc(key: Int) -> Int {\nkey % capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc loadFactor() -> Double {\nDouble(size / capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket {\nif pair.key == key {\nreturn pair.val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de nil\nreturn nil\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif loadFactor() > loadThres {\nextend()\n}\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket {\nif pair.key == key {\npair.val = val\nreturn\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nlet pair = Pair(key: key, val: val)\nbuckets[index].append(pair)\nsize += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (pairIndex, pair) in bucket.enumerated() {\nif pair.key == key {\nbuckets[index].remove(at: pairIndex)\n}\n}\nsize -= 1\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet bucketsTmp = buckets\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio\nbuckets = Array(repeating: [], count: capacity)\nsize = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in bucketsTmp {\nfor pair in bucket {\nput(key: pair.key, val: pair.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor bucket in buckets {\nlet res = bucket.map { \"\\($0.key) -> \\($0.val)\" }\nSwift.print(res)\n}\n}\n}\n
        hash_map_chaining.js
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n#size; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio; // \u6269\u5bb9\u500d\u6570\n#buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0;\nthis.#capacity = 4;\nthis.#loadThres = 2.0 / 3.0;\nthis.#extendRatio = 2;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor() {\nreturn this.#size / this.#capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (const pair of bucket) {\nif (pair.key === key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key, val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (const pair of bucket) {\nif (pair.key === key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nconst pair = new Pair(key, val);\nbucket.push(pair);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key) {\nconst index = this.#hashFunc(key);\nlet bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (let i = 0; i < bucket.length; i++) {\nif (bucket[i].key === key) {\nbucket.splice(i, 1);\nthis.#size--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const bucket of bucketsTmp) {\nfor (const pair of bucket) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nfor (const bucket of this.#buckets) {\nlet res = [];\nfor (const pair of bucket) {\nres.push(pair.key + ' -> ' + pair.val);\n}\nconsole.log(res);\n}\n}\n}\n
        hash_map_chaining.ts
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n#size: number; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio: number; // \u6269\u5bb9\u500d\u6570\n#buckets: Pair[][]; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0;\nthis.#capacity = 4;\nthis.#loadThres = 2.0 / 3.0;\nthis.#extendRatio = 2;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key: number): number {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor(): number {\nreturn this.#size / this.#capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key: number): string | null {\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (const pair of bucket) {\nif (pair.key === key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key: number, val: string): void {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (const pair of bucket) {\nif (pair.key === key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nconst pair = new Pair(key, val);\nbucket.push(pair);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key: number): void {\nconst index = this.#hashFunc(key);\nlet bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (let i = 0; i < bucket.length; i++) {\nif (bucket[i].key === key) {\nbucket.splice(i, 1);\nthis.#size--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend(): void {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const bucket of bucketsTmp) {\nfor (const pair of bucket) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint(): void {\nfor (const bucket of this.#buckets) {\nlet res = [];\nfor (const pair of bucket) {\nres.push(pair.key + ' -> ' + pair.val);\n}\nconsole.log(res);\n}\n}\n}\n
        hash_map_chaining.dart
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nlate int size; // \u952e\u503c\u5bf9\u6570\u91cf\nlate int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nlate double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nlate int extendRatio; // \u6269\u5bb9\u500d\u6570\nlate List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = List.generate(capacity, (_) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair pair in bucket) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair pair in bucket) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nPair pair = Pair(key, val);\nbucket.add(pair);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (Pair pair in bucket) {\nif (pair.key == key) {\nbucket.remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = List.generate(capacity, (_) => []);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (List<Pair> bucket in bucketsTmp) {\nfor (Pair pair in bucket) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (List<Pair> bucket in buckets) {\nList<String> res = [];\nfor (Pair pair in bucket) {\nres.add(\"${pair.key} -> ${pair.val}\");\n}\nprint(res);\n}\n}\n}\n
        hash_map_chaining.rs
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapChaining {\nsize: i32,\ncapacity: i32,\nload_thres: f32,\nextend_ratio: i32,\nbuckets: Vec<Vec<Pair>>,\n}\nimpl HashMapChaining {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new() -> Self {\nSelf {\nsize: 0,\ncapacity: 4,\nload_thres: 2.0 / 3.0,\nextend_ratio: 2,\nbuckets: vec![vec![]; 4],\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\nkey as usize % self.capacity as usize\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfn load_factor(&self) -> f32 {\nself.size as f32 / self.capacity as f32\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfn remove(&mut self, key: i32) -> Option<String> {\nlet index = self.hash_func(key);\nlet bucket = &mut self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor i in 0..bucket.len() {\nif bucket[i].key == key {\nlet pair = bucket.remove(i);\nself.size -= 1;\nreturn Some(pair.val);\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nNone\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfn extend(&mut self) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet buckets_tmp = std::mem::replace(&mut self.buckets, vec![]);\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio;\nself.buckets = vec![Vec::new(); self.capacity as usize];\nself.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in buckets_tmp {\nfor pair in bucket {\nself.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfn print(&self) {\nfor bucket in &self.buckets {\nlet mut res = Vec::new();\nfor pair in bucket {\nres.push(format!(\"{} -> {}\", pair.key, pair.val));\n}\nprintln!(\"{:?}\", res);\n}\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfn put(&mut self, key: i32, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres {\nself.extend();\n}\nlet index = self.hash_func(key);\nlet bucket = &mut self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket {\nif pair.key == key {\npair.val = val.clone();\nreturn;\n}\n}\nlet bucket = &mut self.buckets[index];\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nlet pair = Pair {\nkey,\nval: val.clone(),\n};\nbucket.push(pair);\nself.size += 1;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfn get(&self, key: i32) -> Option<&str> {\nlet index = self.hash_func(key);\nlet bucket = &self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket {\nif pair.key == key {\nreturn Some(&pair.val);\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nNone\n}\n}\n
        hash_map_chaining.c
        /* \u94fe\u8868\u8282\u70b9 */\ntypedef struct Node {\nPair *pair;\nstruct Node *next;\n} Node;\n/* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\nint size;         // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;  // \u6269\u5bb9\u500d\u6570\nNode **buckets;   // \u6876\u6570\u7ec4\n} HashMapChaining;\n/* \u6784\u9020\u51fd\u6570 */\nHashMapChaining *newHashMapChaining() {\nHashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));\nhashMap->size = 0;\nhashMap->capacity = 4;\nhashMap->loadThres = 2.0 / 3.0;\nhashMap->extendRatio = 2;\nhashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\nfor (int i = 0; i < hashMap->capacity; i++) {\nhashMap->buckets[i] = NULL;\n}\nreturn hashMap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapChaining(HashMapChaining *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nNode *cur = hashMap->buckets[i];\nwhile (cur) {\nNode *tmp = cur;\ncur = cur->next;\nfree(tmp->pair);\nfree(tmp);\n}\n}\nfree(hashMap->buckets);\nfree(hashMap);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapChaining *hashMap, int key) {\nreturn key % hashMap->capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapChaining *hashMap) {\nreturn (double)hashMap->size / (double)hashMap->capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapChaining *hashMap, int key) {\nint index = hashFunc(hashMap, key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nNode *cur = hashMap->buckets[index];\nwhile (cur) {\nif (cur->pair->key == key) {\nreturn cur->pair->val;\n}\ncur = cur->next;\n}\nreturn \"\"; // \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(HashMapChaining *hashMap, int key, const char *val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor(hashMap) > hashMap->loadThres) {\nextend(hashMap);\n}\nint index = hashFunc(hashMap, key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nNode *cur = hashMap->buckets[index];\nwhile (cur) {\nif (cur->pair->key == key) {\nstrcpy(cur->pair->val, val); // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nreturn;\n}\ncur = cur->next;\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nPair *newPair = (Pair *)malloc(sizeof(Pair));\nnewPair->key = key;\nstrcpy(newPair->val, val);\nNode *newNode = (Node *)malloc(sizeof(Node));\nnewNode->pair = newPair;\nnewNode->next = hashMap->buckets[index];\nhashMap->buckets[index] = newNode;\nhashMap->size++;\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapChaining *hashMap) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nint oldCapacity = hashMap->capacity;\nNode **oldBuckets = hashMap->buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nhashMap->capacity *= hashMap->extendRatio;\nhashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\nfor (int i = 0; i < hashMap->capacity; i++) {\nhashMap->buckets[i] = NULL;\n}\nhashMap->size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (int i = 0; i < oldCapacity; i++) {\nNode *cur = oldBuckets[i];\nwhile (cur) {\nput(hashMap, cur->pair->key, cur->pair->val);\nNode *temp = cur;\ncur = cur->next;\n// \u91ca\u653e\u5185\u5b58\nfree(temp->pair);\nfree(temp);\n}\n}\nfree(oldBuckets);\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapChaining *hashMap, int key) {\nint index = hashFunc(hashMap, key);\nNode *cur = hashMap->buckets[index];\nNode *pre = NULL;\nwhile (cur) {\nif (cur->pair->key == key) {\n// \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nif (pre) {\npre->next = cur->next;\n} else {\nhashMap->buckets[index] = cur->next;\n}\n// \u91ca\u653e\u5185\u5b58\nfree(cur->pair);\nfree(cur);\nhashMap->size--;\nreturn;\n}\npre = cur;\ncur = cur->next;\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapChaining *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nNode *cur = hashMap->buckets[i];\nprintf(\"[\");\nwhile (cur) {\nprintf(\"%d -> %s, \", cur->pair->key, cur->pair->val);\ncur = cur->next;\n}\nprintf(\"]\\n\");\n}\n}\n
        hash_map_chaining.zig
        [class]{HashMapChaining}-[func]{}\n

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u94fe\u8868\u5f88\u957f\u65f6\uff0c\u67e5\u8be2\u6548\u7387 \\(O(n)\\) \u5f88\u5dee\u3002\u6b64\u65f6\u53ef\u4ee5\u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u201cAVL \u6811\u201d\u6216\u201c\u7ea2\u9ed1\u6811\u201d\uff0c\u4ece\u800c\u5c06\u67e5\u8be2\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(\\log n)\\) \u3002

        "},{"location":"chapter_hashing/hash_collision/#622","title":"6.2.2 \u00a0 \u5f00\u653e\u5bfb\u5740","text":"

        \u300c\u5f00\u653e\u5bfb\u5740 open addressing\u300d\u4e0d\u5f15\u5165\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\uff0c\u800c\u662f\u901a\u8fc7\u201c\u591a\u6b21\u63a2\u6d4b\u201d\u6765\u5904\u7406\u54c8\u5e0c\u51b2\u7a81\uff0c\u63a2\u6d4b\u65b9\u5f0f\u4e3b\u8981\u5305\u62ec\u7ebf\u6027\u63a2\u6d4b\u3001\u5e73\u65b9\u63a2\u6d4b\u3001\u591a\u6b21\u54c8\u5e0c\u7b49\u3002

        \u4e0b\u9762\u4ee5\u7ebf\u6027\u63a2\u6d4b\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\u7684\u5de5\u4f5c\u673a\u5236\u3002

        "},{"location":"chapter_hashing/hash_collision/#1","title":"1. \u00a0 \u7ebf\u6027\u63a2\u6d4b","text":"

        \u7ebf\u6027\u63a2\u6d4b\u91c7\u7528\u56fa\u5b9a\u6b65\u957f\u7684\u7ebf\u6027\u641c\u7d22\u6765\u8fdb\u884c\u63a2\u6d4b\uff0c\u5176\u64cd\u4f5c\u65b9\u6cd5\u4e0e\u666e\u901a\u54c8\u5e0c\u8868\u6709\u6240\u4e0d\u540c\u3002

        • \u63d2\u5165\u5143\u7d20\uff1a\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u82e5\u53d1\u73b0\u6876\u5185\u5df2\u6709\u5143\u7d20\uff0c\u5219\u4ece\u51b2\u7a81\u4f4d\u7f6e\u5411\u540e\u7ebf\u6027\u904d\u5386\uff08\u6b65\u957f\u901a\u5e38\u4e3a \\(1\\) \uff09\uff0c\u76f4\u81f3\u627e\u5230\u7a7a\u6876\uff0c\u5c06\u5143\u7d20\u63d2\u5165\u5176\u4e2d\u3002
        • \u67e5\u627e\u5143\u7d20\uff1a\u82e5\u53d1\u73b0\u54c8\u5e0c\u51b2\u7a81\uff0c\u5219\u4f7f\u7528\u76f8\u540c\u6b65\u957f\u5411\u540e\u7ebf\u6027\u904d\u5386\uff0c\u76f4\u5230\u627e\u5230\u5bf9\u5e94\u5143\u7d20\uff0c\u8fd4\u56de value \u5373\u53ef\uff1b\u5982\u679c\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u76ee\u6807\u5143\u7d20\u4e0d\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u8fd4\u56de \\(\\text{None}\\) \u3002

        \u56fe 6-6 \u5c55\u793a\u4e86\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u7684\u952e\u503c\u5bf9\u5206\u5e03\u3002\u6839\u636e\u6b64\u54c8\u5e0c\u51fd\u6570\uff0c\u6700\u540e\u4e24\u4f4d\u76f8\u540c\u7684 key \u90fd\u4f1a\u88ab\u6620\u5c04\u5230\u76f8\u540c\u7684\u6876\u3002\u800c\u901a\u8fc7\u7ebf\u6027\u63a2\u6d4b\uff0c\u5b83\u4eec\u88ab\u4f9d\u6b21\u5b58\u50a8\u5728\u8be5\u6876\u4ee5\u53ca\u4e4b\u4e0b\u7684\u6876\u4e2d\u3002

        \u56fe 6-6 \u00a0 \u5f00\u653e\u5bfb\u5740\u548c\u7ebf\u6027\u63a2\u6d4b

        \u7136\u800c\uff0c\u7ebf\u6027\u63a2\u6d4b\u5bb9\u6613\u4ea7\u751f\u201c\u805a\u96c6\u73b0\u8c61\u201d\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6570\u7ec4\u4e2d\u8fde\u7eed\u88ab\u5360\u7528\u7684\u4f4d\u7f6e\u8d8a\u957f\uff0c\u8fd9\u4e9b\u8fde\u7eed\u4f4d\u7f6e\u53d1\u751f\u54c8\u5e0c\u51b2\u7a81\u7684\u53ef\u80fd\u6027\u8d8a\u5927\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u4fc3\u4f7f\u8be5\u4f4d\u7f6e\u7684\u805a\u5806\u751f\u957f\uff0c\u5f62\u6210\u6076\u6027\u5faa\u73af\uff0c\u6700\u7ec8\u5bfc\u81f4\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u6548\u7387\u52a3\u5316\u3002

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\u4e2d\u76f4\u63a5\u5220\u9664\u5143\u7d20\u3002\u8fd9\u662f\u56e0\u4e3a\u5220\u9664\u5143\u7d20\u4f1a\u5728\u6570\u7ec4\u5185\u4ea7\u751f\u4e00\u4e2a\u7a7a\u6876 \\(\\text{None}\\) \uff0c\u800c\u5f53\u67e5\u8be2\u5143\u7d20\u65f6\uff0c\u7ebf\u6027\u63a2\u6d4b\u5230\u8be5\u7a7a\u6876\u5c31\u4f1a\u8fd4\u56de\uff0c\u56e0\u6b64\u5728\u8be5\u7a7a\u6876\u4e4b\u4e0b\u7684\u5143\u7d20\u90fd\u65e0\u6cd5\u518d\u88ab\u8bbf\u95ee\u5230\uff0c\u7a0b\u5e8f\u53ef\u80fd\u8bef\u5224\u8fd9\u4e9b\u5143\u7d20\u4e0d\u5b58\u5728\u3002

        \u56fe 6-7 \u00a0 \u5728\u5f00\u653e\u5bfb\u5740\u4e2d\u5220\u9664\u5143\u7d20\u5bfc\u81f4\u7684\u67e5\u8be2\u95ee\u9898

        \u4e3a\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u300c\u61d2\u5220\u9664 lazy deletion\u300d\u673a\u5236\uff1a\u5b83\u4e0d\u76f4\u63a5\u4ece\u54c8\u5e0c\u8868\u4e2d\u79fb\u9664\u5143\u7d20\uff0c\u800c\u662f\u5229\u7528\u4e00\u4e2a\u5e38\u91cf TOMBSTONE \u6765\u6807\u8bb0\u8fd9\u4e2a\u6876\u3002\u5728\u8be5\u673a\u5236\u4e0b\uff0c\\(\\text{None}\\) \u548c TOMBSTONE \u90fd\u4ee3\u8868\u7a7a\u6876\uff0c\u90fd\u53ef\u4ee5\u653e\u7f6e\u952e\u503c\u5bf9\u3002\u4f46\u4e0d\u540c\u7684\u662f\uff0c\u7ebf\u6027\u63a2\u6d4b\u5230 TOMBSTONE \u65f6\u5e94\u8be5\u7ee7\u7eed\u904d\u5386\uff0c\u56e0\u4e3a\u5176\u4e4b\u4e0b\u53ef\u80fd\u8fd8\u5b58\u5728\u952e\u503c\u5bf9\u3002

        \u7136\u800c\uff0c\u61d2\u5220\u9664\u53ef\u80fd\u4f1a\u52a0\u901f\u54c8\u5e0c\u8868\u7684\u6027\u80fd\u9000\u5316\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u6b21\u5220\u9664\u64cd\u4f5c\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5220\u9664\u6807\u8bb0\uff0c\u968f\u7740 TOMBSTONE \u7684\u589e\u52a0\uff0c\u641c\u7d22\u65f6\u95f4\u4e5f\u4f1a\u589e\u52a0\uff0c\u56e0\u4e3a\u7ebf\u6027\u63a2\u6d4b\u53ef\u80fd\u9700\u8981\u8df3\u8fc7\u591a\u4e2a TOMBSTONE \u624d\u80fd\u627e\u5230\u76ee\u6807\u5143\u7d20\u3002

        \u4e3a\u6b64\uff0c\u8003\u8651\u5728\u7ebf\u6027\u63a2\u6d4b\u4e2d\u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a TOMBSTONE \u7684\u7d22\u5f15\uff0c\u5e76\u5c06\u641c\u7d22\u5230\u7684\u76ee\u6807\u5143\u7d20\u4e0e\u8be5 TOMBSTONE \u4ea4\u6362\u4f4d\u7f6e\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u5f53\u6bcf\u6b21\u67e5\u8be2\u6216\u6dfb\u52a0\u5143\u7d20\u65f6\uff0c\u5143\u7d20\u4f1a\u88ab\u79fb\u52a8\u81f3\u8ddd\u79bb\u7406\u60f3\u4f4d\u7f6e\uff08\u63a2\u6d4b\u8d77\u59cb\u70b9\uff09\u66f4\u8fd1\u7684\u6876\uff0c\u4ece\u800c\u4f18\u5316\u67e5\u8be2\u6548\u7387\u3002

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5305\u542b\u61d2\u5220\u9664\u7684\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u3002\u4e3a\u4e86\u66f4\u52a0\u5145\u5206\u5730\u4f7f\u7528\u54c8\u5e0c\u8868\u7684\u7a7a\u95f4\uff0c\u6211\u4eec\u5c06\u54c8\u5e0c\u8868\u770b\u4f5c\u4e00\u4e2a\u201c\u73af\u5f62\u6570\u7ec4\u201d\uff0c\u5f53\u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u56de\u5230\u5934\u90e8\u7ee7\u7eed\u904d\u5386\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map_open_addressing.py
        class HashMapOpenAddressing:\n\"\"\"\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\nself.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\nself.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nself.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\nself.buckets: list[Pair | None] = [None] * self.capacity  # \u6876\u6570\u7ec4\nself.TOMBSTONE = Pair(-1, \"-1\")  # \u5220\u9664\u6807\u8bb0\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nreturn key % self.capacity\ndef load_factor(self) -> float:\n\"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\nreturn self.size / self.capacity\ndef find_bucket(self, key: int) -> int:\n\"\"\"\u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\"\"\"\nindex = self.hash_func(key)\nfirst_tombstone = -1\n# \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile self.buckets[index] is not None:\n# \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif self.buckets[index].key == key:\n# \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif first_tombstone != -1:\nself.buckets[first_tombstone] = self.buckets[index]\nself.buckets[index] = self.TOMBSTONE\nreturn first_tombstone  # \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\nreturn index  # \u8fd4\u56de\u6876\u7d22\u5f15\n# \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif first_tombstone == -1 and self.buckets[index] is self.TOMBSTONE:\nfirst_tombstone = index\n# \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % self.capacity\n# \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn index if first_tombstone == -1 else first_tombstone\ndef get(self, key: int) -> str:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nreturn self.buckets[index].val\n# \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de None\nreturn None\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n# \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres:\nself.extend()\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nself.buckets[index].val = val\nreturn\n# \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nself.buckets[index] = Pair(key, val)\nself.size += 1\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nself.buckets[index] = self.TOMBSTONE\nself.size -= 1\ndef extend(self):\n\"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n# \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nbuckets_tmp = self.buckets\n# \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio\nself.buckets = [None] * self.capacity\nself.size = 0\n# \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in buckets_tmp:\nif pair not in [None, self.TOMBSTONE]:\nself.put(pair.key, pair.val)\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor pair in self.buckets:\nif pair is None:\nprint(\"None\")\nelif pair is self.TOMBSTONE:\nprint(\"TOMBSTONE\")\nelse:\nprint(pair.key, \"->\", pair.val)\n
        hash_map_open_addressing.cpp
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate:\nint size;                             // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity = 4;                     // \u54c8\u5e0c\u8868\u5bb9\u91cf\nconst double loadThres = 2.0 / 3.0;     // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nconst int extendRatio = 2;            // \u6269\u5bb9\u500d\u6570\nvector<Pair *> buckets;               // \u6876\u6570\u7ec4\nPair *TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapOpenAddressing() : size(0), buckets(capacity, nullptr) {\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~HashMapOpenAddressing() {\nfor (Pair *pair : buckets) {\nif (pair != nullptr && pair != TOMBSTONE) {\ndelete pair;\n}\n}\ndelete TOMBSTONE;\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double)size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != nullptr) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index]->key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\nreturn buckets[index]->val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\nbuckets[index]->val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\ndelete buckets[index];\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nvector<Pair *> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = vector<Pair *>(capacity, nullptr);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair *pair : bucketsTmp) {\nif (pair != nullptr && pair != TOMBSTONE) {\nput(pair->key, pair->val);\ndelete pair;\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (Pair *pair : buckets) {\nif (pair == nullptr) {\ncout << \"nullptr\" << endl;\n} else if (pair == TOMBSTONE) {\ncout << \"TOMBSTONE\" << endl;\n} else {\ncout << pair->key << \" -> \" << pair->val << endl;\n}\n}\n}\n};\n
        hash_map_open_addressing.java
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate int size; // \u952e\u503c\u5bf9\u6570\u91cf\nprivate int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nprivate final double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nprivate final int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nprivate Pair[] buckets; // \u6876\u6570\u7ec4\nprivate final Pair TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapOpenAddressing() {\nsize = 0;\nbuckets = new Pair[capacity];\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate int hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nprivate double loadFactor() {\nreturn (double) size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nprivate int findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index].key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic String get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nreturn buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nprivate void extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair[] bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new Pair[capacity];\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair pair : bucketsTmp) {\nif (pair != null && pair != TOMBSTONE) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void print() {\nfor (Pair pair : buckets) {\nif (pair == null) {\nSystem.out.println(\"null\");\n} else if (pair == TOMBSTONE) {\nSystem.out.println(\"TOMBSTONE\");\n} else {\nSystem.out.println(pair.key + \" -> \" + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.cs
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nPair[] buckets; // \u6876\u6570\u7ec4\nPair TOMBSTONE = new(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapOpenAddressing() {\nsize = 0;\nbuckets = new Pair[capacity];\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble LoadFactor() {\nreturn (double)size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint FindBucket(int key) {\nint index = HashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index].key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nreturn buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (LoadFactor() > loadThres) {\nExtend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid Extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair[] bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new Pair[capacity];\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nforeach (Pair pair in bucketsTmp) {\nif (pair != null && pair != TOMBSTONE) {\nPut(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (Pair pair in buckets) {\nif (pair == null) {\nConsole.WriteLine(\"null\");\n} else if (pair == TOMBSTONE) {\nConsole.WriteLine(\"TOMBSTONE\");\n} else {\nConsole.WriteLine(pair.key + \" -> \" + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.go
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntype hashMapOpenAddressing struct {\nsize        int     // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity    int     // \u54c8\u5e0c\u8868\u5bb9\u91cf\nloadThres   float64 // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextendRatio int     // \u6269\u5bb9\u500d\u6570\nbuckets     []pair  // \u6876\u6570\u7ec4\nremoved     pair    // \u5220\u9664\u6807\u8bb0\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapOpenAddressing() *hashMapOpenAddressing {\nbuckets := make([]pair, 4)\nreturn &hashMapOpenAddressing{\nsize:        0,\ncapacity:    4,\nloadThres:   2.0 / 3.0,\nextendRatio: 2,\nbuckets:     buckets,\nremoved: pair{\nkey: -1,\nval: \"-1\",\n},\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapOpenAddressing) hashFunc(key int) int {\nreturn key % m.capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapOpenAddressing) loadFactor() float64 {\nreturn float64(m.size) / float64(m.capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) get(key int) string {\nidx := m.hashFunc(key)\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u8fd4\u56de null\nif m.buckets[j] == (pair{}) {\nreturn \"\"\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif m.buckets[j].key == key && m.buckets[j] != m.removed {\nreturn m.buckets[j].val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\"\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) put(key int, val string) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif m.loadFactor() > m.loadThres {\nm.extend()\n}\nidx := m.hashFunc(key)\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\u3001\u6216\u5e26\u6709\u5220\u9664\u6807\u8bb0\u7684\u6876\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u653e\u5165\u8be5\u6876\nif m.buckets[j] == (pair{}) || m.buckets[j] == m.removed {\nm.buckets[j] = pair{\nkey: key,\nval: val,\n}\nm.size += 1\nreturn\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val\nif m.buckets[j].key == key {\nm.buckets[j].val = val\n}\n}\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) remove(key int) {\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif m.buckets[j] == (pair{}) {\nreturn\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u6807\u8bb0\u5220\u9664\u5e76\u8fd4\u56de\nif m.buckets[j].key == key {\nm.buckets[j] = m.removed\nm.size -= 1\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\ntmpBuckets := make([]pair, len(m.buckets))\ncopy(tmpBuckets, m.buckets)\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nm.capacity *= m.extendRatio\nm.buckets = make([]pair, m.capacity)\nm.size = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor _, p := range tmpBuckets {\nif p != (pair{}) && p != m.removed {\nm.put(p.key, p.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) print() {\nfor _, p := range m.buckets {\nif p != (pair{}) {\nfmt.Println(strconv.Itoa(p.key) + \" -> \" + p.val)\n} else {\nfmt.Println(\"nil\")\n}\n}\n}\n
        hash_map_open_addressing.swift
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nvar size: Int // \u952e\u503c\u5bf9\u6570\u91cf\nvar capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\nvar loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nvar extendRatio: Int // \u6269\u5bb9\u500d\u6570\nvar buckets: [Pair?] // \u6876\u6570\u7ec4\nvar TOMBSTONE: Pair // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\nsize = 0\ncapacity = 4\nloadThres = 2.0 / 3.0\nextendRatio = 2\nbuckets = Array(repeating: nil, count: capacity)\nTOMBSTONE = Pair(key: -1, val: \"-1\")\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc hashFunc(key: Int) -> Int {\nkey % capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc loadFactor() -> Double {\nDouble(size / capacity)\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nfunc findBucket(key: Int) -> Int {\nvar index = hashFunc(key: key)\nvar firstTombstone = -1\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile buckets[index] != nil {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif buckets[index]!.key == key {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif firstTombstone != -1 {\nbuckets[firstTombstone] = buckets[index]\nbuckets[index] = TOMBSTONE\nreturn firstTombstone // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif firstTombstone == -1 && buckets[index] == TOMBSTONE {\nfirstTombstone = index\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nreturn buckets[index]!.val\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn nil\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif loadFactor() > loadThres {\nextend()\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nbuckets[index]!.val = val\nreturn\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = Pair(key: key, val: val)\nsize += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nbuckets[index] = TOMBSTONE\nsize -= 1\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet bucketsTmp = buckets\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio\nbuckets = Array(repeating: nil, count: capacity)\nsize = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in bucketsTmp {\nif let pair, pair != TOMBSTONE {\nput(key: pair.key, val: pair.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor pair in buckets {\nif pair == nil {\nSwift.print(\"null\")\n} else if pair == TOMBSTONE {\nSwift.print(\"TOMBSTONE\")\n} else {\nSwift.print(\"\\(pair!.key) -> \\(pair!.val)\")\n}\n}\n}\n}\n
        hash_map_open_addressing.js
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n#size; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio; // \u6269\u5bb9\u500d\u6570\n#buckets; // \u6876\u6570\u7ec4\n#TOMBSTONE; // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\nthis.#capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nthis.#loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nthis.#extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nthis.#buckets = Array(this.#capacity).fill(null); // \u6876\u6570\u7ec4\nthis.#TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor() {\nreturn this.#size / this.#capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n#findBucket(key) {\nlet index = this.#hashFunc(key);\nlet firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (this.#buckets[index] !== null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (this.#buckets[index].key === key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone !== -1) {\nthis.#buckets[firstTombstone] = this.#buckets[index];\nthis.#buckets[index] = this.#TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (\nfirstTombstone === -1 &&\nthis.#buckets[index] === this.#TOMBSTONE\n) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % this.#capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone === -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nreturn this.#buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key, val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nthis.#buckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nthis.#buckets[index] = new Pair(key, val);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nthis.#buckets[index] = this.#TOMBSTONE;\nthis.#size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = Array(this.#capacity).fill(null);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const pair of bucketsTmp) {\nif (pair !== null && pair !== this.#TOMBSTONE) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nfor (const pair of this.#buckets) {\nif (pair === null) {\nconsole.log('null');\n} else if (pair === this.#TOMBSTONE) {\nconsole.log('TOMBSTONE');\n} else {\nconsole.log(pair.key + ' -> ' + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.ts
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate size: number; // \u952e\u503c\u5bf9\u6570\u91cf\nprivate capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nprivate loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nprivate extendRatio: number; // \u6269\u5bb9\u500d\u6570\nprivate buckets: Array<Pair | null>; // \u6876\u6570\u7ec4\nprivate TOMBSTONE: Pair; // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\nthis.capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nthis.loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nthis.extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nthis.buckets = Array(this.capacity).fill(null); // \u6876\u6570\u7ec4\nthis.TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate hashFunc(key: number): number {\nreturn key % this.capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nprivate loadFactor(): number {\nreturn this.size / this.capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nprivate findBucket(key: number): number {\nlet index = this.hashFunc(key);\nlet firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (this.buckets[index] !== null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (this.buckets[index]!.key === key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone !== -1) {\nthis.buckets[firstTombstone] = this.buckets[index];\nthis.buckets[index] = this.TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (\nfirstTombstone === -1 &&\nthis.buckets[index] === this.TOMBSTONE\n) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % this.capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone === -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key: number): string | null {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nreturn this.buckets[index]!.val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key: number, val: string): void {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.loadFactor() > this.loadThres) {\nthis.extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nthis.buckets[index]!.val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nthis.buckets[index] = new Pair(key, val);\nthis.size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key: number): void {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nthis.buckets[index] = this.TOMBSTONE;\nthis.size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nprivate extend(): void {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.capacity *= this.extendRatio;\nthis.buckets = Array(this.capacity).fill(null);\nthis.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const pair of bucketsTmp) {\nif (pair !== null && pair !== this.TOMBSTONE) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint(): void {\nfor (const pair of this.buckets) {\nif (pair === null) {\nconsole.log('null');\n} else if (pair === this.TOMBSTONE) {\nconsole.log('TOMBSTONE');\n} else {\nconsole.log(pair.key + ' -> ' + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.dart
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nlate int _size; // \u952e\u503c\u5bf9\u6570\u91cf\nint _capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble _loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint _extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nlate List<Pair?> _buckets; // \u6876\u6570\u7ec4\nPair _TOMBSTONE = Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapOpenAddressing() {\n_size = 0;\n_buckets = List.generate(_capacity, (index) => null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % _capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn _size / _capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (_buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (_buckets[index]!.key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\n_buckets[firstTombstone] = _buckets[index];\n_buckets[index] = _TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && _buckets[index] == _TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % _capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\nreturn _buckets[index]!.val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > _loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n_buckets[index]!.val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n_buckets[index] = new Pair(key, val);\n_size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n_buckets[index] = _TOMBSTONE;\n_size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<Pair?> bucketsTmp = _buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n_capacity *= _extendRatio;\n_buckets = List.generate(_capacity, (index) => null);\n_size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair? pair in bucketsTmp) {\nif (pair != null && pair != _TOMBSTONE) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (Pair? pair in _buckets) {\nif (pair == null) {\nprint(\"null\");\n} else if (pair == _TOMBSTONE) {\nprint(\"TOMBSTONE\");\n} else {\nprint(\"${pair.key} -> ${pair.val}\");\n}\n}\n}\n}\n
        hash_map_open_addressing.rs
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapOpenAddressing {\nsize: usize,                    // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity: usize,                // \u54c8\u5e0c\u8868\u5bb9\u91cf\nload_thres: f64,                // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextend_ratio: usize,            // \u6269\u5bb9\u500d\u6570\nbuckets: Vec<Option<Pair>>,     // \u6876\u6570\u7ec4\nTOMBSTONE: Option<Pair>,        // \u5220\u9664\u6807\u8bb0\n}\nimpl HashMapOpenAddressing {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new() -> Self {\nSelf {\nsize: 0,\ncapacity: 4,\nload_thres: 2.0 / 3.0,\nextend_ratio: 2,\nbuckets: vec![None; 4],\nTOMBSTONE: Some(Pair {key: -1, val: \"-1\".to_string()}),\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\n(key % self.capacity as i32) as usize\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfn load_factor(&self) -> f64 {\nself.size as f64 / self.capacity as f64\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nfn find_bucket(&mut self, key: i32) -> usize {\nlet mut index = self.hash_func(key);\nlet mut first_tombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile self.buckets[index].is_some() {\n// \u82e5\u9047\u5230 key\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nif self.buckets[index].as_ref().unwrap().key == key {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u5efa\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif first_tombstone != -1 {\nself.buckets[first_tombstone as usize] = self.buckets[index].take();\nself.buckets[index] = self.TOMBSTONE.clone();\nreturn first_tombstone as usize;    // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index;   // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif first_tombstone == -1 && self.buckets[index] == self.TOMBSTONE {\nfirst_tombstone = index as i32;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % self.capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nif first_tombstone == -1 { index } else { first_tombstone as usize }\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfn get(&mut self, key: i32) -> Option<&str> {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nreturn self.buckets[index].as_ref().map(|pair| &pair.val as &str);\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nNone\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfn put(&mut self, key: i32, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres {\nself.extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nself.buckets[index].as_mut().unwrap().val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nself.buckets[index] = Some(Pair { key, val });\nself.size += 1;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfn remove(&mut self, key: i32) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nself.buckets[index] = self.TOMBSTONE.clone();\nself.size -= 1;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfn extend(&mut self) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet buckets_tmp = self.buckets.clone();\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio;\nself.buckets = vec![None; self.capacity];\nself.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in buckets_tmp {\nif pair.is_none() || pair == self.TOMBSTONE {\ncontinue;\n}\nlet pair = pair.unwrap();\nself.put(pair.key, pair.val);\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfn print(&self) {\nfor pair in &self.buckets {\nif pair.is_none() {\nprintln!(\"null\");\n} else if pair == &self.TOMBSTONE {\nprintln!(\"TOMBSTONE\");\n} else {\nlet pair = pair.as_ref().unwrap();\nprintln!(\"{} -> {}\", pair.key, pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.c
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\nint size;         // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;  // \u6269\u5bb9\u500d\u6570\nPair **buckets;   // \u6876\u6570\u7ec4\nPair *TOMBSTONE;  // \u5220\u9664\u6807\u8bb0\n} HashMapOpenAddressing;\n/* \u6784\u9020\u51fd\u6570 */\nHashMapOpenAddressing *newHashMapOpenAddressing() {\nHashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));\nhashMap->size = 0;\nhashMap->capacity = 4;\nhashMap->loadThres = 2.0 / 3.0;\nhashMap->extendRatio = 2;\nhashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\nhashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));\nhashMap->TOMBSTONE->key = -1;\nhashMap->TOMBSTONE->val = \"-1\";\nreturn hashMap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nPair *pair = hashMap->buckets[i];\nif (pair != NULL && pair != hashMap->TOMBSTONE) {\nfree(pair->val);\nfree(pair);\n}\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapOpenAddressing *hashMap, int key) {\nreturn key % hashMap->capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapOpenAddressing *hashMap) {\nreturn (double)hashMap->size / (double)hashMap->capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(HashMapOpenAddressing *hashMap, int key) {\nint index = hashFunc(hashMap, key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (hashMap->buckets[index] != NULL) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (hashMap->buckets[index]->key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nhashMap->buckets[firstTombstone] = hashMap->buckets[index];\nhashMap->buckets[index] = hashMap->TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && hashMap->buckets[index] == hashMap->TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % hashMap->capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapOpenAddressing *hashMap, int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nreturn hashMap->buckets[index]->val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(HashMapOpenAddressing *hashMap, int key, char *val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor(hashMap) > hashMap->loadThres) {\nextend(hashMap);\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nfree(hashMap->buckets[index]->val);\nhashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val + 1)));\nstrcpy(hashMap->buckets[index]->val, val);\nhashMap->buckets[index]->val[strlen(val)] = '\\0';\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nPair *pair = (Pair *)malloc(sizeof(Pair));\npair->key = key;\npair->val = (char *)malloc(sizeof(strlen(val + 1)));\nstrcpy(pair->val, val);\npair->val[strlen(val)] = '\\0';\nhashMap->buckets[index] = pair;\nhashMap->size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapOpenAddressing *hashMap, int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nPair *pair = hashMap->buckets[index];\nfree(pair->val);\nfree(pair);\nhashMap->buckets[index] = hashMap->TOMBSTONE;\nhashMap->size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapOpenAddressing *hashMap) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair **bucketsTmp = hashMap->buckets;\nint oldCapacity = hashMap->capacity;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nhashMap->capacity *= hashMap->extendRatio;\nhashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\nhashMap->size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (int i = 0; i < oldCapacity; i++) {\nPair *pair = bucketsTmp[i];\nif (pair != NULL && pair != hashMap->TOMBSTONE) {\nput(hashMap, pair->key, pair->val);\nfree(pair->val);\nfree(pair);\n}\n}\nfree(bucketsTmp);\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapOpenAddressing *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nPair *pair = hashMap->buckets[i];\nif (pair == NULL) {\nprintf(\"NULL\\n\");\n} else if (pair == hashMap->TOMBSTONE) {\nprintf(\"TOMBSTONE\\n\");\n} else {\nprintf(\"%d -> %s\\n\", pair->key, pair->val);\n}\n}\n}\n
        hash_map_open_addressing.zig
        [class]{HashMapOpenAddressing}-[func]{}\n
        "},{"location":"chapter_hashing/hash_collision/#2","title":"2. \u00a0 \u5e73\u65b9\u63a2\u6d4b","text":"

        \u5e73\u65b9\u63a2\u6d4b\u4e0e\u7ebf\u6027\u63a2\u6d4b\u7c7b\u4f3c\uff0c\u90fd\u662f\u5f00\u653e\u5bfb\u5740\u7684\u5e38\u89c1\u7b56\u7565\u4e4b\u4e00\u3002\u5f53\u53d1\u751f\u51b2\u7a81\u65f6\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e0d\u662f\u7b80\u5355\u5730\u8df3\u8fc7\u4e00\u4e2a\u56fa\u5b9a\u7684\u6b65\u6570\uff0c\u800c\u662f\u8df3\u8fc7\u201c\u63a2\u6d4b\u6b21\u6570\u7684\u5e73\u65b9\u201d\u7684\u6b65\u6570\uff0c\u5373 \\(1, 4, 9, \\dots\\) \u6b65\u3002

        \u5e73\u65b9\u63a2\u6d4b\u4e3b\u8981\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\u3002

        • \u5e73\u65b9\u63a2\u6d4b\u901a\u8fc7\u8df3\u8fc7\u5e73\u65b9\u7684\u8ddd\u79bb\uff0c\u8bd5\u56fe\u7f13\u89e3\u7ebf\u6027\u63a2\u6d4b\u7684\u805a\u96c6\u6548\u5e94\u3002
        • \u5e73\u65b9\u63a2\u6d4b\u4f1a\u8df3\u8fc7\u66f4\u5927\u7684\u8ddd\u79bb\u6765\u5bfb\u627e\u7a7a\u4f4d\u7f6e\uff0c\u6709\u52a9\u4e8e\u6570\u636e\u5206\u5e03\u5f97\u66f4\u52a0\u5747\u5300\u3002

        \u7136\u800c\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e5f\u5e76\u4e0d\u662f\u5b8c\u7f8e\u7684\u3002

        • \u4ecd\u7136\u5b58\u5728\u805a\u96c6\u73b0\u8c61\uff0c\u5373\u67d0\u4e9b\u4f4d\u7f6e\u6bd4\u5176\u4ed6\u4f4d\u7f6e\u66f4\u5bb9\u6613\u88ab\u5360\u7528\u3002
        • \u7531\u4e8e\u5e73\u65b9\u7684\u589e\u957f\uff0c\u5e73\u65b9\u63a2\u6d4b\u53ef\u80fd\u4e0d\u4f1a\u63a2\u6d4b\u6574\u4e2a\u54c8\u5e0c\u8868\uff0c\u8fd9\u610f\u5473\u7740\u5373\u4f7f\u54c8\u5e0c\u8868\u4e2d\u6709\u7a7a\u6876\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e5f\u53ef\u80fd\u65e0\u6cd5\u8bbf\u95ee\u5230\u5b83\u3002
        "},{"location":"chapter_hashing/hash_collision/#3","title":"3. \u00a0 \u591a\u6b21\u54c8\u5e0c","text":"

        \u987e\u540d\u601d\u4e49\uff0c\u591a\u6b21\u54c8\u5e0c\u65b9\u6cd5\u4f7f\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570 \\(f_1(x)\\)\u3001\\(f_2(x)\\)\u3001\\(f_3(x)\\)\u3001\\(\\dots\\) \u8fdb\u884c\u63a2\u6d4b\u3002

        • \u63d2\u5165\u5143\u7d20\uff1a\u82e5\u54c8\u5e0c\u51fd\u6570 \\(f_1(x)\\) \u51fa\u73b0\u51b2\u7a81\uff0c\u5219\u5c1d\u8bd5 \\(f_2(x)\\) \uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u627e\u5230\u7a7a\u6876\u540e\u63d2\u5165\u5143\u7d20\u3002
        • \u67e5\u627e\u5143\u7d20\uff1a\u5728\u76f8\u540c\u7684\u54c8\u5e0c\u51fd\u6570\u987a\u5e8f\u4e0b\u8fdb\u884c\u67e5\u627e\uff0c\u76f4\u5230\u627e\u5230\u76ee\u6807\u5143\u7d20\u65f6\u8fd4\u56de\uff1b\u82e5\u9047\u5230\u7a7a\u6876\u6216\u5df2\u5c1d\u8bd5\u6240\u6709\u54c8\u5e0c\u51fd\u6570\uff0c\u8bf4\u660e\u54c8\u5e0c\u8868\u4e2d\u4e0d\u5b58\u5728\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(\\text{None}\\) \u3002

        \u4e0e\u7ebf\u6027\u63a2\u6d4b\u76f8\u6bd4\uff0c\u591a\u6b21\u54c8\u5e0c\u65b9\u6cd5\u4e0d\u6613\u4ea7\u751f\u805a\u96c6\uff0c\u4f46\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u4f1a\u5e26\u6765\u989d\u5916\u7684\u8ba1\u7b97\u91cf\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\u3001\u5e73\u65b9\u63a2\u6d4b\u548c\u591a\u6b21\u54c8\u5e0c\uff09\u54c8\u5e0c\u8868\u90fd\u5b58\u5728\u201c\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u201d\u7684\u95ee\u9898\u3002

        "},{"location":"chapter_hashing/hash_collision/#623","title":"6.2.3 \u00a0 \u7f16\u7a0b\u8bed\u8a00\u7684\u9009\u62e9","text":"

        \u5404\u4e2a\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u7b56\u7565\uff0c\u4ee5\u4e0b\u4e3e\u51e0\u4e2a\u4f8b\u5b50\u3002

        • Python \u91c7\u7528\u5f00\u653e\u5bfb\u5740\u3002\u5b57\u5178 dict \u4f7f\u7528\u4f2a\u968f\u673a\u6570\u8fdb\u884c\u63a2\u6d4b\u3002
        • Java \u91c7\u7528\u94fe\u5f0f\u5730\u5740\u3002\u81ea JDK 1.8 \u4ee5\u6765\uff0c\u5f53 HashMap \u5185\u6570\u7ec4\u957f\u5ea6\u8fbe\u5230 64 \u4e14\u94fe\u8868\u957f\u5ea6\u8fbe\u5230 8 \u65f6\uff0c\u94fe\u8868\u4f1a\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u4ee5\u63d0\u5347\u67e5\u627e\u6027\u80fd\u3002
        • Go \u91c7\u7528\u94fe\u5f0f\u5730\u5740\u3002Go \u89c4\u5b9a\u6bcf\u4e2a\u6876\u6700\u591a\u5b58\u50a8 8 \u4e2a\u952e\u503c\u5bf9\uff0c\u8d85\u51fa\u5bb9\u91cf\u5219\u8fde\u63a5\u4e00\u4e2a\u6ea2\u51fa\u6876\u3002\u5f53\u6ea2\u51fa\u6876\u8fc7\u591a\u65f6\uff0c\u4f1a\u6267\u884c\u4e00\u6b21\u7279\u6b8a\u7684\u7b49\u91cf\u6269\u5bb9\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u6027\u80fd\u3002
        "},{"location":"chapter_hashing/hash_map/","title":"6.1 \u00a0 \u54c8\u5e0c\u8868","text":"

        \u300c\u54c8\u5e0c\u8868 hash table\u300d\uff0c\u53c8\u79f0\u300c\u6563\u5217\u8868\u300d\uff0c\u5176\u901a\u8fc7\u5efa\u7acb\u952e key \u4e0e\u503c value \u4e4b\u95f4\u7684\u6620\u5c04\uff0c\u5b9e\u73b0\u9ad8\u6548\u7684\u5143\u7d20\u67e5\u8be2\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u5411\u54c8\u5e0c\u8868\u8f93\u5165\u4e00\u4e2a\u952e key \uff0c\u5219\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u83b7\u53d6\u5bf9\u5e94\u7684\u503c value \u3002

        \u5982\u56fe 6-1 \u6240\u793a\uff0c\u7ed9\u5b9a \\(n\\) \u4e2a\u5b66\u751f\uff0c\u6bcf\u4e2a\u5b66\u751f\u90fd\u6709\u201c\u59d3\u540d\u201d\u548c\u201c\u5b66\u53f7\u201d\u4e24\u9879\u6570\u636e\u3002\u5047\u5982\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u201c\u8f93\u5165\u4e00\u4e2a\u5b66\u53f7\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u59d3\u540d\u201d\u7684\u67e5\u8be2\u529f\u80fd\uff0c\u5219\u53ef\u4ee5\u91c7\u7528\u56fe 6-1 \u6240\u793a\u7684\u54c8\u5e0c\u8868\u6765\u5b9e\u73b0\u3002

        \u56fe 6-1 \u00a0 \u54c8\u5e0c\u8868\u7684\u62bd\u8c61\u8868\u793a

        \u9664\u54c8\u5e0c\u8868\u5916\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u67e5\u8be2\u529f\u80fd\uff0c\u5b83\u4eec\u7684\u6548\u7387\u5bf9\u6bd4\u5982\u8868 6-1 \u6240\u793a\u3002

        • \u6dfb\u52a0\u5143\u7d20\uff1a\u4ec5\u9700\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u6570\u7ec4\uff08\u94fe\u8868\uff09\u7684\u5c3e\u90e8\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002
        • \u67e5\u8be2\u5143\u7d20\uff1a\u7531\u4e8e\u6570\u7ec4\uff08\u94fe\u8868\uff09\u662f\u4e71\u5e8f\u7684\uff0c\u56e0\u6b64\u9700\u8981\u904d\u5386\u5176\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u5143\u7d20\uff1a\u9700\u8981\u5148\u67e5\u8be2\u5230\u5143\u7d20\uff0c\u518d\u4ece\u6570\u7ec4\uff08\u94fe\u8868\uff09\u4e2d\u5220\u9664\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002

        \u8868 6-1 \u00a0 \u5143\u7d20\u67e5\u8be2\u6548\u7387\u5bf9\u6bd4

        \u6570\u7ec4 \u94fe\u8868 \u54c8\u5e0c\u8868 \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(1)\\) \u6dfb\u52a0\u5143\u7d20 \\(O(1)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(1)\\)

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u5728\u54c8\u5e0c\u8868\u4e2d\u8fdb\u884c\u589e\u5220\u67e5\u6539\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662f \\(O(1)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002

        "},{"location":"chapter_hashing/hash_map/#611","title":"6.1.1 \u00a0 \u54c8\u5e0c\u8868\u5e38\u7528\u64cd\u4f5c","text":"

        \u54c8\u5e0c\u8868\u7684\u5e38\u89c1\u64cd\u4f5c\u5305\u62ec\uff1a\u521d\u59cb\u5316\u3001\u67e5\u8be2\u64cd\u4f5c\u3001\u6dfb\u52a0\u952e\u503c\u5bf9\u548c\u5220\u9664\u952e\u503c\u5bf9\u7b49\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map.py
        # \u521d\u59cb\u5316\u54c8\u5e0c\u8868\nhmap: dict = {}\n# \u6dfb\u52a0\u64cd\u4f5c\n# \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nhmap[12836] = \"\u5c0f\u54c8\"\nhmap[15937] = \"\u5c0f\u5570\"\nhmap[16750] = \"\u5c0f\u7b97\"\nhmap[13276] = \"\u5c0f\u6cd5\"\nhmap[10583] = \"\u5c0f\u9e2d\"\n# \u67e5\u8be2\u64cd\u4f5c\n# \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname: str = hmap[15937]\n# \u5220\u9664\u64cd\u4f5c\n# \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nhmap.pop(10583)\n
        hash_map.cpp
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nunordered_map<int, string> map;\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\";\nmap[15937] = \"\u5c0f\u5570\";\nmap[16750] = \"\u5c0f\u7b97\";\nmap[13276] = \"\u5c0f\u6cd5\";\nmap[10583] = \"\u5c0f\u9e2d\";\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.erase(10583);\n
        hash_map.java
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nMap<Integer, String> map = new HashMap<>();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.put(12836, \"\u5c0f\u54c8\");   map.put(15937, \"\u5c0f\u5570\");   map.put(16750, \"\u5c0f\u7b97\");   map.put(13276, \"\u5c0f\u6cd5\");\nmap.put(10583, \"\u5c0f\u9e2d\");\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map.get(15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.remove(10583);\n
        hash_map.cs
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nDictionary<int, string> map = new() {\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\n{ 12836, \"\u5c0f\u54c8\" },\n{ 15937, \"\u5c0f\u5570\" },\n{ 16750, \"\u5c0f\u7b97\" },\n{ 13276, \"\u5c0f\u6cd5\" },\n{ 10583, \"\u5c0f\u9e2d\" }\n};\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.Remove(10583);\n
        hash_map_test.go
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nhmap := make(map[int]string)\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nhmap[12836] = \"\u5c0f\u54c8\"\nhmap[15937] = \"\u5c0f\u5570\"\nhmap[16750] = \"\u5c0f\u7b97\"\nhmap[13276] = \"\u5c0f\u6cd5\"\nhmap[10583] = \"\u5c0f\u9e2d\"\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname := hmap[15937]\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\ndelete(hmap, 10583)\n
        hash_map.swift
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nvar map: [Int: String] = [:]\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\"\nmap[15937] = \"\u5c0f\u5570\"\nmap[16750] = \"\u5c0f\u7b97\"\nmap[13276] = \"\u5c0f\u6cd5\"\nmap[10583] = \"\u5c0f\u9e2d\"\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map[15937]!\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.removeValue(forKey: 10583)\n
        hash_map.js
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nconst map = new Map();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.set(12836, '\u5c0f\u54c8');\nmap.set(15937, '\u5c0f\u5570');\nmap.set(16750, '\u5c0f\u7b97');\nmap.set(13276, '\u5c0f\u6cd5');\nmap.set(10583, '\u5c0f\u9e2d');\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.delete(10583);\n
        hash_map.ts
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nconst map = new Map<number, string>();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.set(12836, '\u5c0f\u54c8');\nmap.set(15937, '\u5c0f\u5570');\nmap.set(16750, '\u5c0f\u7b97');\nmap.set(13276, '\u5c0f\u6cd5');\nmap.set(10583, '\u5c0f\u9e2d');\nconsole.info('\\n\u6dfb\u52a0\u5b8c\u6210\u540e\uff0c\u54c8\u5e0c\u8868\u4e3a\\nKey -> Value');\nconsole.info(map);\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\nconsole.info('\\n\u8f93\u5165\u5b66\u53f7 15937 \uff0c\u67e5\u8be2\u5230\u59d3\u540d ' + name);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.delete(10583);\nconsole.info('\\n\u5220\u9664 10583 \u540e\uff0c\u54c8\u5e0c\u8868\u4e3a\\nKey -> Value');\nconsole.info(map);\n
        hash_map.dart
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nMap<int, String> map = {};\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\";\nmap[15937] = \"\u5c0f\u5570\";\nmap[16750] = \"\u5c0f\u7b97\";\nmap[13276] = \"\u5c0f\u6cd5\";\nmap[10583] = \"\u5c0f\u9e2d\";\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.remove(10583);\n
        hash_map.rs
        use std::collections::HashMap;\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nlet mut map: HashMap<i32, String> = HashMap::new();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.insert(12836, \"\u5c0f\u54c8\".to_string());\nmap.insert(15937, \"\u5c0f\u5570\".to_string());\nmap.insert(16750, \"\u5c0f\u7b97\".to_string());\nmap.insert(13279, \"\u5c0f\u6cd5\".to_string());\nmap.insert(10583, \"\u5c0f\u9e2d\".to_string());\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet _name: Option<&String> = map.get(&15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nlet _removed_value: Option<String> = map.remove(&10583);\n
        hash_map.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u8868\n
        hash_map.zig
        \n

        \u54c8\u5e0c\u8868\u6709\u4e09\u79cd\u5e38\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff1a\u904d\u5386\u952e\u503c\u5bf9\u3001\u904d\u5386\u952e\u548c\u904d\u5386\u503c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map.py
        # \u904d\u5386\u54c8\u5e0c\u8868\n# \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor key, value in hmap.items():\nprint(key, \"->\", value)\n# \u5355\u72ec\u904d\u5386\u952e key\nfor key in hmap.keys():\nprint(key)\n# \u5355\u72ec\u904d\u5386\u503c value\nfor value in hmap.values():\nprint(value)\n
        hash_map.cpp
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (auto kv: map) {\ncout << kv.first << \" -> \" << kv.second << endl;\n}\n// \u4f7f\u7528\u8fed\u4ee3\u5668\u904d\u5386 key->value\nfor (auto iter = map.begin(); iter != map.end(); iter++) {\ncout << iter->first << \"->\" << iter->second << endl;\n}\n
        hash_map.java
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (Map.Entry <Integer, String> kv: map.entrySet()) {\nSystem.out.println(kv.getKey() + \" -> \" + kv.getValue());\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor (int key: map.keySet()) {\nSystem.out.println(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor (String val: map.values()) {\nSystem.out.println(val);\n}\n
        hash_map.cs
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nforeach (var kv in map) {\nConsole.WriteLine(kv.Key + \" -> \" + kv.Value);\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nforeach (int key in map.Keys) {\nConsole.WriteLine(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nforeach (string val in map.Values) {\nConsole.WriteLine(val);\n}\n
        hash_map_test.go
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor key, value := range hmap {\nfmt.Println(key, \"->\", value)\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor key := range hmap {\nfmt.Println(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor _, value := range hmap {\nfmt.Println(value)\n}\n
        hash_map.swift
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in map {\nprint(\"\\(key) -> \\(value)\")\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys {\nprint(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values {\nprint(value)\n}\n
        hash_map.js
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\nconsole.info('\\n\u904d\u5386\u952e\u503c\u5bf9 Key->Value');\nfor (const [k, v] of map.entries()) {\nconsole.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\nconsole.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\nconsole.info(v);\n}\n
        hash_map.ts
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\nconsole.info('\\n\u904d\u5386\u952e\u503c\u5bf9 Key->Value');\nfor (const [k, v] of map.entries()) {\nconsole.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\nconsole.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\nconsole.info(v);\n}\n
        hash_map.dart
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nmap.forEach((key, value) {\nprint('$key -> $value');\n});\n// \u5355\u72ec\u904d\u5386\u952e Key\nmap.keys.forEach((key) {\nprint(key);\n});\n// \u5355\u72ec\u904d\u5386\u503c Value\nmap.values.forEach((value) {\nprint(value);\n});\n
        hash_map.rs
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in &map {\nprintln!(\"{key} -> {value}\");\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys() {\nprintln!(\"{key}\"); }\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values() {\nprintln!(\"{value}\");\n}\n
        hash_map.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u8868\n
        hash_map.zig
        \n
        "},{"location":"chapter_hashing/hash_map/#612","title":"6.1.2 \u00a0 \u54c8\u5e0c\u8868\u7b80\u5355\u5b9e\u73b0","text":"

        \u6211\u4eec\u5148\u8003\u8651\u6700\u7b80\u5355\u7684\u60c5\u51b5\uff0c\u4ec5\u7528\u4e00\u4e2a\u6570\u7ec4\u6765\u5b9e\u73b0\u54c8\u5e0c\u8868\u3002\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u7a7a\u4f4d\u79f0\u4e3a\u300c\u6876 bucket\u300d\uff0c\u6bcf\u4e2a\u6876\u53ef\u5b58\u50a8\u4e00\u4e2a\u952e\u503c\u5bf9\u3002\u56e0\u6b64\uff0c\u67e5\u8be2\u64cd\u4f5c\u5c31\u662f\u627e\u5230 key \u5bf9\u5e94\u7684\u6876\uff0c\u5e76\u5728\u6876\u4e2d\u83b7\u53d6 value \u3002

        \u90a3\u4e48\uff0c\u5982\u4f55\u57fa\u4e8e key \u5b9a\u4f4d\u5bf9\u5e94\u7684\u6876\u5462\uff1f\u8fd9\u662f\u901a\u8fc7\u300c\u54c8\u5e0c\u51fd\u6570 hash function\u300d\u5b9e\u73b0\u7684\u3002\u54c8\u5e0c\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u4e00\u4e2a\u8f83\u5927\u7684\u8f93\u5165\u7a7a\u95f4\u6620\u5c04\u5230\u4e00\u4e2a\u8f83\u5c0f\u7684\u8f93\u51fa\u7a7a\u95f4\u3002\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u8f93\u5165\u7a7a\u95f4\u662f\u6240\u6709 key \uff0c\u8f93\u51fa\u7a7a\u95f4\u662f\u6240\u6709\u6876\uff08\u6570\u7ec4\u7d22\u5f15\uff09\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8f93\u5165\u4e00\u4e2a key \uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u5f97\u5230\u8be5 key \u5bf9\u5e94\u7684\u952e\u503c\u5bf9\u5728\u6570\u7ec4\u4e2d\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002

        \u8f93\u5165\u4e00\u4e2a key \uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u8ba1\u7b97\u8fc7\u7a0b\u5206\u4e3a\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u901a\u8fc7\u67d0\u79cd\u54c8\u5e0c\u7b97\u6cd5 hash() \u8ba1\u7b97\u5f97\u5230\u54c8\u5e0c\u503c\u3002
        2. \u5c06\u54c8\u5e0c\u503c\u5bf9\u6876\u6570\u91cf\uff08\u6570\u7ec4\u957f\u5ea6\uff09capacity \u53d6\u6a21\uff0c\u4ece\u800c\u83b7\u53d6\u8be5 key \u5bf9\u5e94\u7684\u6570\u7ec4\u7d22\u5f15 index \u3002
        index = hash(key) % capacity\n

        \u968f\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5229\u7528 index \u5728\u54c8\u5e0c\u8868\u4e2d\u8bbf\u95ee\u5bf9\u5e94\u7684\u6876\uff0c\u4ece\u800c\u83b7\u53d6 value \u3002

        \u8bbe\u6570\u7ec4\u957f\u5ea6 capacity = 100\u3001\u54c8\u5e0c\u7b97\u6cd5 hash(key) = key \uff0c\u6613\u5f97\u54c8\u5e0c\u51fd\u6570\u4e3a key % 100 \u3002\u56fe 6-2 \u4ee5 key \u5b66\u53f7\u548c value \u59d3\u540d\u4e3a\u4f8b\uff0c\u5c55\u793a\u4e86\u54c8\u5e0c\u51fd\u6570\u7684\u5de5\u4f5c\u539f\u7406\u3002

        \u56fe 6-2 \u00a0 \u54c8\u5e0c\u51fd\u6570\u5de5\u4f5c\u539f\u7406

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u54c8\u5e0c\u8868\u3002\u5176\u4e2d\uff0c\u6211\u4eec\u5c06 key \u548c value \u5c01\u88c5\u6210\u4e00\u4e2a\u7c7b Pair \uff0c\u4ee5\u8868\u793a\u952e\u503c\u5bf9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_hash_map.py
        class Pair:\n\"\"\"\u952e\u503c\u5bf9\"\"\"\ndef __init__(self, key: int, val: str):\nself.key = key\nself.val = val\nclass ArrayHashMap:\n\"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nself.buckets: list[Pair | None] = [None] * 100\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nindex = key % 100\nreturn index\ndef get(self, key: int) -> str:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\nindex: int = self.hash_func(key)\npair: Pair = self.buckets[index]\nif pair is None:\nreturn None\nreturn pair.val\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\npair = Pair(key, val)\nindex: int = self.hash_func(key)\nself.buckets[index] = pair\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\nindex: int = self.hash_func(key)\n# \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\nself.buckets[index] = None\ndef entry_set(self) -> list[Pair]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\"\"\"\nresult: list[Pair] = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair)\nreturn result\ndef key_set(self) -> list[int]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u952e\"\"\"\nresult = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair.key)\nreturn result\ndef value_set(self) -> list[str]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u503c\"\"\"\nresult = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair.val)\nreturn result\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor pair in self.buckets:\nif pair is not None:\nprint(pair.key, \"->\", pair.val)\n
        array_hash_map.cpp
        /* \u952e\u503c\u5bf9 */\nstruct Pair {\npublic:\nint key;\nstring val;\nPair(int key, string val) {\nthis->key = key;\nthis->val = val;\n}\n};\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate:\nvector<Pair *> buckets;\npublic:\nArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = vector<Pair *>(100);\n}\n~ArrayHashMap() {\n// \u91ca\u653e\u5185\u5b58\nfor (const auto &bucket : buckets) {\ndelete bucket;\n}\nbuckets.clear();\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\nint index = hashFunc(key);\nPair *pair = buckets[index];\nif (pair == nullptr)\nreturn \"\";\nreturn pair->val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\nPair *pair = new Pair(key, val);\nint index = hashFunc(key);\nbuckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\n// \u91ca\u653e\u5185\u5b58\u5e76\u7f6e\u4e3a nullptr\ndelete buckets[index];\nbuckets[index] = nullptr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvector<Pair *> pairSet() {\nvector<Pair *> pairSet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\npairSet.push_back(pair);\n}\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvector<int> keySet() {\nvector<int> keySet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\nkeySet.push_back(pair->key);\n}\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvector<string> valueSet() {\nvector<string> valueSet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\nvalueSet.push_back(pair->val);\n}\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (Pair *kv : pairSet()) {\ncout << kv->key << \" -> \" << kv->val << endl;\n}\n}\n};\n
        array_hash_map.java
        /* \u952e\u503c\u5bf9 */\nclass Pair {\npublic int key;\npublic String val;\npublic Pair(int key, String val) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate List<Pair> buckets;\npublic ArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = new ArrayList<>();\nfor (int i = 0; i < 100; i++) {\nbuckets.add(null);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate int hashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic String get(int key) {\nint index = hashFunc(key);\nPair pair = buckets.get(index);\nif (pair == null)\nreturn null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void put(int key, String val) {\nPair pair = new Pair(key, val);\nint index = hashFunc(key);\nbuckets.set(index, pair);\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void remove(int key) {\nint index = hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nbuckets.set(index, null);\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic List<Pair> pairSet() {\nList<Pair> pairSet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\npairSet.add(pair);\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic List<Integer> keySet() {\nList<Integer> keySet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\nkeySet.add(pair.key);\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic List<String> valueSet() {\nList<String> valueSet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\nvalueSet.add(pair.val);\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void print() {\nfor (Pair kv : pairSet()) {\nSystem.out.println(kv.key + \" -> \" + kv.val);\n}\n}\n}\n
        array_hash_map.cs
        /* \u952e\u503c\u5bf9 int->string */\nclass Pair(int key, string val) {\npublic int key = key;\npublic string val = val;\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nList<Pair?> buckets;\npublic ArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = [];\nfor (int i = 0; i < 100; i++) {\nbuckets.Add(null);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\nint index = HashFunc(key);\nPair? pair = buckets[index];\nif (pair == null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\nPair pair = new(key, val);\nint index = HashFunc(key);\nbuckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\nint index = HashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nbuckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic List<Pair> PairSet() {\nList<Pair> pairSet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\npairSet.Add(pair);\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic List<int> KeySet() {\nList<int> keySet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\nkeySet.Add(pair.key);\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic List<string> ValueSet() {\nList<string> valueSet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\nvalueSet.Add(pair.val);\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (Pair kv in PairSet()) {\nConsole.WriteLine(kv.key + \" -> \" + kv.val);\n}\n}\n}\n
        array_hash_map.go
        /* \u952e\u503c\u5bf9 */\ntype pair struct {\nkey int\nval string\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntype arrayHashMap struct {\nbuckets []*pair\n}\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nfunc newArrayHashMap() *arrayHashMap {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets := make([]*pair, 100)\nreturn &arrayHashMap{buckets: buckets}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (a *arrayHashMap) hashFunc(key int) int {\nindex := key % 100\nreturn index\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (a *arrayHashMap) get(key int) string {\nindex := a.hashFunc(key)\npair := a.buckets[index]\nif pair == nil {\nreturn \"Not Found\"\n}\nreturn pair.val\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (a *arrayHashMap) put(key int, val string) {\npair := &pair{key: key, val: val}\nindex := a.hashFunc(key)\na.buckets[index] = pair\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (a *arrayHashMap) remove(key int) {\nindex := a.hashFunc(key)\n// \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\na.buckets[index] = nil\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u5bf9 */\nfunc (a *arrayHashMap) pairSet() []*pair {\nvar pairs []*pair\nfor _, pair := range a.buckets {\nif pair != nil {\npairs = append(pairs, pair)\n}\n}\nreturn pairs\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc (a *arrayHashMap) keySet() []int {\nvar keys []int\nfor _, pair := range a.buckets {\nif pair != nil {\nkeys = append(keys, pair.key)\n}\n}\nreturn keys\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc (a *arrayHashMap) valueSet() []string {\nvar values []string\nfor _, pair := range a.buckets {\nif pair != nil {\nvalues = append(values, pair.val)\n}\n}\nreturn values\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (a *arrayHashMap) print() {\nfor _, pair := range a.buckets {\nif pair != nil {\nfmt.Println(pair.key, \"->\", pair.val)\n}\n}\n}\n
        array_hash_map.swift
        /* \u952e\u503c\u5bf9 */\nclass Pair: Equatable {\npublic var key: Int\npublic var val: String\npublic init(key: Int, val: String) {\nself.key = key\nself.val = val\n}\npublic static func == (lhs: Pair, rhs: Pair) -> Bool {\nlhs.key == rhs.key && lhs.val == rhs.val\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate var buckets: [Pair?] = []\ninit() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nfor _ in 0 ..< 100 {\nbuckets.append(nil)\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate func hashFunc(key: Int) -> Int {\nlet index = key % 100\nreturn index\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\nlet index = hashFunc(key: key)\nlet pair = buckets[index]\nreturn pair?.val\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\nlet pair = Pair(key: key, val: val)\nlet index = hashFunc(key: key)\nbuckets[index] = pair\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\nlet index = hashFunc(key: key)\n// \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\nbuckets[index] = nil\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nfunc pairSet() -> [Pair] {\nvar pairSet: [Pair] = []\nfor pair in buckets {\nif let pair = pair {\npairSet.append(pair)\n}\n}\nreturn pairSet\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc keySet() -> [Int] {\nvar keySet: [Int] = []\nfor pair in buckets {\nif let pair = pair {\nkeySet.append(pair.key)\n}\n}\nreturn keySet\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc valueSet() -> [String] {\nvar valueSet: [String] = []\nfor pair in buckets {\nif let pair = pair {\nvalueSet.append(pair.val)\n}\n}\nreturn valueSet\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor pair in pairSet() {\nSwift.print(\"\\(pair.key) -> \\(pair.val)\")\n}\n}\n}\n
        array_hash_map.js
        /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\nconstructor(key, val) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n#buckets;\nconstructor() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nthis.#buckets = new Array(100).fill(null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % 100;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\nlet index = this.#hashFunc(key);\nlet pair = this.#buckets[index];\nif (pair === null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nset(key, val) {\nlet index = this.#hashFunc(key);\nthis.#buckets[index] = new Pair(key, val);\n}\n/* \u5220\u9664\u64cd\u4f5c */\ndelete(key) {\nlet index = this.#hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nthis.#buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nentries() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i]);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nkeys() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i].key);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvalues() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i].val);\n}\n}\nreturn arr;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nlet pairSet = this.entries();\nfor (const pair of pairSet) {\nconsole.info(`${pair.key} -> ${pair.val}`);\n}\n}\n}\n
        array_hash_map.ts
        /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\npublic key: number;\npublic val: string;\nconstructor(key: number, val: string) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate readonly buckets: (Pair | null)[];\nconstructor() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nthis.buckets = new Array(100).fill(null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate hashFunc(key: number): number {\nreturn key % 100;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic get(key: number): string | null {\nlet index = this.hashFunc(key);\nlet pair = this.buckets[index];\nif (pair === null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic set(key: number, val: string) {\nlet index = this.hashFunc(key);\nthis.buckets[index] = new Pair(key, val);\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic delete(key: number) {\nlet index = this.hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nthis.buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic entries(): (Pair | null)[] {\nlet arr: (Pair | null)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i]);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic keys(): (number | undefined)[] {\nlet arr: (number | undefined)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i].key);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic values(): (string | undefined)[] {\nlet arr: (string | undefined)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i].val);\n}\n}\nreturn arr;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic print() {\nlet pairSet = this.entries();\nfor (const pair of pairSet) {\nconsole.info(`${pair.key} -> ${pair.val}`);\n}\n}\n}\n
        array_hash_map.dart
        /* \u952e\u503c\u5bf9 */\nclass Pair {\nint key;\nString val;\nPair(this.key, this.val);\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nlate List<Pair?> _buckets;\nArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n_buckets = List.filled(100, null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint _hashFunc(int key) {\nfinal int index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\nfinal int index = _hashFunc(key);\nfinal Pair? pair = _buckets[index];\nif (pair == null) {\nreturn null;\n}\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\nfinal Pair pair = Pair(key, val);\nfinal int index = _hashFunc(key);\n_buckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nfinal int index = _hashFunc(key);\n_buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nList<Pair> pairSet() {\nList<Pair> pairSet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\npairSet.add(pair);\n}\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nList<int> keySet() {\nList<int> keySet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\nkeySet.add(pair.key);\n}\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nList<String> values() {\nList<String> valueSet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\nvalueSet.add(pair.val);\n}\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (final Pair kv in pairSet()) {\nprint(\"${kv.key} -> ${kv.val}\");\n}\n}\n}\n
        array_hash_map.rs
        /* \u952e\u503c\u5bf9 */\n#[derive(Debug, Clone, PartialEq)]\npub struct Pair {\npub key: i32,\npub val: String,\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\npub struct ArrayHashMap {\nbuckets: Vec<Option<Pair>>\n}\nimpl ArrayHashMap {\npub fn new() -> ArrayHashMap {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nSelf { buckets: vec![None; 100] }\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\nkey as usize % 100\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npub fn get(&self, key: i32) -> Option<&String> {\nlet index = self.hash_func(key);\nself.buckets[index].as_ref().map(|pair| &pair.val)\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npub fn put(&mut self, key: i32, val: &str) {\nlet index = self.hash_func(key);\nself.buckets[index] = Some(Pair {\nkey,\nval: val.to_string(),\n});\n}\n/* \u5220\u9664\u64cd\u4f5c */\npub fn remove(&mut self, key: i32) {\nlet index = self.hash_func(key);\n// \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\nself.buckets[index] = None;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npub fn entry_set(&self) -> Vec<&Pair> {\nself.buckets.iter().filter_map(|pair| pair.as_ref()).collect()\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npub fn key_set(&self) -> Vec<&i32> {\nself.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.key)).collect()\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npub fn value_set(&self) -> Vec<&String> {\nself.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.val)).collect()\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npub fn print(&self) {\nfor pair in self.entry_set() {\nprintln!(\"{} -> {}\", pair.key, pair.val);\n}\n}\n}\n
        array_hash_map.c
        /* \u952e\u503c\u5bf9 int->string */\ntypedef struct {\nint key;\nchar *val;\n} Pair;\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntypedef struct {\nPair *buckets[HASHTABLE_CAPACITY];\n} ArrayHashMap;\n/* \u6784\u9020\u51fd\u6570 */\nArrayHashMap *newArrayHashMap() {\nArrayHashMap *hmap = malloc(sizeof(ArrayHashMap));\nreturn hmap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayHashMap(ArrayHashMap *hmap) {\nfor (int i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nfree(hmap->buckets[i]->val);\nfree(hmap->buckets[i]);\n}\n}\nfree(hmap);\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(ArrayHashMap *hmap, const int key, const char *val) {\nPair *Pair = malloc(sizeof(Pair));\nPair->key = key;\nPair->val = malloc(strlen(val) + 1);\nstrcpy(Pair->val, val);\nint index = hashFunc(key);\nhmap->buckets[index] = Pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(ArrayHashMap *hmap, const int key) {\nint index = hashFunc(key);\nfree(hmap->buckets[index]->val);\nfree(hmap->buckets[index]);\nhmap->buckets[index] = NULL;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvoid pairSet(ArrayHashMap *hmap, MapSet *set) {\nPair *entries;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nentries = malloc(sizeof(Pair) * total);\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nentries[index].key = hmap->buckets[i]->key;\nentries[index].val = malloc(strlen(hmap->buckets[i]->val) + 1);\nstrcpy(entries[index].val, hmap->buckets[i]->val);\nindex++;\n}\n}\nset->set = entries;\nset->len = total;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvoid keySet(ArrayHashMap *hmap, MapSet *set) {\nint *keys;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nkeys = malloc(total * sizeof(int));\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nkeys[index] = hmap->buckets[i]->key;\nindex++;\n}\n}\nset->set = keys;\nset->len = total;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvoid valueSet(ArrayHashMap *hmap, MapSet *set) {\nchar **vals;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nvals = malloc(total * sizeof(char *));\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nvals[index] = hmap->buckets[i]->val;\nindex++;\n}\n}\nset->set = vals;\nset->len = total;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(ArrayHashMap *hmap) {\nint i;\nMapSet set;\npairSet(hmap, &set);\nPair *entries = (Pair *)set.set;\nfor (i = 0; i < set.len; i++) {\nprintf(\"%d -> %s\\n\", entries[i].key, entries[i].val);\n}\nfree(set.set);\n}\n
        array_hash_map.zig
        // \u952e\u503c\u5bf9\nconst Pair = struct {\nkey: usize = undefined,\nval: []const u8 = undefined,\npub fn init(key: usize, val: []const u8) Pair {\nreturn Pair {\n.key = key,\n.val = val,\n};\n}\n};\n// \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\nfn ArrayHashMap(comptime T: type) type {\nreturn struct {\nbucket: ?std.ArrayList(?T) = null,\nmem_allocator: std.mem.Allocator = undefined,\nconst Self = @This();\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nself.mem_allocator = allocator;\n// \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 100 \u7684\u6876\uff08\u6570\u7ec4\uff09\nself.bucket = std.ArrayList(?T).init(self.mem_allocator);\nvar i: i32 = 0;\nwhile (i < 100) : (i += 1) {\ntry self.bucket.?.append(null);\n}\n}\n// \u6790\u6784\u51fd\u6570\npub fn deinit(self: *Self) void {\nif (self.bucket != null) self.bucket.?.deinit();\n}\n// \u54c8\u5e0c\u51fd\u6570\nfn hashFunc(key: usize) usize {\nvar index = key % 100;\nreturn index;\n}\n// \u67e5\u8be2\u64cd\u4f5c\npub fn get(self: *Self, key: usize) []const u8 {\nvar index = hashFunc(key);\nvar pair = self.bucket.?.items[index];\nreturn pair.?.val;\n}\n// \u6dfb\u52a0\u64cd\u4f5c\npub fn put(self: *Self, key: usize, val: []const u8) !void {\nvar pair = Pair.init(key, val);\nvar index = hashFunc(key);\nself.bucket.?.items[index] = pair;\n}\n// \u5220\u9664\u64cd\u4f5c\npub fn remove(self: *Self, key: usize) !void {\nvar index = hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nself.bucket.?.items[index] = null;\n}       // \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\npub fn pairSet(self: *Self) !std.ArrayList(T) {\nvar entry_set = std.ArrayList(T).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry entry_set.append(item.?);\n}\nreturn entry_set;\n}  // \u83b7\u53d6\u6240\u6709\u952e\npub fn keySet(self: *Self) !std.ArrayList(usize) {\nvar key_set = std.ArrayList(usize).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry key_set.append(item.?.key);\n}\nreturn key_set;\n}  // \u83b7\u53d6\u6240\u6709\u503c\npub fn valueSet(self: *Self) !std.ArrayList([]const u8) {\nvar value_set = std.ArrayList([]const u8).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry value_set.append(item.?.val);\n}\nreturn value_set;\n}\n// \u6253\u5370\u54c8\u5e0c\u8868\npub fn print(self: *Self) !void {\nvar entry_set = try self.pairSet();\ndefer entry_set.deinit();\nfor (entry_set.items) |item| {\nstd.debug.print(\"{} -> {s}\\n\", .{item.key, item.val});\n}\n}\n};\n}\n
        "},{"location":"chapter_hashing/hash_map/#613","title":"6.1.3 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u4e0e\u6269\u5bb9","text":"

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u6240\u6709 key \u6784\u6210\u7684\u8f93\u5165\u7a7a\u95f4\u6620\u5c04\u5230\u6570\u7ec4\u6240\u6709\u7d22\u5f15\u6784\u6210\u7684\u8f93\u51fa\u7a7a\u95f4\uff0c\u800c\u8f93\u5165\u7a7a\u95f4\u5f80\u5f80\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u7406\u8bba\u4e0a\u4e00\u5b9a\u5b58\u5728\u201c\u591a\u4e2a\u8f93\u5165\u5bf9\u5e94\u76f8\u540c\u8f93\u51fa\u201d\u7684\u60c5\u51b5\u3002

        \u5bf9\u4e8e\u4e0a\u8ff0\u793a\u4f8b\u4e2d\u7684\u54c8\u5e0c\u51fd\u6570\uff0c\u5f53\u8f93\u5165\u7684 key \u540e\u4e24\u4f4d\u76f8\u540c\u65f6\uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u8f93\u51fa\u7ed3\u679c\u4e5f\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u67e5\u8be2\u5b66\u53f7\u4e3a 12836 \u548c 20336 \u7684\u4e24\u4e2a\u5b66\u751f\u65f6\uff0c\u6211\u4eec\u5f97\u5230\uff1a

        12836 % 100 = 36\n20336 % 100 = 36\n

        \u5982\u56fe 6-3 \u6240\u793a\uff0c\u4e24\u4e2a\u5b66\u53f7\u6307\u5411\u4e86\u540c\u4e00\u4e2a\u59d3\u540d\uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u5bf9\u7684\u3002\u6211\u4eec\u5c06\u8fd9\u79cd\u591a\u4e2a\u8f93\u5165\u5bf9\u5e94\u540c\u4e00\u8f93\u51fa\u7684\u60c5\u51b5\u79f0\u4e3a\u300c\u54c8\u5e0c\u51b2\u7a81 hash collision\u300d\u3002

        \u56fe 6-3 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u793a\u4f8b

        \u5bb9\u6613\u60f3\u5230\uff0c\u54c8\u5e0c\u8868\u5bb9\u91cf \\(n\\) \u8d8a\u5927\uff0c\u591a\u4e2a key \u88ab\u5206\u914d\u5230\u540c\u4e00\u4e2a\u6876\u4e2d\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\uff0c\u51b2\u7a81\u5c31\u8d8a\u5c11\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6269\u5bb9\u54c8\u5e0c\u8868\u6765\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u3002

        \u5982\u56fe 6-4 \u6240\u793a\uff0c\u6269\u5bb9\u524d\u952e\u503c\u5bf9 (136, A) \u548c (236, D) \u53d1\u751f\u51b2\u7a81\uff0c\u6269\u5bb9\u540e\u51b2\u7a81\u6d88\u5931\u3002

        \u56fe 6-4 \u00a0 \u54c8\u5e0c\u8868\u6269\u5bb9

        \u7c7b\u4f3c\u4e8e\u6570\u7ec4\u6269\u5bb9\uff0c\u54c8\u5e0c\u8868\u6269\u5bb9\u9700\u5c06\u6240\u6709\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u8fc1\u79fb\u81f3\u65b0\u54c8\u5e0c\u8868\uff0c\u975e\u5e38\u8017\u65f6\uff1b\u5e76\u4e14\u7531\u4e8e\u54c8\u5e0c\u8868\u5bb9\u91cf capacity \u6539\u53d8\uff0c\u6211\u4eec\u9700\u8981\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u6765\u91cd\u65b0\u8ba1\u7b97\u6240\u6709\u952e\u503c\u5bf9\u7684\u5b58\u50a8\u4f4d\u7f6e\uff0c\u8fd9\u8fdb\u4e00\u6b65\u63d0\u9ad8\u4e86\u6269\u5bb9\u8fc7\u7a0b\u7684\u8ba1\u7b97\u5f00\u9500\u3002\u4e3a\u6b64\uff0c\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u9884\u7559\u8db3\u591f\u5927\u7684\u54c8\u5e0c\u8868\u5bb9\u91cf\uff0c\u9632\u6b62\u9891\u7e41\u6269\u5bb9\u3002

        \u300c\u8d1f\u8f7d\u56e0\u5b50 load factor\u300d\u662f\u54c8\u5e0c\u8868\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u5176\u5b9a\u4e49\u4e3a\u54c8\u5e0c\u8868\u7684\u5143\u7d20\u6570\u91cf\u9664\u4ee5\u6876\u6570\u91cf\uff0c\u7528\u4e8e\u8861\u91cf\u54c8\u5e0c\u51b2\u7a81\u7684\u4e25\u91cd\u7a0b\u5ea6\uff0c\u4e5f\u5e38\u4f5c\u4e3a\u54c8\u5e0c\u8868\u6269\u5bb9\u7684\u89e6\u53d1\u6761\u4ef6\u3002\u4f8b\u5982\u5728 Java \u4e2d\uff0c\u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7 \\(0.75\\) \u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c06\u54c8\u5e0c\u8868\u6269\u5bb9\u81f3\u539f\u5148\u7684 \\(2\\) \u500d\u3002

        "},{"location":"chapter_hashing/summary/","title":"6.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_hashing/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u8f93\u5165 key \uff0c\u54c8\u5e0c\u8868\u80fd\u591f\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u67e5\u8be2\u5230 value \uff0c\u6548\u7387\u975e\u5e38\u9ad8\u3002
        • \u5e38\u89c1\u7684\u54c8\u5e0c\u8868\u64cd\u4f5c\u5305\u62ec\u67e5\u8be2\u3001\u6dfb\u52a0\u952e\u503c\u5bf9\u3001\u5220\u9664\u952e\u503c\u5bf9\u548c\u904d\u5386\u54c8\u5e0c\u8868\u7b49\u3002
        • \u54c8\u5e0c\u51fd\u6570\u5c06 key \u6620\u5c04\u4e3a\u6570\u7ec4\u7d22\u5f15\uff0c\u4ece\u800c\u8bbf\u95ee\u5bf9\u5e94\u6876\u5e76\u83b7\u53d6 value \u3002
        • \u4e24\u4e2a\u4e0d\u540c\u7684 key \u53ef\u80fd\u5728\u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u540e\u5f97\u5230\u76f8\u540c\u7684\u6570\u7ec4\u7d22\u5f15\uff0c\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u51fa\u9519\uff0c\u8fd9\u79cd\u73b0\u8c61\u88ab\u79f0\u4e3a\u54c8\u5e0c\u51b2\u7a81\u3002
        • \u54c8\u5e0c\u8868\u5bb9\u91cf\u8d8a\u5927\uff0c\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\u3002\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7\u6269\u5bb9\u54c8\u5e0c\u8868\u6765\u7f13\u89e3\u54c8\u5e0c\u51b2\u7a81\u3002\u4e0e\u6570\u7ec4\u6269\u5bb9\u7c7b\u4f3c\uff0c\u54c8\u5e0c\u8868\u6269\u5bb9\u64cd\u4f5c\u7684\u5f00\u9500\u5f88\u5927\u3002
        • \u8d1f\u8f7d\u56e0\u5b50\u5b9a\u4e49\u4e3a\u54c8\u5e0c\u8868\u4e2d\u5143\u7d20\u6570\u91cf\u9664\u4ee5\u6876\u6570\u91cf\uff0c\u53cd\u6620\u4e86\u54c8\u5e0c\u51b2\u7a81\u7684\u4e25\u91cd\u7a0b\u5ea6\uff0c\u5e38\u7528\u4f5c\u89e6\u53d1\u54c8\u5e0c\u8868\u6269\u5bb9\u7684\u6761\u4ef6\u3002
        • \u94fe\u5f0f\u5730\u5740\u901a\u8fc7\u5c06\u5355\u4e2a\u5143\u7d20\u8f6c\u5316\u4e3a\u94fe\u8868\uff0c\u5c06\u6240\u6709\u51b2\u7a81\u5143\u7d20\u5b58\u50a8\u5728\u540c\u4e00\u4e2a\u94fe\u8868\u4e2d\u3002\u7136\u800c\uff0c\u94fe\u8868\u8fc7\u957f\u4f1a\u964d\u4f4e\u67e5\u8be2\u6548\u7387\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fdb\u4e00\u6b65\u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u6765\u63d0\u9ad8\u6548\u7387\u3002
        • \u5f00\u653e\u5bfb\u5740\u901a\u8fc7\u591a\u6b21\u63a2\u6d4b\u6765\u5904\u7406\u54c8\u5e0c\u51b2\u7a81\u3002\u7ebf\u6027\u63a2\u6d4b\u4f7f\u7528\u56fa\u5b9a\u6b65\u957f\uff0c\u7f3a\u70b9\u662f\u4e0d\u80fd\u5220\u9664\u5143\u7d20\uff0c\u4e14\u5bb9\u6613\u4ea7\u751f\u805a\u96c6\u3002\u591a\u6b21\u54c8\u5e0c\u4f7f\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u8fdb\u884c\u63a2\u6d4b\uff0c\u76f8\u8f83\u7ebf\u6027\u63a2\u6d4b\u66f4\u4e0d\u6613\u4ea7\u751f\u805a\u96c6\uff0c\u4f46\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u589e\u52a0\u4e86\u8ba1\u7b97\u91cf\u3002
        • \u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u3002\u4f8b\u5982\uff0cJava \u7684 HashMap \u4f7f\u7528\u94fe\u5f0f\u5730\u5740\uff0c\u800c Python \u7684 Dict \u91c7\u7528\u5f00\u653e\u5bfb\u5740\u3002
        • \u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u54c8\u5e0c\u7b97\u6cd5\u5177\u6709\u786e\u5b9a\u6027\u3001\u9ad8\u6548\u7387\u548c\u5747\u5300\u5206\u5e03\u7684\u7279\u70b9\u3002\u5728\u5bc6\u7801\u5b66\u4e2d\uff0c\u54c8\u5e0c\u7b97\u6cd5\u8fd8\u5e94\u8be5\u5177\u5907\u6297\u78b0\u649e\u6027\u548c\u96ea\u5d29\u6548\u5e94\u3002
        • \u54c8\u5e0c\u7b97\u6cd5\u901a\u5e38\u91c7\u7528\u5927\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u4ee5\u6700\u5927\u5316\u5730\u4fdd\u8bc1\u54c8\u5e0c\u503c\u5747\u5300\u5206\u5e03\uff0c\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u3002
        • \u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5\u5305\u62ec MD5\u3001SHA-1\u3001SHA-2 \u548c SHA-3 \u7b49\u3002MD5 \u5e38\u7528\u4e8e\u6821\u9a8c\u6587\u4ef6\u5b8c\u6574\u6027\uff0cSHA-2 \u5e38\u7528\u4e8e\u5b89\u5168\u5e94\u7528\u4e0e\u534f\u8bae\u3002
        • \u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u4e3a\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u7b97\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u54c8\u5e0c\u8868\u4e2d\u7684\u6876\u7d22\u5f15\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u4e0d\u53ef\u53d8\u5bf9\u8c61\u662f\u53ef\u54c8\u5e0c\u7684\u3002
        "},{"location":"chapter_hashing/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u4ec0\u4e48\u4e0d\u662f \\(O(n)\\) \uff1f

        \u5f53\u54c8\u5e0c\u51b2\u7a81\u6bd4\u8f83\u4e25\u91cd\u65f6\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u9000\u5316\u81f3 \\(O(n)\\) \u3002\u5f53\u54c8\u5e0c\u51fd\u6570\u8bbe\u8ba1\u5f97\u6bd4\u8f83\u597d\u3001\u5bb9\u91cf\u8bbe\u7f6e\u6bd4\u8f83\u5408\u7406\u3001\u51b2\u7a81\u6bd4\u8f83\u5e73\u5747\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002\u6211\u4eec\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u7684\u54c8\u5e0c\u8868\u65f6\uff0c\u901a\u5e38\u8ba4\u4e3a\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002

        \u4e3a\u4ec0\u4e48\u4e0d\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570 \\(f(x) = x\\) \u5462\uff1f\u8fd9\u6837\u5c31\u4e0d\u4f1a\u6709\u51b2\u7a81\u4e86

        \u5728 \\(f(x) = x\\) \u54c8\u5e0c\u51fd\u6570\u4e0b\uff0c\u6bcf\u4e2a\u5143\u7d20\u5bf9\u5e94\u552f\u4e00\u7684\u6876\u7d22\u5f15\uff0c\u8fd9\u4e0e\u6570\u7ec4\u7b49\u4ef7\u3002\u7136\u800c\uff0c\u8f93\u5165\u7a7a\u95f4\u901a\u5e38\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\uff08\u6570\u7ec4\u957f\u5ea6\uff09\uff0c\u56e0\u6b64\u54c8\u5e0c\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u5f80\u5f80\u662f\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u54c8\u5e0c\u8868\u7684\u76ee\u6807\u662f\u5c06\u4e00\u4e2a\u8f83\u5927\u7684\u72b6\u6001\u7a7a\u95f4\u6620\u5c04\u5230\u4e00\u4e2a\u8f83\u5c0f\u7684\u7a7a\u95f4\uff0c\u5e76\u63d0\u4f9b \\(O(1)\\) \u7684\u67e5\u8be2\u6548\u7387\u3002

        \u54c8\u5e0c\u8868\u5e95\u5c42\u5b9e\u73b0\u662f\u6570\u7ec4\u3001\u94fe\u8868\u3001\u4e8c\u53c9\u6811\uff0c\u4f46\u4e3a\u4ec0\u4e48\u6548\u7387\u53ef\u4ee5\u6bd4\u5b83\u4eec\u66f4\u9ad8\u5462\uff1f

        \u9996\u5148\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u6548\u7387\u53d8\u9ad8\uff0c\u4f46\u7a7a\u95f4\u6548\u7387\u53d8\u4f4e\u4e86\u3002\u54c8\u5e0c\u8868\u6709\u76f8\u5f53\u4e00\u90e8\u5206\u5185\u5b58\u672a\u4f7f\u7528\u3002

        \u5176\u6b21\uff0c\u53ea\u662f\u5728\u7279\u5b9a\u4f7f\u7528\u573a\u666f\u4e0b\u65f6\u95f4\u6548\u7387\u53d8\u9ad8\u4e86\u3002\u5982\u679c\u4e00\u4e2a\u529f\u80fd\u80fd\u591f\u5728\u76f8\u540c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u4f7f\u7528\u6570\u7ec4\u6216\u94fe\u8868\u5b9e\u73b0\uff0c\u90a3\u4e48\u901a\u5e38\u6bd4\u54c8\u5e0c\u8868\u66f4\u5feb\u3002\u8fd9\u662f\u56e0\u4e3a\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u9700\u8981\u5f00\u9500\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u5e38\u6570\u9879\u66f4\u5927\u3002

        \u6700\u540e\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u80fd\u53d1\u751f\u52a3\u5316\u3002\u4f8b\u5982\u5728\u94fe\u5f0f\u5730\u5740\u4e2d\uff0c\u6211\u4eec\u91c7\u53d6\u5728\u94fe\u8868\u6216\u7ea2\u9ed1\u6811\u4e2d\u6267\u884c\u67e5\u627e\u64cd\u4f5c\uff0c\u4ecd\u7136\u6709\u9000\u5316\u81f3 \\(O(n)\\) \u65f6\u95f4\u7684\u98ce\u9669\u3002

        \u591a\u6b21\u54c8\u5e0c\u6709\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u7684\u7f3a\u9677\u5417\uff1f\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u7a7a\u95f4\u8fd8\u80fd\u518d\u6b21\u4f7f\u7528\u5417\uff1f

        \u591a\u6b21\u54c8\u5e0c\u662f\u5f00\u653e\u5bfb\u5740\u7684\u4e00\u79cd\uff0c\u5f00\u653e\u5bfb\u5740\u6cd5\u90fd\u6709\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u7684\u7f3a\u9677\uff0c\u9700\u8981\u901a\u8fc7\u6807\u8bb0\u5220\u9664\u3002\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u7a7a\u95f4\u53ef\u4ee5\u518d\u6b21\u4f7f\u7528\u3002\u5f53\u5c06\u65b0\u5143\u7d20\u63d2\u5165\u54c8\u5e0c\u8868\uff0c\u5e76\u4e14\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u627e\u5230\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u4f4d\u7f6e\u65f6\uff0c\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u88ab\u65b0\u5143\u7d20\u4f7f\u7528\u3002\u8fd9\u6837\u505a\u65e2\u80fd\u4fdd\u6301\u54c8\u5e0c\u8868\u7684\u63a2\u6d4b\u5e8f\u5217\u4e0d\u53d8\uff0c\u53c8\u80fd\u4fdd\u8bc1\u54c8\u5e0c\u8868\u7684\u7a7a\u95f4\u4f7f\u7528\u7387\u3002

        \u4e3a\u4ec0\u4e48\u5728\u7ebf\u6027\u63a2\u6d4b\u4e2d\uff0c\u67e5\u627e\u5143\u7d20\u7684\u65f6\u5019\u4f1a\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81\u5462\uff1f

        \u67e5\u627e\u7684\u65f6\u5019\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u627e\u5230\u5bf9\u5e94\u7684\u6876\u548c\u952e\u503c\u5bf9\uff0c\u53d1\u73b0 key \u4e0d\u5339\u914d\uff0c\u8fd9\u5c31\u4ee3\u8868\u6709\u54c8\u5e0c\u51b2\u7a81\u3002\u56e0\u6b64\uff0c\u7ebf\u6027\u63a2\u6d4b\u6cd5\u4f1a\u6839\u636e\u9884\u5148\u8bbe\u5b9a\u7684\u6b65\u957f\u4f9d\u6b21\u5411\u4e0b\u67e5\u627e\uff0c\u76f4\u81f3\u627e\u5230\u6b63\u786e\u7684\u952e\u503c\u5bf9\u6216\u65e0\u6cd5\u627e\u5230\u8df3\u51fa\u4e3a\u6b62\u3002

        \u4e3a\u4ec0\u4e48\u54c8\u5e0c\u8868\u6269\u5bb9\u80fd\u591f\u7f13\u89e3\u54c8\u5e0c\u51b2\u7a81\uff1f

        \u54c8\u5e0c\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u5f80\u5f80\u662f\u5bf9\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u53d6\u4f59\uff0c\u8ba9\u8f93\u51fa\u503c\u843d\u5728\u6570\u7ec4\u7d22\u5f15\u8303\u56f4\u5185\uff1b\u5728\u6269\u5bb9\u540e\uff0c\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u53d1\u751f\u53d8\u5316\uff0c\u800c key \u5bf9\u5e94\u7684\u7d22\u5f15\u4e5f\u53ef\u80fd\u53d1\u751f\u53d8\u5316\u3002\u539f\u5148\u843d\u5728\u540c\u4e00\u4e2a\u6876\u7684\u591a\u4e2a key \uff0c\u5728\u6269\u5bb9\u540e\u53ef\u80fd\u4f1a\u88ab\u5206\u914d\u5230\u591a\u4e2a\u6876\u4e2d\uff0c\u4ece\u800c\u5b9e\u73b0\u54c8\u5e0c\u51b2\u7a81\u7684\u7f13\u89e3\u3002

        "},{"location":"chapter_heap/","title":"\u7b2c 8 \u7ae0 \u00a0 \u5806","text":"

        Abstract

        \u5806\u5c31\u50cf\u662f\u5c71\u5cb3\u5cf0\u5ce6\uff0c\u5c42\u53e0\u8d77\u4f0f\u3001\u5f62\u6001\u5404\u5f02\u3002

        \u5ea7\u5ea7\u5c71\u5cf0\u9ad8\u4f4e\u9519\u843d\uff0c\u800c\u6700\u9ad8\u7684\u5c71\u5cf0\u603b\u662f\u6700\u5148\u6620\u5165\u773c\u5e18\u3002

        "},{"location":"chapter_heap/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 8.1 \u00a0 \u5806
        • 8.2 \u00a0 \u5efa\u5806\u64cd\u4f5c
        • 8.3 \u00a0 Top-K \u95ee\u9898
        • 8.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_heap/build_heap/","title":"8.2 \u00a0 \u5efa\u5806\u64cd\u4f5c","text":"

        \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u4f7f\u7528\u4e00\u4e2a\u5217\u8868\u7684\u6240\u6709\u5143\u7d20\u6765\u6784\u5efa\u4e00\u4e2a\u5806\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u88ab\u79f0\u4e3a\u201c\u5efa\u5806\u64cd\u4f5c\u201d\u3002

        "},{"location":"chapter_heap/build_heap/#821","title":"8.2.1 \u00a0 \u501f\u52a9\u5165\u5806\u64cd\u4f5c\u5b9e\u73b0","text":"

        \u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u5806\uff0c\u7136\u540e\u904d\u5386\u5217\u8868\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e2a\u5143\u7d20\u6267\u884c\u201c\u5165\u5806\u64cd\u4f5c\u201d\uff0c\u5373\u5148\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u5806\u7684\u5c3e\u90e8\uff0c\u518d\u5bf9\u8be5\u5143\u7d20\u6267\u884c\u201c\u4ece\u5e95\u81f3\u9876\u201d\u5806\u5316\u3002

        \u6bcf\u5f53\u4e00\u4e2a\u5143\u7d20\u5165\u5806\uff0c\u5806\u7684\u957f\u5ea6\u5c31\u52a0\u4e00\u3002\u7531\u4e8e\u8282\u70b9\u662f\u4ece\u9876\u5230\u5e95\u4f9d\u6b21\u88ab\u6dfb\u52a0\u8fdb\u4e8c\u53c9\u6811\u7684\uff0c\u56e0\u6b64\u5806\u662f\u201c\u81ea\u4e0a\u800c\u4e0b\u201d\u6784\u5efa\u7684\u3002

        \u8bbe\u5143\u7d20\u6570\u91cf\u4e3a \\(n\\) \uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u5165\u5806\u64cd\u4f5c\u4f7f\u7528 \\(O(\\log{n})\\) \u65f6\u95f4\uff0c\u56e0\u6b64\u8be5\u5efa\u5806\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        "},{"location":"chapter_heap/build_heap/#822","title":"8.2.2 \u00a0 \u901a\u8fc7\u904d\u5386\u5806\u5316\u5b9e\u73b0","text":"

        \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u79cd\u66f4\u4e3a\u9ad8\u6548\u7684\u5efa\u5806\u65b9\u6cd5\uff0c\u5171\u5206\u4e3a\u4e24\u6b65\u3002

        1. \u5c06\u5217\u8868\u6240\u6709\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u5230\u5806\u4e2d\uff0c\u6b64\u65f6\u5806\u7684\u6027\u8d28\u5c1a\u672a\u5f97\u5230\u6ee1\u8db3\u3002
        2. \u5012\u5e8f\u904d\u5386\u5806\uff08\u5373\u5c42\u5e8f\u904d\u5386\u7684\u5012\u5e8f\uff09\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u6267\u884c\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u3002

        \u6bcf\u5f53\u5806\u5316\u4e00\u4e2a\u8282\u70b9\u540e\uff0c\u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u5c31\u5f62\u6210\u4e00\u4e2a\u5408\u6cd5\u7684\u5b50\u5806\u3002\u800c\u7531\u4e8e\u662f\u5012\u5e8f\u904d\u5386\uff0c\u56e0\u6b64\u5806\u662f\u201c\u81ea\u4e0b\u800c\u4e0a\u201d\u6784\u5efa\u7684\u3002

        \u4e4b\u6240\u4ee5\u9009\u62e9\u5012\u5e8f\u904d\u5386\uff0c\u662f\u56e0\u4e3a\u8fd9\u6837\u80fd\u591f\u4fdd\u8bc1\u5f53\u524d\u8282\u70b9\u4e4b\u4e0b\u7684\u5b50\u6811\u5df2\u7ecf\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\u8fd9\u6837\u5806\u5316\u5f53\u524d\u8282\u70b9\u624d\u662f\u6709\u6548\u7684\u3002

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u53f6\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5929\u7136\u5c31\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\u56e0\u6b64\u65e0\u987b\u5806\u5316\u3002\u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u6700\u540e\u4e00\u4e2a\u975e\u53f6\u8282\u70b9\u662f\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9\uff0c\u6211\u4eec\u4ece\u5b83\u5f00\u59cb\u5012\u5e8f\u904d\u5386\u5e76\u6267\u884c\u5806\u5316\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def __init__(self, nums: list[int]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806\"\"\"\n# \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nself.max_heap = nums\n# \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in range(self.parent(self.size() - 1), -1, -1):\nself.sift_down(i)\n
        my_heap.cpp
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(vector<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = nums;\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.java
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(List<Integer> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = new ArrayList<>(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.cs
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(IEnumerable<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = new List<int>(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nvar size = Parent(this.Size() - 1);\nfor (int i = size; i >= 0; i--) {\nSiftDown(i);\n}\n}\n
        my_heap.go
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u5207\u7247\u5efa\u5806 */\nfunc newMaxHeap(nums []any) *maxHeap {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nh := &maxHeap{data: nums}\nfor i := h.parent(len(h.data) - 1); i >= 0; i-- {\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nh.siftDown(i)\n}\nreturn h\n}\n
        my_heap.swift
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\ninit(nums: [Int]) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = nums\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in stride(from: parent(i: size() - 1), through: 0, by: -1) {\nsiftDown(i: i)\n}\n}\n
        my_heap.js
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u5efa\u7acb\u7a7a\u5806\u6216\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nconstructor(nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nthis.#maxHeap = nums === undefined ? [] : [...nums];\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = this.#parent(this.size() - 1); i >= 0; i--) {\nthis.#siftDown(i);\n}\n}\n
        my_heap.ts
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u5efa\u7acb\u7a7a\u5806\u6216\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nconstructor(nums?: number[]) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nthis.maxHeap = nums === undefined ? [] : [...nums];\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = this.parent(this.size() - 1); i >= 0; i--) {\nthis.siftDown(i);\n}\n}\n
        my_heap.dart
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(List<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\n_maxHeap = nums;\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = _parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.rs
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nfn new(nums: Vec<i32>) -> Self {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nlet mut heap = MaxHeap { max_heap: nums };\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in (0..=Self::parent(heap.size() - 1)).rev() {\nheap.sift_down(i);\n}\nheap\n}\n
        my_heap.c
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u5207\u7247\u5efa\u5806 */\nMaxHeap *newMaxHeap(int nums[], int size) {\n// \u6240\u6709\u5143\u7d20\u5165\u5806\nMaxHeap *maxHeap = (MaxHeap *)malloc(sizeof(MaxHeap));\nmaxHeap->size = size;\nmemcpy(maxHeap->data, nums, size * sizeof(int));\nfor (int i = parent(maxHeap, size - 1); i >= 0; i--) {\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nsiftDown(maxHeap, i);\n}\nreturn maxHeap;\n}\n
        my_heap.zig
        // \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806\nfn init(self: *Self, allocator: std.mem.Allocator, nums: []const T) !void {\nif (self.max_heap != null) return;\nself.max_heap = std.ArrayList(T).init(allocator);\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\ntry self.max_heap.?.appendSlice(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nvar i: usize = parent(self.size() - 1) + 1;\nwhile (i > 0) : (i -= 1) {\ntry self.siftDown(i - 1);\n}\n}\n
        "},{"location":"chapter_heap/build_heap/#823","title":"8.2.3 \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u4e0b\u9762\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u63a8\u7b97\u7b2c\u4e8c\u79cd\u5efa\u5806\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        • \u5047\u8bbe\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u5219\u53f6\u8282\u70b9\u6570\u91cf\u4e3a \\((n + 1) / 2\\) \uff0c\u5176\u4e2d \\(/\\) \u4e3a\u5411\u4e0b\u6574\u9664\u3002\u56e0\u6b64\u9700\u8981\u5806\u5316\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\((n - 1) / 2\\) \u3002
        • \u5728\u4ece\u9876\u81f3\u5e95\u5806\u5316\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u6700\u591a\u5806\u5316\u5230\u53f6\u8282\u70b9\uff0c\u56e0\u6b64\u6700\u5927\u8fed\u4ee3\u6b21\u6570\u4e3a\u4e8c\u53c9\u6811\u9ad8\u5ea6 \\(\\log n\\) \u3002

        \u5c06\u4e0a\u8ff0\u4e24\u8005\u76f8\u4e58\uff0c\u53ef\u5f97\u5230\u5efa\u5806\u8fc7\u7a0b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u4f46\u8fd9\u4e2a\u4f30\u7b97\u7ed3\u679c\u5e76\u4e0d\u51c6\u786e\uff0c\u56e0\u4e3a\u6211\u4eec\u6ca1\u6709\u8003\u8651\u5230\u4e8c\u53c9\u6811\u5e95\u5c42\u8282\u70b9\u6570\u91cf\u8fdc\u591a\u4e8e\u9876\u5c42\u8282\u70b9\u7684\u6027\u8d28\u3002

        \u63a5\u4e0b\u6765\u6211\u4eec\u6765\u8fdb\u884c\u66f4\u4e3a\u51c6\u786e\u7684\u8ba1\u7b97\u3002\u4e3a\u4e86\u964d\u4f4e\u8ba1\u7b97\u96be\u5ea6\uff0c\u5047\u8bbe\u7ed9\u5b9a\u4e00\u4e2a\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \u3001\u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u201c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u201d\uff0c\u8be5\u5047\u8bbe\u4e0d\u4f1a\u5f71\u54cd\u8ba1\u7b97\u7ed3\u679c\u7684\u6b63\u786e\u6027\u3002

        \u56fe 8-5 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u5404\u5c42\u8282\u70b9\u6570\u91cf

        \u5982\u56fe 8-5 \u6240\u793a\uff0c\u8282\u70b9\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u7684\u6700\u5927\u8fed\u4ee3\u6b21\u6570\u7b49\u4e8e\u8be5\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u800c\u8be5\u8ddd\u79bb\u6b63\u662f\u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5404\u5c42\u7684\u201c\u8282\u70b9\u6570\u91cf \\(\\times\\) \u8282\u70b9\u9ad8\u5ea6\u201d\u6c42\u548c\uff0c\u5f97\u5230\u6240\u6709\u8282\u70b9\u7684\u5806\u5316\u8fed\u4ee3\u6b21\u6570\u7684\u603b\u548c\u3002

        \\[ T(h) = 2^0h + 2^1(h-1) + 2^2(h-2) + \\dots + 2^{(h-1)}\\times1 \\]

        \u5316\u7b80\u4e0a\u5f0f\u9700\u8981\u501f\u52a9\u4e2d\u5b66\u7684\u6570\u5217\u77e5\u8bc6\uff0c\u5148\u5bf9 \\(T(h)\\) \u4e58\u4ee5 \\(2\\) \uff0c\u5f97\u5230\uff1a

        \\[ \\begin{aligned} T(h) & = 2^0h + 2^1(h-1) + 2^2(h-2) + \\dots + 2^{h-1}\\times1 \\newline 2 T(h) & = 2^1h + 2^2(h-1) + 2^3(h-2) + \\dots + 2^{h}\\times1 \\newline \\end{aligned} \\]

        \u4f7f\u7528\u9519\u4f4d\u76f8\u51cf\u6cd5\uff0c\u7528\u4e0b\u5f0f \\(2 T(h)\\) \u51cf\u53bb\u4e0a\u5f0f \\(T(h)\\) \uff0c\u53ef\u5f97\uff1a

        \\[ 2T(h) - T(h) = T(h) = -2^0h + 2^1 + 2^2 + \\dots + 2^{h-1} + 2^h \\]

        \u89c2\u5bdf\u4e0a\u5f0f\uff0c\u53d1\u73b0 \\(T(h)\\) \u662f\u4e00\u4e2a\u7b49\u6bd4\u6570\u5217\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\u6c42\u548c\u516c\u5f0f\uff0c\u5f97\u5230\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\uff1a

        \\[ \\begin{aligned} T(h) & = 2 \\frac{1 - 2^h}{1 - 2} - h \\newline & = 2^{h+1} - h - 2 \\newline & = O(2^h) \\end{aligned} \\]

        \u8fdb\u4e00\u6b65\u5730\uff0c\u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n = 2^{h+1} - 1\\) \uff0c\u6613\u5f97\u590d\u6742\u5ea6\u4e3a \\(O(2^h) = O(n)\\) \u3002\u4ee5\u4e0a\u63a8\u7b97\u8868\u660e\uff0c\u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002

        "},{"location":"chapter_heap/heap/","title":"8.1 \u00a0 \u5806","text":"

        \u300c\u5806 heap\u300d\u662f\u4e00\u79cd\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u4e3b\u8981\u53ef\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff0c\u5982\u56fe 8-1 \u6240\u793a\u3002

        • \u300c\u5927\u9876\u5806 max heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\geq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002
        • \u300c\u5c0f\u9876\u5806 min heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\leq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002

        \u56fe 8-1 \u00a0 \u5c0f\u9876\u5806\u4e0e\u5927\u9876\u5806

        \u5806\u4f5c\u4e3a\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a\u7279\u4f8b\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u6700\u5e95\u5c42\u8282\u70b9\u9760\u5de6\u586b\u5145\uff0c\u5176\u4ed6\u5c42\u7684\u8282\u70b9\u90fd\u88ab\u586b\u6ee1\u3002
        • \u6211\u4eec\u5c06\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u79f0\u4e3a\u201c\u5806\u9876\u201d\uff0c\u5c06\u5e95\u5c42\u6700\u9760\u53f3\u7684\u8282\u70b9\u79f0\u4e3a\u201c\u5806\u5e95\u201d\u3002
        • \u5bf9\u4e8e\u5927\u9876\u5806\uff08\u5c0f\u9876\u5806\uff09\uff0c\u5806\u9876\u5143\u7d20\uff08\u6839\u8282\u70b9\uff09\u7684\u503c\u5206\u522b\u662f\u6700\u5927\uff08\u6700\u5c0f\uff09\u7684\u3002
        "},{"location":"chapter_heap/heap/#811","title":"8.1.1 \u00a0 \u5806\u5e38\u7528\u64cd\u4f5c","text":"

        \u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684\u662f\u300c\u4f18\u5148\u961f\u5217 priority queue\u300d\uff0c\u8fd9\u662f\u4e00\u79cd\u62bd\u8c61\u6570\u636e\u7ed3\u6784\uff0c\u5b9a\u4e49\u4e3a\u5177\u6709\u4f18\u5148\u7ea7\u6392\u5e8f\u7684\u961f\u5217\u3002

        \u5b9e\u9645\u4e0a\uff0c\u5806\u901a\u5e38\u7528\u4e8e\u5b9e\u73b0\u4f18\u5148\u961f\u5217\uff0c\u5927\u9876\u5806\u76f8\u5f53\u4e8e\u5143\u7d20\u6309\u4ece\u5927\u5230\u5c0f\u7684\u987a\u5e8f\u51fa\u961f\u7684\u4f18\u5148\u961f\u5217\u3002\u4ece\u4f7f\u7528\u89d2\u5ea6\u6765\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u201c\u4f18\u5148\u961f\u5217\u201d\u548c\u201c\u5806\u201d\u770b\u4f5c\u7b49\u4ef7\u7684\u6570\u636e\u7ed3\u6784\u3002\u56e0\u6b64\uff0c\u672c\u4e66\u5bf9\u4e24\u8005\u4e0d\u505a\u7279\u522b\u533a\u5206\uff0c\u7edf\u4e00\u79f0\u4f5c\u201c\u5806\u201d\u3002

        \u5806\u7684\u5e38\u7528\u64cd\u4f5c\u89c1\u8868 8-1 \uff0c\u65b9\u6cd5\u540d\u9700\u8981\u6839\u636e\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002

        \u8868 8-1 \u00a0 \u5806\u7684\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u5806 \\(O(\\log n)\\) pop() \u5806\u9876\u5143\u7d20\u51fa\u5806 \\(O(\\log n)\\) peek() \u8bbf\u95ee\u5806\u9876\u5143\u7d20\uff08\u5927 / \u5c0f\u9876\u5806\u5206\u522b\u4e3a\u6700\u5927 / \u5c0f\u503c\uff09 \\(O(1)\\) size() \u83b7\u53d6\u5806\u7684\u5143\u7d20\u6570\u91cf \\(O(1)\\) isEmpty() \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a \\(O(1)\\)

        \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684\u5806\u7c7b\uff08\u6216\u4f18\u5148\u961f\u5217\u7c7b\uff09\u3002

        \u7c7b\u4f3c\u4e8e\u6392\u5e8f\u7b97\u6cd5\u4e2d\u7684\u201c\u4ece\u5c0f\u5230\u5927\u6392\u5217\u201d\u548c\u201c\u4ece\u5927\u5230\u5c0f\u6392\u5217\u201d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e00\u4e2a flag \u6216\u4fee\u6539 Comparator \u5b9e\u73b0\u201c\u5c0f\u9876\u5806\u201d\u4e0e\u201c\u5927\u9876\u5806\u201d\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig heap.py
        # \u521d\u59cb\u5316\u5c0f\u9876\u5806\nmin_heap, flag = [], 1\n# \u521d\u59cb\u5316\u5927\u9876\u5806\nmax_heap, flag = [], -1\n# Python \u7684 heapq \u6a21\u5757\u9ed8\u8ba4\u5b9e\u73b0\u5c0f\u9876\u5806\n# \u8003\u8651\u5c06\u201c\u5143\u7d20\u53d6\u8d1f\u201d\u540e\u518d\u5165\u5806\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5c06\u5927\u5c0f\u5173\u7cfb\u98a0\u5012\uff0c\u4ece\u800c\u5b9e\u73b0\u5927\u9876\u5806\n# \u5728\u672c\u793a\u4f8b\u4e2d\uff0cflag = 1 \u65f6\u5bf9\u5e94\u5c0f\u9876\u5806\uff0cflag = -1 \u65f6\u5bf9\u5e94\u5927\u9876\u5806\n# \u5143\u7d20\u5165\u5806\nheapq.heappush(max_heap, flag * 1)\nheapq.heappush(max_heap, flag * 3)\nheapq.heappush(max_heap, flag * 2)\nheapq.heappush(max_heap, flag * 5)\nheapq.heappush(max_heap, flag * 4)\n# \u83b7\u53d6\u5806\u9876\u5143\u7d20\npeek: int = flag * max_heap[0] # 5\n# \u5806\u9876\u5143\u7d20\u51fa\u5806\n# \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nval = flag * heapq.heappop(max_heap) # 5\nval = flag * heapq.heappop(max_heap) # 4\nval = flag * heapq.heappop(max_heap) # 3\nval = flag * heapq.heappop(max_heap) # 2\nval = flag * heapq.heappop(max_heap) # 1\n# \u83b7\u53d6\u5806\u5927\u5c0f\nsize: int = len(max_heap)\n# \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = not max_heap\n# \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806\nmin_heap: list[int] = [1, 3, 2, 5, 4]\nheapq.heapify(min_heap)\n
        heap.cpp
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\npriority_queue<int, vector<int>, greater<int>> minHeap;\n// \u521d\u59cb\u5316\u5927\u9876\u5806\npriority_queue<int, vector<int>, less<int>> maxHeap;\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.push(1);\nmaxHeap.push(3);\nmaxHeap.push(2);\nmaxHeap.push(5);\nmaxHeap.push(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.top(); // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nmaxHeap.pop(); // 5\nmaxHeap.pop(); // 4\nmaxHeap.pop(); // 3\nmaxHeap.pop(); // 2\nmaxHeap.pop(); // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.empty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nvector<int> input{1, 3, 2, 5, 4};\npriority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end());\n
        heap.java
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nQueue<Integer> minHeap = new PriorityQueue<>();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\uff08\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4fee\u6539 Comparator \u5373\u53ef\uff09\nQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.offer(1);\nmaxHeap.offer(3);\nmaxHeap.offer(2);\nmaxHeap.offer(5);\nmaxHeap.offer(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.peek(); // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\npeek = maxHeap.poll(); // 5\npeek = maxHeap.poll(); // 4\npeek = maxHeap.poll(); // 3\npeek = maxHeap.poll(); // 2\npeek = maxHeap.poll(); // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = maxHeap.isEmpty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nminHeap = new PriorityQueue<>(Arrays.asList(1, 3, 2, 5, 4));\n
        heap.cs
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nPriorityQueue<int, int> minHeap = new();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\uff08\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4fee\u6539 Comparator \u5373\u53ef\uff09\nPriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x));\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.Enqueue(1, 1);\nmaxHeap.Enqueue(3, 3);\nmaxHeap.Enqueue(2, 2);\nmaxHeap.Enqueue(5, 5);\nmaxHeap.Enqueue(4, 4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.Peek();//5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\npeek = maxHeap.Dequeue();  // 5\npeek = maxHeap.Dequeue();  // 4\npeek = maxHeap.Dequeue();  // 3\npeek = maxHeap.Dequeue();  // 2\npeek = maxHeap.Dequeue();  // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.Count;\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.Count == 0;\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nminHeap = new PriorityQueue<int, int>([(1, 1), (3, 3), (2, 2), (5, 5), (4, 4)]);\n
        heap.go
        // Go \u8bed\u8a00\u4e2d\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0 heap.Interface \u6765\u6784\u5efa\u6574\u6570\u5927\u9876\u5806\n// \u5b9e\u73b0 heap.Interface \u9700\u8981\u540c\u65f6\u5b9e\u73b0 sort.Interface\ntype intHeap []any\n// Push heap.Interface \u7684\u65b9\u6cd5\uff0c\u5b9e\u73b0\u63a8\u5165\u5143\u7d20\u5230\u5806\nfunc (h *intHeap) Push(x any) {\n// Push \u548c Pop \u4f7f\u7528 pointer receiver \u4f5c\u4e3a\u53c2\u6570\n// \u56e0\u4e3a\u5b83\u4eec\u4e0d\u4ec5\u4f1a\u5bf9\u5207\u7247\u7684\u5185\u5bb9\u8fdb\u884c\u8c03\u6574\uff0c\u8fd8\u4f1a\u4fee\u6539\u5207\u7247\u7684\u957f\u5ea6\u3002\n*h = append(*h, x.(int))\n}\n// Pop heap.Interface \u7684\u65b9\u6cd5\uff0c\u5b9e\u73b0\u5f39\u51fa\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Pop() any {\n// \u5f85\u51fa\u5806\u5143\u7d20\u5b58\u653e\u5728\u6700\u540e\nlast := (*h)[len(*h)-1]\n*h = (*h)[:len(*h)-1]\nreturn last\n}\n// Len sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Len() int {\nreturn len(*h)\n}\n// Less sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Less(i, j int) bool {\n// \u5982\u679c\u5b9e\u73b0\u5c0f\u9876\u5806\uff0c\u5219\u9700\u8981\u8c03\u6574\u4e3a\u5c0f\u4e8e\u53f7\nreturn (*h)[i].(int) > (*h)[j].(int)\n}\n// Swap sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Swap(i, j int) {\n(*h)[i], (*h)[j] = (*h)[j], (*h)[i]\n}\n// Top \u83b7\u53d6\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Top() any {\nreturn (*h)[0]\n}\n/* Driver Code */\nfunc TestHeap(t *testing.T) {\n/* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5927\u9876\u5806\nmaxHeap := &intHeap{}\nheap.Init(maxHeap)\n/* \u5143\u7d20\u5165\u5806 */\n// \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u6dfb\u52a0\u5143\u7d20\nheap.Push(maxHeap, 1)\nheap.Push(maxHeap, 3)\nheap.Push(maxHeap, 2)\nheap.Push(maxHeap, 4)\nheap.Push(maxHeap, 5)\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\ntop := maxHeap.Top()\nfmt.Printf(\"\u5806\u9876\u5143\u7d20\u4e3a %d\\n\", top)\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u79fb\u9664\u5143\u7d20\nheap.Pop(maxHeap) // 5\nheap.Pop(maxHeap) // 4\nheap.Pop(maxHeap) // 3\nheap.Pop(maxHeap) // 2\nheap.Pop(maxHeap) // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nsize := len(*maxHeap)\nfmt.Printf(\"\u5806\u5143\u7d20\u6570\u91cf\u4e3a %d\\n\", size)\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nisEmpty := len(*maxHeap) == 0\nfmt.Printf(\"\u5806\u662f\u5426\u4e3a\u7a7a %t\\n\", isEmpty)\n}\n
        heap.swift
        // Swift \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.js
        // JavaScript \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.ts
        // TypeScript \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.dart
        // Dart \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.rs
        use std::collections::BinaryHeap;\nuse std::cmp::Reverse;\n/* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nlet mut min_heap = BinaryHeap::<Reverse<i32>>::new();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\nlet mut max_heap = BinaryHeap::new();\n/* \u5143\u7d20\u5165\u5806 */\nmax_heap.push(1);\nmax_heap.push(3);\nmax_heap.push(2);\nmax_heap.push(5);\nmax_heap.push(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nlet peek = max_heap.peek().unwrap();  // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nlet peek = max_heap.pop().unwrap();   // 5\nlet peek = max_heap.pop().unwrap();   // 4\nlet peek = max_heap.pop().unwrap();   // 3\nlet peek = max_heap.pop().unwrap();   // 2\nlet peek = max_heap.pop().unwrap();   // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nlet size = max_heap.len();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = max_heap.is_empty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nlet min_heap = BinaryHeap::from(vec![Reverse(1), Reverse(3), Reverse(2), Reverse(5), Reverse(4)]);\n
        heap.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.zig
        \n
        "},{"location":"chapter_heap/heap/#812","title":"8.1.2 \u00a0 \u5806\u7684\u5b9e\u73b0","text":"

        \u4e0b\u6587\u5b9e\u73b0\u7684\u662f\u5927\u9876\u5806\u3002\u82e5\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u5c0f\u9876\u5806\uff0c\u53ea\u9700\u5c06\u6240\u6709\u5927\u5c0f\u903b\u8f91\u5224\u65ad\u53d6\u9006\uff08\u4f8b\u5982\uff0c\u5c06 \\(\\geq\\) \u66ff\u6362\u4e3a \\(\\leq\\) \uff09\u3002\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u3002

        "},{"location":"chapter_heap/heap/#1","title":"1. \u00a0 \u5806\u7684\u5b58\u50a8\u4e0e\u8868\u793a","text":"

        \u201c\u4e8c\u53c9\u6811\u201d\u7ae0\u8282\u8bb2\u8fc7\uff0c\u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u7528\u6570\u7ec4\u6765\u8868\u793a\u3002\u7531\u4e8e\u5806\u6b63\u662f\u4e00\u79cd\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u91c7\u7528\u6570\u7ec4\u6765\u5b58\u50a8\u5806\u3002

        \u5f53\u4f7f\u7528\u6570\u7ec4\u8868\u793a\u4e8c\u53c9\u6811\u65f6\uff0c\u5143\u7d20\u4ee3\u8868\u8282\u70b9\u503c\uff0c\u7d22\u5f15\u4ee3\u8868\u8282\u70b9\u5728\u4e8c\u53c9\u6811\u4e2d\u7684\u4f4d\u7f6e\u3002\u8282\u70b9\u6307\u9488\u901a\u8fc7\u7d22\u5f15\u6620\u5c04\u516c\u5f0f\u6765\u5b9e\u73b0\u3002

        \u5982\u56fe 8-2 \u6240\u793a\uff0c\u7ed9\u5b9a\u7d22\u5f15 \\(i\\) \uff0c\u5176\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 2\\) \uff0c\u7236\u8282\u70b9\u7d22\u5f15\u4e3a \\((i - 1) / 2\\)\uff08\u5411\u4e0b\u6574\u9664\uff09\u3002\u5f53\u7d22\u5f15\u8d8a\u754c\u65f6\uff0c\u8868\u793a\u7a7a\u8282\u70b9\u6216\u8282\u70b9\u4e0d\u5b58\u5728\u3002

        \u56fe 8-2 \u00a0 \u5806\u7684\u8868\u793a\u4e0e\u5b58\u50a8

        \u6211\u4eec\u53ef\u4ee5\u5c06\u7d22\u5f15\u6620\u5c04\u516c\u5f0f\u5c01\u88c5\u6210\u51fd\u6570\uff0c\u65b9\u4fbf\u540e\u7eed\u4f7f\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def left(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn 2 * i + 1\ndef right(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn 2 * i + 2\ndef parent(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn (i - 1) // 2  # \u5411\u4e0b\u6574\u9664\n
        my_heap.cpp
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.java
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.cs
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint Left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint Right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint Parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.go
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) left(i int) int {\nreturn 2*i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) right(i int) int {\nreturn 2*i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) parent(i int) int {\n// \u5411\u4e0b\u6574\u9664\nreturn (i - 1) / 2\n}\n
        my_heap.swift
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n2 * i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfunc parent(i: Int) -> Int {\n(i - 1) / 2 // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.js
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\n#left(i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\n#right(i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\n#parent(i) {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.ts
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nleft(i: number): number {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nright(i: number): number {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nparent(i: number): number {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.dart
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint _left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint _right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint _parent(int i) {\nreturn (i - 1) ~/ 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.rs
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfn left(i: usize) -> usize {\n2 * i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfn right(i: usize) -> usize {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfn parent(i: usize) -> usize {\n(i - 1) / 2 // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.c
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(MaxHeap *maxHeap, int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(MaxHeap *maxHeap, int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(MaxHeap *maxHeap, int i) {\nreturn (i - 1) / 2;\n}\n
        my_heap.zig
        // \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\nfn left(i: usize) usize {\nreturn 2 * i + 1;\n}\n// \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\nfn right(i: usize) usize {\nreturn 2 * i + 2;\n}\n// \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15\nfn parent(i: usize) usize {\n// return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\nreturn @divFloor(i - 1, 2);\n}\n
        "},{"location":"chapter_heap/heap/#2","title":"2. \u00a0 \u8bbf\u95ee\u5806\u9876\u5143\u7d20","text":"

        \u5806\u9876\u5143\u7d20\u5373\u4e3a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u4e5f\u5c31\u662f\u5217\u8868\u7684\u9996\u4e2a\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u5806\u9876\u5143\u7d20\"\"\"\nreturn self.max_heap[0]\n
        my_heap.cpp
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn maxHeap[0];\n}\n
        my_heap.java
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn maxHeap.get(0);\n}\n
        my_heap.cs
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint Peek() {\nreturn maxHeap[0];\n}\n
        my_heap.go
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc (h *maxHeap) peek() any {\nreturn h.data[0]\n}\n
        my_heap.swift
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nmaxHeap[0]\n}\n
        my_heap.js
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek() {\nreturn this.#maxHeap[0];\n}\n
        my_heap.ts
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek(): number {\nreturn this.maxHeap[0];\n}\n
        my_heap.dart
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn _maxHeap[0];\n}\n
        my_heap.rs
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<i32> {\nself.max_heap.first().copied()\n}\n
        my_heap.c
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek(MaxHeap *maxHeap) {\nreturn maxHeap->data[0];\n}\n
        my_heap.zig
        // \u8bbf\u95ee\u5806\u9876\u5143\u7d20\nfn peek(self: *Self) T {\nreturn self.max_heap.?.items[0];\n}  
        "},{"location":"chapter_heap/heap/#3","title":"3. \u00a0 \u5143\u7d20\u5165\u5806","text":"

        \u7ed9\u5b9a\u5143\u7d20 val \uff0c\u6211\u4eec\u9996\u5148\u5c06\u5176\u6dfb\u52a0\u5230\u5806\u5e95\u3002\u6dfb\u52a0\u4e4b\u540e\uff0c\u7531\u4e8e val \u53ef\u80fd\u5927\u4e8e\u5806\u4e2d\u5176\u4ed6\u5143\u7d20\uff0c\u5806\u7684\u6210\u7acb\u6761\u4ef6\u53ef\u80fd\u5df2\u88ab\u7834\u574f\uff0c\u56e0\u6b64\u9700\u8981\u4fee\u590d\u4ece\u63d2\u5165\u8282\u70b9\u5230\u6839\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u7684\u5404\u4e2a\u8282\u70b9\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u88ab\u79f0\u4e3a\u300c\u5806\u5316 heapify\u300d\u3002

        \u8003\u8651\u4ece\u5165\u5806\u8282\u70b9\u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u6267\u884c\u5806\u5316\u3002\u5982\u56fe 8-3 \u6240\u793a\uff0c\u6211\u4eec\u6bd4\u8f83\u63d2\u5165\u8282\u70b9\u4e0e\u5176\u7236\u8282\u70b9\u7684\u503c\uff0c\u5982\u679c\u63d2\u5165\u8282\u70b9\u66f4\u5927\uff0c\u5219\u5c06\u5b83\u4eec\u4ea4\u6362\u3002\u7136\u540e\u7ee7\u7eed\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4ece\u5e95\u81f3\u9876\u4fee\u590d\u5806\u4e2d\u7684\u5404\u4e2a\u8282\u70b9\uff0c\u76f4\u81f3\u8d8a\u8fc7\u6839\u8282\u70b9\u6216\u9047\u5230\u65e0\u987b\u4ea4\u6362\u7684\u8282\u70b9\u65f6\u7ed3\u675f\u3002

        <1><2><3><4><5><6><7><8><9>

        \u56fe 8-3 \u00a0 \u5143\u7d20\u5165\u5806\u6b65\u9aa4

        \u8bbe\u8282\u70b9\u603b\u6570\u4e3a \\(n\\) \uff0c\u5219\u6811\u7684\u9ad8\u5ea6\u4e3a \\(O(\\log n)\\) \u3002\u7531\u6b64\u53ef\u77e5\uff0c\u5806\u5316\u64cd\u4f5c\u7684\u5faa\u73af\u8f6e\u6570\u6700\u591a\u4e3a \\(O(\\log n)\\) \uff0c\u5143\u7d20\u5165\u5806\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def push(self, val: int):\n\"\"\"\u5143\u7d20\u5165\u5806\"\"\"\n# \u6dfb\u52a0\u8282\u70b9\nself.max_heap.append(val)\n# \u4ece\u5e95\u81f3\u9876\u5806\u5316\nself.sift_up(self.size() - 1)\ndef sift_up(self, i: int):\n\"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\"\"\"\nwhile True:\n# \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\np = self.parent(i)\n# \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 or self.max_heap[i] <= self.max_heap[p]:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, p)\n# \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n
        my_heap.cpp
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.push_back(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap[i] <= maxHeap[p])\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap[i], maxHeap[p]);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.java
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap.get(i) <= maxHeap.get(p))\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.cs
        /* \u5143\u7d20\u5165\u5806 */\nvoid Push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.Add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nSiftUp(Size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid SiftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = Parent(i);\n// \u82e5\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap[i] <= maxHeap[p])\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nSwap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.go
        /* \u5143\u7d20\u5165\u5806 */\nfunc (h *maxHeap) push(val any) {\n// \u6dfb\u52a0\u8282\u70b9\nh.data = append(h.data, val)\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nh.siftUp(len(h.data) - 1)\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc (h *maxHeap) siftUp(i int) {\nfor true {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\np := h.parent(i)\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 || h.data[i].(int) <= h.data[p].(int) {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nh.swap(i, p)\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n}\n}\n
        my_heap.swift
        /* \u5143\u7d20\u5165\u5806 */\nfunc push(val: Int) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.append(val)\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(i: size() - 1)\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc siftUp(i: Int) {\nvar i = i\nwhile true {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nlet p = parent(i: i)\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 || maxHeap[i] <= maxHeap[p] {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i: i, j: p)\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n}\n}\n
        my_heap.js
        /* \u5143\u7d20\u5165\u5806 */\npush(val) {\n// \u6dfb\u52a0\u8282\u70b9\nthis.#maxHeap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nthis.#siftUp(this.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\n#siftUp(i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nconst p = this.#parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.#swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.ts
        /* \u5143\u7d20\u5165\u5806 */\npush(val: number): void {\n// \u6dfb\u52a0\u8282\u70b9\nthis.maxHeap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nthis.siftUp(this.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nsiftUp(i: number): void {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nconst p = this.parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || this.maxHeap[i] <= this.maxHeap[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.dart
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\n_maxHeap.add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = _parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || _maxHeap[i] <= _maxHeap[p]) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n_swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.rs
        /* \u5143\u7d20\u5165\u5806 */\nfn push(&mut self, val: i32) {\n// \u6dfb\u52a0\u8282\u70b9\nself.max_heap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nself.sift_up(self.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfn sift_up(&mut self, mut i: usize) {\nloop {\n// \u8282\u70b9 i \u5df2\u7ecf\u662f\u5806\u9876\u8282\u70b9\u4e86\uff0c\u7ed3\u675f\u5806\u5316\nif i == 0 {\nbreak;\n}\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nlet p = Self::parent(i);\n// \u5f53\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif self.max_heap[i] <= self.max_heap[p] {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.c
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(MaxHeap *maxHeap, int val) {\n// \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e0d\u5e94\u8be5\u6dfb\u52a0\u8fd9\u4e48\u591a\u8282\u70b9\nif (maxHeap->size == MAX_SIZE) {\nprintf(\"heap is full!\");\nreturn;\n}\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap->data[maxHeap->size] = val;\nmaxHeap->size++;\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(maxHeap, maxHeap->size - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(MaxHeap *maxHeap, int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(maxHeap, i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap->data[i] <= maxHeap->data[p]) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap, i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.zig
        // \u5143\u7d20\u5165\u5806\nfn push(self: *Self, val: T) !void {\n// \u6dfb\u52a0\u8282\u70b9\ntry self.max_heap.?.append(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\ntry self.siftUp(self.size() - 1);\n}  // \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\nfn siftUp(self: *Self, i_: usize) !void {\nvar i = i_;\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nvar p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 or self.max_heap.?.items[i] <= self.max_heap.?.items[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\ntry self.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        "},{"location":"chapter_heap/heap/#4","title":"4. \u00a0 \u5806\u9876\u5143\u7d20\u51fa\u5806","text":"

        \u5806\u9876\u5143\u7d20\u662f\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u5373\u5217\u8868\u9996\u5143\u7d20\u3002\u5982\u679c\u6211\u4eec\u76f4\u63a5\u4ece\u5217\u8868\u4e2d\u5220\u9664\u9996\u5143\u7d20\uff0c\u90a3\u4e48\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u7d22\u5f15\u90fd\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u8fd9\u5c06\u4f7f\u5f97\u540e\u7eed\u4f7f\u7528\u5806\u5316\u8fdb\u884c\u4fee\u590d\u53d8\u5f97\u56f0\u96be\u3002\u4e3a\u4e86\u5c3d\u91cf\u51cf\u5c11\u5143\u7d20\u7d22\u5f15\u7684\u53d8\u52a8\uff0c\u6211\u4eec\u91c7\u7528\u4ee5\u4e0b\u64cd\u4f5c\u6b65\u9aa4\u3002

        1. \u4ea4\u6362\u5806\u9876\u5143\u7d20\u4e0e\u5806\u5e95\u5143\u7d20\uff08\u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff09\u3002
        2. \u4ea4\u6362\u5b8c\u6210\u540e\uff0c\u5c06\u5806\u5e95\u4ece\u5217\u8868\u4e2d\u5220\u9664\uff08\u6ce8\u610f\uff0c\u7531\u4e8e\u5df2\u7ecf\u4ea4\u6362\uff0c\u56e0\u6b64\u5b9e\u9645\u4e0a\u5220\u9664\u7684\u662f\u539f\u6765\u7684\u5806\u9876\u5143\u7d20\uff09\u3002
        3. \u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u6267\u884c\u5806\u5316\u3002

        \u5982\u56fe 8-4 \u6240\u793a\uff0c\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u7684\u64cd\u4f5c\u65b9\u5411\u4e0e\u201c\u4ece\u5e95\u81f3\u9876\u5806\u5316\u201d\u76f8\u53cd\uff0c\u6211\u4eec\u5c06\u6839\u8282\u70b9\u7684\u503c\u4e0e\u5176\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u5c06\u6700\u5927\u7684\u5b50\u8282\u70b9\u4e0e\u6839\u8282\u70b9\u4ea4\u6362\u3002\u7136\u540e\u5faa\u73af\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u76f4\u5230\u8d8a\u8fc7\u53f6\u8282\u70b9\u6216\u9047\u5230\u65e0\u987b\u4ea4\u6362\u7684\u8282\u70b9\u65f6\u7ed3\u675f\u3002

        <1><2><3><4><5><6><7><8><9><10>

        \u56fe 8-4 \u00a0 \u5806\u9876\u5143\u7d20\u51fa\u5806\u6b65\u9aa4

        \u4e0e\u5143\u7d20\u5165\u5806\u64cd\u4f5c\u76f8\u4f3c\uff0c\u5806\u9876\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u4e3a \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def pop(self) -> int:\n\"\"\"\u5143\u7d20\u51fa\u5806\"\"\"\n# \u5224\u7a7a\u5904\u7406\nif self.is_empty():\nraise IndexError(\"\u5806\u4e3a\u7a7a\")\n# \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nself.swap(0, self.size() - 1)\n# \u5220\u9664\u8282\u70b9\nval = self.max_heap.pop()\n# \u4ece\u9876\u81f3\u5e95\u5806\u5316\nself.sift_down(0)\n# \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\ndef sift_down(self, i: int):\n\"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\nwhile True:\n# \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl, r, ma = self.left(i), self.right(i), i\nif l < self.size() and self.max_heap[l] > self.max_heap[ma]:\nma = l\nif r < self.size() and self.max_heap[r] > self.max_heap[ma]:\nma = r\n# \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, ma)\n# \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n
        my_heap.cpp
        /* \u5143\u7d20\u51fa\u5806 */\nvoid pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty()) {\nthrow out_of_range(\"\u5806\u4e3a\u7a7a\");\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(maxHeap[0], maxHeap[size() - 1]);\n// \u5220\u9664\u8282\u70b9\nmaxHeap.pop_back();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = left(i), r = right(i), ma = i;\nif (l < size() && maxHeap[l] > maxHeap[ma])\nma = l;\nif (r < size() && maxHeap[r] > maxHeap[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\nswap(maxHeap[i], maxHeap[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.java
        /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(0, size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap.remove(size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = left(i), r = right(i), ma = i;\nif (l < size() && maxHeap.get(l) > maxHeap.get(ma))\nma = l;\nif (r < size() && maxHeap.get(r) > maxHeap.get(ma))\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.cs
        /* \u5143\u7d20\u51fa\u5806 */\nint Pop() {\n// \u5224\u7a7a\u5904\u7406\nif (IsEmpty())\nthrow new IndexOutOfRangeException();\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nSwap(0, Size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap.Last();\nmaxHeap.RemoveAt(Size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nSiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = Left(i), r = Right(i), ma = i;\nif (l < Size() && maxHeap[l] > maxHeap[ma])\nma = l;\nif (r < Size() && maxHeap[r] > maxHeap[ma])\nma = r;\n// \u82e5\u201c\u8282\u70b9 i \u6700\u5927\u201d\u6216\u201c\u8d8a\u8fc7\u53f6\u8282\u70b9\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nSwap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.go
        /* \u5143\u7d20\u51fa\u5806 */\nfunc (h *maxHeap) pop() any {\n// \u5224\u7a7a\u5904\u7406\nif h.isEmpty() {\nfmt.Println(\"error\")\nreturn nil\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nh.swap(0, h.size()-1)\n// \u5220\u9664\u8282\u70b9\nval := h.data[len(h.data)-1]\nh.data = h.data[:len(h.data)-1]\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nh.siftDown(0)\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc (h *maxHeap) siftDown(i int) {\nfor true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\nl, r, max := h.left(i), h.right(i), i\nif l < h.size() && h.data[l].(int) > h.data[max].(int) {\nmax = l\n}\nif r < h.size() && h.data[r].(int) > h.data[max].(int) {\nmax = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif max == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nh.swap(i, max)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = max\n}\n}\n
        my_heap.swift
        /* \u5143\u7d20\u51fa\u5806 */\nfunc pop() -> Int {\n// \u5224\u7a7a\u5904\u7406\nif isEmpty() {\nfatalError(\"\u5806\u4e3a\u7a7a\")\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(i: 0, j: size() - 1)\n// \u5220\u9664\u8282\u70b9\nlet val = maxHeap.remove(at: size() - 1)\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(i: 0)\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(i: Int) {\nvar i = i\nwhile true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = left(i: i)\nlet r = right(i: i)\nvar ma = i\nif l < size(), maxHeap[l] > maxHeap[ma] {\nma = l\n}\nif r < size(), maxHeap[r] > maxHeap[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i: i, j: ma)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n
        my_heap.js
        /* \u5143\u7d20\u51fa\u5806 */\npop() {\n// \u5224\u7a7a\u5904\u7406\nif (this.isEmpty()) throw new Error('\u5806\u4e3a\u7a7a');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nthis.#swap(0, this.size() - 1);\n// \u5220\u9664\u8282\u70b9\nconst val = this.#maxHeap.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nthis.#siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\n#siftDown(i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nconst l = this.#left(i),\nr = this.#right(i);\nlet ma = i;\nif (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;\nif (r < this.size() && this.#maxHeap[r] > this.#maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.#swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.ts
        /* \u5143\u7d20\u51fa\u5806 */\npop(): number {\n// \u5224\u7a7a\u5904\u7406\nif (this.isEmpty()) throw new RangeError('Heap is empty.');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nthis.swap(0, this.size() - 1);\n// \u5220\u9664\u8282\u70b9\nconst val = this.maxHeap.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nthis.siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nsiftDown(i: number): void {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nconst l = this.left(i),\nr = this.right(i);\nlet ma = i;\nif (l < this.size() && this.maxHeap[l] > this.maxHeap[ma]) ma = l;\nif (r < this.size() && this.maxHeap[r] > this.maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.dart
        /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty()) throw Exception('\u5806\u4e3a\u7a7a');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n_swap(0, size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = _maxHeap.removeLast();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = _left(i);\nint r = _right(i);\nint ma = i;\nif (l < size() && _maxHeap[l] > _maxHeap[ma]) ma = l;\nif (r < size() && _maxHeap[r] > _maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\n_swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.rs
        /* \u5143\u7d20\u51fa\u5806 */\nfn pop(&mut self) -> i32 {\n// \u5224\u7a7a\u5904\u7406\nif self.is_empty() {\npanic!(\"index out of bounds\");\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nself.swap(0, self.size() - 1);\n// \u5220\u9664\u8282\u70b9\nlet val = self.max_heap.remove(self.size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nself.sift_down(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nval\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(&mut self, mut i: usize) {\nloop {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet (l, r, mut ma) = (Self::left(i), Self::right(i), i);\nif l < self.size() && self.max_heap[l] > self.max_heap[ma] {\nma = l;\n}\nif r < self.size() && self.max_heap[r] > self.max_heap[ma] {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.c
        /* \u5143\u7d20\u51fa\u5806 */\nint pop(MaxHeap *maxHeap) {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty(maxHeap)) {\nprintf(\"heap is empty!\");\nreturn INT_MAX;\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(maxHeap, 0, size(maxHeap) - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap->data[maxHeap->size - 1];\nmaxHeap->size--;\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(maxHeap, 0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(MaxHeap *maxHeap, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\nint l = left(maxHeap, i);\nint r = right(maxHeap, i);\nint max = i;\nif (l < size(maxHeap) && maxHeap->data[l] > maxHeap->data[max]) {\nmax = l;\n}\nif (r < size(maxHeap) && maxHeap->data[r] > maxHeap->data[max]) {\nmax = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (max == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap, i, max);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = max;\n}\n}\n
        my_heap.zig
        // \u5143\u7d20\u51fa\u5806\nfn pop(self: *Self) !T {\n// \u5224\u65ad\u5904\u7406\nif (self.isEmpty()) unreachable;\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\ntry self.swap(0, self.size() - 1);\n// \u5220\u9664\u8282\u70b9\nvar val = self.max_heap.?.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\ntry self.siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n} // \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\nfn siftDown(self: *Self, i_: usize) !void {\nvar i = i_;\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nvar l = left(i);\nvar r = right(i);\nvar ma = i;\nif (l < self.size() and self.max_heap.?.items[l] > self.max_heap.?.items[ma]) ma = l;\nif (r < self.size() and self.max_heap.?.items[r] > self.max_heap.?.items[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\ntry self.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        "},{"location":"chapter_heap/heap/#813","title":"8.1.3 \u00a0 \u5806\u5e38\u89c1\u5e94\u7528","text":"
        • \u4f18\u5148\u961f\u5217\uff1a\u5806\u901a\u5e38\u4f5c\u4e3a\u5b9e\u73b0\u4f18\u5148\u961f\u5217\u7684\u9996\u9009\u6570\u636e\u7ed3\u6784\uff0c\u5176\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log n)\\) \uff0c\u800c\u5efa\u961f\u64cd\u4f5c\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u975e\u5e38\u9ad8\u6548\u3002
        • \u5806\u6392\u5e8f\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u4eec\u5efa\u7acb\u4e00\u4e2a\u5806\uff0c\u7136\u540e\u4e0d\u65ad\u5730\u6267\u884c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\uff0c\u4ece\u800c\u5f97\u5230\u6709\u5e8f\u6570\u636e\u3002\u7136\u800c\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528\u4e00\u79cd\u66f4\u4f18\u96c5\u7684\u65b9\u5f0f\u5b9e\u73b0\u5806\u6392\u5e8f\uff0c\u8be6\u89c1\u201c\u5806\u6392\u5e8f\u201d\u7ae0\u8282\u3002
        • \u83b7\u53d6\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\uff1a\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5178\u7684\u7b97\u6cd5\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u662f\u4e00\u79cd\u5178\u578b\u5e94\u7528\uff0c\u4f8b\u5982\u9009\u62e9\u70ed\u5ea6\u524d 10 \u7684\u65b0\u95fb\u4f5c\u4e3a\u5fae\u535a\u70ed\u641c\uff0c\u9009\u53d6\u9500\u91cf\u524d 10 \u7684\u5546\u54c1\u7b49\u3002
        "},{"location":"chapter_heap/summary/","title":"8.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_heap/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u5806\u662f\u4e00\u68f5\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u6839\u636e\u6210\u7acb\u6761\u4ef6\u53ef\u5206\u4e3a\u5927\u9876\u5806\u548c\u5c0f\u9876\u5806\u3002\u5927\uff08\u5c0f\uff09\u9876\u5806\u7684\u5806\u9876\u5143\u7d20\u662f\u6700\u5927\uff08\u5c0f\uff09\u7684\u3002
        • \u4f18\u5148\u961f\u5217\u7684\u5b9a\u4e49\u662f\u5177\u6709\u51fa\u961f\u4f18\u5148\u7ea7\u7684\u961f\u5217\uff0c\u901a\u5e38\u4f7f\u7528\u5806\u6765\u5b9e\u73b0\u3002
        • \u5806\u7684\u5e38\u7528\u64cd\u4f5c\u53ca\u5176\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5305\u62ec\uff1a\u5143\u7d20\u5165\u5806 \\(O(\\log n)\\)\u3001\u5806\u9876\u5143\u7d20\u51fa\u5806 \\(O(\\log n)\\) \u548c\u8bbf\u95ee\u5806\u9876\u5143\u7d20 \\(O(1)\\) \u7b49\u3002
        • \u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u7528\u6570\u7ec4\u8868\u793a\uff0c\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b58\u50a8\u5806\u3002
        • \u5806\u5316\u64cd\u4f5c\u7528\u4e8e\u7ef4\u62a4\u5806\u7684\u6027\u8d28\uff0c\u5728\u5165\u5806\u548c\u51fa\u5806\u64cd\u4f5c\u4e2d\u90fd\u4f1a\u7528\u5230\u3002
        • \u8f93\u5165 \\(n\\) \u4e2a\u5143\u7d20\u5e76\u5efa\u5806\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(n)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002
        • Top-K \u662f\u4e00\u4e2a\u7ecf\u5178\u7b97\u6cd5\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u5806\u6570\u636e\u7ed3\u6784\u9ad8\u6548\u89e3\u51b3\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log k)\\) \u3002
        "},{"location":"chapter_heap/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6570\u636e\u7ed3\u6784\u7684\u201c\u5806\u201d\u4e0e\u5185\u5b58\u7ba1\u7406\u7684\u201c\u5806\u201d\u662f\u540c\u4e00\u4e2a\u6982\u5ff5\u5417\uff1f

        \u4e24\u8005\u4e0d\u662f\u540c\u4e00\u4e2a\u6982\u5ff5\uff0c\u53ea\u662f\u78b0\u5de7\u90fd\u53eb\u5806\u3002\u8ba1\u7b97\u673a\u7cfb\u7edf\u5185\u5b58\u4e2d\u7684\u5806\u662f\u52a8\u6001\u5185\u5b58\u5206\u914d\u7684\u4e00\u90e8\u5206\uff0c\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5b58\u50a8\u6570\u636e\u3002\u7a0b\u5e8f\u53ef\u4ee5\u8bf7\u6c42\u4e00\u5b9a\u91cf\u7684\u5806\u5185\u5b58\uff0c\u7528\u4e8e\u5b58\u50a8\u5982\u5bf9\u8c61\u548c\u6570\u7ec4\u7b49\u590d\u6742\u7ed3\u6784\u3002\u5f53\u8fd9\u4e9b\u6570\u636e\u4e0d\u518d\u9700\u8981\u65f6\uff0c\u7a0b\u5e8f\u9700\u8981\u91ca\u653e\u8fd9\u4e9b\u5185\u5b58\uff0c\u4ee5\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\u3002\u76f8\u8f83\u4e8e\u6808\u5185\u5b58\uff0c\u5806\u5185\u5b58\u7684\u7ba1\u7406\u548c\u4f7f\u7528\u9700\u8981\u66f4\u8c28\u614e\uff0c\u4f7f\u7528\u4e0d\u5f53\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u548c\u91ce\u6307\u9488\u7b49\u95ee\u9898\u3002

        "},{"location":"chapter_heap/top_k/","title":"8.3 \u00a0 Top-K \u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u65e0\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u8fd4\u56de\u6570\u7ec4\u4e2d\u524d \\(k\\) \u5927\u7684\u5143\u7d20\u3002

        \u5bf9\u4e8e\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u5148\u4ecb\u7ecd\u4e24\u79cd\u601d\u8def\u6bd4\u8f83\u76f4\u63a5\u7684\u89e3\u6cd5\uff0c\u518d\u4ecb\u7ecd\u6548\u7387\u66f4\u9ad8\u7684\u5806\u89e3\u6cd5\u3002

        "},{"location":"chapter_heap/top_k/#831","title":"8.3.1 \u00a0 \u65b9\u6cd5\u4e00\uff1a\u904d\u5386\u9009\u62e9","text":"

        \u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u56fe 8-6 \u6240\u793a\u7684 \\(k\\) \u8f6e\u904d\u5386\uff0c\u5206\u522b\u5728\u6bcf\u8f6e\u4e2d\u63d0\u53d6\u7b2c \\(1\\)\u3001\\(2\\)\u3001\\(\\dots\\)\u3001\\(k\\) \u5927\u7684\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nk)\\) \u3002

        \u6b64\u65b9\u6cd5\u53ea\u9002\u7528\u4e8e \\(k \\ll n\\) \u7684\u60c5\u51b5\uff0c\u56e0\u4e3a\u5f53 \\(k\\) \u4e0e \\(n\\) \u6bd4\u8f83\u63a5\u8fd1\u65f6\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411\u4e8e \\(O(n^2)\\) \uff0c\u975e\u5e38\u8017\u65f6\u3002

        \u56fe 8-6 \u00a0 \u904d\u5386\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        Tip

        \u5f53 \\(k = n\\) \u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5b8c\u6574\u7684\u6709\u5e8f\u5e8f\u5217\uff0c\u6b64\u65f6\u7b49\u4ef7\u4e8e\u201c\u9009\u62e9\u6392\u5e8f\u201d\u7b97\u6cd5\u3002

        "},{"location":"chapter_heap/top_k/#832","title":"8.3.2 \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u6392\u5e8f","text":"

        \u5982\u56fe 8-7 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u5bf9\u6570\u7ec4 nums \u8fdb\u884c\u6392\u5e8f\uff0c\u518d\u8fd4\u56de\u6700\u53f3\u8fb9\u7684 \\(k\\) \u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u663e\u7136\uff0c\u8be5\u65b9\u6cd5\u201c\u8d85\u989d\u201d\u5b8c\u6210\u4efb\u52a1\u4e86\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u627e\u51fa\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\u5373\u53ef\uff0c\u800c\u4e0d\u9700\u8981\u6392\u5e8f\u5176\u4ed6\u5143\u7d20\u3002

        \u56fe 8-7 \u00a0 \u6392\u5e8f\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        "},{"location":"chapter_heap/top_k/#833","title":"8.3.3 \u00a0 \u65b9\u6cd5\u4e09\uff1a\u5806","text":"

        \u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u5806\u66f4\u52a0\u9ad8\u6548\u5730\u89e3\u51b3 Top-K \u95ee\u9898\uff0c\u6d41\u7a0b\u5982\u56fe 8-8 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316\u4e00\u4e2a\u5c0f\u9876\u5806\uff0c\u5176\u5806\u9876\u5143\u7d20\u6700\u5c0f\u3002
        2. \u5148\u5c06\u6570\u7ec4\u7684\u524d \\(k\\) \u4e2a\u5143\u7d20\u4f9d\u6b21\u5165\u5806\u3002
        3. \u4ece\u7b2c \\(k + 1\\) \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\uff0c\u5e76\u5c06\u5f53\u524d\u5143\u7d20\u5165\u5806\u3002
        4. \u904d\u5386\u5b8c\u6210\u540e\uff0c\u5806\u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 8-8 \u00a0 \u57fa\u4e8e\u5806\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig top_k.py
        def top_k_heap(nums: list[int], k: int) -> list[int]:\n\"\"\"\u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20\"\"\"\n# \u521d\u59cb\u5316\u5c0f\u9876\u5806\nheap = []\n# \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor i in range(k):\nheapq.heappush(heap, nums[i])\n# \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i in range(k, len(nums)):\n# \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > heap[0]:\nheapq.heappop(heap)\nheapq.heappush(heap, nums[i])\nreturn heap\n
        top_k.cpp
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\npriority_queue<int, vector<int>, greater<int>> topKHeap(vector<int> &nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\npriority_queue<int, vector<int>, greater<int>> heap;\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.push(nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.size(); i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.top()) {\nheap.pop();\nheap.push(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.java
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nQueue<Integer> topKHeap(int[] nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nQueue<Integer> heap = new PriorityQueue<Integer>();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.offer(nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.peek()) {\nheap.poll();\nheap.offer(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.cs
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nPriorityQueue<int, int> TopKHeap(int[] nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nPriorityQueue<int, int> heap = new();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.Enqueue(nums[i], nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.Length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.Peek()) {\nheap.Dequeue();\nheap.Enqueue(nums[i], nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.go
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunc topKHeap(nums []int, k int) *minHeap {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nh := &minHeap{}\nheap.Init(h)\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor i := 0; i < k; i++ {\nheap.Push(h, nums[i])\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i := k; i < len(nums); i++ {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > h.Top().(int) {\nheap.Pop(h)\nheap.Push(h, nums[i])\n}\n}\nreturn h\n}\n
        top_k.swift
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunc topKHeap(nums: [Int], k: Int) -> [Int] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5c0f\u9876\u5806\uff0c\u5e76\u5c06\u524d k \u4e2a\u5143\u7d20\u5efa\u5806\nvar heap = Heap(nums.prefix(k))\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i in stride(from: k, to: nums.count, by: 1) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > heap.min()! {\n_ = heap.removeMin()\nheap.insert(nums[i])\n}\n}\nreturn heap.unordered\n}\n
        top_k.js
        /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap, val) {\n// \u5143\u7d20\u53d6\u53cd\nmaxHeap.push(-val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.pop();\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.peek();\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn maxHeap.getMaxHeap().map((num) => -num);\n}\n/* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunction topKHeap(nums, k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nconst maxHeap = new MaxHeap([]);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (let i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (let i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\n// \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\nreturn getMinHeap(maxHeap);\n}\n
        top_k.ts
        /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap: MaxHeap, val: number): void {\n// \u5143\u7d20\u53d6\u53cd\nmaxHeap.push(-val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap: MaxHeap): number {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.pop();\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap: MaxHeap): number {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.peek();\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap: MaxHeap): number[] {\n// \u5143\u7d20\u53d6\u53cd\nreturn maxHeap.getMaxHeap().map((num: number) => -num);\n}\n/* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunction topKHeap(nums: number[], k: number): number[] {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nconst maxHeap = new MaxHeap([]);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (let i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (let i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\n// \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\nreturn getMinHeap(maxHeap);\n}\n
        top_k.dart
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nMinHeap topKHeap(List<int> nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\uff0c\u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nMinHeap heap = MinHeap(nums.sublist(0, k));\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.peek()) {\nheap.pop();\nheap.push(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.rs
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfn top_k_heap(nums: Vec<i32>, k: usize) -> BinaryHeap<Reverse<i32>> {\n// BinaryHeap \u662f\u5927\u9876\u5806\uff0c\u4f7f\u7528 Reverse \u5c06\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u5b9e\u73b0\u5c0f\u9876\u5806\nlet mut heap = BinaryHeap::<Reverse<i32>>::new();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor &num in nums.iter().take(k) {\nheap.push(Reverse(num));\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor &num in nums.iter().skip(k) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif num > heap.peek().unwrap().0 {\nheap.pop();\nheap.push(Reverse(num));\n}\n}\nheap\n}\n
        top_k.c
        /* \u5143\u7d20\u5165\u5806 */\nvoid pushMinHeap(MaxHeap *maxHeap, int val) {\n// \u5143\u7d20\u53d6\u53cd\npush(maxHeap, -val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nint popMinHeap(MaxHeap *maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -pop(maxHeap);\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peekMinHeap(MaxHeap *maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -peek(maxHeap);\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nint *getMinHeap(MaxHeap *maxHeap) {\n// \u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\u5e76\u5b58\u5165 res \u6570\u7ec4\nint *res = (int *)malloc(maxHeap->size * sizeof(int));\nfor (int i = 0; i < maxHeap->size; i++) {\nres[i] = -maxHeap->data[i];\n}\nreturn res;\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nint *getMinHeap(MaxHeap *maxHeap) {\n// \u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\u5e76\u5b58\u5165 res \u6570\u7ec4\nint *res = (int *)malloc(maxHeap->size * sizeof(int));\nfor (int i = 0; i < maxHeap->size; i++) {\nres[i] = -maxHeap->data[i];\n}\nreturn res;\n}\n// \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20\u7684\u51fd\u6570\nint *topKHeap(int *nums, int sizeNums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nint *empty = (int *)malloc(0);\nMaxHeap *maxHeap = newMaxHeap(empty, 0);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < sizeNums; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\nint *res = getMinHeap(maxHeap);\n// \u91ca\u653e\u5185\u5b58\ndelMaxHeap(maxHeap);\nreturn res;\n}\n
        top_k.zig
        [class]{}-[func]{topKHeap}\n

        \u603b\u5171\u6267\u884c\u4e86 \\(n\\) \u8f6e\u5165\u5806\u548c\u51fa\u5806\uff0c\u5806\u7684\u6700\u5927\u957f\u5ea6\u4e3a \\(k\\) \uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log k)\\) \u3002\u8be5\u65b9\u6cd5\u7684\u6548\u7387\u5f88\u9ad8\uff0c\u5f53 \\(k\\) \u8f83\u5c0f\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411 \\(O(n)\\) \uff1b\u5f53 \\(k\\) \u8f83\u5927\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 \\(O(n \\log n)\\) \u3002

        \u53e6\u5916\uff0c\u8be5\u65b9\u6cd5\u9002\u7528\u4e8e\u52a8\u6001\u6570\u636e\u6d41\u7684\u4f7f\u7528\u573a\u666f\u3002\u5728\u4e0d\u65ad\u52a0\u5165\u6570\u636e\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u6301\u7eed\u7ef4\u62a4\u5806\u5185\u7684\u5143\u7d20\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u5927 \\(k\\) \u4e2a\u5143\u7d20\u7684\u52a8\u6001\u66f4\u65b0\u3002

        "},{"location":"chapter_introduction/","title":"\u7b2c 1 \u7ae0 \u00a0 \u521d\u8bc6\u7b97\u6cd5","text":"

        Abstract

        \u4e00\u4f4d\u5c11\u5973\u7fe9\u7fe9\u8d77\u821e\uff0c\u4e0e\u6570\u636e\u4ea4\u7ec7\u5728\u4e00\u8d77\uff0c\u88d9\u6446\u4e0a\u98d8\u626c\u7740\u7b97\u6cd5\u7684\u65cb\u5f8b\u3002

        \u5979\u9080\u8bf7\u4f60\u5171\u821e\uff0c\u8bf7\u7d27\u8ddf\u5979\u7684\u6b65\u4f10\uff0c\u8e0f\u5165\u5145\u6ee1\u903b\u8f91\u4e0e\u7f8e\u611f\u7684\u7b97\u6cd5\u4e16\u754c\u3002

        "},{"location":"chapter_introduction/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 1.1 \u00a0 \u7b97\u6cd5\u65e0\u5904\u4e0d\u5728
        • 1.2 \u00a0 \u7b97\u6cd5\u662f\u4ec0\u4e48
        • 1.3 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_introduction/algorithms_are_everywhere/","title":"1.1 \u00a0 \u7b97\u6cd5\u65e0\u5904\u4e0d\u5728","text":"

        \u5f53\u6211\u4eec\u542c\u5230\u201c\u7b97\u6cd5\u201d\u8fd9\u4e2a\u8bcd\u65f6\uff0c\u5f88\u81ea\u7136\u5730\u4f1a\u60f3\u5230\u6570\u5b66\u3002\u7136\u800c\u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7b97\u6cd5\u5e76\u4e0d\u6d89\u53ca\u590d\u6742\u6570\u5b66\uff0c\u800c\u662f\u66f4\u591a\u5730\u4f9d\u8d56\u57fa\u672c\u903b\u8f91\uff0c\u8fd9\u4e9b\u903b\u8f91\u5728\u6211\u4eec\u7684\u65e5\u5e38\u751f\u6d3b\u4e2d\u5904\u5904\u53ef\u89c1\u3002

        \u5728\u6b63\u5f0f\u63a2\u8ba8\u7b97\u6cd5\u4e4b\u524d\uff0c\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u4e8b\u5b9e\u503c\u5f97\u5206\u4eab\uff1a\u4f60\u5df2\u7ecf\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u5b66\u4f1a\u4e86\u8bb8\u591a\u7b97\u6cd5\uff0c\u5e76\u4e60\u60ef\u5c06\u5b83\u4eec\u5e94\u7528\u5230\u65e5\u5e38\u751f\u6d3b\u4e2d\u4e86\u3002\u4e0b\u9762\u6211\u5c06\u4e3e\u51e0\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\u6765\u8bc1\u5b9e\u8fd9\u4e00\u70b9\u3002

        \u4f8b\u4e00\uff1a\u67e5\u9605\u5b57\u5178\u3002\u5728\u5b57\u5178\u91cc\uff0c\u6bcf\u4e2a\u6c49\u5b57\u90fd\u5bf9\u5e94\u4e00\u4e2a\u62fc\u97f3\uff0c\u800c\u5b57\u5178\u662f\u6309\u7167\u62fc\u97f3\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u7684\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u67e5\u627e\u4e00\u4e2a\u62fc\u97f3\u9996\u5b57\u6bcd\u4e3a \\(r\\) \u7684\u5b57\uff0c\u901a\u5e38\u4f1a\u6309\u7167\u56fe 1-1 \u6240\u793a\u7684\u65b9\u5f0f\u5b9e\u73b0\u3002

        1. \u7ffb\u5f00\u5b57\u5178\u7ea6\u4e00\u534a\u7684\u9875\u6570\uff0c\u67e5\u770b\u8be5\u9875\u7684\u9996\u5b57\u6bcd\u662f\u4ec0\u4e48\uff0c\u5047\u8bbe\u9996\u5b57\u6bcd\u4e3a \\(m\\) \u3002
        2. \u7531\u4e8e\u5728\u62fc\u97f3\u5b57\u6bcd\u8868\u4e2d \\(r\\) \u4f4d\u4e8e \\(m\\) \u4e4b\u540e\uff0c\u6240\u4ee5\u6392\u9664\u5b57\u5178\u524d\u534a\u90e8\u5206\uff0c\u67e5\u627e\u8303\u56f4\u7f29\u5c0f\u5230\u540e\u534a\u90e8\u5206\u3002
        3. \u4e0d\u65ad\u91cd\u590d\u6b65\u9aa4 1. \u548c \u6b65\u9aa4 2. \uff0c\u76f4\u81f3\u627e\u5230\u62fc\u97f3\u9996\u5b57\u6bcd\u4e3a \\(r\\) \u7684\u9875\u7801\u4e3a\u6b62\u3002
        <1><2><3><4><5>

        \u56fe 1-1 \u00a0 \u67e5\u5b57\u5178\u6b65\u9aa4

        \u67e5\u5b57\u5178\u8fd9\u4e2a\u5c0f\u5b66\u751f\u5fc5\u5907\u6280\u80fd\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u8457\u540d\u7684\u201c\u4e8c\u5206\u67e5\u627e\u201d\u7b97\u6cd5\u3002\u4ece\u6570\u636e\u7ed3\u6784\u7684\u89d2\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u5178\u89c6\u4e3a\u4e00\u4e2a\u5df2\u6392\u5e8f\u7684\u201c\u6570\u7ec4\u201d\uff1b\u4ece\u7b97\u6cd5\u7684\u89d2\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u67e5\u5b57\u5178\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u770b\u4f5c\u201c\u4e8c\u5206\u67e5\u627e\u201d\u3002

        \u4f8b\u4e8c\uff1a\u6574\u7406\u6251\u514b\u3002\u6211\u4eec\u5728\u6253\u724c\u65f6\uff0c\u6bcf\u5c40\u90fd\u9700\u8981\u6574\u7406\u624b\u4e2d\u7684\u6251\u514b\u724c\uff0c\u4f7f\u5176\u4ece\u5c0f\u5230\u5927\u6392\u5217\uff0c\u5b9e\u73b0\u6d41\u7a0b\u5982\u56fe 1-2 \u6240\u793a\u3002

        1. \u5c06\u6251\u514b\u724c\u5212\u5206\u4e3a\u201c\u6709\u5e8f\u201d\u548c\u201c\u65e0\u5e8f\u201d\u4e24\u90e8\u5206\uff0c\u5e76\u5047\u8bbe\u521d\u59cb\u72b6\u6001\u4e0b\u6700\u5de6 1 \u5f20\u6251\u514b\u724c\u5df2\u7ecf\u6709\u5e8f\u3002
        2. \u5728\u65e0\u5e8f\u90e8\u5206\u62bd\u51fa\u4e00\u5f20\u6251\u514b\u724c\uff0c\u63d2\u5165\u81f3\u6709\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\uff1b\u5b8c\u6210\u540e\u6700\u5de6 2 \u5f20\u6251\u514b\u5df2\u7ecf\u6709\u5e8f\u3002
        3. \u4e0d\u65ad\u5faa\u73af\u6b65\u9aa4 2. \uff0c\u6bcf\u4e00\u8f6e\u5c06\u4e00\u5f20\u6251\u514b\u724c\u4ece\u65e0\u5e8f\u90e8\u5206\u63d2\u5165\u81f3\u6709\u5e8f\u90e8\u5206\uff0c\u76f4\u81f3\u6240\u6709\u6251\u514b\u724c\u90fd\u6709\u5e8f\u3002

        \u56fe 1-2 \u00a0 \u6251\u514b\u6392\u5e8f\u6b65\u9aa4

        \u4e0a\u8ff0\u6574\u7406\u6251\u514b\u724c\u7684\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u201c\u63d2\u5165\u6392\u5e8f\u201d\u7b97\u6cd5\uff0c\u5b83\u5728\u5904\u7406\u5c0f\u578b\u6570\u636e\u96c6\u65f6\u975e\u5e38\u9ad8\u6548\u3002\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u7684\u6392\u5e8f\u5e93\u51fd\u6570\u4e2d\u90fd\u6709\u63d2\u5165\u6392\u5e8f\u7684\u8eab\u5f71\u3002

        \u4f8b\u4e09\uff1a\u8d27\u5e01\u627e\u96f6\u3002\u5047\u8bbe\u6211\u4eec\u5728\u8d85\u5e02\u8d2d\u4e70\u4e86 \\(69\\) \u5143\u7684\u5546\u54c1\uff0c\u7ed9\u4e86\u6536\u94f6\u5458 \\(100\\) \u5143\uff0c\u5219\u6536\u94f6\u5458\u9700\u8981\u627e\u6211\u4eec \\(31\\) \u5143\u3002\u4ed6\u4f1a\u5f88\u81ea\u7136\u5730\u5b8c\u6210\u5982\u56fe 1-3 \u6240\u793a\u7684\u601d\u8003\u3002

        1. \u53ef\u9009\u9879\u662f\u6bd4 \\(31\\) \u5143\u9762\u503c\u66f4\u5c0f\u7684\u8d27\u5e01\uff0c\u5305\u62ec \\(1\\) \u5143\u3001\\(5\\) \u5143\u3001\\(10\\) \u5143\u3001\\(20\\) \u5143\u3002
        2. \u4ece\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(20\\) \u5143\uff0c\u5269\u4f59 \\(31 - 20 = 11\\) \u5143\u3002
        3. \u4ece\u5269\u4f59\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(10\\) \u5143\uff0c\u5269\u4f59 \\(11 - 10 = 1\\) \u5143\u3002
        4. \u4ece\u5269\u4f59\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(1\\) \u5143\uff0c\u5269\u4f59 \\(1 - 1 = 0\\) \u5143\u3002
        5. \u5b8c\u6210\u627e\u96f6\uff0c\u65b9\u6848\u4e3a \\(20 + 10 + 1 = 31\\) \u5143\u3002

        \u56fe 1-3 \u00a0 \u8d27\u5e01\u627e\u96f6\u8fc7\u7a0b

        \u5728\u4ee5\u4e0a\u6b65\u9aa4\u4e2d\uff0c\u6211\u4eec\u6bcf\u4e00\u6b65\u90fd\u91c7\u53d6\u5f53\u524d\u770b\u6765\u6700\u597d\u7684\u9009\u62e9\uff08\u5c3d\u53ef\u80fd\u7528\u5927\u9762\u989d\u7684\u8d27\u5e01\uff09\uff0c\u6700\u7ec8\u5f97\u5230\u4e86\u53ef\u884c\u7684\u627e\u96f6\u65b9\u6848\u3002\u4ece\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\u8fd9\u79cd\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u201c\u8d2a\u5fc3\u201d\u7b97\u6cd5\u3002

        \u5c0f\u5230\u70f9\u996a\u4e00\u9053\u83dc\uff0c\u5927\u5230\u661f\u9645\u822a\u884c\uff0c\u51e0\u4e4e\u6240\u6709\u95ee\u9898\u7684\u89e3\u51b3\u90fd\u79bb\u4e0d\u5f00\u7b97\u6cd5\u3002\u8ba1\u7b97\u673a\u7684\u51fa\u73b0\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u901a\u8fc7\u7f16\u7a0b\u5c06\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u540c\u65f6\u7f16\u5199\u4ee3\u7801\u8c03\u7528 CPU \u548c GPU \u6267\u884c\u7b97\u6cd5\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6211\u4eec\u5c31\u80fd\u628a\u751f\u6d3b\u4e2d\u7684\u95ee\u9898\u8f6c\u79fb\u5230\u8ba1\u7b97\u673a\u4e0a\uff0c\u4ee5\u66f4\u9ad8\u6548\u7684\u65b9\u5f0f\u89e3\u51b3\u5404\u79cd\u590d\u6742\u95ee\u9898\u3002

        Tip

        \u5982\u679c\u4f60\u5bf9\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u3001\u6570\u7ec4\u548c\u4e8c\u5206\u67e5\u627e\u7b49\u6982\u5ff5\u4ecd\u611f\u5230\u4e00\u77e5\u534a\u89e3\uff0c\u8bf7\u7ee7\u7eed\u5f80\u4e0b\u9605\u8bfb\uff0c\u672c\u4e66\u5c06\u5f15\u5bfc\u4f60\u8fc8\u5165\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u77e5\u8bc6\u6bbf\u5802\u3002

        "},{"location":"chapter_introduction/summary/","title":"1.3 \u00a0 \u5c0f\u7ed3","text":"
        • \u7b97\u6cd5\u5728\u65e5\u5e38\u751f\u6d3b\u4e2d\u65e0\u5904\u4e0d\u5728\uff0c\u5e76\u4e0d\u662f\u9065\u4e0d\u53ef\u53ca\u7684\u9ad8\u6df1\u77e5\u8bc6\u3002\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u5df2\u7ecf\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u5b66\u4f1a\u4e86\u8bb8\u591a\u7b97\u6cd5\uff0c\u7528\u4ee5\u89e3\u51b3\u751f\u6d3b\u4e2d\u7684\u5927\u5c0f\u95ee\u9898\u3002
        • \u67e5\u9605\u5b57\u5178\u7684\u539f\u7406\u4e0e\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u76f8\u4e00\u81f4\u3002\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u4f53\u73b0\u4e86\u5206\u800c\u6cbb\u4e4b\u7684\u91cd\u8981\u7b97\u6cd5\u601d\u60f3\u3002
        • \u6574\u7406\u6251\u514b\u7684\u8fc7\u7a0b\u4e0e\u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\u975e\u5e38\u7c7b\u4f3c\u3002\u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\u9002\u5408\u6392\u5e8f\u5c0f\u578b\u6570\u636e\u96c6\u3002
        • \u8d27\u5e01\u627e\u96f6\u7684\u6b65\u9aa4\u672c\u8d28\u4e0a\u662f\u8d2a\u5fc3\u7b97\u6cd5\uff0c\u6bcf\u4e00\u6b65\u90fd\u91c7\u53d6\u5f53\u524d\u770b\u6765\u6700\u597d\u7684\u9009\u62e9\u3002
        • \u7b97\u6cd5\u662f\u5728\u6709\u9650\u65f6\u95f4\u5185\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u4e00\u7ec4\u6307\u4ee4\u6216\u64cd\u4f5c\u6b65\u9aa4\uff0c\u800c\u6570\u636e\u7ed3\u6784\u662f\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u548c\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\u3002
        • \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7d27\u5bc6\u76f8\u8fde\u3002\u6570\u636e\u7ed3\u6784\u662f\u7b97\u6cd5\u7684\u57fa\u77f3\uff0c\u800c\u7b97\u6cd5\u662f\u6570\u636e\u7ed3\u6784\u53d1\u6325\u4f5c\u7528\u7684\u821e\u53f0\u3002
        • \u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7c7b\u6bd4\u4e3a\u62fc\u88c5\u79ef\u6728\uff0c\u79ef\u6728\u4ee3\u8868\u6570\u636e\uff0c\u79ef\u6728\u7684\u5f62\u72b6\u548c\u8fde\u63a5\u65b9\u5f0f\u7b49\u4ee3\u8868\u6570\u636e\u7ed3\u6784\uff0c\u62fc\u88c5\u79ef\u6728\u7684\u6b65\u9aa4\u5219\u5bf9\u5e94\u7b97\u6cd5\u3002
        "},{"location":"chapter_introduction/what_is_dsa/","title":"1.2 \u00a0 \u7b97\u6cd5\u662f\u4ec0\u4e48","text":""},{"location":"chapter_introduction/what_is_dsa/#121","title":"1.2.1 \u00a0 \u7b97\u6cd5\u5b9a\u4e49","text":"

        \u300c\u7b97\u6cd5 algorithm\u300d\u662f\u5728\u6709\u9650\u65f6\u95f4\u5185\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u4e00\u7ec4\u6307\u4ee4\u6216\u64cd\u4f5c\u6b65\u9aa4\uff0c\u5b83\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u95ee\u9898\u662f\u660e\u786e\u7684\uff0c\u5305\u542b\u6e05\u6670\u7684\u8f93\u5165\u548c\u8f93\u51fa\u5b9a\u4e49\u3002
        • \u5177\u6709\u53ef\u884c\u6027\uff0c\u80fd\u591f\u5728\u6709\u9650\u6b65\u9aa4\u3001\u65f6\u95f4\u548c\u5185\u5b58\u7a7a\u95f4\u4e0b\u5b8c\u6210\u3002
        • \u5404\u6b65\u9aa4\u90fd\u6709\u786e\u5b9a\u7684\u542b\u4e49\uff0c\u5728\u76f8\u540c\u7684\u8f93\u5165\u548c\u8fd0\u884c\u6761\u4ef6\u4e0b\uff0c\u8f93\u51fa\u59cb\u7ec8\u76f8\u540c\u3002
        "},{"location":"chapter_introduction/what_is_dsa/#122","title":"1.2.2 \u00a0 \u6570\u636e\u7ed3\u6784\u5b9a\u4e49","text":"

        \u300c\u6570\u636e\u7ed3\u6784 data structure\u300d\u662f\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u548c\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u5177\u6709\u4ee5\u4e0b\u8bbe\u8ba1\u76ee\u6807\u3002

        • \u7a7a\u95f4\u5360\u7528\u5c3d\u91cf\u5c11\uff0c\u4ee5\u8282\u7701\u8ba1\u7b97\u673a\u5185\u5b58\u3002
        • \u6570\u636e\u64cd\u4f5c\u5c3d\u53ef\u80fd\u5feb\u901f\uff0c\u6db5\u76d6\u6570\u636e\u8bbf\u95ee\u3001\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66f4\u65b0\u7b49\u3002
        • \u63d0\u4f9b\u7b80\u6d01\u7684\u6570\u636e\u8868\u793a\u548c\u903b\u8f91\u4fe1\u606f\uff0c\u4ee5\u4fbf\u7b97\u6cd5\u9ad8\u6548\u8fd0\u884c\u3002

        \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1\u662f\u4e00\u4e2a\u5145\u6ee1\u6743\u8861\u7684\u8fc7\u7a0b\u3002\u5982\u679c\u60f3\u5728\u67d0\u65b9\u9762\u53d6\u5f97\u63d0\u5347\uff0c\u5f80\u5f80\u9700\u8981\u5728\u53e6\u4e00\u65b9\u9762\u4f5c\u51fa\u59a5\u534f\u3002\u4e0b\u9762\u4e3e\u4e24\u4e2a\u4f8b\u5b50\u3002

        • \u94fe\u8868\u76f8\u8f83\u4e8e\u6570\u7ec4\uff0c\u5728\u6570\u636e\u6dfb\u52a0\u548c\u5220\u9664\u64cd\u4f5c\u4e0a\u66f4\u52a0\u4fbf\u6377\uff0c\u4f46\u727a\u7272\u4e86\u6570\u636e\u8bbf\u95ee\u901f\u5ea6\u3002
        • \u56fe\u76f8\u8f83\u4e8e\u94fe\u8868\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e30\u5bcc\u7684\u903b\u8f91\u4fe1\u606f\uff0c\u4f46\u9700\u8981\u5360\u7528\u66f4\u5927\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        "},{"location":"chapter_introduction/what_is_dsa/#123","title":"1.2.3 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5173\u7cfb","text":"

        \u5982\u56fe 1-4 \u6240\u793a\uff0c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u9ad8\u5ea6\u76f8\u5173\u3001\u7d27\u5bc6\u7ed3\u5408\uff0c\u5177\u4f53\u8868\u73b0\u5728\u4ee5\u4e0b\u4e09\u4e2a\u65b9\u9762\u3002

        • \u6570\u636e\u7ed3\u6784\u662f\u7b97\u6cd5\u7684\u57fa\u77f3\u3002\u6570\u636e\u7ed3\u6784\u4e3a\u7b97\u6cd5\u63d0\u4f9b\u4e86\u7ed3\u6784\u5316\u5b58\u50a8\u7684\u6570\u636e\uff0c\u4ee5\u53ca\u64cd\u4f5c\u6570\u636e\u7684\u65b9\u6cd5\u3002
        • \u7b97\u6cd5\u662f\u6570\u636e\u7ed3\u6784\u53d1\u6325\u4f5c\u7528\u7684\u821e\u53f0\u3002\u6570\u636e\u7ed3\u6784\u672c\u8eab\u4ec5\u5b58\u50a8\u6570\u636e\u4fe1\u606f\uff0c\u7ed3\u5408\u7b97\u6cd5\u624d\u80fd\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u3002
        • \u7b97\u6cd5\u901a\u5e38\u53ef\u4ee5\u57fa\u4e8e\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff0c\u4f46\u6267\u884c\u6548\u7387\u53ef\u80fd\u76f8\u5dee\u5f88\u5927\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u662f\u5173\u952e\u3002

        \u56fe 1-4 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5173\u7cfb

        \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u72b9\u5982\u56fe 1-5 \u6240\u793a\u7684\u62fc\u88c5\u79ef\u6728\u3002\u4e00\u5957\u79ef\u6728\uff0c\u9664\u4e86\u5305\u542b\u8bb8\u591a\u96f6\u4ef6\u4e4b\u5916\uff0c\u8fd8\u9644\u6709\u8be6\u7ec6\u7684\u7ec4\u88c5\u8bf4\u660e\u4e66\u3002\u6211\u4eec\u6309\u7167\u8bf4\u660e\u4e66\u4e00\u6b65\u6b65\u64cd\u4f5c\uff0c\u5c31\u80fd\u7ec4\u88c5\u51fa\u7cbe\u7f8e\u7684\u79ef\u6728\u6a21\u578b\u3002

        \u56fe 1-5 \u00a0 \u62fc\u88c5\u79ef\u6728

        \u4e24\u8005\u7684\u8be6\u7ec6\u5bf9\u5e94\u5173\u7cfb\u5982\u8868 1-1 \u6240\u793a\u3002

        \u8868 1-1 \u00a0 \u5c06\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7c7b\u6bd4\u4e3a\u62fc\u88c5\u79ef\u6728

        \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u62fc\u88c5\u79ef\u6728 \u8f93\u5165\u6570\u636e \u672a\u62fc\u88c5\u7684\u79ef\u6728 \u6570\u636e\u7ed3\u6784 \u79ef\u6728\u7ec4\u7ec7\u5f62\u5f0f\uff0c\u5305\u62ec\u5f62\u72b6\u3001\u5927\u5c0f\u3001\u8fde\u63a5\u65b9\u5f0f\u7b49 \u7b97\u6cd5 \u628a\u79ef\u6728\u62fc\u6210\u76ee\u6807\u5f62\u6001\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u6b65\u9aa4 \u8f93\u51fa\u6570\u636e \u79ef\u6728\u6a21\u578b

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u662f\u72ec\u7acb\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u3002\u6b63\u56e0\u5982\u6b64\uff0c\u672c\u4e66\u5f97\u4ee5\u63d0\u4f9b\u57fa\u4e8e\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u5b9e\u73b0\u3002

        \u7ea6\u5b9a\u4fd7\u6210\u7684\u7b80\u79f0

        \u5728\u5b9e\u9645\u8ba8\u8bba\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u201c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u201d\u7b80\u79f0\u4e3a\u201c\u7b97\u6cd5\u201d\u3002\u6bd4\u5982\u4f17\u6240\u5468\u77e5\u7684 LeetCode \u7b97\u6cd5\u9898\u76ee\uff0c\u5b9e\u9645\u4e0a\u540c\u65f6\u8003\u67e5\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u4e24\u65b9\u9762\u7684\u77e5\u8bc6\u3002

        "},{"location":"chapter_preface/","title":"\u7b2c 0 \u7ae0 \u00a0 \u524d\u8a00","text":"

        Abstract

        \u7b97\u6cd5\u72b9\u5982\u7f8e\u5999\u7684\u4ea4\u54cd\u4e50\uff0c\u6bcf\u4e00\u884c\u4ee3\u7801\u90fd\u50cf\u97f5\u5f8b\u822c\u6d41\u6dcc\u3002

        \u613f\u8fd9\u672c\u4e66\u5728\u4f60\u7684\u8111\u6d77\u4e2d\u8f7b\u8f7b\u54cd\u8d77\uff0c\u7559\u4e0b\u72ec\u7279\u800c\u6df1\u523b\u7684\u65cb\u5f8b\u3002

        "},{"location":"chapter_preface/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 0.1 \u00a0 \u5173\u4e8e\u672c\u4e66
        • 0.2 \u00a0 \u5982\u4f55\u4f7f\u7528\u672c\u4e66
        • 0.3 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_preface/about_the_book/","title":"0.1 \u00a0 \u5173\u4e8e\u672c\u4e66","text":"

        \u672c\u9879\u76ee\u65e8\u5728\u521b\u5efa\u4e00\u672c\u5f00\u6e90\u3001\u514d\u8d39\u3001\u65b0\u624b\u53cb\u597d\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5165\u95e8\u6559\u7a0b\u3002

        • \u5168\u4e66\u91c7\u7528\u52a8\u753b\u56fe\u89e3\uff0c\u7ed3\u6784\u5316\u5730\u8bb2\u89e3\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u77e5\u8bc6\uff0c\u5185\u5bb9\u6e05\u6670\u6613\u61c2\u3001\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1\u3002
        • \u7b97\u6cd5\u6e90\u4ee3\u7801\u7686\u53ef\u4e00\u952e\u8fd0\u884c\uff0c\u652f\u6301 Python\u3001C++\u3001Java\u3001C#\u3001Go\u3001Swift\u3001JavaScript\u3001TypeScript\u3001Dart\u3001Rust\u3001C\u3001Zig \u7b49\u8bed\u8a00\u3002
        • \u9f13\u52b1\u8bfb\u8005\u5728\u7ae0\u8282\u8ba8\u8bba\u533a\u4e92\u5e2e\u4e92\u52a9\u3001\u5171\u540c\u8fdb\u6b65\uff0c\u63d0\u95ee\u4e0e\u8bc4\u8bba\u901a\u5e38\u53ef\u5728\u4e24\u65e5\u5185\u5f97\u5230\u56de\u590d\u3002
        "},{"location":"chapter_preface/about_the_book/#011","title":"0.1.1 \u00a0 \u8bfb\u8005\u5bf9\u8c61","text":"

        \u82e5\u4f60\u662f\u7b97\u6cd5\u521d\u5b66\u8005\uff0c\u4ece\u672a\u63a5\u89e6\u8fc7\u7b97\u6cd5\uff0c\u6216\u8005\u5df2\u7ecf\u6709\u4e00\u4e9b\u5237\u9898\u7ecf\u9a8c\uff0c\u5bf9\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6709\u6a21\u7cca\u7684\u8ba4\u8bc6\uff0c\u5728\u4f1a\u4e0e\u4e0d\u4f1a\u4e4b\u95f4\u53cd\u590d\u6a2a\u8df3\uff0c\u90a3\u4e48\u672c\u4e66\u6b63\u662f\u4e3a\u4f60\u91cf\u8eab\u5b9a\u5236\u7684\uff01

        \u5982\u679c\u4f60\u5df2\u7ecf\u79ef\u7d2f\u4e00\u5b9a\u5237\u9898\u91cf\uff0c\u719f\u6089\u5927\u90e8\u5206\u9898\u578b\uff0c\u90a3\u4e48\u672c\u4e66\u53ef\u52a9\u4f60\u56de\u987e\u4e0e\u68b3\u7406\u7b97\u6cd5\u77e5\u8bc6\u4f53\u7cfb\uff0c\u4ed3\u5e93\u6e90\u4ee3\u7801\u53ef\u4ee5\u5f53\u4f5c\u201c\u5237\u9898\u5de5\u5177\u5e93\u201d\u6216\u201c\u7b97\u6cd5\u5b57\u5178\u201d\u6765\u4f7f\u7528\u3002

        \u82e5\u4f60\u662f\u7b97\u6cd5\u5927\u795e\uff0c\u6211\u4eec\u671f\u5f85\u6536\u5230\u4f60\u7684\u5b9d\u8d35\u5efa\u8bae\uff0c\u6216\u8005\u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c\u3002

        \u524d\u7f6e\u6761\u4ef6

        \u4f60\u9700\u8981\u81f3\u5c11\u5177\u5907\u4efb\u4e00\u8bed\u8a00\u7684\u7f16\u7a0b\u57fa\u7840\uff0c\u80fd\u591f\u9605\u8bfb\u548c\u7f16\u5199\u7b80\u5355\u4ee3\u7801\u3002

        "},{"location":"chapter_preface/about_the_book/#012","title":"0.1.2 \u00a0 \u5185\u5bb9\u7ed3\u6784","text":"

        \u672c\u4e66\u7684\u4e3b\u8981\u5185\u5bb9\u5982\u56fe 0-1 \u6240\u793a\u3002

        • \u590d\u6742\u5ea6\u5206\u6790\uff1a\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u7684\u8bc4\u4ef7\u7ef4\u5ea6\u4e0e\u65b9\u6cd5\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u3001\u5e38\u89c1\u7c7b\u578b\u3001\u793a\u4f8b\u7b49\u3002
        • \u6570\u636e\u7ed3\u6784\uff1a\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u6570\u636e\u7ed3\u6784\u7684\u5206\u7c7b\u65b9\u6cd5\u3002\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u7684\u5b9a\u4e49\u3001\u4f18\u7f3a\u70b9\u3001\u5e38\u7528\u64cd\u4f5c\u3001\u5e38\u89c1\u7c7b\u578b\u3001\u5178\u578b\u5e94\u7528\u3001\u5b9e\u73b0\u65b9\u6cd5\u7b49\u3002
        • \u7b97\u6cd5\uff1a\u641c\u7d22\u3001\u6392\u5e8f\u3001\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u3001\u8d2a\u5fc3\u7b49\u7b97\u6cd5\u7684\u5b9a\u4e49\u3001\u4f18\u7f3a\u70b9\u3001\u6548\u7387\u3001\u5e94\u7528\u573a\u666f\u3001\u89e3\u9898\u6b65\u9aa4\u548c\u793a\u4f8b\u95ee\u9898\u7b49\u3002

        \u56fe 0-1 \u00a0 \u672c\u4e66\u4e3b\u8981\u5185\u5bb9

        "},{"location":"chapter_preface/about_the_book/#013","title":"0.1.3 \u00a0 \u81f4\u8c22","text":"

        \u5728\u672c\u4e66\u7684\u521b\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u5f97\u5230\u4e86\u8bb8\u591a\u4eba\u7684\u5e2e\u52a9\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a

        • \u611f\u8c22\u6211\u5728\u516c\u53f8\u7684\u5bfc\u5e08\u674e\u6c50\u535a\u58eb\uff0c\u5728\u4e00\u6b21\u7545\u8c08\u4e2d\u4f60\u9f13\u52b1\u6211\u201c\u5feb\u884c\u52a8\u8d77\u6765\u201d\uff0c\u575a\u5b9a\u4e86\u6211\u5199\u8fd9\u672c\u4e66\u7684\u51b3\u5fc3\uff1b
        • \u611f\u8c22\u6211\u7684\u5973\u670b\u53cb\u6ce1\u6ce1\u4f5c\u4e3a\u672c\u4e66\u7684\u9996\u4f4d\u8bfb\u8005\uff0c\u4ece\u7b97\u6cd5\u5c0f\u767d\u7684\u89d2\u5ea6\u63d0\u51fa\u8bb8\u591a\u5b9d\u8d35\u5efa\u8bae\uff0c\u4f7f\u5f97\u672c\u4e66\u66f4\u9002\u5408\u65b0\u624b\u9605\u8bfb\uff1b
        • \u611f\u8c22\u817e\u5b9d\u3001\u7426\u5b9d\u3001\u98de\u5b9d\u4e3a\u672c\u4e66\u8d77\u4e86\u4e00\u4e2a\u5bcc\u6709\u521b\u610f\u7684\u540d\u5b57\uff0c\u5524\u8d77\u5927\u5bb6\u5199\u4e0b\u7b2c\u4e00\u884c\u4ee3\u7801 \"Hello World!\" \u7684\u7f8e\u597d\u56de\u5fc6\uff1b
        • \u611f\u8c22\u6821\u94e8\u5728\u77e5\u8bc6\u4ea7\u6743\u65b9\u9762\u63d0\u4f9b\u7684\u4e13\u4e1a\u5e2e\u52a9\uff0c\u8fd9\u5bf9\u672c\u5f00\u6e90\u4e66\u7684\u53d1\u5c55\u8d77\u5230\u4e86\u91cd\u8981\u7684\u4f5c\u7528\uff1b
        • \u611f\u8c22\u82cf\u6f7c\u4e3a\u672c\u4e66\u8bbe\u8ba1\u4e86\u7cbe\u7f8e\u7684\u5c01\u9762\u548c logo \uff0c\u5e76\u5728\u6211\u7684\u5f3a\u8feb\u75c7\u4e0b\u591a\u6b21\u8010\u5fc3\u4fee\u6539\uff1b
        • \u611f\u8c22 @squidfunk \u63d0\u4f9b\u7684\u5199\u4f5c\u6392\u7248\u5efa\u8bae\uff0c\u4ee5\u53ca\u4ed6\u5f00\u53d1\u7684\u5f00\u6e90\u6587\u6863\u4e3b\u9898 Material-for-MkDocs \u3002

        \u5728\u5199\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u9605\u8bfb\u4e86\u8bb8\u591a\u5173\u4e8e\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u6559\u6750\u548c\u6587\u7ae0\u3002\u8fd9\u4e9b\u4f5c\u54c1\u4e3a\u672c\u4e66\u63d0\u4f9b\u4e86\u4f18\u79c0\u7684\u8303\u672c\uff0c\u786e\u4fdd\u4e86\u672c\u4e66\u5185\u5bb9\u7684\u51c6\u786e\u6027\u4e0e\u54c1\u8d28\u3002\u5728\u6b64\u611f\u8c22\u6240\u6709\u8001\u5e08\u548c\u524d\u8f88\u4eec\u7684\u6770\u51fa\u8d21\u732e\uff01

        \u672c\u4e66\u5021\u5bfc\u624b\u8111\u5e76\u7528\u7684\u5b66\u4e60\u65b9\u5f0f\uff0c\u5728\u8fd9\u4e00\u70b9\u4e0a\u6df1\u53d7\u300a\u52a8\u624b\u5b66\u6df1\u5ea6\u5b66\u4e60\u300b\u7684\u542f\u53d1\u3002\u5728\u6b64\u5411\u5404\u4f4d\u8bfb\u8005\u5f3a\u70c8\u63a8\u8350\u8fd9\u672c\u4f18\u79c0\u7684\u8457\u4f5c\u3002

        \u8877\u5fc3\u611f\u8c22\u6211\u7684\u7236\u6bcd\uff0c\u6b63\u662f\u4f60\u4eec\u4e00\u76f4\u4ee5\u6765\u7684\u652f\u6301\u4e0e\u9f13\u52b1\uff0c\u8ba9\u6211\u6709\u673a\u4f1a\u505a\u8fd9\u4ef6\u5bcc\u6709\u8da3\u5473\u7684\u4e8b\u3002

        "},{"location":"chapter_preface/suggestions/","title":"0.2 \u00a0 \u5982\u4f55\u4f7f\u7528\u672c\u4e66","text":"

        Tip

        \u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u7684\u9605\u8bfb\u4f53\u9a8c\uff0c\u5efa\u8bae\u4f60\u901a\u8bfb\u672c\u8282\u5185\u5bb9\u3002

        "},{"location":"chapter_preface/suggestions/#021","title":"0.2.1 \u00a0 \u884c\u6587\u98ce\u683c\u7ea6\u5b9a","text":"
        • \u6807\u9898\u540e\u6807\u6ce8 * \u7684\u662f\u9009\u8bfb\u7ae0\u8282\uff0c\u5185\u5bb9\u76f8\u5bf9\u56f0\u96be\u3002\u5982\u679c\u4f60\u7684\u65f6\u95f4\u6709\u9650\uff0c\u53ef\u4ee5\u5148\u8df3\u8fc7\u3002
        • \u91cd\u8981\u4e13\u6709\u540d\u8bcd\u53ca\u5176\u82f1\u6587\u7ffb\u8bd1\u4f1a\u7528 \u300c \u300d \u62ec\u53f7\u6807\u6ce8\uff0c\u4f8b\u5982 \u300c\u6570\u7ec4 array\u300d \u3002\u5efa\u8bae\u8bb0\u4f4f\u5b83\u4eec\uff0c\u4ee5\u4fbf\u9605\u8bfb\u6587\u732e\u3002
        • \u4e13\u6709\u540d\u8bcd\u548c\u6709\u7279\u6307\u542b\u4e49\u7684\u8bcd\u53e5\u4f1a\u4f7f\u7528 \u201c\u5f15\u53f7\u201d \u6807\u6ce8\uff0c\u4ee5\u907f\u514d\u6b67\u4e49\u3002
        • \u91cd\u8981\u540d\u8bcd\u3001\u91cd\u70b9\u5185\u5bb9\u548c\u603b\u7ed3\u6027\u8bed\u53e5\u4f1a\u88ab \u52a0\u7c97 \uff0c\u8fd9\u7c7b\u6587\u5b57\u503c\u5f97\u7279\u522b\u5173\u6ce8\u3002
        • \u5f53\u6d89\u53ca\u7f16\u7a0b\u8bed\u8a00\u4e4b\u95f4\u4e0d\u4e00\u81f4\u7684\u540d\u8bcd\u65f6\uff0c\u672c\u4e66\u5747\u4ee5 Python \u4e3a\u51c6\uff0c\u4f8b\u5982\u4f7f\u7528 \\(\\text{None}\\) \u6765\u8868\u793a\u201c\u7a7a\u201d\u3002
        • \u672c\u4e66\u90e8\u5206\u653e\u5f03\u4e86\u7f16\u7a0b\u8bed\u8a00\u7684\u6ce8\u91ca\u89c4\u8303\uff0c\u4ee5\u6362\u53d6\u66f4\u52a0\u7d27\u51d1\u7684\u5185\u5bb9\u6392\u7248\u3002\u6ce8\u91ca\u4e3b\u8981\u5206\u4e3a\u4e09\u79cd\u7c7b\u578b\uff1a\u6807\u9898\u6ce8\u91ca\u3001\u5185\u5bb9\u6ce8\u91ca\u3001\u591a\u884c\u6ce8\u91ca\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        \"\"\"\u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49\"\"\"\n# \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\"\"\"\n\u591a\u884c\n\u6ce8\u91ca\n\"\"\"\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        // \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n// \u591a\u884c\n// \u6ce8\u91ca\n
        "},{"location":"chapter_preface/suggestions/#022","title":"0.2.2 \u00a0 \u5728\u52a8\u753b\u56fe\u89e3\u4e2d\u9ad8\u6548\u5b66\u4e60","text":"

        \u76f8\u8f83\u4e8e\u6587\u5b57\uff0c\u89c6\u9891\u548c\u56fe\u7247\u5177\u6709\u66f4\u9ad8\u7684\u4fe1\u606f\u5bc6\u5ea6\u548c\u7ed3\u6784\u5316\u7a0b\u5ea6\uff0c\u66f4\u6613\u4e8e\u7406\u89e3\u3002\u5728\u672c\u4e66\u4e2d\uff0c\u91cd\u70b9\u548c\u96be\u70b9\u77e5\u8bc6\u5c06\u4e3b\u8981\u901a\u8fc7\u52a8\u753b\u548c\u56fe\u89e3\u5f62\u5f0f\u5c55\u793a\uff0c\u800c\u6587\u5b57\u5219\u4f5c\u4e3a\u52a8\u753b\u548c\u56fe\u7247\u7684\u89e3\u91ca\u4e0e\u8865\u5145\u3002

        \u5982\u679c\u4f60\u5728\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u53d1\u73b0\u67d0\u6bb5\u5185\u5bb9\u63d0\u4f9b\u4e86\u5982\u56fe 0-2 \u6240\u793a\u7684\u52a8\u753b\u6216\u56fe\u89e3\uff0c\u8bf7\u4ee5\u56fe\u4e3a\u4e3b\u3001\u4ee5\u6587\u5b57\u4e3a\u8f85\uff0c\u7efc\u5408\u4e24\u8005\u6765\u7406\u89e3\u5185\u5bb9\u3002

        \u56fe 0-2 \u00a0 \u52a8\u753b\u56fe\u89e3\u793a\u4f8b

        "},{"location":"chapter_preface/suggestions/#023","title":"0.2.3 \u00a0 \u5728\u4ee3\u7801\u5b9e\u8df5\u4e2d\u52a0\u6df1\u7406\u89e3","text":"

        \u672c\u4e66\u7684\u914d\u5957\u4ee3\u7801\u6258\u7ba1\u5728 GitHub \u4ed3\u5e93\u3002\u5982\u56fe 0-3 \u6240\u793a\uff0c\u6e90\u4ee3\u7801\u9644\u6709\u6d4b\u8bd5\u6837\u4f8b\uff0c\u53ef\u4e00\u952e\u8fd0\u884c\u3002

        \u5982\u679c\u65f6\u95f4\u5141\u8bb8\uff0c\u5efa\u8bae\u4f60\u53c2\u7167\u4ee3\u7801\u81ea\u884c\u6572\u4e00\u904d\u3002\u5982\u679c\u5b66\u4e60\u65f6\u95f4\u6709\u9650\uff0c\u8bf7\u81f3\u5c11\u901a\u8bfb\u5e76\u8fd0\u884c\u6240\u6709\u4ee3\u7801\u3002

        \u4e0e\u9605\u8bfb\u4ee3\u7801\u76f8\u6bd4\uff0c\u7f16\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u5f80\u5f80\u80fd\u5e26\u6765\u66f4\u591a\u6536\u83b7\u3002\u52a8\u624b\u5b66\uff0c\u624d\u662f\u771f\u7684\u5b66\u3002

        \u56fe 0-3 \u00a0 \u8fd0\u884c\u4ee3\u7801\u793a\u4f8b

        \u8fd0\u884c\u4ee3\u7801\u7684\u524d\u7f6e\u5de5\u4f5c\u4e3b\u8981\u5206\u4e3a\u4e09\u6b65\u3002

        \u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5\u672c\u5730\u7f16\u7a0b\u73af\u5883\u3002\u8bf7\u53c2\u7167\u9644\u5f55\u6240\u793a\u7684\u6559\u7a0b\u8fdb\u884c\u5b89\u88c5\uff0c\u5982\u679c\u5df2\u5b89\u88c5\uff0c\u5219\u53ef\u8df3\u8fc7\u6b64\u6b65\u9aa4\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u514b\u9686\u6216\u4e0b\u8f7d\u4ee3\u7801\u4ed3\u5e93\u3002\u524d\u5f80 GitHub \u4ed3\u5e93\u3002

        \u5982\u679c\u5df2\u7ecf\u5b89\u88c5 Git \uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u514b\u9686\u672c\u4ed3\u5e93\uff1a

        git clone https://github.com/krahets/hello-algo.git\n

        \u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728\u56fe 0-4 \u6240\u793a\u7684\u4f4d\u7f6e\uff0c\u70b9\u51fb\u201cDownload ZIP\u201d\u6309\u94ae\u76f4\u63a5\u4e0b\u8f7d\u4ee3\u7801\u538b\u7f29\u5305\uff0c\u7136\u540e\u5728\u672c\u5730\u89e3\u538b\u5373\u53ef\u3002

        \u56fe 0-4 \u00a0 \u514b\u9686\u4ed3\u5e93\u4e0e\u4e0b\u8f7d\u4ee3\u7801

        \u7b2c\u4e09\u6b65\uff1a\u8fd0\u884c\u6e90\u4ee3\u7801\u3002\u5982\u56fe 0-5 \u6240\u793a\uff0c\u5bf9\u4e8e\u9876\u90e8\u6807\u6709\u6587\u4ef6\u540d\u79f0\u7684\u4ee3\u7801\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u4ed3\u5e93\u7684 codes \u6587\u4ef6\u5939\u5185\u627e\u5230\u5bf9\u5e94\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\u3002\u6e90\u4ee3\u7801\u6587\u4ef6\u53ef\u4e00\u952e\u8fd0\u884c\uff0c\u5c06\u5e2e\u52a9\u4f60\u8282\u7701\u4e0d\u5fc5\u8981\u7684\u8c03\u8bd5\u65f6\u95f4\uff0c\u8ba9\u4f60\u80fd\u591f\u4e13\u6ce8\u4e8e\u5b66\u4e60\u5185\u5bb9\u3002

        \u56fe 0-5 \u00a0 \u4ee3\u7801\u5757\u4e0e\u5bf9\u5e94\u7684\u6e90\u4ee3\u7801\u6587\u4ef6

        "},{"location":"chapter_preface/suggestions/#024","title":"0.2.4 \u00a0 \u5728\u63d0\u95ee\u8ba8\u8bba\u4e2d\u5171\u540c\u6210\u957f","text":"

        \u5728\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u8bf7\u4e0d\u8981\u8f7b\u6613\u8df3\u8fc7\u90a3\u4e9b\u6ca1\u5b66\u660e\u767d\u7684\u77e5\u8bc6\u70b9\u3002\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u63d0\u51fa\u4f60\u7684\u95ee\u9898\uff0c\u6211\u548c\u5c0f\u4f19\u4f34\u4eec\u5c06\u7aed\u8bda\u4e3a\u4f60\u89e3\u7b54\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u53ef\u5728\u4e24\u5929\u5185\u56de\u590d\u3002

        \u5982\u56fe 0-6 \u6240\u793a\uff0c\u6bcf\u4e2a\u7ae0\u8282\u7684\u5e95\u90e8\u90fd\u914d\u6709\u8bc4\u8bba\u533a\u3002\u5e0c\u671b\u4f60\u80fd\u591a\u5173\u6ce8\u8bc4\u8bba\u533a\u7684\u5185\u5bb9\u3002\u4e00\u65b9\u9762\uff0c\u4f60\u53ef\u4ee5\u4e86\u89e3\u5927\u5bb6\u9047\u5230\u7684\u95ee\u9898\uff0c\u4ece\u800c\u67e5\u6f0f\u8865\u7f3a\uff0c\u6fc0\u53d1\u66f4\u6df1\u5165\u7684\u601d\u8003\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u671f\u5f85\u4f60\u80fd\u6177\u6168\u5730\u56de\u7b54\u5176\u4ed6\u5c0f\u4f19\u4f34\u7684\u95ee\u9898\uff0c\u5206\u4eab\u4f60\u7684\u89c1\u89e3\uff0c\u5e2e\u52a9\u4ed6\u4eba\u8fdb\u6b65\u3002

        \u56fe 0-6 \u00a0 \u8bc4\u8bba\u533a\u793a\u4f8b

        "},{"location":"chapter_preface/suggestions/#025","title":"0.2.5 \u00a0 \u7b97\u6cd5\u5b66\u4e60\u8def\u7ebf","text":"

        \u4ece\u603b\u4f53\u4e0a\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b66\u4e60\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u8fc7\u7a0b\u5212\u5206\u4e3a\u4e09\u4e2a\u9636\u6bb5\u3002

        1. \u9636\u6bb5\u4e00\uff1a\u7b97\u6cd5\u5165\u95e8\u3002\u6211\u4eec\u9700\u8981\u719f\u6089\u5404\u79cd\u6570\u636e\u7ed3\u6784\u7684\u7279\u70b9\u548c\u7528\u6cd5\uff0c\u5b66\u4e60\u4e0d\u540c\u7b97\u6cd5\u7684\u539f\u7406\u3001\u6d41\u7a0b\u3001\u7528\u9014\u548c\u6548\u7387\u7b49\u65b9\u9762\u7684\u5185\u5bb9\u3002
        2. \u9636\u6bb5\u4e8c\uff1a\u5237\u7b97\u6cd5\u9898\u3002\u5efa\u8bae\u4ece\u70ed\u95e8\u9898\u76ee\u5f00\u5237\uff0c\u5982\u201c\u5251\u6307 Offer\u201d\u548c\u201cLeetCode Hot 100\u201d\uff0c\u5148\u79ef\u7d2f\u81f3\u5c11 100 \u9053\u9898\u76ee\uff0c\u719f\u6089\u4e3b\u6d41\u7684\u7b97\u6cd5\u95ee\u9898\u3002\u521d\u6b21\u5237\u9898\u65f6\uff0c\u201c\u77e5\u8bc6\u9057\u5fd8\u201d\u53ef\u80fd\u662f\u4e00\u4e2a\u6311\u6218\uff0c\u4f46\u8bf7\u653e\u5fc3\uff0c\u8fd9\u662f\u5f88\u6b63\u5e38\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u201c\u827e\u5bbe\u6d69\u65af\u9057\u5fd8\u66f2\u7ebf\u201d\u6765\u590d\u4e60\u9898\u76ee\uff0c\u901a\u5e38\u5728\u8fdb\u884c 3\uff5e5 \u8f6e\u7684\u91cd\u590d\u540e\uff0c\u5c31\u80fd\u5c06\u5176\u7262\u8bb0\u5728\u5fc3\u3002
        3. \u9636\u6bb5\u4e09\uff1a\u642d\u5efa\u77e5\u8bc6\u4f53\u7cfb\u3002\u5728\u5b66\u4e60\u65b9\u9762\uff0c\u6211\u4eec\u53ef\u4ee5\u9605\u8bfb\u7b97\u6cd5\u4e13\u680f\u6587\u7ae0\u3001\u89e3\u9898\u6846\u67b6\u548c\u7b97\u6cd5\u6559\u6750\uff0c\u4ee5\u4e0d\u65ad\u4e30\u5bcc\u77e5\u8bc6\u4f53\u7cfb\u3002\u5728\u5237\u9898\u65b9\u9762\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u91c7\u7528\u8fdb\u9636\u5237\u9898\u7b56\u7565\uff0c\u5982\u6309\u4e13\u9898\u5206\u7c7b\u3001\u4e00\u9898\u591a\u89e3\u3001\u4e00\u89e3\u591a\u9898\u7b49\uff0c\u76f8\u5173\u7684\u5237\u9898\u5fc3\u5f97\u53ef\u4ee5\u5728\u5404\u4e2a\u793e\u533a\u627e\u5230\u3002

        \u5982\u56fe 0-7 \u6240\u793a\uff0c\u672c\u4e66\u5185\u5bb9\u4e3b\u8981\u6db5\u76d6\u201c\u9636\u6bb5\u4e00\u201d\uff0c\u65e8\u5728\u5e2e\u52a9\u4f60\u66f4\u9ad8\u6548\u5730\u5c55\u5f00\u9636\u6bb5\u4e8c\u548c\u9636\u6bb5\u4e09\u7684\u5b66\u4e60\u3002

        \u56fe 0-7 \u00a0 \u7b97\u6cd5\u5b66\u4e60\u8def\u7ebf

        "},{"location":"chapter_preface/summary/","title":"0.3 \u00a0 \u5c0f\u7ed3","text":"
        • \u672c\u4e66\u7684\u4e3b\u8981\u53d7\u4f17\u662f\u7b97\u6cd5\u521d\u5b66\u8005\u3002\u5982\u679c\u5df2\u6709\u4e00\u5b9a\u57fa\u7840\uff0c\u672c\u4e66\u80fd\u5e2e\u52a9\u4f60\u7cfb\u7edf\u56de\u987e\u7b97\u6cd5\u77e5\u8bc6\uff0c\u4e66\u4e2d\u6e90\u4ee3\u7801\u4e5f\u53ef\u4f5c\u4e3a\u201c\u5237\u9898\u5de5\u5177\u5e93\u201d\u4f7f\u7528\u3002
        • \u4e66\u4e2d\u5185\u5bb9\u4e3b\u8981\u5305\u62ec\u590d\u6742\u5ea6\u5206\u6790\u3001\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u4e09\u90e8\u5206\uff0c\u6db5\u76d6\u4e86\u8be5\u9886\u57df\u7684\u5927\u90e8\u5206\u4e3b\u9898\u3002
        • \u5bf9\u4e8e\u7b97\u6cd5\u65b0\u624b\uff0c\u5728\u521d\u5b66\u9636\u6bb5\u9605\u8bfb\u4e00\u672c\u5165\u95e8\u4e66\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u4ee5\u5c11\u8d70\u8bb8\u591a\u5f2f\u8def\u3002
        • \u4e66\u4e2d\u7684\u52a8\u753b\u548c\u56fe\u89e3\u901a\u5e38\u7528\u4e8e\u4ecb\u7ecd\u91cd\u70b9\u548c\u96be\u70b9\u77e5\u8bc6\u3002\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u5e94\u7ed9\u4e88\u8fd9\u4e9b\u5185\u5bb9\u66f4\u591a\u5173\u6ce8\u3002
        • \u5b9e\u8df5\u4e43\u5b66\u4e60\u7f16\u7a0b\u4e4b\u6700\u4f73\u9014\u5f84\u3002\u5f3a\u70c8\u5efa\u8bae\u8fd0\u884c\u6e90\u4ee3\u7801\u5e76\u4eb2\u81ea\u6572\u4ee3\u7801\u3002
        • \u672c\u4e66\u7f51\u9875\u7248\u7684\u6bcf\u4e2a\u7ae0\u8282\u90fd\u8bbe\u6709\u8ba8\u8bba\u533a\uff0c\u6b22\u8fce\u968f\u65f6\u5206\u4eab\u4f60\u7684\u7591\u60d1\u4e0e\u89c1\u89e3\u3002
        "},{"location":"chapter_reference/","title":"\u53c2\u8003\u6587\u732e","text":"

        [1] Thomas H. Cormen, et al. Introduction to Algorithms (3rd Edition).

        [2] Aditya Bhargava. Grokking Algorithms: An Illustrated Guide for Programmers and Other Curious People (1st Edition).

        [3] \u4e25\u851a\u654f. \u6570\u636e\u7ed3\u6784\uff08C \u8bed\u8a00\u7248\uff09.

        [4] \u9093\u4fca\u8f89. \u6570\u636e\u7ed3\u6784\uff08C++ \u8bed\u8a00\u7248\uff0c\u7b2c\u4e09\u7248\uff09.

        [5] \u9a6c\u514b \u827e\u4f26 \u7ef4\u65af\u8457\uff0c\u9648\u8d8a\u8bd1. \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5206\u6790\uff1aJava\u8bed\u8a00\u63cf\u8ff0\uff08\u7b2c\u4e09\u7248\uff09.

        [6] \u7a0b\u6770. \u5927\u8bdd\u6570\u636e\u7ed3\u6784.

        [7] \u738b\u4e89. \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u4e4b\u7f8e.

        [8] Gayle Laakmann McDowell. Cracking the Coding Interview: 189 Programming Questions and Solutions (6th Edition).

        [9] Aston Zhang, et al. Dive into Deep Learning.

        "},{"location":"chapter_searching/","title":"\u7b2c 10 \u7ae0 \u00a0 \u641c\u7d22","text":"

        Abstract

        \u641c\u7d22\u662f\u4e00\u573a\u672a\u77e5\u7684\u5192\u9669\uff0c\u6211\u4eec\u6216\u8bb8\u9700\u8981\u8d70\u904d\u795e\u79d8\u7a7a\u95f4\u7684\u6bcf\u4e2a\u89d2\u843d\uff0c\u53c8\u6216\u8bb8\u53ef\u4ee5\u5feb\u901f\u9501\u5b9a\u76ee\u6807\u3002

        \u5728\u8fd9\u573a\u5bfb\u89c5\u4e4b\u65c5\u4e2d\uff0c\u6bcf\u4e00\u6b21\u63a2\u7d22\u90fd\u53ef\u80fd\u5f97\u5230\u4e00\u4e2a\u672a\u66fe\u6599\u60f3\u7684\u7b54\u6848\u3002

        "},{"location":"chapter_searching/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 10.1 \u00a0 \u4e8c\u5206\u67e5\u627e
        • 10.2 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9
        • 10.3 \u00a0 \u4e8c\u5206\u67e5\u627e\u8fb9\u754c
        • 10.4 \u00a0 \u54c8\u5e0c\u4f18\u5316\u7b56\u7565
        • 10.5 \u00a0 \u91cd\u8bc6\u641c\u7d22\u7b97\u6cd5
        • 10.6 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_searching/binary_search/","title":"10.1 \u00a0 \u4e8c\u5206\u67e5\u627e","text":"

        \u300c\u4e8c\u5206\u67e5\u627e binary search\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u9ad8\u6548\u641c\u7d22\u7b97\u6cd5\u3002\u5b83\u5229\u7528\u6570\u636e\u7684\u6709\u5e8f\u6027\uff0c\u6bcf\u8f6e\u7f29\u5c0f\u4e00\u534a\u641c\u7d22\u8303\u56f4\uff0c\u76f4\u81f3\u627e\u5230\u76ee\u6807\u5143\u7d20\u6216\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u4e3a\u6b62\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5143\u7d20\u6309\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u6392\u5217\u4e14\u4e0d\u91cd\u590d\u3002\u8bf7\u67e5\u627e\u5e76\u8fd4\u56de\u5143\u7d20 target \u5728\u8be5\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u3002\u82e5\u6570\u7ec4\u4e0d\u5305\u542b\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002\u793a\u4f8b\u5982\u56fe 10-1 \u6240\u793a\u3002

        \u56fe 10-1 \u00a0 \u4e8c\u5206\u67e5\u627e\u793a\u4f8b\u6570\u636e

        \u5982\u56fe 10-2 \u6240\u793a\uff0c\u6211\u4eec\u5148\u521d\u59cb\u5316\u6307\u9488 \\(i = 0\\) \u548c \\(j = n - 1\\) \uff0c\u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u548c\u5c3e\u5143\u7d20\uff0c\u4ee3\u8868\u641c\u7d22\u533a\u95f4 \\([0, n - 1]\\) \u3002\u8bf7\u6ce8\u610f\uff0c\u4e2d\u62ec\u53f7\u8868\u793a\u95ed\u533a\u95f4\uff0c\u5176\u5305\u542b\u8fb9\u754c\u503c\u672c\u8eab\u3002

        \u63a5\u4e0b\u6765\uff0c\u5faa\u73af\u6267\u884c\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 \\(m = \\lfloor {(i + j) / 2} \\rfloor\\) \uff0c\u5176\u4e2d \\(\\lfloor \\: \\rfloor\\) \u8868\u793a\u5411\u4e0b\u53d6\u6574\u64cd\u4f5c\u3002
        2. \u5224\u65ad nums[m] \u548c target \u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5206\u4e3a\u4ee5\u4e0b\u4e09\u79cd\u60c5\u51b5\u3002
          1. \u5f53 nums[m] < target \u65f6\uff0c\u8bf4\u660e target \u5728\u533a\u95f4 \\([m + 1, j]\\) \u4e2d\uff0c\u56e0\u6b64\u6267\u884c \\(i = m + 1\\) \u3002
          2. \u5f53 nums[m] > target \u65f6\uff0c\u8bf4\u660e target \u5728\u533a\u95f4 \\([i, m - 1]\\) \u4e2d\uff0c\u56e0\u6b64\u6267\u884c \\(j = m - 1\\) \u3002
          3. \u5f53 nums[m] = target \u65f6\uff0c\u8bf4\u660e\u627e\u5230 target \uff0c\u56e0\u6b64\u8fd4\u56de\u7d22\u5f15 \\(m\\) \u3002

        \u82e5\u6570\u7ec4\u4e0d\u5305\u542b\u76ee\u6807\u5143\u7d20\uff0c\u641c\u7d22\u533a\u95f4\u6700\u7ec8\u4f1a\u7f29\u5c0f\u4e3a\u7a7a\u3002\u6b64\u65f6\u8fd4\u56de \\(-1\\) \u3002

        <1><2><3><4><5><6><7>

        \u56fe 10-2 \u00a0 \u4e8c\u5206\u67e5\u627e\u6d41\u7a0b

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e \\(i\\) \u548c \\(j\\) \u90fd\u662f int \u7c7b\u578b\uff0c\u56e0\u6b64 \\(i + j\\) \u53ef\u80fd\u4f1a\u8d85\u51fa int \u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u3002\u4e3a\u4e86\u907f\u514d\u5927\u6570\u8d8a\u754c\uff0c\u6211\u4eec\u901a\u5e38\u91c7\u7528\u516c\u5f0f \\(m = \\lfloor {i + (j - i) / 2} \\rfloor\\) \u6765\u8ba1\u7b97\u4e2d\u70b9\u3002

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search.py
        def binary_search(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09\"\"\"\n# \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\ni, j = 0, len(nums) - 1\n# \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j:\n# \u7406\u8bba\u4e0a Python \u7684\u6570\u5b57\u53ef\u4ee5\u65e0\u9650\u5927\uff08\u53d6\u51b3\u4e8e\u5185\u5b58\u5927\u5c0f\uff09\uff0c\u65e0\u987b\u8003\u8651\u5927\u6570\u8d8a\u754c\u95ee\u9898\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nreturn m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn -1  # \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n
        binary_search.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(vector<int> &nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.size() - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.java
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(int[] nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.cs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint BinarySearch(int[] nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.Length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.go
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunc binarySearch(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\ni, j := 0, len(nums)-1\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nfor i <= j {\nm := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.swift
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nvar i = 0\nvar j = nums.count - 1\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.js
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunction binarySearch(nums, target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet i = 0,\nj = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\nconst m = parseInt(i + (j - i) / 2);\nif (nums[m] < target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse return m; // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.ts
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunction binarySearch(nums: number[], target: number): number {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet i = 0,\nj = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = Math.floor(i + (j - i) / 2);\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\nreturn -1; // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n}\n
        binary_search.dart
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(List<int> nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.rs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet mut i = 0;\nlet mut j = nums.len() as i32 - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j {\nlet m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}                       }\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.c
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(int *nums, int len, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = len - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.zig
        // \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09\nfn binarySearch(comptime T: type, nums: std.ArrayList(T), target: T) T {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nvar i: usize = 0;\nvar j: usize = nums.items.len - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nvar m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn @intCast(m);\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n

        \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(\\log n)\\) \uff1a\u5728\u4e8c\u5206\u5faa\u73af\u4e2d\uff0c\u533a\u95f4\u6bcf\u8f6e\u7f29\u5c0f\u4e00\u534a\uff0c\u5faa\u73af\u6b21\u6570\u4e3a \\(\\log_2 n\\) \u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\) \uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7a7a\u95f4\u3002

        "},{"location":"chapter_searching/binary_search/#1011","title":"10.1.1 \u00a0 \u533a\u95f4\u8868\u793a\u65b9\u6cd5","text":"

        \u9664\u4e86\u4e0a\u8ff0\u53cc\u95ed\u533a\u95f4\u5916\uff0c\u5e38\u89c1\u7684\u533a\u95f4\u8868\u793a\u8fd8\u6709\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u533a\u95f4\uff0c\u5b9a\u4e49\u4e3a \\([0, n)\\) \uff0c\u5373\u5de6\u8fb9\u754c\u5305\u542b\u81ea\u8eab\uff0c\u53f3\u8fb9\u754c\u4e0d\u5305\u542b\u81ea\u8eab\u3002\u5728\u8be5\u8868\u793a\u4e0b\uff0c\u533a\u95f4 \\([i, j]\\) \u5728 \\(i = j\\) \u65f6\u4e3a\u7a7a\u3002

        \u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u8be5\u8868\u793a\u5b9e\u73b0\u5177\u6709\u76f8\u540c\u529f\u80fd\u7684\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search.py
        def binary_search_lcro(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09\"\"\"\n# \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\ni, j = 0, len(nums)\n# \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\nelif nums[m] > target:\nj = m  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nelse:\nreturn m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn -1  # \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n
        binary_search.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(vector<int> &nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.size();\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.java
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(int[] nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.cs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint BinarySearchLCRO(int[] nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.Length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.go
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunc binarySearchLCRO(nums []int, target int) int {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\ni, j := 0, len(nums)\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nfor i < j {\nm := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.swift
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunc binarySearchLCRO(nums: [Int], target: Int) -> Int {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nvar i = 0\nvar j = nums.count\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.js
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunction binarySearchLCRO(nums, target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet i = 0,\nj = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\nconst m = parseInt(i + (j - i) / 2);\nif (nums[m] < target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nelse return m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.ts
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunction binarySearchLCRO(nums: number[], target: number): number {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet i = 0,\nj = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = Math.floor(i + (j - i) / 2);\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\nreturn -1; // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n}\n
        binary_search.dart
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(List<int> nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.rs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfn binary_search_lcro(nums: &[i32], target: i32) -> i32 {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet mut i = 0;\nlet mut j = nums.len() as i32;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j {\nlet m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m - 1;\n} else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}                       }\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.c
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(int *nums, int len, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = len;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.zig
        // \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09\nfn binarySearchLCRO(comptime T: type, nums: std.ArrayList(T), target: T) T {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nvar i: usize = 0;\nvar j: usize = nums.items.len;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nvar m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn @intCast(m);\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n

        \u5982\u56fe 10-3 \u6240\u793a\uff0c\u5728\u4e24\u79cd\u533a\u95f4\u8868\u793a\u4e0b\uff0c\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u7684\u521d\u59cb\u5316\u3001\u5faa\u73af\u6761\u4ef6\u548c\u7f29\u5c0f\u533a\u95f4\u64cd\u4f5c\u7686\u6709\u6240\u4e0d\u540c\u3002

        \u7531\u4e8e\u201c\u53cc\u95ed\u533a\u95f4\u201d\u8868\u793a\u4e2d\u7684\u5de6\u53f3\u8fb9\u754c\u90fd\u88ab\u5b9a\u4e49\u4e3a\u95ed\u533a\u95f4\uff0c\u56e0\u6b64\u901a\u8fc7\u6307\u9488 \\(i\\) \u548c\u6307\u9488 \\(j\\) \u7f29\u5c0f\u533a\u95f4\u7684\u64cd\u4f5c\u4e5f\u662f\u5bf9\u79f0\u7684\u3002\u8fd9\u6837\u66f4\u4e0d\u5bb9\u6613\u51fa\u9519\uff0c\u56e0\u6b64\u4e00\u822c\u5efa\u8bae\u91c7\u7528\u201c\u53cc\u95ed\u533a\u95f4\u201d\u7684\u5199\u6cd5\u3002

        \u56fe 10-3 \u00a0 \u4e24\u79cd\u533a\u95f4\u5b9a\u4e49

        "},{"location":"chapter_searching/binary_search/#1012","title":"10.1.2 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u4e8c\u5206\u67e5\u627e\u5728\u65f6\u95f4\u548c\u7a7a\u95f4\u65b9\u9762\u90fd\u6709\u8f83\u597d\u7684\u6027\u80fd\u3002

        • \u4e8c\u5206\u67e5\u627e\u7684\u65f6\u95f4\u6548\u7387\u9ad8\u3002\u5728\u5927\u6570\u636e\u91cf\u4e0b\uff0c\u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5177\u6709\u663e\u8457\u4f18\u52bf\u3002\u4f8b\u5982\uff0c\u5f53\u6570\u636e\u5927\u5c0f \\(n = 2^{20}\\) \u65f6\uff0c\u7ebf\u6027\u67e5\u627e\u9700\u8981 \\(2^{20} = 1048576\\) \u8f6e\u5faa\u73af\uff0c\u800c\u4e8c\u5206\u67e5\u627e\u4ec5\u9700 \\(\\log_2 2^{20} = 20\\) \u8f6e\u5faa\u73af\u3002
        • \u4e8c\u5206\u67e5\u627e\u65e0\u987b\u989d\u5916\u7a7a\u95f4\u3002\u76f8\u8f83\u4e8e\u9700\u8981\u501f\u52a9\u989d\u5916\u7a7a\u95f4\u7684\u641c\u7d22\u7b97\u6cd5\uff08\u4f8b\u5982\u54c8\u5e0c\u67e5\u627e\uff09\uff0c\u4e8c\u5206\u67e5\u627e\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\u3002

        \u7136\u800c\uff0c\u4e8c\u5206\u67e5\u627e\u5e76\u975e\u9002\u7528\u4e8e\u6240\u6709\u60c5\u51b5\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u4e8c\u5206\u67e5\u627e\u4ec5\u9002\u7528\u4e8e\u6709\u5e8f\u6570\u636e\u3002\u82e5\u8f93\u5165\u6570\u636e\u65e0\u5e8f\uff0c\u4e3a\u4e86\u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u800c\u4e13\u95e8\u8fdb\u884c\u6392\u5e8f\uff0c\u5f97\u4e0d\u507f\u5931\u3002\u56e0\u4e3a\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u4e3a \\(O(n \\log n)\\) \uff0c\u6bd4\u7ebf\u6027\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u90fd\u66f4\u9ad8\u3002\u5bf9\u4e8e\u9891\u7e41\u63d2\u5165\u5143\u7d20\u7684\u573a\u666f\uff0c\u4e3a\u4fdd\u6301\u6570\u7ec4\u6709\u5e8f\u6027\uff0c\u9700\u8981\u5c06\u5143\u7d20\u63d2\u5165\u5230\u7279\u5b9a\u4f4d\u7f6e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u4e5f\u662f\u975e\u5e38\u6602\u8d35\u7684\u3002
        • \u4e8c\u5206\u67e5\u627e\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u3002\u4e8c\u5206\u67e5\u627e\u9700\u8981\u8df3\u8dc3\u5f0f\uff08\u975e\u8fde\u7eed\u5730\uff09\u8bbf\u95ee\u5143\u7d20\uff0c\u800c\u5728\u94fe\u8868\u4e2d\u6267\u884c\u8df3\u8dc3\u5f0f\u8bbf\u95ee\u7684\u6548\u7387\u8f83\u4f4e\uff0c\u56e0\u6b64\u4e0d\u9002\u5408\u5e94\u7528\u5728\u94fe\u8868\u6216\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u5c0f\u6570\u636e\u91cf\u4e0b\uff0c\u7ebf\u6027\u67e5\u627e\u6027\u80fd\u66f4\u4f73\u3002\u5728\u7ebf\u6027\u67e5\u627e\u4e2d\uff0c\u6bcf\u8f6e\u53ea\u9700 1 \u6b21\u5224\u65ad\u64cd\u4f5c\uff1b\u800c\u5728\u4e8c\u5206\u67e5\u627e\u4e2d\uff0c\u9700\u8981 1 \u6b21\u52a0\u6cd5\u30011 \u6b21\u9664\u6cd5\u30011 ~ 3 \u6b21\u5224\u65ad\u64cd\u4f5c\u30011 \u6b21\u52a0\u6cd5\uff08\u51cf\u6cd5\uff09\uff0c\u5171 4 ~ 6 \u4e2a\u5355\u5143\u64cd\u4f5c\uff1b\u56e0\u6b64\uff0c\u5f53\u6570\u636e\u91cf \\(n\\) \u8f83\u5c0f\u65f6\uff0c\u7ebf\u6027\u67e5\u627e\u53cd\u800c\u6bd4\u4e8c\u5206\u67e5\u627e\u66f4\u5feb\u3002
        "},{"location":"chapter_searching/binary_search_edge/","title":"10.3 \u00a0 \u4e8c\u5206\u67e5\u627e\u8fb9\u754c","text":""},{"location":"chapter_searching/binary_search_edge/#1031","title":"10.3.1 \u00a0 \u67e5\u627e\u5de6\u8fb9\u754c","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002\u8bf7\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u5de6\u4e00\u4e2a\u5143\u7d20 target \u7684\u7d22\u5f15\u3002\u82e5\u6570\u7ec4\u4e2d\u4e0d\u5305\u542b\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002

        \u56de\u5fc6\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\u7684\u65b9\u6cd5\uff0c\u641c\u7d22\u5b8c\u6210\u540e \\(i\\) \u6307\u5411\u6700\u5de6\u4e00\u4e2a target \uff0c\u56e0\u6b64\u67e5\u627e\u63d2\u5165\u70b9\u672c\u8d28\u4e0a\u662f\u5728\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target \u7684\u7d22\u5f15\u3002

        \u8003\u8651\u901a\u8fc7\u67e5\u627e\u63d2\u5165\u70b9\u7684\u51fd\u6570\u5b9e\u73b0\u67e5\u627e\u5de6\u8fb9\u754c\u3002\u8bf7\u6ce8\u610f\uff0c\u6570\u7ec4\u4e2d\u53ef\u80fd\u4e0d\u5305\u542b target \uff0c\u8fd9\u79cd\u60c5\u51b5\u53ef\u80fd\u5bfc\u81f4\u4ee5\u4e0b\u4e24\u79cd\u7ed3\u679c\u3002

        • \u63d2\u5165\u70b9\u7684\u7d22\u5f15 \\(i\\) \u8d8a\u754c\u3002
        • \u5143\u7d20 nums[i] \u4e0e target \u4e0d\u76f8\u7b49\u3002

        \u5f53\u9047\u5230\u4ee5\u4e0a\u4e24\u79cd\u60c5\u51b5\u65f6\uff0c\u76f4\u63a5\u8fd4\u56de \\(-1\\) \u5373\u53ef\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_edge.py
        def binary_search_left_edge(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target\"\"\"\n# \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\ni = binary_search_insertion(nums, target)\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == len(nums) or nums[i] != target:\nreturn -1\n# \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n
        binary_search_edge.cpp
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(vector<int> &nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.size() || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.java
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(int[] nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binary_search_insertion.binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.cs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint BinarySearchLeftEdge(int[] nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binary_search_insertion.BinarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.Length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.go
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunc binarySearchLeftEdge(nums []int, target int) int {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\ni := binarySearchInsertion(nums, target)\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == len(nums) || nums[i] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n}\n
        binary_search_edge.swift
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunc binarySearchLeftEdge(nums: [Int], target: Int) -> Int {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nlet i = binarySearchInsertion(nums: nums, target: target)\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == nums.count || nums[i] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n}\n
        binary_search_edge.js
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunction binarySearchLeftEdge(nums, target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nconst i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i === nums.length || nums[i] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.ts
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunction binarySearchLeftEdge(nums: Array<number>, target: number): number {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nconst i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i === nums.length || nums[i] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.dart
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(List<int> nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.rs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfn binary_search_left_edge(nums: &[i32], target: i32) -> i32 {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nlet i = binary_search_insertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == nums.len() as i32 || nums[i as usize] != target {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\ni\n}\n
        binary_search_edge.c
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(int *nums, int numSize, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, numSize, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == numSize || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.zig
        [class]{}-[func]{binarySearchLeftEdge}\n
        "},{"location":"chapter_searching/binary_search_edge/#1032","title":"10.3.2 \u00a0 \u67e5\u627e\u53f3\u8fb9\u754c","text":"

        \u90a3\u4e48\u5982\u4f55\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \u5462\uff1f\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u4fee\u6539\u4ee3\u7801\uff0c\u66ff\u6362\u5728 nums[m] == target \u60c5\u51b5\u4e0b\u7684\u6307\u9488\u6536\u7f29\u64cd\u4f5c\u3002\u4ee3\u7801\u5728\u6b64\u7701\u7565\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u3002

        \u4e0b\u9762\u6211\u4eec\u4ecb\u7ecd\u4e24\u79cd\u66f4\u52a0\u53d6\u5de7\u7684\u65b9\u6cd5\u3002

        "},{"location":"chapter_searching/binary_search_edge/#1","title":"1. \u00a0 \u590d\u7528\u67e5\u627e\u5de6\u8fb9\u754c","text":"

        \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u67e5\u627e\u6700\u5de6\u5143\u7d20\u7684\u51fd\u6570\u6765\u67e5\u627e\u6700\u53f3\u5143\u7d20\uff0c\u5177\u4f53\u65b9\u6cd5\u4e3a\uff1a\u5c06\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\u3002

        \u5982\u56fe 10-7 \u6240\u793a\uff0c\u67e5\u627e\u5b8c\u6210\u540e\uff0c\u6307\u9488 \\(i\\) \u6307\u5411\u6700\u5de6\u4e00\u4e2a target + 1\uff08\u5982\u679c\u5b58\u5728\uff09\uff0c\u800c \\(j\\) \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0c\u56e0\u6b64\u8fd4\u56de \\(j\\) \u5373\u53ef\u3002

        \u56fe 10-7 \u00a0 \u5c06\u67e5\u627e\u53f3\u8fb9\u754c\u8f6c\u5316\u4e3a\u67e5\u627e\u5de6\u8fb9\u754c

        \u8bf7\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u63d2\u5165\u70b9\u662f \\(i\\) \uff0c\u56e0\u6b64\u9700\u8981\u5c06\u5176\u51cf \\(1\\) \uff0c\u4ece\u800c\u83b7\u5f97 \\(j\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_edge.py
        def binary_search_right_edge(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target\"\"\"\n# \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\ni = binary_search_insertion(nums, target + 1)\n# j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nj = i - 1\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 or nums[j] != target:\nreturn -1\n# \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n
        binary_search_edge.cpp
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(vector<int> &nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.java
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(int[] nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binary_search_insertion.binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.cs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint BinarySearchRightEdge(int[] nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binary_search_insertion.BinarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.go
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunc binarySearchRightEdge(nums []int, target int) int {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\ni := binarySearchInsertion(nums, target+1)\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nj := i - 1\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n}\n
        binary_search_edge.swift
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunc binarySearchRightEdge(nums: [Int], target: Int) -> Int {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nlet i = binarySearchInsertion(nums: nums, target: target + 1)\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nlet j = i - 1\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n}\n
        binary_search_edge.js
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunction binarySearchRightEdge(nums, target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nconst i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nconst j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j === -1 || nums[j] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.ts
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunction binarySearchRightEdge(nums: Array<number>, target: number): number {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nconst i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nconst j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j === -1 || nums[j] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.dart
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(List<int> nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.rs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfn binary_search_right_edge(nums: &[i32], target: i32) -> i32 {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nlet i = binary_search_insertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nlet j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j as usize] != target {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nj\n}\n
        binary_search_edge.c
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(int *nums, int numSize, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, numSize, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.zig
        [class]{}-[func]{binarySearchRightEdge}\n
        "},{"location":"chapter_searching/binary_search_edge/#2","title":"2. \u00a0 \u8f6c\u5316\u4e3a\u67e5\u627e\u5143\u7d20","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u5f53\u6570\u7ec4\u4e0d\u5305\u542b target \u65f6\uff0c\u6700\u7ec8 \\(i\\) \u548c \\(j\\) \u4f1a\u5206\u522b\u6307\u5411\u9996\u4e2a\u5927\u4e8e\u3001\u5c0f\u4e8e target \u7684\u5143\u7d20\u3002

        \u56e0\u6b64\uff0c\u5982\u56fe 10-8 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u7684\u5143\u7d20\uff0c\u7528\u4e8e\u67e5\u627e\u5de6\u53f3\u8fb9\u754c\u3002

        • \u67e5\u627e\u6700\u5de6\u4e00\u4e2a target \uff1a\u53ef\u4ee5\u8f6c\u5316\u4e3a\u67e5\u627e target - 0.5 \uff0c\u5e76\u8fd4\u56de\u6307\u9488 \\(i\\) \u3002
        • \u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \uff1a\u53ef\u4ee5\u8f6c\u5316\u4e3a\u67e5\u627e target + 0.5 \uff0c\u5e76\u8fd4\u56de\u6307\u9488 \\(j\\) \u3002

        \u56fe 10-8 \u00a0 \u5c06\u67e5\u627e\u8fb9\u754c\u8f6c\u5316\u4e3a\u67e5\u627e\u5143\u7d20

        \u4ee3\u7801\u5728\u6b64\u7701\u7565\uff0c\u4ee5\u4e0b\u4e24\u70b9\u503c\u5f97\u6ce8\u610f\u3002

        • \u7ed9\u5b9a\u6570\u7ec4\u4e0d\u5305\u542b\u5c0f\u6570\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u65e0\u987b\u5173\u5fc3\u5982\u4f55\u5904\u7406\u76f8\u7b49\u7684\u60c5\u51b5\u3002
        • \u56e0\u4e3a\u8be5\u65b9\u6cd5\u5f15\u5165\u4e86\u5c0f\u6570\uff0c\u6240\u4ee5\u9700\u8981\u5c06\u51fd\u6570\u4e2d\u7684\u53d8\u91cf target \u6539\u4e3a\u6d6e\u70b9\u6570\u7c7b\u578b\u3002
        "},{"location":"chapter_searching/binary_search_insertion/","title":"10.2 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9","text":"

        \u4e8c\u5206\u67e5\u627e\u4e0d\u4ec5\u53ef\u7528\u4e8e\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff0c\u8fd8\u53ef\u7528\u4e8e\u89e3\u51b3\u8bb8\u591a\u53d8\u79cd\u95ee\u9898\uff0c\u6bd4\u5982\u641c\u7d22\u76ee\u6807\u5143\u7d20\u7684\u63d2\u5165\u4f4d\u7f6e\u3002

        "},{"location":"chapter_searching/binary_search_insertion/#1021","title":"10.2.1 \u00a0 \u65e0\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u5143\u7d20 target \uff0c\u6570\u7ec4\u4e0d\u5b58\u5728\u91cd\u590d\u5143\u7d20\u3002\u73b0\u5c06 target \u63d2\u5165\u6570\u7ec4 nums \u4e2d\uff0c\u5e76\u4fdd\u6301\u5176\u6709\u5e8f\u6027\u3002\u82e5\u6570\u7ec4\u4e2d\u5df2\u5b58\u5728\u5143\u7d20 target \uff0c\u5219\u63d2\u5165\u5230\u5176\u5de6\u65b9\u3002\u8bf7\u8fd4\u56de\u63d2\u5165\u540e target \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u3002

        \u56fe 10-4 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\u793a\u4f8b\u6570\u636e

        \u5982\u679c\u60f3\u590d\u7528\u4e0a\u4e00\u8282\u7684\u4e8c\u5206\u67e5\u627e\u4ee3\u7801\uff0c\u5219\u9700\u8981\u56de\u7b54\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\u3002

        \u95ee\u9898\u4e00\uff1a\u5f53\u6570\u7ec4\u4e2d\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u70b9\u7684\u7d22\u5f15\u662f\u5426\u662f\u8be5\u5143\u7d20\u7684\u7d22\u5f15\uff1f

        \u9898\u76ee\u8981\u6c42\u5c06 target \u63d2\u5165\u5230\u76f8\u7b49\u5143\u7d20\u7684\u5de6\u8fb9\uff0c\u8fd9\u610f\u5473\u7740\u65b0\u63d2\u5165\u7684 target \u66ff\u6362\u4e86\u539f\u6765 target \u7684\u4f4d\u7f6e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6570\u7ec4\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u70b9\u7684\u7d22\u5f15\u5c31\u662f\u8be5 target \u7684\u7d22\u5f15\u3002

        \u95ee\u9898\u4e8c\uff1a\u5f53\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728 target \u65f6\uff0c\u63d2\u5165\u70b9\u662f\u54ea\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff1f

        \u8fdb\u4e00\u6b65\u601d\u8003\u4e8c\u5206\u67e5\u627e\u8fc7\u7a0b\uff1a\u5f53 nums[m] < target \u65f6 \\(i\\) \u79fb\u52a8\uff0c\u8fd9\u610f\u5473\u7740\u6307\u9488 \\(i\\) \u5728\u5411\u5927\u4e8e\u7b49\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002\u540c\u7406\uff0c\u6307\u9488 \\(j\\) \u59cb\u7ec8\u5728\u5411\u5c0f\u4e8e\u7b49\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002

        \u56e0\u6b64\u4e8c\u5206\u7ed3\u675f\u65f6\u4e00\u5b9a\u6709\uff1a\\(i\\) \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\uff0c\\(j\\) \u6307\u5411\u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u3002\u6613\u5f97\u5f53\u6570\u7ec4\u4e0d\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u7d22\u5f15\u4e3a \\(i\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_insertion.py
        def binary_search_insertion_simple(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09\"\"\"\ni, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nreturn m  # \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n
        binary_search_insertion.cpp
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(vector<int> &nums, int target) {\nint i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.java
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(int[] nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.cs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint BinarySearchInsertionSimple(int[] nums, int target) {\nint i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.go
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertionSimple(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\ni, j := 0, len(nums)-1\nfor i <= j {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm := i + (j-i)/2\nif nums[m] < target {\n// target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target {\n// target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else {\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\nreturn m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.swift
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertionSimple(nums: [Int], target: Int) -> Int {\nvar i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target {\ni = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m] > target {\nj = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.js
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(nums, target) {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.ts
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(\nnums: Array<number>,\ntarget: number\n): number {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.dart
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(List<int> nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.rs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\npub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 {\nlet (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {\ni = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m as usize] > target {\nj = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1;  // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\ni\n}\n
        binary_search_insertion.c
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(int *nums, int numSize, int target) {\nint i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.zig
        [class]{}-[func]{binarySearchInsertionSimple}\n
        "},{"location":"chapter_searching/binary_search_insertion/#1022","title":"10.2.2 \u00a0 \u5b58\u5728\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u5728\u4e0a\u4e00\u9898\u7684\u57fa\u7840\u4e0a\uff0c\u89c4\u5b9a\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u5176\u4f59\u4e0d\u53d8\u3002

        \u5047\u8bbe\u6570\u7ec4\u4e2d\u5b58\u5728\u591a\u4e2a target \uff0c\u5219\u666e\u901a\u4e8c\u5206\u67e5\u627e\u53ea\u80fd\u8fd4\u56de\u5176\u4e2d\u4e00\u4e2a target \u7684\u7d22\u5f15\uff0c\u800c\u65e0\u6cd5\u786e\u5b9a\u8be5\u5143\u7d20\u7684\u5de6\u8fb9\u548c\u53f3\u8fb9\u8fd8\u6709\u591a\u5c11 target\u3002

        \u9898\u76ee\u8981\u6c42\u5c06\u76ee\u6807\u5143\u7d20\u63d2\u5165\u5230\u6700\u5de6\u8fb9\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5de6\u4e00\u4e2a target \u7684\u7d22\u5f15\u3002\u521d\u6b65\u8003\u8651\u901a\u8fc7\u56fe 10-5 \u6240\u793a\u7684\u6b65\u9aa4\u5b9e\u73b0\u3002

        1. \u6267\u884c\u4e8c\u5206\u67e5\u627e\uff0c\u5f97\u5230\u4efb\u610f\u4e00\u4e2a target \u7684\u7d22\u5f15\uff0c\u8bb0\u4e3a \\(k\\) \u3002
        2. \u4ece\u7d22\u5f15 \\(k\\) \u5f00\u59cb\uff0c\u5411\u5de6\u8fdb\u884c\u7ebf\u6027\u904d\u5386\uff0c\u5f53\u627e\u5230\u6700\u5de6\u8fb9\u7684 target \u65f6\u8fd4\u56de\u3002

        \u56fe 10-5 \u00a0 \u7ebf\u6027\u67e5\u627e\u91cd\u590d\u5143\u7d20\u7684\u63d2\u5165\u70b9

        \u6b64\u65b9\u6cd5\u867d\u7136\u53ef\u7528\uff0c\u4f46\u5176\u5305\u542b\u7ebf\u6027\u67e5\u627e\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5f53\u6570\u7ec4\u4e2d\u5b58\u5728\u5f88\u591a\u91cd\u590d\u7684 target \u65f6\uff0c\u8be5\u65b9\u6cd5\u6548\u7387\u5f88\u4f4e\u3002

        \u73b0\u8003\u8651\u62d3\u5c55\u4e8c\u5206\u67e5\u627e\u4ee3\u7801\u3002\u5982\u56fe 10-6 \u6240\u793a\uff0c\u6574\u4f53\u6d41\u7a0b\u4fdd\u6301\u4e0d\u53d8\uff0c\u6bcf\u8f6e\u5148\u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 \\(m\\) \uff0c\u518d\u5224\u65ad target \u548c nums[m] \u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u3002

        • \u5f53 nums[m] < target \u6216 nums[m] > target \u65f6\uff0c\u8bf4\u660e\u8fd8\u6ca1\u6709\u627e\u5230 target \uff0c\u56e0\u6b64\u91c7\u7528\u666e\u901a\u4e8c\u5206\u67e5\u627e\u7684\u7f29\u5c0f\u533a\u95f4\u64cd\u4f5c\uff0c\u4ece\u800c\u4f7f\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5411 target \u9760\u8fd1\u3002
        • \u5f53 nums[m] == target \u65f6\uff0c\u8bf4\u660e\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 \\([i, m - 1]\\) \u4e2d\uff0c\u56e0\u6b64\u91c7\u7528 \\(j = m - 1\\) \u6765\u7f29\u5c0f\u533a\u95f4\uff0c\u4ece\u800c\u4f7f\u6307\u9488 \\(j\\) \u5411\u5c0f\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002

        \u5faa\u73af\u5b8c\u6210\u540e\uff0c\\(i\\) \u6307\u5411\u6700\u5de6\u8fb9\u7684 target \uff0c\\(j\\) \u6307\u5411\u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\uff0c\u56e0\u6b64\u7d22\u5f15 \\(i\\) \u5c31\u662f\u63d2\u5165\u70b9\u3002

        <1><2><3><4><5><6><7><8>

        \u56fe 10-6 \u00a0 \u4e8c\u5206\u67e5\u627e\u91cd\u590d\u5143\u7d20\u7684\u63d2\u5165\u70b9\u7684\u6b65\u9aa4

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5224\u65ad\u5206\u652f nums[m] > target \u548c nums[m] == target \u7684\u64cd\u4f5c\u76f8\u540c\uff0c\u56e0\u6b64\u4e24\u8005\u53ef\u4ee5\u5408\u5e76\u3002

        \u5373\u4fbf\u5982\u6b64\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u5c06\u5224\u65ad\u6761\u4ef6\u4fdd\u6301\u5c55\u5f00\uff0c\u56e0\u4e3a\u5176\u903b\u8f91\u66f4\u52a0\u6e05\u6670\u3001\u53ef\u8bfb\u6027\u66f4\u597d\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_insertion.py
        def binary_search_insertion(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09\"\"\"\ni, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nj = m - 1  # \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n# \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n
        binary_search_insertion.cpp
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(vector<int> &nums, int target) {\nint i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.java
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(int[] nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.cs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint BinarySearchInsertion(int[] nums, int target) {\nint i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.go
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertion(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\ni, j := 0, len(nums)-1\nfor i <= j {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm := i + (j-i)/2\nif nums[m] < target {\n// target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target {\n// target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else {\n// \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.swift
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertion(nums: [Int], target: Int) -> Int {\nvar i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target {\ni = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m] > target {\nj = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1 // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.js
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertion(nums, target) {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.ts
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertion(nums: Array<number>, target: number): number {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.dart
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(List<int> nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.rs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\npub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 {\nlet (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {\ni = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m as usize] > target {\nj = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1;  // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\ni\n}\n
        binary_search_insertion.c
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(int *nums, int numSize, int target) {\nint i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.zig
        [class]{}-[func]{binarySearchInsertion}\n

        Tip

        \u672c\u8282\u7684\u4ee3\u7801\u90fd\u662f\u201c\u53cc\u95ed\u533a\u95f4\u201d\u5199\u6cd5\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u5199\u6cd5\u3002

        \u603b\u7684\u6765\u770b\uff0c\u4e8c\u5206\u67e5\u627e\u65e0\u975e\u5c31\u662f\u7ed9\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5206\u522b\u8bbe\u5b9a\u641c\u7d22\u76ee\u6807\uff0c\u76ee\u6807\u53ef\u80fd\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u5143\u7d20\uff08\u4f8b\u5982 target \uff09\uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u4e2a\u5143\u7d20\u8303\u56f4\uff08\u4f8b\u5982\u5c0f\u4e8e target \u7684\u5143\u7d20\uff09\u3002

        \u5728\u4e0d\u65ad\u7684\u5faa\u73af\u4e8c\u5206\u4e2d\uff0c\u6307\u9488 \\(i\\) \u548c \\(j\\) \u90fd\u9010\u6e10\u903c\u8fd1\u9884\u5148\u8bbe\u5b9a\u7684\u76ee\u6807\u3002\u6700\u7ec8\uff0c\u5b83\u4eec\u6216\u662f\u6210\u529f\u627e\u5230\u7b54\u6848\uff0c\u6216\u662f\u8d8a\u8fc7\u8fb9\u754c\u540e\u505c\u6b62\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/","title":"10.4 \u00a0 \u54c8\u5e0c\u4f18\u5316\u7b56\u7565","text":"

        \u5728\u7b97\u6cd5\u9898\u4e2d\uff0c\u6211\u4eec\u5e38\u901a\u8fc7\u5c06\u7ebf\u6027\u67e5\u627e\u66ff\u6362\u4e3a\u54c8\u5e0c\u67e5\u627e\u6765\u964d\u4f4e\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u7b97\u6cd5\u9898\u6765\u52a0\u6df1\u7406\u89e3\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u5143\u7d20 target \uff0c\u8bf7\u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u201c\u548c\u201d\u4e3a target \u7684\u4e24\u4e2a\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u7d22\u5f15\u3002\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u89e3\u5373\u53ef\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/#1041","title":"10.4.1 \u00a0 \u7ebf\u6027\u67e5\u627e\uff1a\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4","text":"

        \u8003\u8651\u76f4\u63a5\u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u3002\u5982\u56fe 10-9 \u6240\u793a\uff0c\u6211\u4eec\u5f00\u542f\u4e00\u4e2a\u4e24\u5c42\u5faa\u73af\uff0c\u5728\u6bcf\u8f6e\u4e2d\u5224\u65ad\u4e24\u4e2a\u6574\u6570\u7684\u548c\u662f\u5426\u4e3a target \uff0c\u82e5\u662f\uff0c\u5219\u8fd4\u56de\u5b83\u4eec\u7684\u7d22\u5f15\u3002

        \u56fe 10-9 \u00a0 \u7ebf\u6027\u67e5\u627e\u6c42\u89e3\u4e24\u6570\u4e4b\u548c

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig two_sum.py
        def two_sum_brute_force(nums: list[int], target: int) -> list[int]:\n\"\"\"\u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\"\"\"\n# \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in range(len(nums) - 1):\nfor j in range(i + 1, len(nums)):\nif nums[i] + nums[j] == target:\nreturn [i, j]\nreturn []\n
        two_sum.cpp
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nvector<int> twoSumBruteForce(vector<int> &nums, int target) {\nint size = nums.size();\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn {i, j};\n}\n}\nreturn {};\n}\n
        two_sum.java
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] twoSumBruteForce(int[] nums, int target) {\nint size = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn new int[] { i, j };\n}\n}\nreturn new int[0];\n}\n
        two_sum.cs
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] TwoSumBruteForce(int[] nums, int target) {\nint size = nums.Length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn [i, j];\n}\n}\nreturn [];\n}\n
        two_sum.go
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums []int, target int) []int {\nsize := len(nums)\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i := 0; i < size-1; i++ {\nfor j := i + 1; i < size; j++ {\nif nums[i]+nums[j] == target {\nreturn []int{i, j}\n}\n}\n}\nreturn nil\n}\n
        two_sum.swift
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums: [Int], target: Int) -> [Int] {\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in nums.indices.dropLast() {\nfor j in nums.indices.dropFirst(i + 1) {\nif nums[i] + nums[j] == target {\nreturn [i, j]\n}\n}\n}\nreturn [0]\n}\n
        two_sum.js
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums, target) {\nconst n = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (let i = 0; i < n; i++) {\nfor (let j = i + 1; j < n; j++) {\nif (nums[i] + nums[j] === target) {\nreturn [i, j];\n}\n}\n}\nreturn [];\n}\n
        two_sum.ts
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums: number[], target: number): number[] {\nconst n = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (let i = 0; i < n; i++) {\nfor (let j = i + 1; j < n; j++) {\nif (nums[i] + nums[j] === target) {\nreturn [i, j];\n}\n}\n}\nreturn [];\n}\n
        two_sum.dart
        /* \u65b9\u6cd5\u4e00\uff1a \u66b4\u529b\u679a\u4e3e */\nList<int> twoSumBruteForce(List<int> nums, int target) {\nint size = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (var i = 0; i < size - 1; i++) {\nfor (var j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target) return [i, j];\n}\n}\nreturn [0];\n}\n
        two_sum.rs
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\npub fn two_sum_brute_force(nums: &Vec<i32>, target: i32) -> Option<Vec<i32>> {\nlet size = nums.len();\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in 0..size - 1 {\nfor j in i + 1..size {\nif nums[i] + nums[j] == target {\nreturn Some(vec![i as i32, j as i32]);\n}\n}\n}\nNone\n}\n
        two_sum.c
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {\nfor (int i = 0; i < numsSize; ++i) {\nfor (int j = i + 1; j < numsSize; ++j) {\nif (nums[i] + nums[j] == target) {\nint *res = malloc(sizeof(int) * 2);\nres[0] = i, res[1] = j;\n*returnSize = 2;\nreturn res;\n}\n}\n}\n*returnSize = 0;\nreturn NULL;\n}\n
        two_sum.zig
        // \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\nfn twoSumBruteForce(nums: []i32, target: i32) ?[2]i32 {\nvar size: usize = nums.len;\nvar i: usize = 0;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nwhile (i < size - 1) : (i += 1) {\nvar j = i + 1;\nwhile (j < size) : (j += 1) {\nif (nums[i] + nums[j] == target) {\nreturn [_]i32{@intCast(i), @intCast(j)};\n}\n}\n}\nreturn null;\n}\n

        \u6b64\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff0c\u5728\u5927\u6570\u636e\u91cf\u4e0b\u975e\u5e38\u8017\u65f6\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/#1042","title":"10.4.2 \u00a0 \u54c8\u5e0c\u67e5\u627e\uff1a\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4","text":"

        \u8003\u8651\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\uff0c\u952e\u503c\u5bf9\u5206\u522b\u4e3a\u6570\u7ec4\u5143\u7d20\u548c\u5143\u7d20\u7d22\u5f15\u3002\u5faa\u73af\u904d\u5386\u6570\u7ec4\uff0c\u6bcf\u8f6e\u6267\u884c\u56fe 10-10 \u6240\u793a\u7684\u6b65\u9aa4\u3002

        1. \u5224\u65ad\u6570\u5b57 target - nums[i] \u662f\u5426\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u82e5\u662f\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u8fd9\u4e24\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u3002
        2. \u5c06\u952e\u503c\u5bf9 nums[i] \u548c\u7d22\u5f15 i \u6dfb\u52a0\u8fdb\u54c8\u5e0c\u8868\u3002
        <1><2><3>

        \u56fe 10-10 \u00a0 \u8f85\u52a9\u54c8\u5e0c\u8868\u6c42\u89e3\u4e24\u6570\u4e4b\u548c

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff0c\u4ec5\u9700\u5355\u5c42\u5faa\u73af\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig two_sum.py
        def two_sum_hash_table(nums: list[int], target: int) -> list[int]:\n\"\"\"\u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\"\"\"\n# \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndic = {}\n# \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor i in range(len(nums)):\nif target - nums[i] in dic:\nreturn [dic[target - nums[i]], i]\ndic[nums[i]] = i\nreturn []\n
        two_sum.cpp
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nvector<int> twoSumHashTable(vector<int> &nums, int target) {\nint size = nums.size();\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nunordered_map<int, int> dic;\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.find(target - nums[i]) != dic.end()) {\nreturn {dic[target - nums[i]], i};\n}\ndic.emplace(nums[i], i);\n}\nreturn {};\n}\n
        two_sum.java
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] twoSumHashTable(int[] nums, int target) {\nint size = nums.length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nMap<Integer, Integer> dic = new HashMap<>();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.containsKey(target - nums[i])) {\nreturn new int[] { dic.get(target - nums[i]), i };\n}\ndic.put(nums[i], i);\n}\nreturn new int[0];\n}\n
        two_sum.cs
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] TwoSumHashTable(int[] nums, int target) {\nint size = nums.Length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nDictionary<int, int> dic = [];\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.ContainsKey(target - nums[i])) {\nreturn [dic[target - nums[i]], i];\n}\ndic.Add(nums[i], i);\n}\nreturn [];\n}\n
        two_sum.go
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunc twoSumHashTable(nums []int, target int) []int {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nhashTable := map[int]int{}\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor idx, val := range nums {\nif preIdx, ok := hashTable[target-val]; ok {\nreturn []int{preIdx, idx}\n}\nhashTable[val] = idx\n}\nreturn nil\n}\n
        two_sum.swift
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunc twoSumHashTable(nums: [Int], target: Int) -> [Int] {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nvar dic: [Int: Int] = [:]\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor i in nums.indices {\nif let j = dic[target - nums[i]] {\nreturn [j, i]\n}\ndic[nums[i]] = i\n}\nreturn [0]\n}\n
        two_sum.js
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunction twoSumHashTable(nums, target) {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet m = {};\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (let i = 0; i < nums.length; i++) {\nif (m[target - nums[i]] !== undefined) {\nreturn [m[target - nums[i]], i];\n} else {\nm[nums[i]] = i;\n}\n}\nreturn [];\n}\n
        two_sum.ts
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunction twoSumHashTable(nums: number[], target: number): number[] {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet m: Map<number, number> = new Map();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (let i = 0; i < nums.length; i++) {\nlet index = m.get(target - nums[i]);\nif (index !== undefined) {\nreturn [index, i];\n} else {\nm.set(nums[i], i);\n}\n}\nreturn [];\n}\n
        two_sum.dart
        /* \u65b9\u6cd5\u4e8c\uff1a \u8f85\u52a9\u54c8\u5e0c\u8868 */\nList<int> twoSumHashTable(List<int> nums, int target) {\nint size = nums.length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nMap<int, int> dic = HashMap();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (var i = 0; i < size; i++) {\nif (dic.containsKey(target - nums[i])) {\nreturn [dic[target - nums[i]]!, i];\n}\ndic.putIfAbsent(nums[i], () => i);\n}\nreturn [0];\n}\n
        two_sum.rs
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\npub fn two_sum_hash_table(nums: &Vec<i32>, target: i32) -> Option<Vec<i32>> {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet mut dic = HashMap::new();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (i, num) in nums.iter().enumerate() {\nmatch dic.get(&(target - num)) {\nSome(v) => return Some(vec![*v as i32, i as i32]),\nNone => dic.insert(num, i as i32)\n};\n}\nNone\n}\n
        two_sum.c
        /* \u54c8\u5e0c\u8868 */\ntypedef struct {\nint key;\nint val;\nUT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n/* \u54c8\u5e0c\u8868\u67e5\u8be2 */\nHashTable *find(HashTable *h, int key) {\nHashTable *tmp;\nHASH_FIND_INT(h, &key, tmp);\nreturn tmp;\n}\n/* \u54c8\u5e0c\u8868\u5143\u7d20\u63d2\u5165 */\nvoid insert(HashTable *h, int key, int val) {\nHashTable *t = find(h, key);\nif (t == NULL) {\nHashTable *tmp = malloc(sizeof(HashTable));\ntmp->key = key, tmp->val = val;\nHASH_ADD_INT(h, key, tmp);\n} else {\nt->val = val;\n}\n}\n/* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint *twoSumHashTable(int *nums, int numsSize, int target, int *returnSize) {\nHashTable *hashtable = NULL;\nfor (int i = 0; i < numsSize; i++) {\nHashTable *t = find(hashtable, target - nums[i]);\nif (t != NULL) {\nint *res = malloc(sizeof(int) * 2);\nres[0] = t->val, res[1] = i;\n*returnSize = 2;\nreturn res;\n}\ninsert(hashtable, nums[i], i);\n}\n*returnSize = 0;\nreturn NULL;\n}\n
        two_sum.zig
        // \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\nfn twoSumHashTable(nums: []i32, target: i32) !?[2]i32 {\nvar size: usize = nums.len;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nvar dic = std.AutoHashMap(i32, i32).init(std.heap.page_allocator);\ndefer dic.deinit();\nvar i: usize = 0;\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nwhile (i < size) : (i += 1) {\nif (dic.contains(target - nums[i])) {\nreturn [_]i32{dic.get(target - nums[i]).?, @intCast(i)};\n}\ntry dic.put(nums[i], @intCast(i));\n}\nreturn null;\n}\n

        \u6b64\u65b9\u6cd5\u901a\u8fc7\u54c8\u5e0c\u67e5\u627e\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n^2)\\) \u964d\u81f3 \\(O(n)\\) \uff0c\u5927\u5e45\u63d0\u5347\u8fd0\u884c\u6548\u7387\u3002

        \u7531\u4e8e\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u989d\u5916\u7684\u54c8\u5e0c\u8868\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u8be5\u65b9\u6cd5\u7684\u6574\u4f53\u65f6\u7a7a\u6548\u7387\u66f4\u4e3a\u5747\u8861\uff0c\u56e0\u6b64\u5b83\u662f\u672c\u9898\u7684\u6700\u4f18\u89e3\u6cd5\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/","title":"10.5 \u00a0 \u91cd\u8bc6\u641c\u7d22\u7b97\u6cd5","text":"

        \u300c\u641c\u7d22\u7b97\u6cd5 searching algorithm\u300d\u7528\u4e8e\u5728\u6570\u636e\u7ed3\u6784\uff08\u4f8b\u5982\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6811\u6216\u56fe\uff09\u4e2d\u641c\u7d22\u4e00\u4e2a\u6216\u4e00\u7ec4\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u3002

        \u641c\u7d22\u7b97\u6cd5\u53ef\u6839\u636e\u5b9e\u73b0\u601d\u8def\u5206\u4e3a\u4ee5\u4e0b\u4e24\u7c7b\u3002

        • \u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u6765\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\uff0c\u4f8b\u5982\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6811\u548c\u56fe\u7684\u904d\u5386\u7b49\u3002
        • \u5229\u7528\u6570\u636e\u7ec4\u7ec7\u7ed3\u6784\u6216\u6570\u636e\u5305\u542b\u7684\u5148\u9a8c\u4fe1\u606f\uff0c\u5b9e\u73b0\u9ad8\u6548\u5143\u7d20\u67e5\u627e\uff0c\u4f8b\u5982\u4e8c\u5206\u67e5\u627e\u3001\u54c8\u5e0c\u67e5\u627e\u548c\u4e8c\u53c9\u641c\u7d22\u6811\u67e5\u627e\u7b49\u3002

        \u4e0d\u96be\u53d1\u73b0\uff0c\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u90fd\u5df2\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u56e0\u6b64\u641c\u7d22\u7b97\u6cd5\u5bf9\u4e8e\u6211\u4eec\u6765\u8bf4\u5e76\u4e0d\u964c\u751f\u3002\u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4ece\u66f4\u52a0\u7cfb\u7edf\u7684\u89c6\u89d2\u5207\u5165\uff0c\u91cd\u65b0\u5ba1\u89c6\u641c\u7d22\u7b97\u6cd5\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1051","title":"10.5.1 \u00a0 \u66b4\u529b\u641c\u7d22","text":"

        \u66b4\u529b\u641c\u7d22\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u7684\u6bcf\u4e2a\u5143\u7d20\u6765\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        • \u201c\u7ebf\u6027\u641c\u7d22\u201d\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u94fe\u8868\u7b49\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002\u5b83\u4ece\u6570\u636e\u7ed3\u6784\u7684\u4e00\u7aef\u5f00\u59cb\uff0c\u9010\u4e2a\u8bbf\u95ee\u5143\u7d20\uff0c\u76f4\u5230\u627e\u5230\u76ee\u6807\u5143\u7d20\u6216\u5230\u8fbe\u53e6\u4e00\u7aef\u4ecd\u6ca1\u6709\u627e\u5230\u76ee\u6807\u5143\u7d20\u4e3a\u6b62\u3002
        • \u201c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u548c\u201c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u662f\u56fe\u548c\u6811\u7684\u4e24\u79cd\u904d\u5386\u7b56\u7565\u3002\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u4ece\u521d\u59cb\u8282\u70b9\u5f00\u59cb\u9010\u5c42\u641c\u7d22\uff0c\u7531\u8fd1\u53ca\u8fdc\u5730\u8bbf\u95ee\u5404\u4e2a\u8282\u70b9\u3002\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u4ece\u521d\u59cb\u8282\u70b9\u5f00\u59cb\uff0c\u6cbf\u7740\u4e00\u6761\u8def\u5f84\u8d70\u5230\u5934\uff0c\u518d\u56de\u6eaf\u5e76\u5c1d\u8bd5\u5176\u4ed6\u8def\u5f84\uff0c\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u6570\u636e\u7ed3\u6784\u3002

        \u66b4\u529b\u641c\u7d22\u7684\u4f18\u70b9\u662f\u7b80\u5355\u4e14\u901a\u7528\u6027\u597d\uff0c\u65e0\u987b\u5bf9\u6570\u636e\u505a\u9884\u5904\u7406\u548c\u501f\u52a9\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\u3002

        \u7136\u800c\uff0c\u6b64\u7c7b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u5143\u7d20\u6570\u91cf\uff0c\u56e0\u6b64\u5728\u6570\u636e\u91cf\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\u6027\u80fd\u8f83\u5dee\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1052","title":"10.5.2 \u00a0 \u81ea\u9002\u5e94\u641c\u7d22","text":"

        \u81ea\u9002\u5e94\u641c\u7d22\u5229\u7528\u6570\u636e\u7684\u7279\u6709\u5c5e\u6027\uff08\u4f8b\u5982\u6709\u5e8f\u6027\uff09\u6765\u4f18\u5316\u641c\u7d22\u8fc7\u7a0b\uff0c\u4ece\u800c\u66f4\u9ad8\u6548\u5730\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        • \u201c\u4e8c\u5206\u67e5\u627e\u201d\u5229\u7528\u6570\u636e\u7684\u6709\u5e8f\u6027\u5b9e\u73b0\u9ad8\u6548\u67e5\u627e\uff0c\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u3002
        • \u201c\u54c8\u5e0c\u67e5\u627e\u201d\u5229\u7528\u54c8\u5e0c\u8868\u5c06\u641c\u7d22\u6570\u636e\u548c\u76ee\u6807\u6570\u636e\u5efa\u7acb\u4e3a\u952e\u503c\u5bf9\u6620\u5c04\uff0c\u4ece\u800c\u5b9e\u73b0\u67e5\u8be2\u64cd\u4f5c\u3002
        • \u201c\u6811\u67e5\u627e\u201d\u5728\u7279\u5b9a\u7684\u6811\u7ed3\u6784\uff08\u4f8b\u5982\u4e8c\u53c9\u641c\u7d22\u6811\uff09\u4e2d\uff0c\u57fa\u4e8e\u6bd4\u8f83\u8282\u70b9\u503c\u6765\u5feb\u901f\u6392\u9664\u8282\u70b9\uff0c\u4ece\u800c\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        \u6b64\u7c7b\u7b97\u6cd5\u7684\u4f18\u70b9\u662f\u6548\u7387\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \u3002

        \u7136\u800c\uff0c\u4f7f\u7528\u8fd9\u4e9b\u7b97\u6cd5\u5f80\u5f80\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u4f8b\u5982\uff0c\u4e8c\u5206\u67e5\u627e\u9700\u8981\u9884\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u54c8\u5e0c\u67e5\u627e\u548c\u6811\u67e5\u627e\u90fd\u9700\u8981\u501f\u52a9\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7ef4\u62a4\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u4e5f\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u5f00\u9500\u3002

        Tip

        \u81ea\u9002\u5e94\u641c\u7d22\u7b97\u6cd5\u5e38\u88ab\u79f0\u4e3a\u67e5\u627e\u7b97\u6cd5\uff0c\u4e3b\u8981\u7528\u4e8e\u5728\u7279\u5b9a\u6570\u636e\u7ed3\u6784\u4e2d\u5feb\u901f\u68c0\u7d22\u76ee\u6807\u5143\u7d20\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1053","title":"10.5.3 \u00a0 \u641c\u7d22\u65b9\u6cd5\u9009\u53d6","text":"

        \u7ed9\u5b9a\u5927\u5c0f\u4e3a \\(n\\) \u7684\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7ebf\u6027\u641c\u7d22\u3001\u4e8c\u5206\u67e5\u627e\u3001\u6811\u67e5\u627e\u3001\u54c8\u5e0c\u67e5\u627e\u7b49\u591a\u79cd\u65b9\u6cd5\u4ece\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\u3002\u5404\u4e2a\u65b9\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u5982\u56fe 10-11 \u6240\u793a\u3002

        \u56fe 10-11 \u00a0 \u591a\u79cd\u641c\u7d22\u7b56\u7565

        \u4e0a\u8ff0\u51e0\u79cd\u65b9\u6cd5\u7684\u64cd\u4f5c\u6548\u7387\u4e0e\u7279\u6027\u5982\u8868 10-1 \u6240\u793a\u3002

        \u8868 10-1 \u00a0 \u67e5\u627e\u7b97\u6cd5\u6548\u7387\u5bf9\u6bd4

        \u7ebf\u6027\u641c\u7d22 \u4e8c\u5206\u67e5\u627e \u6811\u67e5\u627e \u54c8\u5e0c\u67e5\u627e \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u63d2\u5165\u5143\u7d20 \\(O(1)\\) \\(O(n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u989d\u5916\u7a7a\u95f4 \\(O(1)\\) \\(O(1)\\) \\(O(n)\\) \\(O(n)\\) \u6570\u636e\u9884\u5904\u7406 / \u6392\u5e8f \\(O(n \\log n)\\) \u5efa\u6811 \\(O(n \\log n)\\) \u5efa\u54c8\u5e0c\u8868 \\(O(n)\\) \u6570\u636e\u662f\u5426\u6709\u5e8f \u65e0\u5e8f \u6709\u5e8f \u6709\u5e8f \u65e0\u5e8f

        \u641c\u7d22\u7b97\u6cd5\u7684\u9009\u62e9\u8fd8\u53d6\u51b3\u4e8e\u6570\u636e\u4f53\u91cf\u3001\u641c\u7d22\u6027\u80fd\u8981\u6c42\u3001\u6570\u636e\u67e5\u8be2\u4e0e\u66f4\u65b0\u9891\u7387\u7b49\u3002

        \u7ebf\u6027\u641c\u7d22

        • \u901a\u7528\u6027\u8f83\u597d\uff0c\u65e0\u987b\u4efb\u4f55\u6570\u636e\u9884\u5904\u7406\u64cd\u4f5c\u3002\u5047\u5982\u6211\u4eec\u4ec5\u9700\u67e5\u8be2\u4e00\u6b21\u6570\u636e\uff0c\u90a3\u4e48\u5176\u4ed6\u4e09\u79cd\u65b9\u6cd5\u7684\u6570\u636e\u9884\u5904\u7406\u7684\u65f6\u95f4\u6bd4\u7ebf\u6027\u641c\u7d22\u7684\u65f6\u95f4\u8fd8\u8981\u66f4\u957f\u3002
        • \u9002\u7528\u4e8e\u4f53\u91cf\u8f83\u5c0f\u7684\u6570\u636e\uff0c\u6b64\u60c5\u51b5\u4e0b\u65f6\u95f4\u590d\u6742\u5ea6\u5bf9\u6548\u7387\u5f71\u54cd\u8f83\u5c0f\u3002
        • \u9002\u7528\u4e8e\u6570\u636e\u66f4\u65b0\u9891\u7387\u8f83\u9ad8\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u8be5\u65b9\u6cd5\u4e0d\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u4efb\u4f55\u989d\u5916\u7ef4\u62a4\u3002

        \u4e8c\u5206\u67e5\u627e

        • \u9002\u7528\u4e8e\u5927\u6570\u636e\u91cf\u7684\u60c5\u51b5\uff0c\u6548\u7387\u8868\u73b0\u7a33\u5b9a\uff0c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u3002
        • \u6570\u636e\u91cf\u4e0d\u80fd\u8fc7\u5927\uff0c\u56e0\u4e3a\u5b58\u50a8\u6570\u7ec4\u9700\u8981\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        • \u4e0d\u9002\u7528\u4e8e\u9ad8\u9891\u589e\u5220\u6570\u636e\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u7ef4\u62a4\u6709\u5e8f\u6570\u7ec4\u7684\u5f00\u9500\u8f83\u5927\u3002

        \u54c8\u5e0c\u67e5\u627e

        • \u9002\u5408\u5bf9\u67e5\u8be2\u6027\u80fd\u8981\u6c42\u5f88\u9ad8\u7684\u573a\u666f\uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002
        • \u4e0d\u9002\u5408\u9700\u8981\u6709\u5e8f\u6570\u636e\u6216\u8303\u56f4\u67e5\u627e\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u65e0\u6cd5\u7ef4\u62a4\u6570\u636e\u7684\u6709\u5e8f\u6027\u3002
        • \u5bf9\u54c8\u5e0c\u51fd\u6570\u548c\u54c8\u5e0c\u51b2\u7a81\u5904\u7406\u7b56\u7565\u7684\u4f9d\u8d56\u6027\u8f83\u9ad8\uff0c\u5177\u6709\u8f83\u5927\u7684\u6027\u80fd\u52a3\u5316\u98ce\u9669\u3002
        • \u4e0d\u9002\u5408\u6570\u636e\u91cf\u8fc7\u5927\u7684\u60c5\u51b5\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u9700\u8981\u989d\u5916\u7a7a\u95f4\u6765\u6700\u5927\u7a0b\u5ea6\u5730\u51cf\u5c11\u51b2\u7a81\uff0c\u4ece\u800c\u63d0\u4f9b\u826f\u597d\u7684\u67e5\u8be2\u6027\u80fd\u3002

        \u6811\u67e5\u627e

        • \u9002\u7528\u4e8e\u6d77\u91cf\u6570\u636e\uff0c\u56e0\u4e3a\u6811\u8282\u70b9\u5728\u5185\u5b58\u4e2d\u662f\u5206\u6563\u5b58\u50a8\u7684\u3002
        • \u9002\u5408\u9700\u8981\u7ef4\u62a4\u6709\u5e8f\u6570\u636e\u6216\u8303\u56f4\u67e5\u627e\u7684\u573a\u666f\u3002
        • \u5728\u6301\u7eed\u589e\u5220\u8282\u70b9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u80fd\u4ea7\u751f\u503e\u659c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n)\\) \u3002
        • \u82e5\u4f7f\u7528 AVL \u6811\u6216\u7ea2\u9ed1\u6811\uff0c\u5219\u5404\u9879\u64cd\u4f5c\u53ef\u5728 \\(O(\\log n)\\) \u6548\u7387\u4e0b\u7a33\u5b9a\u8fd0\u884c\uff0c\u4f46\u7ef4\u62a4\u6811\u5e73\u8861\u7684\u64cd\u4f5c\u4f1a\u589e\u52a0\u989d\u5916\u5f00\u9500\u3002
        "},{"location":"chapter_searching/summary/","title":"10.6 \u00a0 \u5c0f\u7ed3","text":"
        • \u4e8c\u5206\u67e5\u627e\u4f9d\u8d56\u6570\u636e\u7684\u6709\u5e8f\u6027\uff0c\u901a\u8fc7\u5faa\u73af\u9010\u6b65\u7f29\u51cf\u4e00\u534a\u641c\u7d22\u533a\u95f4\u6765\u8fdb\u884c\u67e5\u627e\u3002\u5b83\u8981\u6c42\u8f93\u5165\u6570\u636e\u6709\u5e8f\uff0c\u4e14\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u6216\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u66b4\u529b\u641c\u7d22\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u7ebf\u6027\u641c\u7d22\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u94fe\u8868\uff0c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u548c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u9002\u7528\u4e8e\u56fe\u548c\u6811\u3002\u6b64\u7c7b\u7b97\u6cd5\u901a\u7528\u6027\u597d\uff0c\u65e0\u987b\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\uff0c\u4f46\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u8f83\u9ad8\u3002
        • \u54c8\u5e0c\u67e5\u627e\u3001\u6811\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u5c5e\u4e8e\u9ad8\u6548\u641c\u7d22\u65b9\u6cd5\uff0c\u53ef\u5728\u7279\u5b9a\u6570\u636e\u7ed3\u6784\u4e2d\u5feb\u901f\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002\u6b64\u7c7b\u7b97\u6cd5\u6548\u7387\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \uff0c\u4f46\u901a\u5e38\u9700\u8981\u501f\u52a9\u989d\u5916\u6570\u636e\u7ed3\u6784\u3002
        • \u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6570\u636e\u4f53\u91cf\u3001\u641c\u7d22\u6027\u80fd\u8981\u6c42\u3001\u6570\u636e\u67e5\u8be2\u548c\u66f4\u65b0\u9891\u7387\u7b49\u56e0\u7d20\u8fdb\u884c\u5177\u4f53\u5206\u6790\uff0c\u4ece\u800c\u9009\u62e9\u5408\u9002\u7684\u641c\u7d22\u65b9\u6cd5\u3002
        • \u7ebf\u6027\u641c\u7d22\u9002\u7528\u4e8e\u5c0f\u578b\u6216\u9891\u7e41\u66f4\u65b0\u7684\u6570\u636e\uff1b\u4e8c\u5206\u67e5\u627e\u9002\u7528\u4e8e\u5927\u578b\u3001\u6392\u5e8f\u7684\u6570\u636e\uff1b\u54c8\u5e0c\u67e5\u627e\u9002\u7528\u4e8e\u5bf9\u67e5\u8be2\u6548\u7387\u8981\u6c42\u8f83\u9ad8\u4e14\u65e0\u987b\u8303\u56f4\u67e5\u8be2\u7684\u6570\u636e\uff1b\u6811\u67e5\u627e\u9002\u7528\u4e8e\u9700\u8981\u7ef4\u62a4\u987a\u5e8f\u548c\u652f\u6301\u8303\u56f4\u67e5\u8be2\u7684\u5927\u578b\u52a8\u6001\u6570\u636e\u3002
        • \u7528\u54c8\u5e0c\u67e5\u627e\u66ff\u6362\u7ebf\u6027\u67e5\u627e\u662f\u4e00\u79cd\u5e38\u7528\u7684\u4f18\u5316\u8fd0\u884c\u65f6\u95f4\u7684\u7b56\u7565\uff0c\u53ef\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \u3002
        "},{"location":"chapter_sorting/","title":"\u7b2c 11 \u7ae0 \u00a0 \u6392\u5e8f","text":"

        Abstract

        \u6392\u5e8f\u72b9\u5982\u4e00\u628a\u5c06\u6df7\u4e71\u53d8\u4e3a\u79e9\u5e8f\u7684\u9b54\u6cd5\u94a5\u5319\uff0c\u4f7f\u6211\u4eec\u80fd\u4ee5\u66f4\u9ad8\u6548\u7684\u65b9\u5f0f\u7406\u89e3\u4e0e\u5904\u7406\u6570\u636e\u3002

        \u65e0\u8bba\u662f\u7b80\u5355\u7684\u5347\u5e8f\uff0c\u8fd8\u662f\u590d\u6742\u7684\u5206\u7c7b\u6392\u5217\uff0c\u6392\u5e8f\u90fd\u5411\u6211\u4eec\u5c55\u793a\u4e86\u6570\u636e\u7684\u548c\u8c10\u7f8e\u611f\u3002

        "},{"location":"chapter_sorting/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 11.1 \u00a0 \u6392\u5e8f\u7b97\u6cd5
        • 11.2 \u00a0 \u9009\u62e9\u6392\u5e8f
        • 11.3 \u00a0 \u5192\u6ce1\u6392\u5e8f
        • 11.4 \u00a0 \u63d2\u5165\u6392\u5e8f
        • 11.5 \u00a0 \u5feb\u901f\u6392\u5e8f
        • 11.6 \u00a0 \u5f52\u5e76\u6392\u5e8f
        • 11.7 \u00a0 \u5806\u6392\u5e8f
        • 11.8 \u00a0 \u6876\u6392\u5e8f
        • 11.9 \u00a0 \u8ba1\u6570\u6392\u5e8f
        • 11.10 \u00a0 \u57fa\u6570\u6392\u5e8f
        • 11.11 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_sorting/bubble_sort/","title":"11.3 \u00a0 \u5192\u6ce1\u6392\u5e8f","text":"

        \u300c\u5192\u6ce1\u6392\u5e8f bubble sort\u300d\u901a\u8fc7\u8fde\u7eed\u5730\u6bd4\u8f83\u4e0e\u4ea4\u6362\u76f8\u90bb\u5143\u7d20\u5b9e\u73b0\u6392\u5e8f\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u50cf\u6c14\u6ce1\u4ece\u5e95\u90e8\u5347\u5230\u9876\u90e8\u4e00\u6837\uff0c\u56e0\u6b64\u5f97\u540d\u5192\u6ce1\u6392\u5e8f\u3002

        \u5982\u56fe 11-4 \u6240\u793a\uff0c\u5192\u6ce1\u8fc7\u7a0b\u53ef\u4ee5\u5229\u7528\u5143\u7d20\u4ea4\u6362\u64cd\u4f5c\u6765\u6a21\u62df\uff1a\u4ece\u6570\u7ec4\u6700\u5de6\u7aef\u5f00\u59cb\u5411\u53f3\u904d\u5386\uff0c\u4f9d\u6b21\u6bd4\u8f83\u76f8\u90bb\u5143\u7d20\u5927\u5c0f\uff0c\u5982\u679c\u201c\u5de6\u5143\u7d20 > \u53f3\u5143\u7d20\u201d\u5c31\u4ea4\u6362\u4e8c\u8005\u3002\u904d\u5386\u5b8c\u6210\u540e\uff0c\u6700\u5927\u7684\u5143\u7d20\u4f1a\u88ab\u79fb\u52a8\u5230\u6570\u7ec4\u7684\u6700\u53f3\u7aef\u3002

        <1><2><3><4><5><6><7>

        \u56fe 11-4 \u00a0 \u5229\u7528\u5143\u7d20\u4ea4\u6362\u64cd\u4f5c\u6a21\u62df\u5192\u6ce1

        "},{"location":"chapter_sorting/bubble_sort/#1131","title":"11.3.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u6b65\u9aa4\u5982\u56fe 11-5 \u6240\u793a\u3002

        1. \u9996\u5148\uff0c\u5bf9 \\(n\\) \u4e2a\u5143\u7d20\u6267\u884c\u201c\u5192\u6ce1\u201d\uff0c\u5c06\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\uff0c
        2. \u63a5\u4e0b\u6765\uff0c\u5bf9\u5269\u4f59 \\(n - 1\\) \u4e2a\u5143\u7d20\u6267\u884c\u201c\u5192\u6ce1\u201d\uff0c\u5c06\u7b2c\u4e8c\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\u3002
        3. \u4ee5\u6b64\u7c7b\u63a8\uff0c\u7ecf\u8fc7 \\(n - 1\\) \u8f6e\u201c\u5192\u6ce1\u201d\u540e\uff0c\u524d \\(n - 1\\) \u5927\u7684\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\u3002
        4. \u4ec5\u5269\u7684\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u662f\u6700\u5c0f\u5143\u7d20\uff0c\u65e0\u987b\u6392\u5e8f\uff0c\u56e0\u6b64\u6570\u7ec4\u6392\u5e8f\u5b8c\u6210\u3002

        \u56fe 11-5 \u00a0 \u5192\u6ce1\u6392\u5e8f\u6d41\u7a0b

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bubble_sort.py
        def bubble_sort(nums: list[int]):\n\"\"\"\u5192\u6ce1\u6392\u5e8f\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(n - 1, 0, -1):\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j + 1] = nums[j + 1], nums[j]\n
        bubble_sort.cpp
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n// \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\nswap(nums[j], nums[j + 1]);\n}\n}\n}\n}\n
        bubble_sort.java
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.cs
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid BubbleSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\n}\n}\n}\n}\n
        bubble_sort.go
        /* \u5192\u6ce1\u6392\u5e8f */\nfunc bubbleSort(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j+1] = nums[j+1], nums[j]\n}\n}\n}\n}\n
        bubble_sort.swift
        /* \u5192\u6ce1\u6392\u5e8f */\nfunc bubbleSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in stride(from: 0, to: i, by: 1) {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\n}\n}\n}\n}\n
        bubble_sort.js
        /* \u5192\u6ce1\u6392\u5e8f */\nfunction bubbleSort(nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.ts
        /* \u5192\u6ce1\u6392\u5e8f */\nfunction bubbleSort(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.dart
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.rs
        /* \u5192\u6ce1\u6392\u5e8f */\nfn bubble_sort(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.c
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = 0; i < size - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < size - 1 - i; j++) {\nif (nums[j] > nums[j + 1]) {\nint temp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = temp;\n}\n}\n}\n}\n
        bubble_sort.zig
        // \u5192\u6ce1\u6392\u5e8f\nfn bubbleSort(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: usize = nums.len - 1;\nwhile (i > 0) : (i -= 1) {\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        "},{"location":"chapter_sorting/bubble_sort/#1132","title":"11.3.2 \u00a0 \u6548\u7387\u4f18\u5316","text":"

        \u6211\u4eec\u53d1\u73b0\uff0c\u5982\u679c\u67d0\u8f6e\u201c\u5192\u6ce1\u201d\u4e2d\u6ca1\u6709\u6267\u884c\u4efb\u4f55\u4ea4\u6362\u64cd\u4f5c\uff0c\u8bf4\u660e\u6570\u7ec4\u5df2\u7ecf\u5b8c\u6210\u6392\u5e8f\uff0c\u53ef\u76f4\u63a5\u8fd4\u56de\u7ed3\u679c\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u589e\u52a0\u4e00\u4e2a\u6807\u5fd7\u4f4d flag \u6765\u76d1\u6d4b\u8fd9\u79cd\u60c5\u51b5\uff0c\u4e00\u65e6\u51fa\u73b0\u5c31\u7acb\u5373\u8fd4\u56de\u3002

        \u7ecf\u8fc7\u4f18\u5316\uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(n^2)\\) \uff1b\u4f46\u5f53\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u6709\u5e8f\u65f6\uff0c\u53ef\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bubble_sort.py
        def bubble_sort_with_flag(nums: list[int]):\n\"\"\"\u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(n - 1, 0, -1):\nflag = False  # \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j + 1] = nums[j + 1], nums[j]\nflag = True  # \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\nif not flag:\nbreak  # \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n
        bubble_sort.cpp
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n// \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\nswap(nums[j], nums[j + 1]);\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag)\nbreak; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.java
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09 */\nvoid bubbleSortWithFlag(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\nboolean flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag)\nbreak; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.cs
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid BubbleSortWithFlag(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\nflag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break;     // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.go
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunc bubbleSortWithFlag(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\nflag := false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j+1] = nums[j+1], nums[j]\nflag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif flag == false { // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\nbreak\n}\n}\n}\n
        bubble_sort.swift
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunc bubbleSortWithFlag(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\nvar flag = false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\nfor j in stride(from: 0, to: i, by: 1) {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\nflag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif !flag { // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\nbreak\n}\n}\n}\n
        bubble_sort.js
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunction bubbleSortWithFlag(nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\nlet flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.ts
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunction bubbleSortWithFlag(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\nlet flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.dart
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.rs
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09 */\nfn bubble_sort_with_flag(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\nlet mut flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif !flag {break};  // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.c
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = 0; i < size - 1; i++) {\nbool flag = false;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < size - 1 - i; j++) {\nif (nums[j] > nums[j + 1]) {\nint temp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = temp;\nflag = true;\n}\n}\nif (!flag)\nbreak;\n}\n}\n
        bubble_sort.zig
        // \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09\nfn bubbleSortWithFlag(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: usize = nums.len - 1;\nwhile (i > 0) : (i -= 1) {\nvar flag = false;   // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true;\n}\n}\nif (!flag) break;   // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        "},{"location":"chapter_sorting/bubble_sort/#1133","title":"11.3.3 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5404\u8f6e\u201c\u5192\u6ce1\u201d\u904d\u5386\u7684\u6570\u7ec4\u957f\u5ea6\u4f9d\u6b21\u4e3a \\(n - 1\\)\u3001\\(n - 2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u603b\u548c\u4e3a \\((n - 1) n / 2\\) \u3002\u5728\u5f15\u5165 flag \u4f18\u5316\u540e\uff0c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u7531\u4e8e\u5728\u201c\u5192\u6ce1\u201d\u4e2d\u9047\u5230\u76f8\u7b49\u5143\u7d20\u4e0d\u4ea4\u6362\u3002
        "},{"location":"chapter_sorting/bucket_sort/","title":"11.8 \u00a0 \u6876\u6392\u5e8f","text":"

        \u524d\u8ff0\u51e0\u79cd\u6392\u5e8f\u7b97\u6cd5\u90fd\u5c5e\u4e8e\u201c\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u7b97\u6cd5\u201d\uff0c\u5b83\u4eec\u901a\u8fc7\u6bd4\u8f83\u5143\u7d20\u95f4\u7684\u5927\u5c0f\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u6b64\u7c7b\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u65e0\u6cd5\u8d85\u8d8a \\(O(n \\log n)\\) \u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u51e0\u79cd\u201c\u975e\u6bd4\u8f83\u6392\u5e8f\u7b97\u6cd5\u201d\uff0c\u5b83\u4eec\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230\u7ebf\u6027\u9636\u3002

        \u300c\u6876\u6392\u5e8f bucket sort\u300d\u662f\u5206\u6cbb\u7b56\u7565\u7684\u4e00\u4e2a\u5178\u578b\u5e94\u7528\u3002\u5b83\u901a\u8fc7\u8bbe\u7f6e\u4e00\u4e9b\u5177\u6709\u5927\u5c0f\u987a\u5e8f\u7684\u6876\uff0c\u6bcf\u4e2a\u6876\u5bf9\u5e94\u4e00\u4e2a\u6570\u636e\u8303\u56f4\uff0c\u5c06\u6570\u636e\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff1b\u7136\u540e\uff0c\u5728\u6bcf\u4e2a\u6876\u5185\u90e8\u5206\u522b\u6267\u884c\u6392\u5e8f\uff1b\u6700\u7ec8\u6309\u7167\u6876\u7684\u987a\u5e8f\u5c06\u6240\u6709\u6570\u636e\u5408\u5e76\u3002

        "},{"location":"chapter_sorting/bucket_sort/#1181","title":"11.8.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8003\u8651\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u662f\u8303\u56f4 \\([0, 1)\\) \u5185\u7684\u6d6e\u70b9\u6570\u3002\u6876\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-13 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316 \\(k\\) \u4e2a\u6876\uff0c\u5c06 \\(n\\) \u4e2a\u5143\u7d20\u5206\u914d\u5230 \\(k\\) \u4e2a\u6876\u4e2d\u3002
        2. \u5bf9\u6bcf\u4e2a\u6876\u5206\u522b\u6267\u884c\u6392\u5e8f\uff08\u8fd9\u91cc\u91c7\u7528\u7f16\u7a0b\u8bed\u8a00\u7684\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff09\u3002
        3. \u6309\u7167\u6876\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u5408\u5e76\u7ed3\u679c\u3002

        \u56fe 11-13 \u00a0 \u6876\u6392\u5e8f\u7b97\u6cd5\u6d41\u7a0b

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bucket_sort.py
        def bucket_sort(nums: list[float]):\n\"\"\"\u6876\u6392\u5e8f\"\"\"\n# \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nk = len(nums) // 2\nbuckets = [[] for _ in range(k)]\n# 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor num in nums:\n# \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\ni = int(num * k)\n# \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].append(num)\n# 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor bucket in buckets:\n# \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort()\n# 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\ni = 0\nfor bucket in buckets:\nfor num in bucket:\nnums[i] = num\ni += 1\n
        bucket_sort.cpp
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(vector<float> &nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.size() / 2;\nvector<vector<float>> buckets(k);\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (float num : nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = num * k;\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\nbuckets[i].push_back(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (vector<float> &bucket : buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nsort(bucket.begin(), bucket.end());\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (vector<float> &bucket : buckets) {\nfor (float num : bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.java
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(float[] nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.length / 2;\nList<List<Float>> buckets = new ArrayList<>();\nfor (int i = 0; i < k; i++) {\nbuckets.add(new ArrayList<>());\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (float num : nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (int) (num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets.get(i).add(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (List<Float> bucket : buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nCollections.sort(bucket);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (List<Float> bucket : buckets) {\nfor (float num : bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.cs
        /* \u6876\u6392\u5e8f */\nvoid BucketSort(float[] nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.Length / 2;\nList<List<float>> buckets = [];\nfor (int i = 0; i < k; i++) {\nbuckets.Add([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nforeach (float num in nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (int)(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].Add(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nforeach (List<float> bucket in buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.Sort();\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint j = 0;\nforeach (List<float> bucket in buckets) {\nforeach (float num in bucket) {\nnums[j++] = num;\n}\n}\n}\n
        bucket_sort.go
        /* \u6876\u6392\u5e8f */\nfunc bucketSort(nums []float64) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nk := len(nums) / 2\nbuckets := make([][]float64, k)\nfor i := 0; i < k; i++ {\nbuckets[i] = make([]float64, 0)\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor _, num := range nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\ni := int(num * float64(k))\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i] = append(buckets[i], num)\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor i := 0; i < k; i++ {\n// \u4f7f\u7528\u5185\u7f6e\u5207\u7247\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nsort.Float64s(buckets[i])\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\ni := 0\nfor _, bucket := range buckets {\nfor _, num := range bucket {\nnums[i] = num\ni++\n}\n}\n}\n
        bucket_sort.swift
        /* \u6876\u6392\u5e8f */\nfunc bucketSort(nums: inout [Double]) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nlet k = nums.count / 2\nvar buckets = (0 ..< k).map { _ in [Double]() }\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor num in nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nlet i = Int(num * Double(k))\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].append(num)\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor i in buckets.indices {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbuckets[i].sort()\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nvar i = nums.startIndex\nfor bucket in buckets {\nfor num in bucket {\nnums[i] = num\nnums.formIndex(after: &i)\n}\n}\n}\n
        bucket_sort.js
        /* \u6876\u6392\u5e8f */\nfunction bucketSort(nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nconst k = nums.length / 2;\nconst buckets = [];\nfor (let i = 0; i < k; i++) {\nbuckets.push([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (const num of nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nconst i = Math.floor(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (const bucket of buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort((a, b) => a - b);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet i = 0;\nfor (const bucket of buckets) {\nfor (const num of bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.ts
        /* \u6876\u6392\u5e8f */\nfunction bucketSort(nums: number[]): void {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nconst k = nums.length / 2;\nconst buckets: number[][] = [];\nfor (let i = 0; i < k; i++) {\nbuckets.push([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (const num of nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nconst i = Math.floor(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (const bucket of buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort((a, b) => a - b);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet i = 0;\nfor (const bucket of buckets) {\nfor (const num of bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.dart
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(List<double> nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.length ~/ 2;\nList<List<double>> buckets = List.generate(k, (index) => []);\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (double _num in nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 _num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (_num * k).toInt();\n// \u5c06 _num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\nbuckets[i].add(_num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (List<double> bucket in buckets) {\nbucket.sort();\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (List<double> bucket in buckets) {\nfor (double _num in bucket) {\nnums[i++] = _num;\n}\n}\n}\n
        bucket_sort.rs
        /* \u6876\u6392\u5e8f */\nfn bucket_sort(nums: &mut [f64]) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nlet k = nums.len() / 2;\nlet mut buckets = vec![vec![]; k];\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor &mut num in &mut *nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nlet i = (num * k as f64) as usize;\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor bucket in &mut buckets {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort_by(|a, b| a.partial_cmp(b).unwrap());\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet mut i = 0;\nfor bucket in &mut buckets {\nfor &mut num in bucket {\nnums[i] = num;\ni += 1;\n}\n}\n}\n
        bucket_sort.c
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(float nums[], int size) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = size / 2;\nfloat **buckets = calloc(k, sizeof(float *));\nfor (int i = 0; i < k; i++) {\n// \u6bcf\u4e2a\u6876\u6700\u591a\u53ef\u4ee5\u5206\u914d k \u4e2a\u5143\u7d20\nbuckets[i] = calloc(ARRAY_SIZE, sizeof(float));\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (int i = 0; i < size; i++) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint bucket_idx = nums[i] * k;\nint j = 0;\n// \u5982\u679c\u6876\u4e2d\u6709\u6570\u636e\u4e14\u6570\u636e\u5c0f\u4e8e\u5f53\u524d\u503c nums[i], \u8981\u5c06\u5176\u653e\u5230\u5f53\u524d\u6876\u7684\u540e\u9762\uff0c\u76f8\u5f53\u4e8e cpp \u4e2d\u7684 push_back\nwhile (buckets[bucket_idx][j] > 0 && buckets[bucket_idx][j] < nums[i]) {\nj++;\n}\nfloat temp = nums[i];\nwhile (j < ARRAY_SIZE && buckets[bucket_idx][j] > 0) {\nswap(&temp, &buckets[bucket_idx][j]);\nj++;\n}\nbuckets[bucket_idx][j] = temp;\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (int i = 0; i < k; i++) {\nqsort(buckets[i], ARRAY_SIZE, sizeof(float), compare_float);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nfor (int i = 0, j = 0; j < k; j++) {\nfor (int l = 0; l < ARRAY_SIZE; l++) {\nif (buckets[j][l] > 0) {\nnums[i++] = buckets[j][l];\n}\n}\n}\n// \u91ca\u653e\u4e0a\u8ff0\u5206\u914d\u7684\u5185\u5b58\nfor (int i = 0; i < k; i++) {\nfree(buckets[i]);\n}\nfree(buckets);\n}\n
        bucket_sort.zig
        [class]{}-[func]{bucketSort}\n
        "},{"location":"chapter_sorting/bucket_sort/#1182","title":"11.8.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"

        \u6876\u6392\u5e8f\u9002\u7528\u4e8e\u5904\u7406\u4f53\u91cf\u5f88\u5927\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u6570\u636e\u5305\u542b 100 \u4e07\u4e2a\u5143\u7d20\uff0c\u7531\u4e8e\u7a7a\u95f4\u9650\u5236\uff0c\u7cfb\u7edf\u5185\u5b58\u65e0\u6cd5\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u6570\u636e\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u5206\u6210 1000 \u4e2a\u6876\uff0c\u7136\u540e\u5206\u522b\u5bf9\u6bcf\u4e2a\u6876\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u540e\u5c06\u7ed3\u679c\u5408\u5e76\u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n + k)\\) \uff1a\u5047\u8bbe\u5143\u7d20\u5728\u5404\u4e2a\u6876\u5185\u5e73\u5747\u5206\u5e03\uff0c\u90a3\u4e48\u6bcf\u4e2a\u6876\u5185\u7684\u5143\u7d20\u6570\u91cf\u4e3a \\(\\frac{n}{k}\\) \u3002\u5047\u8bbe\u6392\u5e8f\u5355\u4e2a\u6876\u4f7f\u7528 \\(O(\\frac{n}{k} \\log\\frac{n}{k})\\) \u65f6\u95f4\uff0c\u5219\u6392\u5e8f\u6240\u6709\u6876\u4f7f\u7528 \\(O(n \\log\\frac{n}{k})\\) \u65f6\u95f4\u3002\u5f53\u6876\u6570\u91cf \\(k\\) \u6bd4\u8f83\u5927\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5219\u8d8b\u5411\u4e8e \\(O(n)\\) \u3002\u5408\u5e76\u7ed3\u679c\u65f6\u9700\u8981\u904d\u5386\u6240\u6709\u6876\u548c\u5143\u7d20\uff0c\u82b1\u8d39 \\(O(n + k)\\) \u65f6\u95f4\u3002
        • \u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u6570\u636e\u88ab\u5206\u914d\u5230\u4e00\u4e2a\u6876\u4e2d\uff0c\u4e14\u6392\u5e8f\u8be5\u6876\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + k)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u9700\u8981\u501f\u52a9 \\(k\\) \u4e2a\u6876\u548c\u603b\u5171 \\(n\\) \u4e2a\u5143\u7d20\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u6876\u6392\u5e8f\u662f\u5426\u7a33\u5b9a\u53d6\u51b3\u4e8e\u6392\u5e8f\u6876\u5185\u5143\u7d20\u7684\u7b97\u6cd5\u662f\u5426\u7a33\u5b9a\u3002
        "},{"location":"chapter_sorting/bucket_sort/#1183","title":"11.8.3 \u00a0 \u5982\u4f55\u5b9e\u73b0\u5e73\u5747\u5206\u914d","text":"

        \u6876\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7406\u8bba\u4e0a\u53ef\u4ee5\u8fbe\u5230 \\(O(n)\\) \uff0c\u5173\u952e\u5728\u4e8e\u5c06\u5143\u7d20\u5747\u5300\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff0c\u56e0\u4e3a\u5b9e\u9645\u6570\u636e\u5f80\u5f80\u4e0d\u662f\u5747\u5300\u5206\u5e03\u7684\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u60f3\u8981\u5c06\u6dd8\u5b9d\u4e0a\u7684\u6240\u6709\u5546\u54c1\u6309\u4ef7\u683c\u8303\u56f4\u5e73\u5747\u5206\u914d\u5230 10 \u4e2a\u6876\u4e2d\uff0c\u4f46\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u4e0d\u5747\uff0c\u4f4e\u4e8e 100 \u5143\u7684\u975e\u5e38\u591a\uff0c\u9ad8\u4e8e 1000 \u5143\u7684\u975e\u5e38\u5c11\u3002\u82e5\u5c06\u4ef7\u683c\u533a\u95f4\u5e73\u5747\u5212\u5206\u4e3a 10 \u4e2a\uff0c\u5404\u4e2a\u6876\u4e2d\u7684\u5546\u54c1\u6570\u91cf\u5dee\u8ddd\u4f1a\u975e\u5e38\u5927\u3002

        \u4e3a\u5b9e\u73b0\u5e73\u5747\u5206\u914d\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u8bbe\u5b9a\u4e00\u6761\u5927\u81f4\u7684\u5206\u754c\u7ebf\uff0c\u5c06\u6570\u636e\u7c97\u7565\u5730\u5206\u5230 3 \u4e2a\u6876\u4e2d\u3002\u5206\u914d\u5b8c\u6bd5\u540e\uff0c\u518d\u5c06\u5546\u54c1\u8f83\u591a\u7684\u6876\u7ee7\u7eed\u5212\u5206\u4e3a 3 \u4e2a\u6876\uff0c\u76f4\u81f3\u6240\u6709\u6876\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u5927\u81f4\u76f8\u7b49\u3002

        \u5982\u56fe 11-14 \u6240\u793a\uff0c\u8fd9\u79cd\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u521b\u5efa\u4e00\u68f5\u9012\u5f52\u6811\uff0c\u76ee\u6807\u662f\u8ba9\u53f6\u8282\u70b9\u7684\u503c\u5c3d\u53ef\u80fd\u5e73\u5747\u3002\u5f53\u7136\uff0c\u4e0d\u4e00\u5b9a\u8981\u6bcf\u8f6e\u5c06\u6570\u636e\u5212\u5206\u4e3a 3 \u4e2a\u6876\uff0c\u5177\u4f53\u5212\u5206\u65b9\u5f0f\u53ef\u6839\u636e\u6570\u636e\u7279\u70b9\u7075\u6d3b\u9009\u62e9\u3002

        \u56fe 11-14 \u00a0 \u9012\u5f52\u5212\u5206\u6876

        \u5982\u679c\u6211\u4eec\u63d0\u524d\u77e5\u9053\u5546\u54c1\u4ef7\u683c\u7684\u6982\u7387\u5206\u5e03\uff0c\u5219\u53ef\u4ee5\u6839\u636e\u6570\u636e\u6982\u7387\u5206\u5e03\u8bbe\u7f6e\u6bcf\u4e2a\u6876\u7684\u4ef7\u683c\u5206\u754c\u7ebf\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6570\u636e\u5206\u5e03\u5e76\u4e0d\u4e00\u5b9a\u9700\u8981\u7279\u610f\u7edf\u8ba1\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u6570\u636e\u7279\u70b9\u91c7\u7528\u67d0\u79cd\u6982\u7387\u6a21\u578b\u8fdb\u884c\u8fd1\u4f3c\u3002

        \u5982\u56fe 11-15 \u6240\u793a\uff0c\u6211\u4eec\u5047\u8bbe\u5546\u54c1\u4ef7\u683c\u670d\u4ece\u6b63\u6001\u5206\u5e03\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5408\u7406\u5730\u8bbe\u5b9a\u4ef7\u683c\u533a\u95f4\uff0c\u4ece\u800c\u5c06\u5546\u54c1\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\u3002

        \u56fe 11-15 \u00a0 \u6839\u636e\u6982\u7387\u5206\u5e03\u5212\u5206\u6876

        "},{"location":"chapter_sorting/counting_sort/","title":"11.9 \u00a0 \u8ba1\u6570\u6392\u5e8f","text":"

        \u300c\u8ba1\u6570\u6392\u5e8f counting sort\u300d\u901a\u8fc7\u7edf\u8ba1\u5143\u7d20\u6570\u91cf\u6765\u5b9e\u73b0\u6392\u5e8f\uff0c\u901a\u5e38\u5e94\u7528\u4e8e\u6574\u6570\u6570\u7ec4\u3002

        "},{"location":"chapter_sorting/counting_sort/#1191","title":"11.9.1 \u00a0 \u7b80\u5355\u5b9e\u73b0","text":"

        \u5148\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u3002\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u201c\u975e\u8d1f\u6574\u6570\u201d\uff0c\u8ba1\u6570\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-16 \u6240\u793a\u3002

        1. \u904d\u5386\u6570\u7ec4\uff0c\u627e\u51fa\u5176\u4e2d\u7684\u6700\u5927\u6570\u5b57\uff0c\u8bb0\u4e3a \\(m\\) \uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(m + 1\\) \u7684\u8f85\u52a9\u6570\u7ec4 counter \u3002
        2. \u501f\u52a9 counter \u7edf\u8ba1 nums \u4e2d\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u5176\u4e2d counter[num] \u5bf9\u5e94\u6570\u5b57 num \u7684\u51fa\u73b0\u6b21\u6570\u3002\u7edf\u8ba1\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u904d\u5386 nums\uff08\u8bbe\u5f53\u524d\u6570\u5b57\u4e3a num\uff09\uff0c\u6bcf\u8f6e\u5c06 counter[num] \u589e\u52a0 \\(1\\) \u5373\u53ef\u3002
        3. \u7531\u4e8e counter \u7684\u5404\u4e2a\u7d22\u5f15\u5929\u7136\u6709\u5e8f\uff0c\u56e0\u6b64\u76f8\u5f53\u4e8e\u6240\u6709\u6570\u5b57\u5df2\u7ecf\u6392\u5e8f\u597d\u4e86\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u904d\u5386 counter \uff0c\u6839\u636e\u5404\u6570\u5b57\u51fa\u73b0\u6b21\u6570\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u586b\u5165 nums \u5373\u53ef\u3002

        \u56fe 11-16 \u00a0 \u8ba1\u6570\u6392\u5e8f\u6d41\u7a0b

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig counting_sort.py
        def counting_sort_naive(nums: list[int]):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\"\"\"\n# \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\n# 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm = 0\nfor num in nums:\nm = max(m, num)\n# 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n# counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter = [0] * (m + 1)\nfor num in nums:\ncounter[num] += 1\n# 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\ni = 0\nfor num in range(m + 1):\nfor _ in range(counter[num]):\nnums[i] = num\ni += 1\n
        counting_sort.cpp
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(vector<int> &nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvector<int> counter(m + 1, 0);\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.java
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.cs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid CountingSortNaive(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nforeach (int num in nums) {\nm = Math.Max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nforeach (int num in nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.go
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunc countingSortNaive(nums []int) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm := 0\nfor _, num := range nums {\nif num > m {\nm = num\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter := make([]int, m+1)\nfor _, num := range nums {\ncounter[num]++\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nfor i, num := 0, 0; num < m+1; num++ {\nfor j := 0; j < counter[num]; j++ {\nnums[i] = num\ni++\n}\n}\n}\n
        counting_sort.swift
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunc countingSortNaive(nums: inout [Int]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = nums.max()!\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvar counter = Array(repeating: 0, count: m + 1)\nfor num in nums {\ncounter[num] += 1\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nvar i = 0\nfor num in stride(from: 0, to: m + 1, by: 1) {\nfor _ in stride(from: 0, to: counter[num], by: 1) {\nnums[i] = num\ni += 1\n}\n}\n}\n
        counting_sort.js
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunction countingSortNaive(nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter = new Array(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet i = 0;\nfor (let num = 0; num < m + 1; num++) {\nfor (let j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.ts
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunction countingSortNaive(nums: number[]): void {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter: number[] = new Array<number>(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet i = 0;\nfor (let num = 0; num < m + 1; num++) {\nfor (let j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.dart
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(List<int> nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int _num in nums) {\nm = max(m, _num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[_num] \u4ee3\u8868 _num \u7684\u51fa\u73b0\u6b21\u6570\nList<int> counter = List.filled(m + 1, 0);\nfor (int _num in nums) {\ncounter[_num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int _num = 0; _num < m + 1; _num++) {\nfor (int j = 0; j < counter[_num]; j++, i++) {\nnums[i] = _num;\n}\n}\n}\n
        counting_sort.rs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfn counting_sort_naive(nums: &mut [i32]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = *nums.into_iter().max().unwrap();\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nlet mut counter = vec![0; m as usize + 1];\nfor &num in &*nums {\ncounter[num as usize] += 1;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet mut i = 0;\nfor num in 0..m + 1 {\nfor _ in 0..counter[num as usize] {\nnums[i] = num;\ni += 1;\n}\n}\n}\n
        counting_sort.c
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(int nums[], int size) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int i = 0; i < size; i++) {\nif (nums[i] > m) {\nm = nums[i];\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint *counter = calloc(m, sizeof(int));\nfor (int i = 0; i < size; i++) {\ncounter[nums[i]]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n// 4. \u91ca\u653e\u5185\u5b58\nfree(counter);\n}\n
        counting_sort.zig
        [class]{}-[func]{countingSortNaive}\n

        \u8ba1\u6570\u6392\u5e8f\u4e0e\u6876\u6392\u5e8f\u7684\u8054\u7cfb

        \u4ece\u6876\u6392\u5e8f\u7684\u89d2\u5ea6\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8ba1\u6570\u6392\u5e8f\u4e2d\u7684\u8ba1\u6570\u6570\u7ec4 counter \u7684\u6bcf\u4e2a\u7d22\u5f15\u89c6\u4e3a\u4e00\u4e2a\u6876\uff0c\u5c06\u7edf\u8ba1\u6570\u91cf\u7684\u8fc7\u7a0b\u770b\u4f5c\u5c06\u5404\u4e2a\u5143\u7d20\u5206\u914d\u5230\u5bf9\u5e94\u7684\u6876\u4e2d\u3002\u672c\u8d28\u4e0a\uff0c\u8ba1\u6570\u6392\u5e8f\u662f\u6876\u6392\u5e8f\u5728\u6574\u578b\u6570\u636e\u4e0b\u7684\u4e00\u4e2a\u7279\u4f8b\u3002

        "},{"location":"chapter_sorting/counting_sort/#1192","title":"11.9.2 \u00a0 \u5b8c\u6574\u5b9e\u73b0","text":"

        \u7ec6\u5fc3\u7684\u8bfb\u8005\u53ef\u80fd\u53d1\u73b0\u4e86\uff0c\u5982\u679c\u8f93\u5165\u6570\u636e\u662f\u5bf9\u8c61\uff0c\u4e0a\u8ff0\u6b65\u9aa4 3. \u5c31\u5931\u6548\u4e86\u3002\u5047\u8bbe\u8f93\u5165\u6570\u636e\u662f\u5546\u54c1\u5bf9\u8c61\uff0c\u6211\u4eec\u60f3\u6309\u7167\u5546\u54c1\u4ef7\u683c\uff08\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff09\u5bf9\u5546\u54c1\u8fdb\u884c\u6392\u5e8f\uff0c\u800c\u4e0a\u8ff0\u7b97\u6cd5\u53ea\u80fd\u7ed9\u51fa\u4ef7\u683c\u7684\u6392\u5e8f\u7ed3\u679c\u3002

        \u90a3\u4e48\u5982\u4f55\u624d\u80fd\u5f97\u5230\u539f\u6570\u636e\u7684\u6392\u5e8f\u7ed3\u679c\u5462\uff1f\u6211\u4eec\u9996\u5148\u8ba1\u7b97 counter \u7684\u201c\u524d\u7f00\u548c\u201d\u3002\u987e\u540d\u601d\u4e49\uff0c\u7d22\u5f15 i \u5904\u7684\u524d\u7f00\u548c prefix[i] \u7b49\u4e8e\u6570\u7ec4\u524d i \u4e2a\u5143\u7d20\u4e4b\u548c\uff1a

        \\[ \\text{prefix}[i] = \\sum_{j=0}^i \\text{counter[j]} \\]

        \u524d\u7f00\u548c\u5177\u6709\u660e\u786e\u7684\u610f\u4e49\uff0cprefix[num] - 1 \u4ee3\u8868\u5143\u7d20 num \u5728\u7ed3\u679c\u6570\u7ec4 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\u3002\u8fd9\u4e2a\u4fe1\u606f\u975e\u5e38\u5173\u952e\uff0c\u56e0\u4e3a\u5b83\u544a\u8bc9\u6211\u4eec\u5404\u4e2a\u5143\u7d20\u5e94\u8be5\u51fa\u73b0\u5728\u7ed3\u679c\u6570\u7ec4\u7684\u54ea\u4e2a\u4f4d\u7f6e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5012\u5e8f\u904d\u5386\u539f\u6570\u7ec4 nums \u7684\u6bcf\u4e2a\u5143\u7d20 num \uff0c\u5728\u6bcf\u8f6e\u8fed\u4ee3\u4e2d\u6267\u884c\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u5c06 num \u586b\u5165\u6570\u7ec4 res \u7684\u7d22\u5f15 prefix[num] - 1 \u5904\u3002
        2. \u4ee4\u524d\u7f00\u548c prefix[num] \u51cf\u5c0f \\(1\\) \uff0c\u4ece\u800c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\u3002

        \u904d\u5386\u5b8c\u6210\u540e\uff0c\u6570\u7ec4 res \u4e2d\u5c31\u662f\u6392\u5e8f\u597d\u7684\u7ed3\u679c\uff0c\u6700\u540e\u4f7f\u7528 res \u8986\u76d6\u539f\u6570\u7ec4 nums \u5373\u53ef\u3002\u56fe 11-17 \u5c55\u793a\u4e86\u5b8c\u6574\u7684\u8ba1\u6570\u6392\u5e8f\u6d41\u7a0b\u3002

        <1><2><3><4><5><6><7><8>

        \u56fe 11-17 \u00a0 \u8ba1\u6570\u6392\u5e8f\u6b65\u9aa4

        \u8ba1\u6570\u6392\u5e8f\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig counting_sort.py
        def counting_sort(nums: list[int]):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\"\"\"\n# \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\n# 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm = max(nums)\n# 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n# counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter = [0] * (m + 1)\nfor num in nums:\ncounter[num] += 1\n# 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n# \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in range(m):\ncounter[i + 1] += counter[i]\n# 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n# \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nn = len(nums)\nres = [0] * n\nfor i in range(n - 1, -1, -1):\nnum = nums[i]\nres[counter[num] - 1] = num  # \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num] -= 1  # \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n# \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in range(n):\nnums[i] = res[i]\n
        counting_sort.cpp
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(vector<int> &nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvector<int> counter(m + 1, 0);\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.size();\nvector<int> res(n);\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--;              // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nnums = res;\n}\n
        counting_sort.java
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.length;\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.cs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid CountingSort(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nforeach (int num in nums) {\nm = Math.Max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nforeach (int num in nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.Length;\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.go
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunc countingSort(nums []int) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm := 0\nfor _, num := range nums {\nif num > m {\nm = num\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter := make([]int, m+1)\nfor _, num := range nums {\ncounter[num]++\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i := 0; i < m; i++ {\ncounter[i+1] += counter[i]\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nn := len(nums)\nres := make([]int, n)\nfor i := n - 1; i >= 0; i-- {\nnum := nums[i]\n// \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\nres[counter[num]-1] = num\n// \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\ncounter[num]--\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\ncopy(nums, res)\n}\n
        counting_sort.swift
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunc countingSort(nums: inout [Int]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = nums.max()!\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvar counter = Array(repeating: 0, count: m + 1)\nfor num in nums {\ncounter[num] += 1\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in stride(from: 0, to: m, by: 1) {\ncounter[i + 1] += counter[i]\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nvar res = Array(repeating: 0, count: nums.count)\nfor i in stride(from: nums.count - 1, through: 0, by: -1) {\nlet num = nums[i]\nres[counter[num] - 1] = num // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num] -= 1 // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in stride(from: 0, to: nums.count, by: 1) {\nnums[i] = res[i]\n}\n}\n
        counting_sort.js
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunction countingSort(nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter = new Array(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (let i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nconst n = nums.length;\nconst res = new Array(n);\nfor (let i = n - 1; i >= 0; i--) {\nconst num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.ts
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunction countingSort(nums: number[]): void {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter: number[] = new Array<number>(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (let i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nconst n = nums.length;\nconst res: number[] = new Array<number>(n);\nfor (let i = n - 1; i >= 0; i--) {\nconst num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.dart
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(List<int> nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int _num in nums) {\nm = max(m, _num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[_num] \u4ee3\u8868 _num \u7684\u51fa\u73b0\u6b21\u6570\nList<int> counter = List.filled(m + 1, 0);\nfor (int _num in nums) {\ncounter[_num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[_num]-1 \u662f _num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.length;\nList<int> res = List.filled(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint _num = nums[i];\nres[counter[_num] - 1] = _num; // \u5c06 _num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[_num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e _num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nnums.setAll(0, res);\n}\n
        counting_sort.rs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfn counting_sort(nums: &mut [i32]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = *nums.into_iter().max().unwrap();\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nlet mut counter = vec![0; m as usize + 1];\nfor &num in &*nums {\ncounter[num as usize] += 1;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in 0..m as usize {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nlet n = nums.len();\nlet mut res = vec![0; n];\nfor i in (0..n).rev() {\nlet num = nums[i];\nres[counter[num as usize] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num as usize] -= 1; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in 0..n {\nnums[i] = res[i];\n}\n}\n
        counting_sort.c
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(int nums[], int size) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int i = 0; i < size; i++) {\nif (nums[i] > m) {\nm = nums[i];\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint *counter = calloc(m, sizeof(int));\nfor (int i = 0; i < size; i++) {\ncounter[nums[i]]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint *res = malloc(sizeof(int) * size);\nfor (int i = size - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--;              // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nmemcpy(nums, res, size * sizeof(int));\n// 5. \u91ca\u653e\u5185\u5b58\nfree(counter);\n}\n
        counting_sort.zig
        [class]{}-[func]{countingSort}\n
        "},{"location":"chapter_sorting/counting_sort/#1193","title":"11.9.3 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n + m)\\) \uff1a\u6d89\u53ca\u904d\u5386 nums \u548c\u904d\u5386 counter \uff0c\u90fd\u4f7f\u7528\u7ebf\u6027\u65f6\u95f4\u3002\u4e00\u822c\u60c5\u51b5\u4e0b \\(n \\gg m\\) \uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u4e8e \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + m)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u501f\u52a9\u4e86\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\) \u548c \\(m\\) \u7684\u6570\u7ec4 res \u548c counter \u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u7531\u4e8e\u5411 res \u4e2d\u586b\u5145\u5143\u7d20\u7684\u987a\u5e8f\u662f\u201c\u4ece\u53f3\u5411\u5de6\u201d\u7684\uff0c\u56e0\u6b64\u5012\u5e8f\u904d\u5386 nums \u53ef\u4ee5\u907f\u514d\u6539\u53d8\u76f8\u7b49\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u7a33\u5b9a\u6392\u5e8f\u3002\u5b9e\u9645\u4e0a\uff0c\u6b63\u5e8f\u904d\u5386 nums \u4e5f\u53ef\u4ee5\u5f97\u5230\u6b63\u786e\u7684\u6392\u5e8f\u7ed3\u679c\uff0c\u4f46\u7ed3\u679c\u662f\u975e\u7a33\u5b9a\u7684\u3002
        "},{"location":"chapter_sorting/counting_sort/#1194","title":"11.9.4 \u00a0 \u5c40\u9650\u6027","text":"

        \u770b\u5230\u8fd9\u91cc\uff0c\u4f60\u4e5f\u8bb8\u4f1a\u89c9\u5f97\u8ba1\u6570\u6392\u5e8f\u975e\u5e38\u5de7\u5999\uff0c\u4ec5\u901a\u8fc7\u7edf\u8ba1\u6570\u91cf\u5c31\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u6392\u5e8f\u3002\u7136\u800c\uff0c\u4f7f\u7528\u8ba1\u6570\u6392\u5e8f\u7684\u524d\u7f6e\u6761\u4ef6\u76f8\u5bf9\u8f83\u4e3a\u4e25\u683c\u3002

        \u8ba1\u6570\u6392\u5e8f\u53ea\u9002\u7528\u4e8e\u975e\u8d1f\u6574\u6570\u3002\u82e5\u60f3\u5c06\u5176\u7528\u4e8e\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\uff0c\u9700\u8981\u786e\u4fdd\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u8f6c\u6362\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u4e0d\u80fd\u6539\u53d8\u5404\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u5927\u5c0f\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u5305\u542b\u8d1f\u6570\u7684\u6574\u6570\u6570\u7ec4\uff0c\u53ef\u4ee5\u5148\u7ed9\u6240\u6709\u6570\u5b57\u52a0\u4e0a\u4e00\u4e2a\u5e38\u6570\uff0c\u5c06\u5168\u90e8\u6570\u5b57\u8f6c\u5316\u4e3a\u6b63\u6570\uff0c\u6392\u5e8f\u5b8c\u6210\u540e\u518d\u8f6c\u6362\u56de\u53bb\u3002

        \u8ba1\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u636e\u91cf\u5927\u4f46\u6570\u636e\u8303\u56f4\u8f83\u5c0f\u7684\u60c5\u51b5\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d \\(m\\) \u4e0d\u80fd\u592a\u5927\uff0c\u5426\u5219\u4f1a\u5360\u7528\u8fc7\u591a\u7a7a\u95f4\u3002\u800c\u5f53 \\(n \\ll m\\) \u65f6\uff0c\u8ba1\u6570\u6392\u5e8f\u4f7f\u7528 \\(O(m)\\) \u65f6\u95f4\uff0c\u53ef\u80fd\u6bd4 \\(O(n \\log n)\\) \u7684\u6392\u5e8f\u7b97\u6cd5\u8fd8\u8981\u6162\u3002

        "},{"location":"chapter_sorting/heap_sort/","title":"11.7 \u00a0 \u5806\u6392\u5e8f","text":"

        Tip

        \u9605\u8bfb\u672c\u8282\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5b66\u5b8c\u201c\u5806\u201c\u7ae0\u8282\u3002

        \u300c\u5806\u6392\u5e8f heap sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5806\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\u7684\u9ad8\u6548\u6392\u5e8f\u7b97\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u5df2\u7ecf\u5b66\u8fc7\u7684\u201c\u5efa\u5806\u64cd\u4f5c\u201d\u548c\u201c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u201d\u5b9e\u73b0\u5806\u6392\u5e8f\u3002

        1. \u8f93\u5165\u6570\u7ec4\u5e76\u5efa\u7acb\u5c0f\u9876\u5806\uff0c\u6b64\u65f6\u6700\u5c0f\u5143\u7d20\u4f4d\u4e8e\u5806\u9876\u3002
        2. \u4e0d\u65ad\u6267\u884c\u51fa\u5806\u64cd\u4f5c\uff0c\u4f9d\u6b21\u8bb0\u5f55\u51fa\u5806\u5143\u7d20\uff0c\u5373\u53ef\u5f97\u5230\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u7684\u5e8f\u5217\u3002

        \u4ee5\u4e0a\u65b9\u6cd5\u867d\u7136\u53ef\u884c\uff0c\u4f46\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u989d\u5916\u6570\u7ec4\u6765\u4fdd\u5b58\u5f39\u51fa\u7684\u5143\u7d20\uff0c\u6bd4\u8f83\u6d6a\u8d39\u7a7a\u95f4\u3002\u5728\u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u4e00\u79cd\u66f4\u52a0\u4f18\u96c5\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002

        "},{"location":"chapter_sorting/heap_sort/#1171","title":"11.7.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u5806\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-12 \u6240\u793a\u3002

        1. \u8f93\u5165\u6570\u7ec4\u5e76\u5efa\u7acb\u5927\u9876\u5806\u3002\u5b8c\u6210\u540e\uff0c\u6700\u5927\u5143\u7d20\u4f4d\u4e8e\u5806\u9876\u3002
        2. \u5c06\u5806\u9876\u5143\u7d20\uff08\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\u4e0e\u5806\u5e95\u5143\u7d20\uff08\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff09\u4ea4\u6362\u3002\u5b8c\u6210\u4ea4\u6362\u540e\uff0c\u5806\u7684\u957f\u5ea6\u51cf \\(1\\) \uff0c\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u52a0 \\(1\\) \u3002
        3. \u4ece\u5806\u9876\u5143\u7d20\u5f00\u59cb\uff0c\u4ece\u9876\u5230\u5e95\u6267\u884c\u5806\u5316\u64cd\u4f5c\uff08Sift Down\uff09\u3002\u5b8c\u6210\u5806\u5316\u540e\uff0c\u5806\u7684\u6027\u8d28\u5f97\u5230\u4fee\u590d\u3002
        4. \u5faa\u73af\u6267\u884c\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\u3002\u5faa\u73af \\(n - 1\\) \u8f6e\u540e\uff0c\u5373\u53ef\u5b8c\u6210\u6570\u7ec4\u6392\u5e8f\u3002

        Tip

        \u5b9e\u9645\u4e0a\uff0c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u4e2d\u4e5f\u5305\u542b\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\uff0c\u53ea\u662f\u591a\u4e86\u4e00\u4e2a\u5f39\u51fa\u5143\u7d20\u7684\u6b65\u9aa4\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12>

        \u56fe 11-12 \u00a0 \u5806\u6392\u5e8f\u6b65\u9aa4

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e0e\u201c\u5806\u201d\u7ae0\u8282\u76f8\u540c\u7684\u4ece\u9876\u81f3\u5e95\u5806\u5316 sift_down() \u51fd\u6570\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u5806\u7684\u957f\u5ea6\u4f1a\u968f\u7740\u63d0\u53d6\u6700\u5927\u5143\u7d20\u800c\u51cf\u5c0f\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u7ed9 sift_down() \u51fd\u6570\u6dfb\u52a0\u4e00\u4e2a\u957f\u5ea6\u53c2\u6570 \\(n\\) \uff0c\u7528\u4e8e\u6307\u5b9a\u5806\u7684\u5f53\u524d\u6709\u6548\u957f\u5ea6\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig heap_sort.py
        def sift_down(nums: list[int], n: int, i: int):\n\"\"\"\u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\nwhile True:\n# \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl = 2 * i + 1\nr = 2 * i + 2\nma = i\nif l < n and nums[l] > nums[ma]:\nma = l\nif r < n and nums[r] > nums[ma]:\nma = r\n# \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nnums[i], nums[ma] = nums[ma], nums[i]\n# \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\ndef heap_sort(nums: list[int]):\n\"\"\"\u5806\u6392\u5e8f\"\"\"\n# \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in range(len(nums) // 2 - 1, -1, -1):\nsift_down(nums, len(nums), i)\n# \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in range(len(nums) - 1, 0, -1):\n# \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nnums[0], nums[i] = nums[i], nums[0]\n# \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsift_down(nums, i, 0)\n
        heap_sort.cpp
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(vector<int> &nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(nums[i], nums[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(vector<int> &nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.size() / 2 - 1; i >= 0; --i) {\nsiftDown(nums, nums.size(), i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.size() - 1; i > 0; --i) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(nums[0], nums[i]);\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.java
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int[] nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(int[] nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.length / 2 - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.cs
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int[] nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\n(nums[ma], nums[i]) = (nums[i], nums[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid HeapSort(int[] nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.Length / 2 - 1; i >= 0; i--) {\nSiftDown(nums, nums.Length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n(nums[i], nums[0]) = (nums[0], nums[i]);\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nSiftDown(nums, i, 0);\n}\n}\n
        heap_sort.go
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(nums *[]int, n, i int) {\nfor true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl := 2*i + 1\nr := 2*i + 2\nma := i\nif l < n && (*nums)[l] > (*nums)[ma] {\nma = l\n}\nif r < n && (*nums)[r] > (*nums)[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n(*nums)[i], (*nums)[ma] = (*nums)[ma], (*nums)[i]\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n/* \u5806\u6392\u5e8f */\nfunc heapSort(nums *[]int) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i := len(*nums)/2 - 1; i >= 0; i-- {\nsiftDown(nums, len(*nums), i)\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i := len(*nums) - 1; i > 0; i-- {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n(*nums)[0], (*nums)[i] = (*nums)[i], (*nums)[0]\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0)\n}\n}\n
        heap_sort.swift
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(nums: inout [Int], n: Int, i: Int) {\nvar i = i\nwhile true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1\nlet r = 2 * i + 2\nvar ma = i\nif l < n, nums[l] > nums[ma] {\nma = l\n}\nif r < n, nums[r] > nums[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nnums.swapAt(i, ma)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n/* \u5806\u6392\u5e8f */\nfunc heapSort(nums: inout [Int]) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in stride(from: nums.count / 2 - 1, through: 0, by: -1) {\nsiftDown(nums: &nums, n: nums.count, i: i)\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nnums.swapAt(0, i)\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums: &nums, n: i, i: 0)\n}\n}\n
        heap_sort.js
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunction siftDown(nums, n, i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet ma = i;\nif (l < n && nums[l] > nums[ma]) {\nma = l;\n}\nif (r < n && nums[r] > nums[ma]) {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n[nums[i], nums[ma]] = [nums[ma], nums[i]];\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfunction heapSort(nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n[nums[0], nums[i]] = [nums[i], nums[0]];\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.ts
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunction siftDown(nums: number[], n: number, i: number): void {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet ma = i;\nif (l < n && nums[l] > nums[ma]) {\nma = l;\n}\nif (r < n && nums[r] > nums[ma]) {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n[nums[i], nums[ma]] = [nums[ma], nums[i]];\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfunction heapSort(nums: number[]): void {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n[nums[0], nums[i]] = [nums[i], nums[0]];\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.dart
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(List<int> nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma]) ma = l;\nif (r < n && nums[r] > nums[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(List<int> nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.length ~/ 2 - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.rs
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(nums: &mut [i32], n: usize, mut i: usize) {\nloop {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet mut ma = i;\nif l < n && nums[l] > nums[ma] {\nma = l;\n}\nif r < n && nums[r] > nums[ma] {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nlet temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfn heap_sort(nums: &mut [i32]) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in (0..=nums.len() / 2 - 1).rev() {\nsift_down(nums, nums.len(), i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in (1..=nums.len() - 1).rev() {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nlet tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsift_down(nums, i, 0);\n}\n}\n
        heap_sort.c
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int nums[], int n, int i) {\nwhile (1) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(int nums[], int n) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = n / 2 - 1; i >= 0; --i) {\nsiftDown(nums, n, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = n - 1; i > 0; --i) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.zig
        [class]{}-[func]{siftDown}\n[class]{}-[func]{heapSort}\n
        "},{"location":"chapter_sorting/heap_sort/#1172","title":"11.7.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5efa\u5806\u64cd\u4f5c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002\u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \uff0c\u5171\u5faa\u73af \\(n - 1\\) \u8f6e\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u51e0\u4e2a\u6307\u9488\u53d8\u91cf\u4f7f\u7528 \\(O(1)\\) \u7a7a\u95f4\u3002\u5143\u7d20\u4ea4\u6362\u548c\u5806\u5316\u64cd\u4f5c\u90fd\u662f\u5728\u539f\u6570\u7ec4\u4e0a\u8fdb\u884c\u7684\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u4ea4\u6362\u5806\u9876\u5143\u7d20\u548c\u5806\u5e95\u5143\u7d20\u65f6\uff0c\u76f8\u7b49\u5143\u7d20\u7684\u76f8\u5bf9\u4f4d\u7f6e\u53ef\u80fd\u53d1\u751f\u53d8\u5316\u3002
        "},{"location":"chapter_sorting/insertion_sort/","title":"11.4 \u00a0 \u63d2\u5165\u6392\u5e8f","text":"

        \u300c\u63d2\u5165\u6392\u5e8f insertion sort\u300d\u662f\u4e00\u79cd\u7b80\u5355\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5b83\u7684\u5de5\u4f5c\u539f\u7406\u4e0e\u624b\u52a8\u6574\u7406\u4e00\u526f\u724c\u7684\u8fc7\u7a0b\u975e\u5e38\u76f8\u4f3c\u3002

        \u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u5728\u672a\u6392\u5e8f\u533a\u95f4\u9009\u62e9\u4e00\u4e2a\u57fa\u51c6\u5143\u7d20\uff0c\u5c06\u8be5\u5143\u7d20\u4e0e\u5176\u5de6\u4fa7\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u5143\u7d20\u9010\u4e00\u6bd4\u8f83\u5927\u5c0f\uff0c\u5e76\u5c06\u8be5\u5143\u7d20\u63d2\u5165\u5230\u6b63\u786e\u7684\u4f4d\u7f6e\u3002

        \u56fe 11-6 \u5c55\u793a\u4e86\u6570\u7ec4\u63d2\u5165\u5143\u7d20\u7684\u64cd\u4f5c\u6d41\u7a0b\u3002\u8bbe\u57fa\u51c6\u5143\u7d20\u4e3a base \uff0c\u6211\u4eec\u9700\u8981\u5c06\u4ece\u76ee\u6807\u7d22\u5f15\u5230 base \u4e4b\u95f4\u7684\u6240\u6709\u5143\u7d20\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\uff0c\u7136\u540e\u5c06 base \u8d4b\u503c\u7ed9\u76ee\u6807\u7d22\u5f15\u3002

        \u56fe 11-6 \u00a0 \u5355\u6b21\u63d2\u5165\u64cd\u4f5c

        "},{"location":"chapter_sorting/insertion_sort/#1141","title":"11.4.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u63d2\u5165\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-7 \u6240\u793a\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6570\u7ec4\u7684\u7b2c 1 \u4e2a\u5143\u7d20\u5df2\u5b8c\u6210\u6392\u5e8f\u3002
        2. \u9009\u53d6\u6570\u7ec4\u7684\u7b2c 2 \u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6570\u7ec4\u7684\u524d 2 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        3. \u9009\u53d6\u7b2c 3 \u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6570\u7ec4\u7684\u524d 3 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        4. \u4ee5\u6b64\u7c7b\u63a8\uff0c\u5728\u6700\u540e\u4e00\u8f6e\u4e2d\uff0c\u9009\u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6240\u6709\u5143\u7d20\u5747\u5df2\u6392\u5e8f\u3002

        \u56fe 11-7 \u00a0 \u63d2\u5165\u6392\u5e8f\u6d41\u7a0b

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig insertion_sort.py
        def insertion_sort(nums: list[int]):\n\"\"\"\u63d2\u5165\u6392\u5e8f\"\"\"\n# \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u533a\u95f4\u4e3a [0, i-1]\nfor i in range(1, len(nums)):\nbase = nums[i]\nj = i - 1\n# \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u533a\u95f4 [0, i-1] \u4e2d\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0 and nums[j] > base:\nnums[j + 1] = nums[j]  # \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1\nnums[j + 1] = base  # \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n
        insertion_sort.cpp
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.size(); i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.java
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.length; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base;        // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.cs
        /* \u63d2\u5165\u6392\u5e8f */\nvoid InsertionSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.Length; i++) {\nint bas = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > bas) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = bas;         // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.go
        /* \u63d2\u5165\u6392\u5e8f */\nfunc insertionSort(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := 1; i < len(nums); i++ {\nbase := nums[i]\nj := i - 1\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nfor j >= 0 && nums[j] > base {\nnums[j+1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--\n}\nnums[j+1] = base // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.swift
        /* \u63d2\u5165\u6392\u5e8f */\nfunc insertionSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor i in stride(from: 1, to: nums.count, by: 1) {\nlet base = nums[i]\nvar j = i - 1\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0, nums[j] > base {\nnums[j + 1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1\n}\nnums[j + 1] = base // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.js
        /* \u63d2\u5165\u6392\u5e8f */\nfunction insertionSort(nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (let i = 1; i < nums.length; i++) {\nlet base = nums[i],\nj = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.ts
        /* \u63d2\u5165\u6392\u5e8f */\nfunction insertionSort(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (let i = 1; i < nums.length; i++) {\nconst base = nums[i];\nlet j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.dart
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.length; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.rs
        /* \u63d2\u5165\u6392\u5e8f */\nfn insertion_sort(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor i in 1..nums.len() {\nlet (base, mut j) = (nums[i],  (i - 1) as i32);\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0 && nums[j as usize] > base {\nnums[(j + 1) as usize] = nums[j as usize]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1;\n}\nnums[(j + 1) as usize] = base;  // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.c
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < size; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\n// \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nnums[j + 1] = nums[j];\nj--;\n}\n// \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\nnums[j + 1] = base;\n}\n}\n
        insertion_sort.zig
        // \u63d2\u5165\u6392\u5e8f\nfn insertionSort(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nvar i: usize = 1;\nwhile (i < nums.len) : (i += 1) {\nvar base = nums[i];\nvar j: usize = i;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 1 and nums[j - 1] > base) : (j -= 1) {\nnums[j] = nums[j - 1];  // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n}\nnums[j] = base;             // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        "},{"location":"chapter_sorting/insertion_sort/#1142","title":"11.4.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n^2)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u63d2\u5165\u64cd\u4f5c\u5206\u522b\u9700\u8981\u5faa\u73af \\(n - 1\\)\u3001\\(n-2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u6b21\uff0c\u6c42\u548c\u5f97\u5230 \\((n - 1) n / 2\\) \uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002\u5728\u9047\u5230\u6709\u5e8f\u6570\u636e\u65f6\uff0c\u63d2\u5165\u64cd\u4f5c\u4f1a\u63d0\u524d\u7ec8\u6b62\u3002\u5f53\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u6709\u5e8f\u65f6\uff0c\u63d2\u5165\u6392\u5e8f\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u63d2\u5165\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u4f1a\u5c06\u5143\u7d20\u63d2\u5165\u5230\u76f8\u7b49\u5143\u7d20\u7684\u53f3\u4fa7\uff0c\u4e0d\u4f1a\u6539\u53d8\u5b83\u4eec\u7684\u987a\u5e8f\u3002
        "},{"location":"chapter_sorting/insertion_sort/#1143","title":"11.4.3 \u00a0 \u63d2\u5165\u6392\u5e8f\u4f18\u52bf","text":"

        \u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u800c\u6211\u4eec\u5373\u5c06\u5b66\u4e60\u7684\u5feb\u901f\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u5c3d\u7ba1\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u66f4\u9ad8\uff0c\u4f46\u5728\u6570\u636e\u91cf\u8f83\u5c0f\u7684\u60c5\u51b5\u4e0b\uff0c\u63d2\u5165\u6392\u5e8f\u901a\u5e38\u66f4\u5feb\u3002

        \u8fd9\u4e2a\u7ed3\u8bba\u4e0e\u7ebf\u6027\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u7684\u9002\u7528\u60c5\u51b5\u7684\u7ed3\u8bba\u7c7b\u4f3c\u3002\u5feb\u901f\u6392\u5e8f\u8fd9\u7c7b \\(O(n \\log n)\\) \u7684\u7b97\u6cd5\u5c5e\u4e8e\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5f80\u5f80\u5305\u542b\u66f4\u591a\u5355\u5143\u8ba1\u7b97\u64cd\u4f5c\u3002\u800c\u5728\u6570\u636e\u91cf\u8f83\u5c0f\u65f6\uff0c\\(n^2\\) \u548c \\(n \\log n\\) \u7684\u6570\u503c\u6bd4\u8f83\u63a5\u8fd1\uff0c\u590d\u6742\u5ea6\u4e0d\u5360\u4e3b\u5bfc\u5730\u4f4d\uff1b\u6bcf\u8f6e\u4e2d\u7684\u5355\u5143\u64cd\u4f5c\u6570\u91cf\u8d77\u5230\u51b3\u5b9a\u6027\u4f5c\u7528\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\uff08\u4f8b\u5982 Java\uff09\u7684\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\u91c7\u7528\u4e86\u63d2\u5165\u6392\u5e8f\uff0c\u5927\u81f4\u601d\u8def\u4e3a\uff1a\u5bf9\u4e8e\u957f\u6570\u7ec4\uff0c\u91c7\u7528\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u4f8b\u5982\u5feb\u901f\u6392\u5e8f\uff1b\u5bf9\u4e8e\u77ed\u6570\u7ec4\uff0c\u76f4\u63a5\u4f7f\u7528\u63d2\u5165\u6392\u5e8f\u3002

        \u867d\u7136\u5192\u6ce1\u6392\u5e8f\u3001\u9009\u62e9\u6392\u5e8f\u548c\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \uff0c\u4f46\u5728\u5b9e\u9645\u60c5\u51b5\u4e2d\uff0c\u63d2\u5165\u6392\u5e8f\u7684\u4f7f\u7528\u9891\u7387\u663e\u8457\u9ad8\u4e8e\u5192\u6ce1\u6392\u5e8f\u548c\u9009\u62e9\u6392\u5e8f\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u5192\u6ce1\u6392\u5e8f\u57fa\u4e8e\u5143\u7d20\u4ea4\u6362\u5b9e\u73b0\uff0c\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf\uff0c\u5171\u6d89\u53ca 3 \u4e2a\u5355\u5143\u64cd\u4f5c\uff1b\u63d2\u5165\u6392\u5e8f\u57fa\u4e8e\u5143\u7d20\u8d4b\u503c\u5b9e\u73b0\uff0c\u4ec5\u9700 1 \u4e2a\u5355\u5143\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u8ba1\u7b97\u5f00\u9500\u901a\u5e38\u6bd4\u63d2\u5165\u6392\u5e8f\u66f4\u9ad8\u3002
        • \u9009\u62e9\u6392\u5e8f\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \u3002\u5982\u679c\u7ed9\u5b9a\u4e00\u7ec4\u90e8\u5206\u6709\u5e8f\u7684\u6570\u636e\uff0c\u63d2\u5165\u6392\u5e8f\u901a\u5e38\u6bd4\u9009\u62e9\u6392\u5e8f\u6548\u7387\u66f4\u9ad8\u3002
        • \u9009\u62e9\u6392\u5e8f\u4e0d\u7a33\u5b9a\uff0c\u65e0\u6cd5\u5e94\u7528\u4e8e\u591a\u7ea7\u6392\u5e8f\u3002
        "},{"location":"chapter_sorting/merge_sort/","title":"11.6 \u00a0 \u5f52\u5e76\u6392\u5e8f","text":"

        \u300c\u5f52\u5e76\u6392\u5e8f merge sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5305\u542b\u56fe 11-10 \u6240\u793a\u7684\u201c\u5212\u5206\u201d\u548c\u201c\u5408\u5e76\u201d\u9636\u6bb5\u3002

        1. \u5212\u5206\u9636\u6bb5\uff1a\u901a\u8fc7\u9012\u5f52\u4e0d\u65ad\u5730\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5206\u5f00\uff0c\u5c06\u957f\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u8f6c\u6362\u4e3a\u77ed\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u3002
        2. \u5408\u5e76\u9636\u6bb5\uff1a\u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u5212\u5206\uff0c\u5f00\u59cb\u5408\u5e76\uff0c\u6301\u7eed\u5730\u5c06\u5de6\u53f3\u4e24\u4e2a\u8f83\u77ed\u7684\u6709\u5e8f\u6570\u7ec4\u5408\u5e76\u4e3a\u4e00\u4e2a\u8f83\u957f\u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u76f4\u81f3\u7ed3\u675f\u3002

        \u56fe 11-10 \u00a0 \u5f52\u5e76\u6392\u5e8f\u7684\u5212\u5206\u4e0e\u5408\u5e76\u9636\u6bb5

        "},{"location":"chapter_sorting/merge_sort/#1161","title":"11.6.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u5982\u56fe 11-11 \u6240\u793a\uff0c\u201c\u5212\u5206\u9636\u6bb5\u201d\u4ece\u9876\u81f3\u5e95\u9012\u5f52\u5730\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5207\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\u3002

        1. \u8ba1\u7b97\u6570\u7ec4\u4e2d\u70b9 mid \uff0c\u9012\u5f52\u5212\u5206\u5de6\u5b50\u6570\u7ec4\uff08\u533a\u95f4 [left, mid] \uff09\u548c\u53f3\u5b50\u6570\u7ec4\uff08\u533a\u95f4 [mid + 1, right] \uff09\u3002
        2. \u9012\u5f52\u6267\u884c\u6b65\u9aa4 1. \uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u533a\u95f4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u3002

        \u201c\u5408\u5e76\u9636\u6bb5\u201d\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u5408\u5e76\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ece\u957f\u5ea6\u4e3a 1 \u7684\u5b50\u6570\u7ec4\u5f00\u59cb\u5408\u5e76\uff0c\u5408\u5e76\u9636\u6bb5\u4e2d\u7684\u6bcf\u4e2a\u5b50\u6570\u7ec4\u90fd\u662f\u6709\u5e8f\u7684\u3002

        <1><2><3><4><5><6><7><8><9><10>

        \u56fe 11-11 \u00a0 \u5f52\u5e76\u6392\u5e8f\u6b65\u9aa4

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u5f52\u5e76\u6392\u5e8f\u4e0e\u4e8c\u53c9\u6811\u540e\u5e8f\u904d\u5386\u7684\u9012\u5f52\u987a\u5e8f\u662f\u4e00\u81f4\u7684\u3002

        • \u540e\u5e8f\u904d\u5386\uff1a\u5148\u9012\u5f52\u5de6\u5b50\u6811\uff0c\u518d\u9012\u5f52\u53f3\u5b50\u6811\uff0c\u6700\u540e\u5904\u7406\u6839\u8282\u70b9\u3002
        • \u5f52\u5e76\u6392\u5e8f\uff1a\u5148\u9012\u5f52\u5de6\u5b50\u6570\u7ec4\uff0c\u518d\u9012\u5f52\u53f3\u5b50\u6570\u7ec4\uff0c\u6700\u540e\u5904\u7406\u5408\u5e76\u3002

        \u5f52\u5e76\u6392\u5e8f\u7684\u5b9e\u73b0\u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\u3002\u8bf7\u6ce8\u610f\uff0cnums \u7684\u5f85\u5408\u5e76\u533a\u95f4\u4e3a [left, right] \uff0c\u800c tmp \u7684\u5bf9\u5e94\u533a\u95f4\u4e3a [0, right - left] \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig merge_sort.py
        def merge(nums: list[int], left: int, mid: int, right: int):\n\"\"\"\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\"\"\"\n# \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n# \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\ntmp = [0] * (right - left + 1)\n# \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\ni, j, k = left, mid + 1, 0\n# \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid and j <= right:\nif nums[i] <= nums[j]:\ntmp[k] = nums[i]\ni += 1\nelse:\ntmp[k] = nums[j]\nj += 1\nk += 1\n# \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid:\ntmp[k] = nums[i]\ni += 1\nk += 1\nwhile j <= right:\ntmp[k] = nums[j]\nj += 1\nk += 1\n# \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in range(0, len(tmp)):\nnums[left + k] = tmp[k]\ndef merge_sort(nums: list[int], left: int, right: int):\n\"\"\"\u5f52\u5e76\u6392\u5e8f\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif left >= right:\nreturn  # \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n# \u5212\u5206\u9636\u6bb5\nmid = (left + right) // 2  # \u8ba1\u7b97\u4e2d\u70b9\nmerge_sort(nums, left, mid)  # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmerge_sort(nums, mid + 1, right)  # \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n# \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right)\n
        merge_sort.cpp
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(vector<int> &nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nvector<int> tmp(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.size(); k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(vector<int> &nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.java
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(int[] nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint[] tmp = new int[right - left + 1];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int[] nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2; // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.cs
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid Merge(int[] nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint[] tmp = new int[right - left + 1];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.Length; ++k) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid MergeSort(int[] nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return;       // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nMergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nMergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nMerge(nums, left, mid, right);\n}\n
        merge_sort.go
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunc merge(nums []int, left, mid, right int) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\ntmp := make([]int, right-left+1)\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\ni, j, k := left, mid+1, 0\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nfor i <= mid && j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[i]\ni++\n} else {\ntmp[k] = nums[j]\nj++\n}\nk++\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nfor i <= mid {\ntmp[k] = nums[i]\ni++\nk++\n}\nfor j <= right {\ntmp[k] = nums[j]\nj++\nk++\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k := 0; k < len(tmp); k++ {\nnums[left+k] = tmp[k]\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums []int, left, right int) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right {\nreturn\n}\n// \u5212\u5206\u9636\u6bb5\nmid := (left + right) / 2\nmergeSort(nums, left, mid)\nmergeSort(nums, mid+1, right)\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right)\n}\n
        merge_sort.swift
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunc merge(nums: inout [Int], left: Int, mid: Int, right: Int) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nvar tmp = Array(repeating: 0, count: right - left + 1)\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nvar i = left, j = mid + 1, k = 0\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid, j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[i]\ni += 1\nk += 1\n} else {\ntmp[k] = nums[j]\nj += 1\nk += 1\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid {\ntmp[k] = nums[i]\ni += 1\nk += 1\n}\nwhile j <= right {\ntmp[k] = nums[j]\nj += 1\nk += 1\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in tmp.indices {\nnums[left + k] = tmp[k]\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums: inout [Int], left: Int, right: Int) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right { // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nreturn\n}\n// \u5212\u5206\u9636\u6bb5\nlet mid = (left + right) / 2 // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums: &nums, left: left, right: mid) // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums: &nums, left: mid + 1, right: right) // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums: &nums, left: left, mid: mid, right: right)\n}\n
        merge_sort.js
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunction merge(nums, left, mid, right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nconst tmp = new Array(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet i = left,\nj = mid + 1,\nk = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums, left, right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.ts
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunction merge(nums: number[], left: number, mid: number, right: number): void {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nconst tmp = new Array(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet i = left,\nj = mid + 1,\nk = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums: number[], left: number, right: number): void {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.dart
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(List<int> nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nList<int> tmp = List.filled(right - left + 1, 0);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(List<int> nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.rs
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfn merge(nums: &mut [i32], left: usize, mid: usize, right: usize) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nlet tmp_size = right - left + 1;\nlet mut tmp = vec![0; tmp_size];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet (mut i, mut j, mut k) = (left, mid + 1, 0);\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid && j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[j];\ni += 1;\n} else {\ntmp[k] = nums[j];\nj += 1;\n}\nk += 1;\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid {\ntmp[k] = nums[i];\nk += 1;\ni += 1;\n}\nwhile j <= right {\ntmp[k] = nums[j];\nk += 1;\nj += 1;\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in 0..tmp_size {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfn merge_sort(nums: &mut [i32], left: usize, right: usize) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right { return; }             // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = (left + right) / 2;     // \u8ba1\u7b97\u4e2d\u70b9\nmerge_sort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmerge_sort(nums, mid + 1, right);  // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.c
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(int *nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint tmpSize = right - left + 1;\nint *tmp = (int *)malloc(tmpSize * sizeof(int));\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmpSize; ++k) {\nnums[left + k] = tmp[k];\n}\n// \u91ca\u653e\u5185\u5b58\nfree(tmp);\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int *nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.zig
        // \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid]\n// \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid + 1, right]\nfn merge(nums: []i32, left: usize, mid: usize, right: usize) !void {\n// \u521d\u59cb\u5316\u8f85\u52a9\u6570\u7ec4\nvar mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\ndefer mem_arena.deinit();\nconst mem_allocator = mem_arena.allocator();\nvar tmp = try mem_allocator.alloc(i32, right + 1 - left);\nstd.mem.copy(i32, tmp, nums[left..right+1]);\n// \u5de6\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15  \nvar leftStart = left - left;\nvar leftEnd = mid - left;\n// \u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15       \nvar rightStart = mid + 1 - left;\nvar rightEnd = right - left;\n// i, j \u5206\u522b\u6307\u5411\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\u7684\u9996\u5143\u7d20\nvar i = leftStart;\nvar j = rightStart;\n// \u901a\u8fc7\u8986\u76d6\u539f\u6570\u7ec4 nums \u6765\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\nvar k = left;\nwhile (k <= right) : (k += 1) {\n// \u82e5\u201c\u5de6\u5b50\u6570\u7ec4\u5df2\u5168\u90e8\u5408\u5e76\u5b8c\u201d\uff0c\u5219\u9009\u53d6\u53f3\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 j++\nif (i > leftEnd) {\nnums[k] = tmp[j];\nj += 1;\n// \u5426\u5219\uff0c\u82e5\u201c\u53f3\u5b50\u6570\u7ec4\u5df2\u5168\u90e8\u5408\u5e76\u5b8c\u201d\u6216\u201c\u5de6\u5b50\u6570\u7ec4\u5143\u7d20 <= \u53f3\u5b50\u6570\u7ec4\u5143\u7d20\u201d\uff0c\u5219\u9009\u53d6\u5de6\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 i++\n} else if  (j > rightEnd or tmp[i] <= tmp[j]) {\nnums[k] = tmp[i];\ni += 1;\n// \u5426\u5219\uff0c\u82e5\u201c\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u672a\u5168\u90e8\u5408\u5e76\u5b8c\u201d\u4e14\u201c\u5de6\u5b50\u6570\u7ec4\u5143\u7d20 > \u53f3\u5b50\u6570\u7ec4\u5143\u7d20\u201d\uff0c\u5219\u9009\u53d6\u53f3\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 j++\n} else {\nnums[k] = tmp[j];\nj += 1;\n}\n}\n}\n// \u5f52\u5e76\u6392\u5e8f\nfn mergeSort(nums: []i32, left: usize, right: usize) !void {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return;              // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nvar mid = (left + right) / 2;           // \u8ba1\u7b97\u4e2d\u70b9\ntry mergeSort(nums, left, mid);         // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\ntry mergeSort(nums, mid + 1, right);    // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\ntry merge(nums, left, mid, right);\n}\n
        "},{"location":"chapter_sorting/merge_sort/#1162","title":"11.6.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5212\u5206\u4ea7\u751f\u9ad8\u5ea6\u4e3a \\(\\log n\\) \u7684\u9012\u5f52\u6811\uff0c\u6bcf\u5c42\u5408\u5e76\u7684\u603b\u64cd\u4f5c\u6570\u91cf\u4e3a \\(n\\) \uff0c\u56e0\u6b64\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u9012\u5f52\u6df1\u5ea6\u4e3a \\(\\log n\\) \uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\u3002\u5408\u5e76\u64cd\u4f5c\u9700\u8981\u501f\u52a9\u8f85\u52a9\u6570\u7ec4\u5b9e\u73b0\uff0c\u4f7f\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u5408\u5e76\u8fc7\u7a0b\u4e2d\uff0c\u76f8\u7b49\u5143\u7d20\u7684\u6b21\u5e8f\u4fdd\u6301\u4e0d\u53d8\u3002
        "},{"location":"chapter_sorting/merge_sort/#1163","title":"11.6.3 \u00a0 \u94fe\u8868\u6392\u5e8f","text":"

        \u5bf9\u4e8e\u94fe\u8868\uff0c\u5f52\u5e76\u6392\u5e8f\u76f8\u8f83\u4e8e\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\u5177\u6709\u663e\u8457\u4f18\u52bf\uff0c\u53ef\u4ee5\u5c06\u94fe\u8868\u6392\u5e8f\u4efb\u52a1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(1)\\) \u3002

        • \u5212\u5206\u9636\u6bb5\uff1a\u53ef\u4ee5\u4f7f\u7528\u201c\u8fed\u4ee3\u201d\u66ff\u4ee3\u201c\u9012\u5f52\u201d\u6765\u5b9e\u73b0\u94fe\u8868\u5212\u5206\u5de5\u4f5c\uff0c\u4ece\u800c\u7701\u53bb\u9012\u5f52\u4f7f\u7528\u7684\u6808\u5e27\u7a7a\u95f4\u3002
        • \u5408\u5e76\u9636\u6bb5\uff1a\u5728\u94fe\u8868\u4e2d\uff0c\u8282\u70b9\u589e\u5220\u64cd\u4f5c\u4ec5\u9700\u6539\u53d8\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\u5b9e\u73b0\uff0c\u56e0\u6b64\u5408\u5e76\u9636\u6bb5\uff08\u5c06\u4e24\u4e2a\u77ed\u6709\u5e8f\u94fe\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u957f\u6709\u5e8f\u94fe\u8868\uff09\u65e0\u987b\u521b\u5efa\u989d\u5916\u94fe\u8868\u3002

        \u5177\u4f53\u5b9e\u73b0\u7ec6\u8282\u6bd4\u8f83\u590d\u6742\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u67e5\u9605\u76f8\u5173\u8d44\u6599\u8fdb\u884c\u5b66\u4e60\u3002

        "},{"location":"chapter_sorting/quick_sort/","title":"11.5 \u00a0 \u5feb\u901f\u6392\u5e8f","text":"

        \u300c\u5feb\u901f\u6392\u5e8f quick sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u8fd0\u884c\u9ad8\u6548\uff0c\u5e94\u7528\u5e7f\u6cdb\u3002

        \u5feb\u901f\u6392\u5e8f\u7684\u6838\u5fc3\u64cd\u4f5c\u662f\u201c\u54e8\u5175\u5212\u5206\u201d\uff0c\u5176\u76ee\u6807\u662f\uff1a\u9009\u62e9\u6570\u7ec4\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u4f5c\u4e3a\u201c\u57fa\u51c6\u6570\u201d\uff0c\u5c06\u6240\u6709\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\u79fb\u5230\u5176\u5de6\u4fa7\uff0c\u800c\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\u79fb\u5230\u5176\u53f3\u4fa7\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u54e8\u5175\u5212\u5206\u7684\u6d41\u7a0b\u5982\u56fe 11-8 \u6240\u793a\u3002

        1. \u9009\u53d6\u6570\u7ec4\u6700\u5de6\u7aef\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\uff0c\u521d\u59cb\u5316\u4e24\u4e2a\u6307\u9488 i \u548c j \u5206\u522b\u6307\u5411\u6570\u7ec4\u7684\u4e24\u7aef\u3002
        2. \u8bbe\u7f6e\u4e00\u4e2a\u5faa\u73af\uff0c\u5728\u6bcf\u8f6e\u4e2d\u4f7f\u7528 i\uff08j\uff09\u5206\u522b\u5bfb\u627e\u7b2c\u4e00\u4e2a\u6bd4\u57fa\u51c6\u6570\u5927\uff08\u5c0f\uff09\u7684\u5143\u7d20\uff0c\u7136\u540e\u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\u3002
        3. \u5faa\u73af\u6267\u884c\u6b65\u9aa4 2. \uff0c\u76f4\u5230 i \u548c j \u76f8\u9047\u65f6\u505c\u6b62\uff0c\u6700\u540e\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u4e2a\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 11-8 \u00a0 \u54e8\u5175\u5212\u5206\u6b65\u9aa4

        \u54e8\u5175\u5212\u5206\u5b8c\u6210\u540e\uff0c\u539f\u6570\u7ec4\u88ab\u5212\u5206\u6210\u4e09\u90e8\u5206\uff1a\u5de6\u5b50\u6570\u7ec4\u3001\u57fa\u51c6\u6570\u3001\u53f3\u5b50\u6570\u7ec4\uff0c\u4e14\u6ee1\u8db3\u201c\u5de6\u5b50\u6570\u7ec4\u4efb\u610f\u5143\u7d20 \\(\\leq\\) \u57fa\u51c6\u6570 \\(\\leq\\) \u53f3\u5b50\u6570\u7ec4\u4efb\u610f\u5143\u7d20\u201d\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u53ea\u9700\u5bf9\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u3002

        \u5feb\u901f\u6392\u5e8f\u7684\u5206\u6cbb\u7b56\u7565

        \u54e8\u5175\u5212\u5206\u7684\u5b9e\u8d28\u662f\u5c06\u4e00\u4e2a\u8f83\u957f\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u7b80\u5316\u4e3a\u4e24\u4e2a\u8f83\u77ed\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def partition(self, nums: list[int], left: int, right: int) -> int:\n\"\"\"\u54e8\u5175\u5212\u5206\"\"\"\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j = left, right\nwhile i < j:\nwhile i < j and nums[j] >= nums[left]:\nj -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile i < j and nums[i] <= nums[left]:\ni += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n# \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n# \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
        quick_sort.cpp
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(vector<int> &nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint partition(vector<int> &nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.java
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(int[] nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint partition(int[] nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.cs
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid Swap(int[] nums, int i, int j) {\n(nums[j], nums[i]) = (nums[i], nums[j]);\n}\n/* \u54e8\u5175\u5212\u5206 */\nint Partition(int[] nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nSwap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nSwap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.go
        /* \u54e8\u5175\u5212\u5206 */\nfunc (q *quickSort) partition(nums []int, left, right int) int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j := left, right\nfor i < j {\nfor i < j && nums[j] >= nums[left] {\nj-- // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nfor i < j && nums[i] <= nums[left] {\ni++ // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.swift
        /* \u5143\u7d20\u4ea4\u6362 */\nfunc swap(nums: inout [Int], i: Int, j: Int) {\nlet tmp = nums[i]\nnums[i] = nums[j]\nnums[j] = tmp\n}\n/* \u54e8\u5175\u5212\u5206 */\nfunc partition(nums: inout [Int], left: Int, right: Int) -> Int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left\nvar j = right\nwhile i < j {\nwhile i < j, nums[j] >= nums[left] {\nj -= 1 // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j, nums[i] <= nums[left] {\ni += 1 // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nswap(nums: &nums, i: i, j: j) // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums: &nums, i: i, j: left) // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.js
        /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums, i, j) {\nlet tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums, left, right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.ts
        /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums: number[], i: number, j: number): void {\nlet tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums: number[], left: number, right: number): number {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.dart
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid _swap(List<int> nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint _partition(List<int> nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n_swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\n_swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.rs
        /* \u54e8\u5175\u5212\u5206 */\nfn partition(nums: &mut [i32], left: usize, right: usize) -> usize {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet (mut i, mut j) = (left, right);\nwhile i < j {\nwhile i < j && nums[j] >= nums[left] {\nj -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j && nums[i] <= nums[left] {\ni += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nnums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nnums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\ni                    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.c
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(int nums[], int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u5feb\u901f\u6392\u5e8f\u7c7b */\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u54e8\u5175\u5212\u5206\nint partition(int nums[], int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\n// \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nj--;\n}\nwhile (i < j && nums[i] <= nums[left]) {\n// \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\ni++;\n}\n// \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\nswap(nums, i, j);\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nswap(nums, i, left);\n// \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\nreturn i;\n}\n
        quick_sort.zig
        // \u5143\u7d20\u4ea4\u6362\nfn swap(nums: []i32, i: usize, j: usize) void {\nvar tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n// \u54e8\u5175\u5212\u5206\nfn partition(nums: []i32, left: usize, right: usize) usize {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left;\nvar j = right;\nwhile (i < j) {\nwhile (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j and nums[i] <= nums[left]) i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j);   // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;               // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1151","title":"11.5.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u5feb\u901f\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-9 \u6240\u793a\u3002

        1. \u9996\u5148\uff0c\u5bf9\u539f\u6570\u7ec4\u6267\u884c\u4e00\u6b21\u201c\u54e8\u5175\u5212\u5206\u201d\uff0c\u5f97\u5230\u672a\u6392\u5e8f\u7684\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u3002
        2. \u7136\u540e\uff0c\u5bf9\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u5206\u522b\u9012\u5f52\u6267\u884c\u201c\u54e8\u5175\u5212\u5206\u201d\u3002
        3. \u6301\u7eed\u9012\u5f52\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\uff0c\u4ece\u800c\u5b8c\u6210\u6574\u4e2a\u6570\u7ec4\u7684\u6392\u5e8f\u3002

        \u56fe 11-9 \u00a0 \u5feb\u901f\u6392\u5e8f\u6d41\u7a0b

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def quick_sort(self, nums: list[int], left: int, right: int):\n\"\"\"\u5feb\u901f\u6392\u5e8f\"\"\"\n# \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right:\nreturn\n# \u54e8\u5175\u5212\u5206\npivot = self.partition(nums, left, right)\n# \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nself.quick_sort(nums, left, pivot - 1)\nself.quick_sort(nums, pivot + 1, right)\n
        quick_sort.cpp
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(vector<int> &nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.java
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.cs
        /* \u5feb\u901f\u6392\u5e8f */\nvoid QuickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = Partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nQuickSort(nums, left, pivot - 1);\nQuickSort(nums, pivot + 1, right);\n}\n
        quick_sort.go
        /* \u5feb\u901f\u6392\u5e8f */\nfunc (q *quickSort) quickSort(nums []int, left, right int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn\n}\n// \u54e8\u5175\u5212\u5206\npivot := q.partition(nums, left, right)\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nq.quickSort(nums, left, pivot-1)\nq.quickSort(nums, pivot+1, right)\n}\n
        quick_sort.swift
        /* \u5feb\u901f\u6392\u5e8f */\nfunc quickSort(nums: inout [Int], left: Int, right: Int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn\n}\n// \u54e8\u5175\u5212\u5206\nlet pivot = partition(nums: &nums, left: left, right: right)\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums: &nums, left: left, right: pivot - 1)\nquickSort(nums: &nums, left: pivot + 1, right: right)\n}\n
        quick_sort.js
        /* \u5feb\u901f\u6392\u5e8f */\nquickSort(nums, left, right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nconst pivot = this.partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nthis.quickSort(nums, left, pivot - 1);\nthis.quickSort(nums, pivot + 1, right);\n}\n
        quick_sort.ts
        /* \u5feb\u901f\u6392\u5e8f */\nquickSort(nums: number[], left: number, right: number): void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nconst pivot = this.partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nthis.quickSort(nums, left, pivot - 1);\nthis.quickSort(nums, pivot + 1, right);\n}\n
        quick_sort.dart
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(List<int> nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nint pivot = _partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.rs
        /* \u5feb\u901f\u6392\u5e8f */\npub fn quick_sort(left: i32, right: i32, nums: &mut [i32]) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nlet pivot = Self::partition(nums, left as usize, right as usize) as i32;\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nSelf::quick_sort(left, pivot - 1, nums);\nSelf::quick_sort(pivot + 1, right, nums);\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b */\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u54e8\u5175\u5212\u5206\nint partition(int nums[], int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\n// \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nj--;\n}\nwhile (i < j && nums[i] <= nums[left]) {\n// \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\ni++;\n}\n// \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\nswap(nums, i, j);\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nswap(nums, i, left);\n// \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\nreturn i;\n}\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u5feb\u901f\u6392\u5e8f\nvoid quickSort(int nums[], int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.zig
        // \u5feb\u901f\u6392\u5e8f\nfn quickSort(nums: []i32, left: usize, right: usize) void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nvar pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1152","title":"11.5.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u5e73\u5747\u60c5\u51b5\u4e0b\uff0c\u54e8\u5175\u5212\u5206\u7684\u9012\u5f52\u5c42\u6570\u4e3a \\(\\log n\\) \uff0c\u6bcf\u5c42\u4e2d\u7684\u603b\u5faa\u73af\u6570\u4e3a \\(n\\) \uff0c\u603b\u4f53\u4f7f\u7528 \\(O(n \\log n)\\) \u65f6\u95f4\u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u90fd\u5c06\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\u5212\u5206\u4e3a\u957f\u5ea6\u4e3a \\(0\\) \u548c \\(n - 1\\) \u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u6b64\u65f6\u9012\u5f52\u5c42\u6570\u8fbe\u5230 \\(n\\) \uff0c\u6bcf\u5c42\u4e2d\u7684\u5faa\u73af\u6570\u4e3a \\(n\\) \uff0c\u603b\u4f53\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u5728\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u5012\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u8fbe\u5230\u6700\u5dee\u9012\u5f52\u6df1\u5ea6 \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002\u6392\u5e8f\u64cd\u4f5c\u662f\u5728\u539f\u6570\u7ec4\u4e0a\u8fdb\u884c\u7684\uff0c\u672a\u501f\u52a9\u989d\u5916\u6570\u7ec4\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u54e8\u5175\u5212\u5206\u7684\u6700\u540e\u4e00\u6b65\uff0c\u57fa\u51c6\u6570\u53ef\u80fd\u4f1a\u88ab\u4ea4\u6362\u81f3\u76f8\u7b49\u5143\u7d20\u7684\u53f3\u4fa7\u3002
        "},{"location":"chapter_sorting/quick_sort/#1153","title":"11.5.3 \u00a0 \u5feb\u901f\u6392\u5e8f\u4e3a\u4ec0\u4e48\u5feb","text":"

        \u4ece\u540d\u79f0\u4e0a\u5c31\u80fd\u770b\u51fa\uff0c\u5feb\u901f\u6392\u5e8f\u5728\u6548\u7387\u65b9\u9762\u5e94\u8be5\u5177\u6709\u4e00\u5b9a\u7684\u4f18\u52bf\u3002\u5c3d\u7ba1\u5feb\u901f\u6392\u5e8f\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u201c\u5f52\u5e76\u6392\u5e8f\u201d\u548c\u201c\u5806\u6392\u5e8f\u201d\u76f8\u540c\uff0c\u4f46\u901a\u5e38\u5feb\u901f\u6392\u5e8f\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u51fa\u73b0\u6700\u5dee\u60c5\u51b5\u7684\u6982\u7387\u5f88\u4f4e\uff1a\u867d\u7136\u5feb\u901f\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u6ca1\u6709\u5f52\u5e76\u6392\u5e8f\u7a33\u5b9a\uff0c\u4f46\u5728\u7edd\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5feb\u901f\u6392\u5e8f\u80fd\u5728 \\(O(n \\log n)\\) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u8fd0\u884c\u3002
        • \u7f13\u5b58\u4f7f\u7528\u6548\u7387\u9ad8\uff1a\u5728\u6267\u884c\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u65f6\uff0c\u7cfb\u7edf\u53ef\u5c06\u6574\u4e2a\u5b50\u6570\u7ec4\u52a0\u8f7d\u5230\u7f13\u5b58\uff0c\u56e0\u6b64\u8bbf\u95ee\u5143\u7d20\u7684\u6548\u7387\u8f83\u9ad8\u3002\u800c\u50cf\u201c\u5806\u6392\u5e8f\u201d\u8fd9\u7c7b\u7b97\u6cd5\u9700\u8981\u8df3\u8dc3\u5f0f\u8bbf\u95ee\u5143\u7d20\uff0c\u4ece\u800c\u7f3a\u4e4f\u8fd9\u4e00\u7279\u6027\u3002
        • \u590d\u6742\u5ea6\u7684\u5e38\u6570\u7cfb\u6570\u5c0f\uff1a\u5728\u4e0a\u8ff0\u4e09\u79cd\u7b97\u6cd5\u4e2d\uff0c\u5feb\u901f\u6392\u5e8f\u7684\u6bd4\u8f83\u3001\u8d4b\u503c\u3001\u4ea4\u6362\u7b49\u64cd\u4f5c\u7684\u603b\u6570\u91cf\u6700\u5c11\u3002\u8fd9\u4e0e\u201c\u63d2\u5165\u6392\u5e8f\u201d\u6bd4\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u66f4\u5feb\u7684\u539f\u56e0\u7c7b\u4f3c\u3002
        "},{"location":"chapter_sorting/quick_sort/#1154","title":"11.5.4 \u00a0 \u57fa\u51c6\u6570\u4f18\u5316","text":"

        \u5feb\u901f\u6392\u5e8f\u5728\u67d0\u4e9b\u8f93\u5165\u4e0b\u7684\u65f6\u95f4\u6548\u7387\u53ef\u80fd\u964d\u4f4e\u3002\u4e3e\u4e00\u4e2a\u6781\u7aef\u4f8b\u5b50\uff0c\u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u662f\u5b8c\u5168\u5012\u5e8f\u7684\uff0c\u7531\u4e8e\u6211\u4eec\u9009\u62e9\u6700\u5de6\u7aef\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\uff0c\u90a3\u4e48\u5728\u54e8\u5175\u5212\u5206\u5b8c\u6210\u540e\uff0c\u57fa\u51c6\u6570\u88ab\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u53f3\u7aef\uff0c\u5bfc\u81f4\u5de6\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(n - 1\\)\u3001\u53f3\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(0\\) \u3002\u5982\u6b64\u9012\u5f52\u4e0b\u53bb\uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u540e\u7684\u53f3\u5b50\u6570\u7ec4\u957f\u5ea6\u90fd\u4e3a \\(0\\) \uff0c\u5206\u6cbb\u7b56\u7565\u5931\u6548\uff0c\u5feb\u901f\u6392\u5e8f\u9000\u5316\u4e3a\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u3002

        \u4e3a\u4e86\u5c3d\u91cf\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u53d1\u751f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f18\u5316\u54e8\u5175\u5212\u5206\u4e2d\u7684\u57fa\u51c6\u6570\u7684\u9009\u53d6\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u968f\u673a\u9009\u53d6\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\u3002\u7136\u800c\uff0c\u5982\u679c\u8fd0\u6c14\u4e0d\u4f73\uff0c\u6bcf\u6b21\u90fd\u9009\u5230\u4e0d\u7406\u60f3\u7684\u57fa\u51c6\u6570\uff0c\u6548\u7387\u4ecd\u7136\u4e0d\u5c3d\u5982\u4eba\u610f\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u751f\u6210\u7684\u662f\u201c\u4f2a\u968f\u673a\u6570\u201d\u3002\u5982\u679c\u6211\u4eec\u9488\u5bf9\u4f2a\u968f\u673a\u6570\u5e8f\u5217\u6784\u5efa\u4e00\u4e2a\u7279\u5b9a\u7684\u6d4b\u8bd5\u6837\u4f8b\uff0c\u90a3\u4e48\u5feb\u901f\u6392\u5e8f\u7684\u6548\u7387\u4ecd\u7136\u53ef\u80fd\u52a3\u5316\u3002

        \u4e3a\u4e86\u8fdb\u4e00\u6b65\u6539\u8fdb\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6570\u7ec4\u4e2d\u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\uff08\u901a\u5e38\u4e3a\u6570\u7ec4\u7684\u9996\u3001\u5c3e\u3001\u4e2d\u70b9\u5143\u7d20\uff09\uff0c\u5e76\u5c06\u8fd9\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\u4f5c\u4e3a\u57fa\u51c6\u6570\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u57fa\u51c6\u6570\u201c\u65e2\u4e0d\u592a\u5c0f\u4e5f\u4e0d\u592a\u5927\u201d\u7684\u6982\u7387\u5c06\u5927\u5e45\u63d0\u5347\u3002\u5f53\u7136\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u9009\u53d6\u66f4\u591a\u5019\u9009\u5143\u7d20\uff0c\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u7b97\u6cd5\u7684\u7a33\u5065\u6027\u3002\u91c7\u7528\u8fd9\u79cd\u65b9\u6cd5\u540e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n^2)\\) \u7684\u6982\u7387\u5927\u5927\u964d\u4f4e\u3002

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def median_three(self, nums: list[int], left: int, mid: int, right: int) -> int:\n\"\"\"\u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\"\"\"\n# \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n# \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) ^ (nums[left] < nums[right]):\nreturn left\nelif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]):\nreturn mid\nreturn right\ndef partition(self, nums: list[int], left: int, right: int) -> int:\n\"\"\"\u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09\"\"\"\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nmed = self.median_three(nums, left, (left + right) // 2, right)\n# \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums[left], nums[med] = nums[med], nums[left]\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j = left, right\nwhile i < j:\nwhile i < j and nums[j] >= nums[left]:\nj -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile i < j and nums[i] <= nums[left]:\ni += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n# \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n# \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
        quick_sort.cpp
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint medianThree(vector<int> &nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint partition(vector<int> &nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.java
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint medianThree(int[] nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint partition(int[] nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.cs
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint MedianThree(int[] nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint Partition(int[] nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = MedianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nSwap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nSwap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nSwap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.go
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc (q *quickSortMedian) medianThree(nums []int, left, mid, right int) int {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\uff08!= \u5728\u8fd9\u91cc\u8d77\u5230\u5f02\u6216\u7684\u4f5c\u7528\uff09\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\nreturn left\n} else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\nreturn mid\n}\nreturn right\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09*/\nfunc (q *quickSortMedian) partition(nums []int, left, right int) int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nmed := q.medianThree(nums, left, (left+right)/2, right)\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums[left], nums[med] = nums[med], nums[left]\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j := left, right\nfor i < j {\nfor i < j && nums[j] >= nums[left] {\nj-- //\u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nfor i < j && nums[i] <= nums[left] {\ni++ //\u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n//\u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n}\n//\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i //\u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.swift
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc medianThree(nums: [Int], left: Int, mid: Int, right: Int) -> Int {\nif (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\nreturn left\n} else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\nreturn mid\n} else {\nreturn right\n}\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nfunc partitionMedian(nums: inout [Int], left: Int, right: Int) -> Int {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = medianThree(nums: nums, left: left, mid: (left + right) / 2, right: right)\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums: &nums, i: left, j: med)\nreturn partition(nums: &nums, left: left, right: right)\n}\n
        quick_sort.js
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(nums, left, mid, right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse return right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\npartition(nums, left, right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = this.medianThree(\nnums,\nleft,\nMath.floor((left + right) / 2),\nright\n);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nthis.swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.ts
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(\nnums: number[],\nleft: number,\nmid: number,\nright: number\n): number {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) {\nreturn left;\n} else if (\nNumber(nums[mid] < nums[left]) ^ Number(nums[mid] < nums[right])\n) {\nreturn mid;\n} else {\nreturn right;\n}\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\npartition(nums: number[], left: number, right: number): number {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = this.medianThree(\nnums,\nleft,\nMath.floor((left + right) / 2),\nright\n);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nthis.swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.dart
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint _medianThree(List<int> nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint _partition(List<int> nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = _medianThree(nums, left, (left + right) ~/ 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n_swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n_swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\n_swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.rs
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) {\nreturn left;\n} else if (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]) {\nreturn mid;\n} right\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nfn partition(nums: &mut [i32], left: usize, right: usize) -> usize {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = Self::median_three(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums.swap(left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet (mut i, mut j) = (left, right);\nwhile i < j {\nwhile i < j && nums[j] >= nums[left] {\nj -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j && nums[i] <= nums[left] {\ni += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nnums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nnums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\ni                    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b\uff08\u4e2d\u4f4d\u57fa\u51c6\u6570\u4f18\u5316\uff09 */\n// \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint medianThree(int nums[], int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */ int partitionMedian(int nums[], int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.zig
        // \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nfn medianThree(nums: []i32, left: usize, mid: usize, right: usize) usize {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) != (nums[left] < nums[right])) {\nreturn left;\n} else if ((nums[mid] < nums[left]) != (nums[mid] < nums[right])) {\nreturn mid;\n} else {\nreturn right;\n}\n}\n// \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09\nfn partition(nums: []i32, left: usize, right: usize) usize {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nvar med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left;\nvar j = right;\nwhile (i < j) {\nwhile (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j and nums[i] <= nums[left]) i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j);   // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;               // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1155","title":"11.5.5 \u00a0 \u5c3e\u9012\u5f52\u4f18\u5316","text":"

        \u5728\u67d0\u4e9b\u8f93\u5165\u4e0b\uff0c\u5feb\u901f\u6392\u5e8f\u53ef\u80fd\u5360\u7528\u7a7a\u95f4\u8f83\u591a\u3002\u4ee5\u5b8c\u5168\u5012\u5e8f\u7684\u8f93\u5165\u6570\u7ec4\u4e3a\u4f8b\uff0c\u8bbe\u9012\u5f52\u4e2d\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(m\\) \uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u90fd\u5c06\u4ea7\u751f\u957f\u5ea6\u4e3a \\(0\\) \u7684\u5de6\u5b50\u6570\u7ec4\u548c\u957f\u5ea6\u4e3a \\(m - 1\\) \u7684\u53f3\u5b50\u6570\u7ec4\uff0c\u8fd9\u610f\u5473\u7740\u6bcf\u4e00\u5c42\u9012\u5f52\u8c03\u7528\u51cf\u5c11\u7684\u95ee\u9898\u89c4\u6a21\u975e\u5e38\u5c0f\uff08\u53ea\u51cf\u5c11\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u9012\u5f52\u6811\u7684\u9ad8\u5ea6\u4f1a\u8fbe\u5230 \\(n - 1\\) \uff0c\u6b64\u65f6\u9700\u8981\u5360\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\u3002

        \u4e3a\u4e86\u9632\u6b62\u6808\u5e27\u7a7a\u95f4\u7684\u7d2f\u79ef\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u8f6e\u54e8\u5175\u6392\u5e8f\u5b8c\u6210\u540e\uff0c\u6bd4\u8f83\u4e24\u4e2a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u4ec5\u5bf9\u8f83\u77ed\u7684\u5b50\u6570\u7ec4\u8fdb\u884c\u9012\u5f52\u3002\u7531\u4e8e\u8f83\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 \\(n / 2\\) \uff0c\u56e0\u6b64\u8fd9\u79cd\u65b9\u6cd5\u80fd\u786e\u4fdd\u9012\u5f52\u6df1\u5ea6\u4e0d\u8d85\u8fc7 \\(\\log n\\) \uff0c\u4ece\u800c\u5c06\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def quick_sort(self, nums: list[int], left: int, right: int):\n\"\"\"\u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\"\"\"\n# \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right:\n# \u54e8\u5175\u5212\u5206\u64cd\u4f5c\npivot = self.partition(nums, left, right)\n# \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif pivot - left < right - pivot:\nself.quick_sort(nums, left, pivot - 1)  # \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\nelse:\nself.quick_sort(nums, pivot + 1, right)  # \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n
        quick_sort.cpp
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(vector<int> &nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.java
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.cs
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid QuickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = Partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nQuickSort(nums, left, pivot - 1);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nQuickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.go
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09*/\nfunc (q *quickSortTailCall) quickSort(nums []int, left, right int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nfor left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\npivot := q.partition(nums, left, right)\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif pivot-left < right-pivot {\nq.quickSort(nums, left, pivot-1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nq.quickSort(nums, pivot+1, right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.swift
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nfunc quickSortTailCall(nums: inout [Int], left: Int, right: Int) {\nvar left = left\nvar right = right\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = partition(nums: &nums, left: left, right: right)\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left) < (right - pivot) {\nquickSortTailCall(nums: &nums, left: left, right: pivot - 1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSortTailCall(nums: &nums, left: pivot + 1, right: right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.js
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nquickSort(nums, left, right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = this.partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nthis.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nthis.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.ts
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nquickSort(nums: number[], left: number, right: number): void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = this.partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nthis.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nthis.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.dart
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(List<int> nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = _partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.rs
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\npub fn quick_sort(mut left: i32, mut right: i32, nums: &mut [i32]) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = Self::partition(nums, left as usize, right as usize) as i32;\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif  pivot - left < right - pivot {\nSelf::quick_sort(left, pivot - 1, nums);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nSelf::quick_sort(pivot + 1, right, nums); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\n// \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\nvoid quickSortTailCall(int nums[], int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSortTailCall(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSortTailCall(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.zig
        // \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\nfn quickSort(nums: []i32, left_: usize, right_: usize) void {\nvar left = left_;\nvar right = right_;\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nvar pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1);   // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                   // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right);  // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        "},{"location":"chapter_sorting/radix_sort/","title":"11.10 \u00a0 \u57fa\u6570\u6392\u5e8f","text":"

        \u4e0a\u4e00\u8282\u4ecb\u7ecd\u4e86\u8ba1\u6570\u6392\u5e8f\uff0c\u5b83\u9002\u7528\u4e8e\u6570\u636e\u91cf \\(n\\) \u8f83\u5927\u4f46\u6570\u636e\u8303\u56f4 \\(m\\) \u8f83\u5c0f\u7684\u60c5\u51b5\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u5bf9 \\(n = 10^6\\) \u4e2a\u5b66\u53f7\u8fdb\u884c\u6392\u5e8f\uff0c\u800c\u5b66\u53f7\u662f\u4e00\u4e2a \\(8\\) \u4f4d\u6570\u5b57\uff0c\u8fd9\u610f\u5473\u7740\u6570\u636e\u8303\u56f4 \\(m = 10^8\\) \u975e\u5e38\u5927\uff0c\u4f7f\u7528\u8ba1\u6570\u6392\u5e8f\u9700\u8981\u5206\u914d\u5927\u91cf\u5185\u5b58\u7a7a\u95f4\uff0c\u800c\u57fa\u6570\u6392\u5e8f\u53ef\u4ee5\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002

        \u300c\u57fa\u6570\u6392\u5e8f radix sort\u300d\u7684\u6838\u5fc3\u601d\u60f3\u4e0e\u8ba1\u6570\u6392\u5e8f\u4e00\u81f4\uff0c\u4e5f\u901a\u8fc7\u7edf\u8ba1\u4e2a\u6570\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u57fa\u6570\u6392\u5e8f\u5229\u7528\u6570\u5b57\u5404\u4f4d\u4e4b\u95f4\u7684\u9012\u8fdb\u5173\u7cfb\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e00\u4f4d\u8fdb\u884c\u6392\u5e8f\uff0c\u4ece\u800c\u5f97\u5230\u6700\u7ec8\u7684\u6392\u5e8f\u7ed3\u679c\u3002

        "},{"location":"chapter_sorting/radix_sort/#11101","title":"11.10.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u4ee5\u5b66\u53f7\u6570\u636e\u4e3a\u4f8b\uff0c\u5047\u8bbe\u6570\u5b57\u7684\u6700\u4f4e\u4f4d\u662f\u7b2c \\(1\\) \u4f4d\uff0c\u6700\u9ad8\u4f4d\u662f\u7b2c \\(8\\) \u4f4d\uff0c\u57fa\u6570\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-18 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316\u4f4d\u6570 \\(k = 1\\) \u3002
        2. \u5bf9\u5b66\u53f7\u7684\u7b2c \\(k\\) \u4f4d\u6267\u884c\u201c\u8ba1\u6570\u6392\u5e8f\u201d\u3002\u5b8c\u6210\u540e\uff0c\u6570\u636e\u4f1a\u6839\u636e\u7b2c \\(k\\) \u4f4d\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002
        3. \u5c06 \\(k\\) \u589e\u52a0 \\(1\\) \uff0c\u7136\u540e\u8fd4\u56de\u6b65\u9aa4 2. \u7ee7\u7eed\u8fed\u4ee3\uff0c\u76f4\u5230\u6240\u6709\u4f4d\u90fd\u6392\u5e8f\u5b8c\u6210\u540e\u7ed3\u675f\u3002

        \u56fe 11-18 \u00a0 \u57fa\u6570\u6392\u5e8f\u7b97\u6cd5\u6d41\u7a0b

        \u4e0b\u9762\u5256\u6790\u4ee3\u7801\u5b9e\u73b0\u3002\u5bf9\u4e8e\u4e00\u4e2a \\(d\\) \u8fdb\u5236\u7684\u6570\u5b57 \\(x\\) \uff0c\u8981\u83b7\u53d6\u5176\u7b2c \\(k\\) \u4f4d \\(x_k\\) \uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8ba1\u7b97\u516c\u5f0f\uff1a

        \\[ x_k = \\lfloor\\frac{x}{d^{k-1}}\\rfloor \\bmod d \\]

        \u5176\u4e2d \\(\\lfloor a \\rfloor\\) \u8868\u793a\u5bf9\u6d6e\u70b9\u6570 \\(a\\) \u5411\u4e0b\u53d6\u6574\uff0c\u800c \\(\\bmod \\: d\\) \u8868\u793a\u5bf9 \\(d\\) \u53d6\u4f59\u3002\u5bf9\u4e8e\u5b66\u53f7\u6570\u636e\uff0c\\(d = 10\\) \u4e14 \\(k \\in [1, 8]\\) \u3002

        \u6b64\u5916\uff0c\u6211\u4eec\u9700\u8981\u5c0f\u5e45\u6539\u52a8\u8ba1\u6570\u6392\u5e8f\u4ee3\u7801\uff0c\u4f7f\u4e4b\u53ef\u4ee5\u6839\u636e\u6570\u5b57\u7684\u7b2c \\(k\\) \u4f4d\u8fdb\u884c\u6392\u5e8f\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig radix_sort.py
        def digit(num: int, exp: int) -> int:\n\"\"\"\u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1)\"\"\"\n# \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num // exp) % 10\ndef counting_sort_digit(nums: list[int], exp: int):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09\"\"\"\n# \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\ncounter = [0] * 10\nn = len(nums)\n# \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in range(n):\nd = digit(nums[i], exp)  # \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1  # \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n# \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in range(1, 10):\ncounter[i] += counter[i - 1]\n# \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nres = [0] * n\nfor i in range(n - 1, -1, -1):\nd = digit(nums[i], exp)\nj = counter[d] - 1  # \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]  # \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1  # \u5c06 d \u7684\u6570\u91cf\u51cf 1\n# \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in range(n):\nnums[i] = res[i]\ndef radix_sort(nums: list[int]):\n\"\"\"\u57fa\u6570\u6392\u5e8f\"\"\"\n# \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nm = max(nums)\n# \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nexp = 1\nwhile exp <= m:\n# \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n# k = 1 -> exp = 1\n# k = 2 -> exp = 10\n# \u5373 exp = 10^(k-1)\ncounting_sort_digit(nums, exp)\nexp *= 10\n
        radix_sort.cpp
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(vector<int> &nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvector<int> counter(10, 0);\nint n = nums.size();\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvector<int> res(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++)\nnums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(vector<int> &nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = *max_element(nums.begin(), nums.end());\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.java
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(int[] nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint[] counter = new int[10];\nint n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++)\nnums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(int[] nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = Integer.MIN_VALUE;\nfor (int num : nums)\nif (num > m)\nm = num;\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.cs
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint Digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid CountingSortDigit(int[] nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint[] counter = new int[10];\nint n = nums.Length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = Digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint d = Digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid RadixSort(int[] nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = int.MinValue;\nforeach (int num in nums) {\nif (num > m) m = num;\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\nCountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.go
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunc digit(num, exp int) int {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunc countingSortDigit(nums []int, exp int) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\ncounter := make([]int, 10)\nn := len(nums)\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i := 0; i < n; i++ {\nd := digit(nums[i], exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++             // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i := 1; i < 10; i++ {\ncounter[i] += counter[i-1]\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nres := make([]int, n)\nfor i := n - 1; i >= 0; i-- {\nd := digit(nums[i], exp)\nj := counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]    // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i := 0; i < n; i++ {\nnums[i] = res[i]\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunc radixSort(nums []int) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nmax := math.MinInt\nfor _, num := range nums {\nif num > max {\nmax = num\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor exp := 1; max >= exp; exp *= 10 {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp)\n}\n}\n
        radix_sort.swift
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunc digit(num: Int, exp: Int) -> Int {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\n(num / exp) % 10\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunc countingSortDigit(nums: inout [Int], exp: Int) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvar counter = Array(repeating: 0, count: 10)\nlet n = nums.count\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in nums.indices {\nlet d = digit(num: nums[i], exp: exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1 // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in 1 ..< 10 {\ncounter[i] += counter[i - 1]\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvar res = Array(repeating: 0, count: n)\nfor i in stride(from: n - 1, through: 0, by: -1) {\nlet d = digit(num: nums[i], exp: exp)\nlet j = counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i] // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1 // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in nums.indices {\nnums[i] = res[i]\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunc radixSort(nums: inout [Int]) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nvar m = Int.min\nfor num in nums {\nif num > m {\nm = num\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor exp in sequence(first: 1, next: { m >= ($0 * 10) ? $0 * 10 : nil }) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums: &nums, exp: exp)\n}\n}\n
        radix_sort.js
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunction digit(num, exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn Math.floor(num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunction countingSortDigit(nums, exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nconst counter = new Array(10).fill(0);\nconst n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (let i = 0; i < n; i++) {\nconst d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (let i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nconst res = new Array(n).fill(0);\nfor (let i = n - 1; i >= 0; i--) {\nconst d = digit(nums[i], exp);\nconst j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunction radixSort(nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = Number.MIN_VALUE;\nfor (const num of nums) {\nif (num > m) {\nm = num;\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (let exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.ts
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunction digit(num: number, exp: number): number {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn Math.floor(num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunction countingSortDigit(nums: number[], exp: number): void {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nconst counter = new Array(10).fill(0);\nconst n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (let i = 0; i < n; i++) {\nconst d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (let i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nconst res = new Array(n).fill(0);\nfor (let i = n - 1; i >= 0; i--) {\nconst d = digit(nums[i], exp);\nconst j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunction radixSort(nums: number[]): void {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = Number.MIN_VALUE;\nfor (const num of nums) {\nif (num > m) {\nm = num;\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (let exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.dart
        /* \u83b7\u53d6\u5143\u7d20 _num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int _num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (_num ~/ exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(List<int> nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nList<int> counter = List<int>.filled(10, 0);\nint n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nList<int> res = List<int>.filled(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) nums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(List<int> nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\n// dart \u4e2d int \u7684\u957f\u5ea6\u662f 64 \u4f4d\u7684\nint m = -1 << 63;\nfor (int _num in nums) if (_num > m) m = _num;\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.rs
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfn digit(num: i32, exp: i32) -> usize {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn ((num / exp) % 10) as usize;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfn counting_sort_digit(nums: &mut [i32], exp: i32) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nlet mut counter = [0; 10];\nlet n = nums.len();\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in 0..n {\nlet d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in 1..10 {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nlet mut res = vec![0; n];\nfor i in (0..n).rev() {\nlet d = digit(nums[i], exp);\nlet j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in 0..n {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfn radix_sort(nums: &mut [i32]) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = *nums.into_iter().max().unwrap();\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nlet mut exp = 1;\nwhile exp <= m {\ncounting_sort_digit(nums, exp);\nexp *= 10;\n}\n}\n
        radix_sort.c
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(int nums[], int size, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint *counter = (int *)malloc((sizeof(int) * 10));\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < size; i++) {\n// \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\nint d = digit(nums[i], exp);\n// \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\ncounter[d]++;\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint *res = (int *)malloc(sizeof(int) * size);\nfor (int i = size - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < size; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(int nums[], int size) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint max = INT32_MIN;\nfor (size_t i = 0; i < size - 1; i++) {\nif (nums[i] > max) {\nmax = nums[i];\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; max >= exp; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, size, exp);\n}\n
        radix_sort.zig
        // \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1)\nfn digit(num: i32, exp: i32) i32 {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn @mod(@divFloor(num, exp), 10);\n}\n// \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09\nfn countingSortDigit(nums: []i32, exp: i32) !void {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvar mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n// defer mem_arena.deinit();\nconst mem_allocator = mem_arena.allocator();\nvar counter = try mem_allocator.alloc(usize, 10);\n@memset(counter, 0);\nvar n = nums.len;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (nums) |num| {\nvar d: u32 = @bitCast(digit(num, exp)); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nvar i: usize = 1;\nwhile (i < 10) : (i += 1) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvar res = try mem_allocator.alloc(i32, n);\ni = n - 1;\nwhile (i >= 0) : (i -= 1) {\nvar d: u32 = @bitCast(digit(nums[i], exp));\nvar j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1;        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\nif (i == 0) break;\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\ni = 0;\nwhile (i < n) : (i += 1) {\nnums[i] = res[i];\n}\n}\n// \u57fa\u6570\u6392\u5e8f\nfn radixSort(nums: []i32) !void {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nvar m: i32 = std.math.minInt(i32);\nfor (nums) |num| {\nif (num > m) m = num;\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nvar exp: i32 = 1;\nwhile (exp <= m) : (exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ntry countingSortDigit(nums, exp);    }\n} 

        \u4e3a\u4ec0\u4e48\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb\u6392\u5e8f\uff1f

        \u5728\u8fde\u7eed\u7684\u6392\u5e8f\u8f6e\u6b21\u4e2d\uff0c\u540e\u4e00\u8f6e\u6392\u5e8f\u4f1a\u8986\u76d6\u524d\u4e00\u8f6e\u6392\u5e8f\u7684\u7ed3\u679c\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u7b2c\u4e00\u8f6e\u6392\u5e8f\u7ed3\u679c \\(a < b\\) \uff0c\u800c\u7b2c\u4e8c\u8f6e\u6392\u5e8f\u7ed3\u679c \\(a > b\\) \uff0c\u90a3\u4e48\u7b2c\u4e8c\u8f6e\u7684\u7ed3\u679c\u5c06\u53d6\u4ee3\u7b2c\u4e00\u8f6e\u7684\u7ed3\u679c\u3002\u7531\u4e8e\u6570\u5b57\u7684\u9ad8\u4f4d\u4f18\u5148\u7ea7\u9ad8\u4e8e\u4f4e\u4f4d\uff0c\u56e0\u6b64\u5e94\u8be5\u5148\u6392\u5e8f\u4f4e\u4f4d\u518d\u6392\u5e8f\u9ad8\u4f4d\u3002

        "},{"location":"chapter_sorting/radix_sort/#11102","title":"11.10.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"

        \u76f8\u8f83\u4e8e\u8ba1\u6570\u6392\u5e8f\uff0c\u57fa\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u503c\u8303\u56f4\u8f83\u5927\u7684\u60c5\u51b5\uff0c\u4f46\u524d\u63d0\u662f\u6570\u636e\u5fc5\u987b\u53ef\u4ee5\u8868\u793a\u4e3a\u56fa\u5b9a\u4f4d\u6570\u7684\u683c\u5f0f\uff0c\u4e14\u4f4d\u6570\u4e0d\u80fd\u8fc7\u5927\u3002\u4f8b\u5982\uff0c\u6d6e\u70b9\u6570\u4e0d\u9002\u5408\u4f7f\u7528\u57fa\u6570\u6392\u5e8f\uff0c\u56e0\u4e3a\u5176\u4f4d\u6570 \\(k\\) \u8fc7\u5927\uff0c\u53ef\u80fd\u5bfc\u81f4\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(nk) \\gg O(n^2)\\) \u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(nk)\\)\uff1a\u8bbe\u6570\u636e\u91cf\u4e3a \\(n\\)\u3001\u6570\u636e\u4e3a \\(d\\) \u8fdb\u5236\u3001\u6700\u5927\u4f4d\u6570\u4e3a \\(k\\) \uff0c\u5219\u5bf9\u67d0\u4e00\u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\u4f7f\u7528 \\(O(n + d)\\) \u65f6\u95f4\uff0c\u6392\u5e8f\u6240\u6709 \\(k\\) \u4f4d\u4f7f\u7528 \\(O((n + d)k)\\) \u65f6\u95f4\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\\(d\\) \u548c \\(k\\) \u90fd\u76f8\u5bf9\u8f83\u5c0f\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + d)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u4e0e\u8ba1\u6570\u6392\u5e8f\u76f8\u540c\uff0c\u57fa\u6570\u6392\u5e8f\u9700\u8981\u501f\u52a9\u957f\u5ea6\u4e3a \\(n\\) \u548c \\(d\\) \u7684\u6570\u7ec4 res \u548c counter \u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u4e0e\u8ba1\u6570\u6392\u5e8f\u76f8\u540c\u3002
        "},{"location":"chapter_sorting/selection_sort/","title":"11.2 \u00a0 \u9009\u62e9\u6392\u5e8f","text":"

        \u300c\u9009\u62e9\u6392\u5e8f selection sort\u300d\u7684\u5de5\u4f5c\u539f\u7406\u975e\u5e38\u7b80\u5355\uff1a\u5f00\u542f\u4e00\u4e2a\u5faa\u73af\uff0c\u6bcf\u8f6e\u4ece\u672a\u6392\u5e8f\u533a\u95f4\u9009\u62e9\u6700\u5c0f\u7684\u5143\u7d20\uff0c\u5c06\u5176\u653e\u5230\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u672b\u5c3e\u3002

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u9009\u62e9\u6392\u5e8f\u7684\u7b97\u6cd5\u6d41\u7a0b\u5982\u56fe 11-2 \u6240\u793a\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u5143\u7d20\u672a\u6392\u5e8f\uff0c\u5373\u672a\u6392\u5e8f\uff08\u7d22\u5f15\uff09\u533a\u95f4\u4e3a \\([0, n-1]\\) \u3002
        2. \u9009\u53d6\u533a\u95f4 \\([0, n-1]\\) \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u7d22\u5f15 \\(0\\) \u5904\u7684\u5143\u7d20\u4ea4\u6362\u3002\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u524d 1 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        3. \u9009\u53d6\u533a\u95f4 \\([1, n-1]\\) \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u7d22\u5f15 \\(1\\) \u5904\u7684\u5143\u7d20\u4ea4\u6362\u3002\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u524d 2 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        4. \u4ee5\u6b64\u7c7b\u63a8\u3002\u7ecf\u8fc7 \\(n - 1\\) \u8f6e\u9009\u62e9\u4e0e\u4ea4\u6362\u540e\uff0c\u6570\u7ec4\u524d \\(n - 1\\) \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        5. \u4ec5\u5269\u7684\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u662f\u6700\u5927\u5143\u7d20\uff0c\u65e0\u987b\u6392\u5e8f\uff0c\u56e0\u6b64\u6570\u7ec4\u6392\u5e8f\u5b8c\u6210\u3002
        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 11-2 \u00a0 \u9009\u62e9\u6392\u5e8f\u6b65\u9aa4

        \u5728\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u7528 \\(k\\) \u6765\u8bb0\u5f55\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig selection_sort.py
        def selection_sort(nums: list[int]):\n\"\"\"\u9009\u62e9\u6392\u5e8f\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in range(n - 1):\n# \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nk = i\nfor j in range(i + 1, n):\nif nums[j] < nums[k]:\nk = j  # \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n# \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums[i], nums[k] = nums[k], nums[i]\n
        selection_sort.cpp
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(vector<int> &nums) {\nint n = nums.size();\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nswap(nums[i], nums[k]);\n}\n}\n
        selection_sort.java
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int[] nums) {\nint n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.cs
        /* \u9009\u62e9\u6392\u5e8f */\nvoid SelectionSort(int[] nums) {\nint n = nums.Length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n(nums[k], nums[i]) = (nums[i], nums[k]);\n}\n}\n
        selection_sort.go
        /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums []int) {\nn := len(nums)\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i := 0; i < n-1; i++ {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nk := i\nfor j := i + 1; j < n; j++ {\nif nums[j] < nums[k] {\n// \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\nk = j\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums[i], nums[k] = nums[k], nums[i]\n}\n}\n
        selection_sort.swift
        /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in nums.indices.dropLast() {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nvar k = i\nfor j in nums.indices.dropFirst(i + 1) {\nif nums[j] < nums[k] {\nk = j // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums.swapAt(i, k)\n}\n}\n
        selection_sort.js
        /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums) {\nlet n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (let i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet k = i;\nfor (let j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n[nums[i], nums[k]] = [nums[k], nums[i]];\n}\n}\n
        selection_sort.ts
        /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums: number[]): void {\nlet n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (let i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet k = i;\nfor (let j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n[nums[i], nums[k]] = [nums[k], nums[i]];\n}\n}\n
        selection_sort.dart
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(List<int> nums) {\nint n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) k = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.rs
        /* \u9009\u62e9\u6392\u5e8f */\nfn selection_sort(nums: &mut [i32]) {\nlet n = nums.len();\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in 0..n-1 {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet mut k = i;\nfor j in i+1..n {\nif nums[j] < nums[k] {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums.swap(i, k);\n}\n}\n
        selection_sort.c
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int nums[], int n) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.zig
        [class]{}-[func]{selectionSort}\n
        "},{"location":"chapter_sorting/selection_sort/#1121","title":"11.2.1 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5916\u5faa\u73af\u5171 \\(n - 1\\) \u8f6e\uff0c\u7b2c\u4e00\u8f6e\u7684\u672a\u6392\u5e8f\u533a\u95f4\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u6700\u540e\u4e00\u8f6e\u7684\u672a\u6392\u5e8f\u533a\u95f4\u957f\u5ea6\u4e3a \\(2\\) \uff0c\u5373\u5404\u8f6e\u5916\u5faa\u73af\u5206\u522b\u5305\u542b \\(n\\)\u3001\\(n - 1\\)\u3001\\(\\dots\\)\u3001\\(3\\)\u3001\\(2\\) \u8f6e\u5185\u5faa\u73af\uff0c\u6c42\u548c\u4e3a \\(\\frac{(n - 1)(n + 2)}{2}\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5982\u56fe 11-3 \u6240\u793a\uff0c\u5143\u7d20 nums[i] \u6709\u53ef\u80fd\u88ab\u4ea4\u6362\u81f3\u4e0e\u5176\u76f8\u7b49\u7684\u5143\u7d20\u7684\u53f3\u8fb9\uff0c\u5bfc\u81f4\u4e24\u8005\u7684\u76f8\u5bf9\u987a\u5e8f\u53d1\u751f\u6539\u53d8\u3002

        \u56fe 11-3 \u00a0 \u9009\u62e9\u6392\u5e8f\u975e\u7a33\u5b9a\u793a\u4f8b

        "},{"location":"chapter_sorting/sorting_algorithm/","title":"11.1 \u00a0 \u6392\u5e8f\u7b97\u6cd5","text":"

        \u300c\u6392\u5e8f\u7b97\u6cd5 sorting algorithm\u300d\u7528\u4e8e\u5bf9\u4e00\u7ec4\u6570\u636e\u6309\u7167\u7279\u5b9a\u987a\u5e8f\u8fdb\u884c\u6392\u5217\u3002\u6392\u5e8f\u7b97\u6cd5\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u56e0\u4e3a\u6709\u5e8f\u6570\u636e\u901a\u5e38\u80fd\u591f\u88ab\u66f4\u9ad8\u6548\u5730\u67e5\u627e\u3001\u5206\u6790\u548c\u5904\u7406\u3002

        \u5982\u56fe 11-1 \u6240\u793a\uff0c\u6392\u5e8f\u7b97\u6cd5\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u662f\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\u7b49\u3002\u6392\u5e8f\u7684\u5224\u65ad\u89c4\u5219\u53ef\u6839\u636e\u9700\u6c42\u8bbe\u5b9a\uff0c\u5982\u6570\u5b57\u5927\u5c0f\u3001\u5b57\u7b26 ASCII \u7801\u987a\u5e8f\u6216\u81ea\u5b9a\u4e49\u89c4\u5219\u3002

        \u56fe 11-1 \u00a0 \u6570\u636e\u7c7b\u578b\u548c\u5224\u65ad\u89c4\u5219\u793a\u4f8b

        "},{"location":"chapter_sorting/sorting_algorithm/#1111","title":"11.1.1 \u00a0 \u8bc4\u4ef7\u7ef4\u5ea6","text":"

        \u8fd0\u884c\u6548\u7387\uff1a\u6211\u4eec\u671f\u671b\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c3d\u91cf\u4f4e\uff0c\u4e14\u603b\u4f53\u64cd\u4f5c\u6570\u91cf\u8f83\u5c11\uff08\u65f6\u95f4\u590d\u6742\u5ea6\u4e2d\u7684\u5e38\u6570\u9879\u53d8\u5c0f\uff09\u3002\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u60c5\u51b5\uff0c\u8fd0\u884c\u6548\u7387\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002

        \u5c31\u5730\u6027\uff1a\u987e\u540d\u601d\u4e49\uff0c\u300c\u539f\u5730\u6392\u5e8f\u300d\u901a\u8fc7\u5728\u539f\u6570\u7ec4\u4e0a\u76f4\u63a5\u64cd\u4f5c\u5b9e\u73b0\u6392\u5e8f\uff0c\u65e0\u987b\u501f\u52a9\u989d\u5916\u7684\u8f85\u52a9\u6570\u7ec4\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u539f\u5730\u6392\u5e8f\u7684\u6570\u636e\u642c\u8fd0\u64cd\u4f5c\u8f83\u5c11\uff0c\u8fd0\u884c\u901f\u5ea6\u4e5f\u66f4\u5feb\u3002

        \u7a33\u5b9a\u6027\uff1a\u300c\u7a33\u5b9a\u6392\u5e8f\u300d\u5728\u5b8c\u6210\u6392\u5e8f\u540e\uff0c\u76f8\u7b49\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u4e0d\u53d1\u751f\u6539\u53d8\u3002

        \u7a33\u5b9a\u6392\u5e8f\u662f\u591a\u7ea7\u6392\u5e8f\u573a\u666f\u7684\u5fc5\u8981\u6761\u4ef6\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5b58\u50a8\u5b66\u751f\u4fe1\u606f\u7684\u8868\u683c\uff0c\u7b2c 1 \u5217\u548c\u7b2c 2 \u5217\u5206\u522b\u662f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u300c\u975e\u7a33\u5b9a\u6392\u5e8f\u300d\u53ef\u80fd\u5bfc\u81f4\u8f93\u5165\u6570\u636e\u7684\u6709\u5e8f\u6027\u4e27\u5931\uff1a

        # \u8f93\u5165\u6570\u636e\u662f\u6309\u7167\u59d3\u540d\u6392\u5e8f\u597d\u7684\n# (name, age)\n('A', 19)\n('B', 18)\n('C', 21)\n('D', 19)\n('E', 23)\n# \u5047\u8bbe\u4f7f\u7528\u975e\u7a33\u5b9a\u6392\u5e8f\u7b97\u6cd5\u6309\u5e74\u9f84\u6392\u5e8f\u5217\u8868\uff0c\n# \u7ed3\u679c\u4e2d ('D', 19) \u548c ('A', 19) \u7684\u76f8\u5bf9\u4f4d\u7f6e\u6539\u53d8\uff0c\n# \u8f93\u5165\u6570\u636e\u6309\u59d3\u540d\u6392\u5e8f\u7684\u6027\u8d28\u4e22\u5931\n('B', 18)\n('D', 19)\n('A', 19)\n('C', 21)\n('E', 23)\n

        \u81ea\u9002\u5e94\u6027\uff1a\u300c\u81ea\u9002\u5e94\u6392\u5e8f\u300d\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u53d7\u8f93\u5165\u6570\u636e\u7684\u5f71\u54cd\uff0c\u5373\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5e76\u4e0d\u5b8c\u5168\u76f8\u7b49\u3002

        \u81ea\u9002\u5e94\u6027\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u6765\u8bc4\u4f30\u3002\u5982\u679c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u5dee\u4e8e\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u8bf4\u660e\u6392\u5e8f\u7b97\u6cd5\u5728\u67d0\u4e9b\u6570\u636e\u4e0b\u6027\u80fd\u53ef\u80fd\u52a3\u5316\uff0c\u56e0\u6b64\u88ab\u89c6\u4e3a\u8d1f\u9762\u5c5e\u6027\uff1b\u800c\u5982\u679c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u4e8e\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u9762\u5c5e\u6027\u3002

        \u662f\u5426\u57fa\u4e8e\u6bd4\u8f83\uff1a\u300c\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u300d\u4f9d\u8d56\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\\(<\\)\u3001\\(=\\)\u3001\\(>\\)\uff09\u6765\u5224\u65ad\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\uff0c\u4ece\u800c\u6392\u5e8f\u6574\u4e2a\u6570\u7ec4\uff0c\u7406\u8bba\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u800c\u300c\u975e\u6bd4\u8f83\u6392\u5e8f\u300d\u4e0d\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe \\(O(n)\\) \uff0c\u4f46\u5176\u901a\u7528\u6027\u76f8\u5bf9\u8f83\u5dee\u3002

        "},{"location":"chapter_sorting/sorting_algorithm/#1112","title":"11.1.2 \u00a0 \u7406\u60f3\u6392\u5e8f\u7b97\u6cd5","text":"

        \u8fd0\u884c\u5feb\u3001\u539f\u5730\u3001\u7a33\u5b9a\u3001\u6b63\u5411\u81ea\u9002\u5e94\u3001\u901a\u7528\u6027\u597d\u3002\u663e\u7136\uff0c\u8fc4\u4eca\u4e3a\u6b62\u5c1a\u672a\u53d1\u73b0\u517c\u5177\u4ee5\u4e0a\u6240\u6709\u7279\u6027\u7684\u6392\u5e8f\u7b97\u6cd5\u3002\u56e0\u6b64\uff0c\u5728\u9009\u62e9\u6392\u5e8f\u7b97\u6cd5\u65f6\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u7279\u70b9\u548c\u95ee\u9898\u9700\u6c42\u6765\u51b3\u5b9a\u3002

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u5171\u540c\u5b66\u4e60\u5404\u79cd\u6392\u5e8f\u7b97\u6cd5\uff0c\u5e76\u57fa\u4e8e\u4e0a\u8ff0\u8bc4\u4ef7\u7ef4\u5ea6\u5bf9\u5404\u4e2a\u6392\u5e8f\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u8fdb\u884c\u5206\u6790\u3002

        "},{"location":"chapter_sorting/summary/","title":"11.11 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_sorting/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u5192\u6ce1\u6392\u5e8f\u901a\u8fc7\u4ea4\u6362\u76f8\u90bb\u5143\u7d20\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2a\u6807\u5fd7\u4f4d\u6765\u5b9e\u73b0\u63d0\u524d\u8fd4\u56de\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5192\u6ce1\u6392\u5e8f\u7684\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u5230 \\(O(n)\\) \u3002
        • \u63d2\u5165\u6392\u5e8f\u6bcf\u8f6e\u5c06\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u5143\u7d20\u63d2\u5165\u5230\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u6b63\u786e\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b8c\u6210\u6392\u5e8f\u3002\u867d\u7136\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u4f46\u7531\u4e8e\u5355\u5143\u64cd\u4f5c\u76f8\u5bf9\u8f83\u5c11\uff0c\u56e0\u6b64\u5728\u5c0f\u6570\u636e\u91cf\u7684\u6392\u5e8f\u4efb\u52a1\u4e2d\u975e\u5e38\u53d7\u6b22\u8fce\u3002
        • \u5feb\u901f\u6392\u5e8f\u57fa\u4e8e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u5b9e\u73b0\u6392\u5e8f\u3002\u5728\u54e8\u5175\u5212\u5206\u4e2d\uff0c\u6709\u53ef\u80fd\u6bcf\u6b21\u90fd\u9009\u53d6\u5230\u6700\u5dee\u7684\u57fa\u51c6\u6570\uff0c\u5bfc\u81f4\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n^2)\\) \u3002\u5f15\u5165\u4e2d\u4f4d\u6570\u57fa\u51c6\u6570\u6216\u968f\u673a\u57fa\u51c6\u6570\u53ef\u4ee5\u964d\u4f4e\u8fd9\u79cd\u52a3\u5316\u7684\u6982\u7387\u3002\u5c3e\u9012\u5f52\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u51cf\u5c11\u9012\u5f52\u6df1\u5ea6\uff0c\u5c06\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u5230 \\(O(\\log n)\\) \u3002
        • \u5f52\u5e76\u6392\u5e8f\u5305\u62ec\u5212\u5206\u548c\u5408\u5e76\u4e24\u4e2a\u9636\u6bb5\uff0c\u5178\u578b\u5730\u4f53\u73b0\u4e86\u5206\u6cbb\u7b56\u7565\u3002\u5728\u5f52\u5e76\u6392\u5e8f\u4e2d\uff0c\u6392\u5e8f\u6570\u7ec4\u9700\u8981\u521b\u5efa\u8f85\u52a9\u6570\u7ec4\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff1b\u7136\u800c\u6392\u5e8f\u94fe\u8868\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(1)\\) \u3002
        • \u6876\u6392\u5e8f\u5305\u542b\u4e09\u4e2a\u6b65\u9aa4\uff1a\u6570\u636e\u5206\u6876\u3001\u6876\u5185\u6392\u5e8f\u548c\u5408\u5e76\u7ed3\u679c\u3002\u5b83\u540c\u6837\u4f53\u73b0\u4e86\u5206\u6cbb\u7b56\u7565\uff0c\u9002\u7528\u4e8e\u6570\u636e\u4f53\u91cf\u5f88\u5927\u7684\u60c5\u51b5\u3002\u6876\u6392\u5e8f\u7684\u5173\u952e\u5728\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u5e73\u5747\u5206\u914d\u3002
        • \u8ba1\u6570\u6392\u5e8f\u662f\u6876\u6392\u5e8f\u7684\u4e00\u4e2a\u7279\u4f8b\uff0c\u5b83\u901a\u8fc7\u7edf\u8ba1\u6570\u636e\u51fa\u73b0\u7684\u6b21\u6570\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u8ba1\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u636e\u91cf\u5927\u4f46\u6570\u636e\u8303\u56f4\u6709\u9650\u7684\u60c5\u51b5\uff0c\u5e76\u4e14\u8981\u6c42\u6570\u636e\u80fd\u591f\u8f6c\u6362\u4e3a\u6b63\u6574\u6570\u3002
        • \u57fa\u6570\u6392\u5e8f\u901a\u8fc7\u9010\u4f4d\u6392\u5e8f\u6765\u5b9e\u73b0\u6570\u636e\u6392\u5e8f\uff0c\u8981\u6c42\u6570\u636e\u80fd\u591f\u8868\u793a\u4e3a\u56fa\u5b9a\u4f4d\u6570\u7684\u6570\u5b57\u3002
        • \u603b\u7684\u6765\u8bf4\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u5230\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff0c\u5177\u6709\u9ad8\u6548\u7387\u3001\u7a33\u5b9a\u3001\u539f\u5730\u4ee5\u53ca\u6b63\u5411\u81ea\u9002\u5e94\u6027\u7b49\u4f18\u70b9\u3002\u7136\u800c\uff0c\u6b63\u5982\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u4e00\u6837\uff0c\u6ca1\u6709\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\u80fd\u591f\u540c\u65f6\u6ee1\u8db3\u6240\u6709\u8fd9\u4e9b\u6761\u4ef6\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u6570\u636e\u7684\u7279\u6027\u6765\u9009\u62e9\u5408\u9002\u7684\u6392\u5e8f\u7b97\u6cd5\u3002
        • \u56fe 11-19 \u5bf9\u6bd4\u4e86\u4e3b\u6d41\u6392\u5e8f\u7b97\u6cd5\u7684\u6548\u7387\u3001\u7a33\u5b9a\u6027\u3001\u5c31\u5730\u6027\u548c\u81ea\u9002\u5e94\u6027\u7b49\u3002

        \u56fe 11-19 \u00a0 \u6392\u5e8f\u7b97\u6cd5\u5bf9\u6bd4

        "},{"location":"chapter_sorting/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6392\u5e8f\u7b97\u6cd5\u7a33\u5b9a\u6027\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u662f\u5fc5\u9700\u7684\uff1f

        \u5728\u73b0\u5b9e\u4e2d\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u662f\u57fa\u4e8e\u5bf9\u8c61\u7684\u67d0\u4e2a\u5c5e\u6027\u8fdb\u884c\u6392\u5e8f\u3002\u4f8b\u5982\uff0c\u5b66\u751f\u6709\u59d3\u540d\u548c\u8eab\u9ad8\u4e24\u4e2a\u5c5e\u6027\uff0c\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u4e00\u4e2a\u591a\u7ea7\u6392\u5e8f\uff1a

        \u5148\u6309\u7167\u59d3\u540d\u8fdb\u884c\u6392\u5e8f\uff0c\u5f97\u5230 (A, 180) (B, 185) (C, 170) (D, 170) \uff1b\u518d\u5bf9\u8eab\u9ad8\u8fdb\u884c\u6392\u5e8f\u3002\u7531\u4e8e\u6392\u5e8f\u7b97\u6cd5\u4e0d\u7a33\u5b9a\uff0c\u56e0\u6b64\u53ef\u80fd\u5f97\u5230 (D, 170) (C, 170) (A, 180) (B, 185) \u3002

        \u53ef\u4ee5\u53d1\u73b0\uff0c\u5b66\u751f D \u548c C \u7684\u4f4d\u7f6e\u53d1\u751f\u4e86\u4ea4\u6362\uff0c\u59d3\u540d\u7684\u6709\u5e8f\u6027\u88ab\u7834\u574f\u4e86\uff0c\u800c\u8fd9\u662f\u6211\u4eec\u4e0d\u5e0c\u671b\u770b\u5230\u7684\u3002

        \u54e8\u5175\u5212\u5206\u4e2d\u201c\u4ece\u53f3\u5f80\u5de6\u67e5\u627e\u201d\u4e0e\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u7684\u987a\u5e8f\u53ef\u4ee5\u4ea4\u6362\u5417\uff1f

        \u4e0d\u884c\uff0c\u5f53\u6211\u4eec\u4ee5\u6700\u5de6\u7aef\u5143\u7d20\u4e3a\u57fa\u51c6\u6570\u65f6\uff0c\u5fc5\u987b\u5148\u201c\u4ece\u53f3\u5f80\u5de6\u67e5\u627e\u201d\u518d\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u3002\u8fd9\u4e2a\u7ed3\u8bba\u6709\u4e9b\u53cd\u76f4\u89c9\uff0c\u6211\u4eec\u6765\u5256\u6790\u4e00\u4e0b\u539f\u56e0\u3002

        \u54e8\u5175\u5212\u5206 partition() \u7684\u6700\u540e\u4e00\u6b65\u662f\u4ea4\u6362 nums[left] \u548c nums[i] \u3002\u5b8c\u6210\u4ea4\u6362\u540e\uff0c\u57fa\u51c6\u6570\u5de6\u8fb9\u7684\u5143\u7d20\u90fd <= \u57fa\u51c6\u6570\uff0c\u8fd9\u5c31\u8981\u6c42\u6700\u540e\u4e00\u6b65\u4ea4\u6362\u524d nums[left] >= nums[i] \u5fc5\u987b\u6210\u7acb\u3002\u5047\u8bbe\u6211\u4eec\u5148\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\uff0c\u90a3\u4e48\u5982\u679c\u627e\u4e0d\u5230\u6bd4\u57fa\u51c6\u6570\u66f4\u5c0f\u7684\u5143\u7d20\uff0c\u5219\u4f1a\u5728 i == j \u65f6\u8df3\u51fa\u5faa\u73af\uff0c\u6b64\u65f6\u53ef\u80fd nums[j] == nums[i] > nums[left]\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6b64\u65f6\u6700\u540e\u4e00\u6b65\u4ea4\u6362\u64cd\u4f5c\u4f1a\u628a\u4e00\u4e2a\u6bd4\u57fa\u51c6\u6570\u66f4\u5927\u7684\u5143\u7d20\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\uff0c\u5bfc\u81f4\u54e8\u5175\u5212\u5206\u5931\u8d25\u3002

        \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u7ed9\u5b9a\u6570\u7ec4 [0, 0, 0, 0, 1] \uff0c\u5982\u679c\u5148\u201c\u4ece\u5de6\u5411\u53f3\u67e5\u627e\u201d\uff0c\u54e8\u5175\u5212\u5206\u540e\u6570\u7ec4\u4e3a [1, 0, 0, 0, 0] \uff0c\u8fd9\u4e2a\u7ed3\u679c\u662f\u4e0d\u6b63\u786e\u7684\u3002

        \u518d\u6df1\u5165\u601d\u8003\u4e00\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u9009\u62e9 nums[right] \u4e3a\u57fa\u51c6\u6570\uff0c\u90a3\u4e48\u6b63\u597d\u53cd\u8fc7\u6765\uff0c\u5fc5\u987b\u5148\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u3002

        \u5173\u4e8e\u5c3e\u9012\u5f52\u4f18\u5316\uff0c\u4e3a\u4ec0\u4e48\u9009\u77ed\u7684\u6570\u7ec4\u80fd\u4fdd\u8bc1\u9012\u5f52\u6df1\u5ea6\u4e0d\u8d85\u8fc7 \\(\\log n\\) \uff1f

        \u9012\u5f52\u6df1\u5ea6\u5c31\u662f\u5f53\u524d\u672a\u8fd4\u56de\u7684\u9012\u5f52\u65b9\u6cd5\u7684\u6570\u91cf\u3002\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u6211\u4eec\u5c06\u539f\u6570\u7ec4\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\u3002\u5728\u5c3e\u9012\u5f52\u4f18\u5316\u540e\uff0c\u5411\u4e0b\u9012\u5f52\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u6700\u5927\u4e3a\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a\u3002\u5047\u8bbe\u6700\u5dee\u60c5\u51b5\uff0c\u4e00\u76f4\u4e3a\u4e00\u534a\u957f\u5ea6\uff0c\u90a3\u4e48\u6700\u7ec8\u7684\u9012\u5f52\u6df1\u5ea6\u5c31\u662f \\(\\log n\\) \u3002

        \u56de\u987e\u539f\u59cb\u7684\u5feb\u901f\u6392\u5e8f\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u4f1a\u8fde\u7eed\u5730\u9012\u5f52\u957f\u5ea6\u8f83\u5927\u7684\u6570\u7ec4\uff0c\u6700\u5dee\u60c5\u51b5\u4e0b\u4e3a \\(n\\)\u3001\\(n - 1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \u3002\u5c3e\u9012\u5f52\u4f18\u5316\u53ef\u4ee5\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u3002

        \u5f53\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u76f8\u7b49\u65f6\uff0c\u5feb\u901f\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(n^2)\\) \u5417\uff1f\u8be5\u5982\u4f55\u5904\u7406\u8fd9\u79cd\u9000\u5316\u60c5\u51b5\uff1f

        \u662f\u7684\u3002\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u8003\u8651\u901a\u8fc7\u54e8\u5175\u5212\u5206\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff1a\u5c0f\u4e8e\u3001\u7b49\u4e8e\u3001\u5927\u4e8e\u57fa\u51c6\u6570\u3002\u4ec5\u5411\u4e0b\u9012\u5f52\u5c0f\u4e8e\u548c\u5927\u4e8e\u7684\u4e24\u90e8\u5206\u3002\u5728\u8be5\u65b9\u6cd5\u4e0b\uff0c\u8f93\u5165\u5143\u7d20\u5168\u90e8\u76f8\u7b49\u7684\u6570\u7ec4\uff0c\u4ec5\u4e00\u8f6e\u54e8\u5175\u5212\u5206\u5373\u53ef\u5b8c\u6210\u6392\u5e8f\u3002

        \u6876\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u4ec0\u4e48\u662f \\(O(n^2)\\) \uff1f

        \u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5143\u7d20\u88ab\u5206\u81f3\u540c\u4e00\u4e2a\u6876\u4e2d\u3002\u5982\u679c\u6211\u4eec\u91c7\u7528\u4e00\u4e2a \\(O(n^2)\\) \u7b97\u6cd5\u6765\u6392\u5e8f\u8fd9\u4e9b\u5143\u7d20\uff0c\u5219\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_stack_and_queue/","title":"\u7b2c 5 \u7ae0 \u00a0 \u6808\u4e0e\u961f\u5217","text":"

        Abstract

        \u6808\u5982\u540c\u53e0\u732b\u732b\uff0c\u800c\u961f\u5217\u5c31\u50cf\u732b\u732b\u6392\u961f\u3002

        \u4e24\u8005\u5206\u522b\u4ee3\u8868\u5148\u5165\u540e\u51fa\u548c\u5148\u5165\u5148\u51fa\u7684\u903b\u8f91\u5173\u7cfb\u3002

        "},{"location":"chapter_stack_and_queue/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 5.1 \u00a0 \u6808
        • 5.2 \u00a0 \u961f\u5217
        • 5.3 \u00a0 \u53cc\u5411\u961f\u5217
        • 5.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_stack_and_queue/deque/","title":"5.3 \u00a0 \u53cc\u5411\u961f\u5217","text":"

        \u5728\u961f\u5217\u4e2d\uff0c\u6211\u4eec\u4ec5\u80fd\u5220\u9664\u5934\u90e8\u5143\u7d20\u6216\u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u3002\u5982\u56fe 5-7 \u6240\u793a\uff0c\u300c\u53cc\u5411\u961f\u5217 double-ended queue\u300d\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u5728\u5934\u90e8\u548c\u5c3e\u90e8\u6267\u884c\u5143\u7d20\u7684\u6dfb\u52a0\u6216\u5220\u9664\u64cd\u4f5c\u3002

        \u56fe 5-7 \u00a0 \u53cc\u5411\u961f\u5217\u7684\u64cd\u4f5c

        "},{"location":"chapter_stack_and_queue/deque/#531","title":"5.3.1 \u00a0 \u53cc\u5411\u961f\u5217\u5e38\u7528\u64cd\u4f5c","text":"

        \u53cc\u5411\u961f\u5217\u7684\u5e38\u7528\u64cd\u4f5c\u5982\u8868 5-3 \u6240\u793a\uff0c\u5177\u4f53\u7684\u65b9\u6cd5\u540d\u79f0\u9700\u8981\u6839\u636e\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002

        \u8868 5-3 \u00a0 \u53cc\u5411\u961f\u5217\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 pushFirst() \u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u9996 \\(O(1)\\) pushLast() \u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u5c3e \\(O(1)\\) popFirst() \u5220\u9664\u961f\u9996\u5143\u7d20 \\(O(1)\\) popLast() \u5220\u9664\u961f\u5c3e\u5143\u7d20 \\(O(1)\\) peekFirst() \u8bbf\u95ee\u961f\u9996\u5143\u7d20 \\(O(1)\\) peekLast() \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 \\(O(1)\\)

        \u540c\u6837\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5df2\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\u7c7b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig deque.py
        from collections import deque\n# \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217\ndeque: deque[int] = deque()\n# \u5143\u7d20\u5165\u961f\ndeque.append(2)      # \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.append(5)\ndeque.append(4)\ndeque.appendleft(3)  # \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.appendleft(1)\n# \u8bbf\u95ee\u5143\u7d20\nfront: int = deque[0]  # \u961f\u9996\u5143\u7d20\nrear: int = deque[-1]  # \u961f\u5c3e\u5143\u7d20\n# \u5143\u7d20\u51fa\u961f\npop_front: int = deque.popleft()  # \u961f\u9996\u5143\u7d20\u51fa\u961f\npop_rear: int = deque.pop()       # \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n# \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(deque)\n# \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(deque) == 0\n
        deque.cpp
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\ndeque<int> deque;\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.push_back(5);\ndeque.push_back(4);\ndeque.push_front(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.push_front(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint front = deque.front(); // \u961f\u9996\u5143\u7d20\nint back = deque.back();   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.pop_front();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.pop_back();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty = deque.empty();\n
        deque.java
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\nDeque<Integer> deque = new LinkedList<>();\n/* \u5143\u7d20\u5165\u961f */\ndeque.offerLast(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.offerLast(5);\ndeque.offerLast(4);\ndeque.offerFirst(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.offerFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.peekFirst();  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.peekLast();    // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\nint popFirst = deque.pollFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\nint popLast = deque.pollLast();    // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = deque.isEmpty();\n
        deque.cs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 C# \u4e2d\uff0c\u5c06\u94fe\u8868 LinkedList \u770b\u4f5c\u53cc\u5411\u961f\u5217\u6765\u4f7f\u7528\nLinkedList<int> deque = new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.AddLast(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.AddLast(5);\ndeque.AddLast(4);\ndeque.AddFirst(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.AddFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.First.Value;  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.Last.Value;    // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.RemoveFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.RemoveLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.Count;\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = deque.Count == 0;\n
        deque_test.go
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Go \u4e2d\uff0c\u5c06 list \u4f5c\u4e3a\u53cc\u5411\u961f\u5217\u4f7f\u7528\ndeque := list.New()\n/* \u5143\u7d20\u5165\u961f */\ndeque.PushBack(2)      // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.PushBack(5)\ndeque.PushBack(4)\ndeque.PushFront(3)     // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.PushFront(1)\n/* \u8bbf\u95ee\u5143\u7d20 */\nfront := deque.Front() // \u961f\u9996\u5143\u7d20\nrear := deque.Back()   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.Remove(front)    // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.Remove(rear)     // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize := deque.Len()\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty := deque.Len() == 0\n
        deque.swift
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u5411\u961f\u5217\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u53cc\u5411\u961f\u5217\u6765\u4f7f\u7528\nvar deque: [Int] = []\n/* \u5143\u7d20\u5165\u961f */\ndeque.append(2) // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.append(5)\ndeque.append(4)\ndeque.insert(3, at: 0) // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.insert(1, at: 0)\n/* \u8bbf\u95ee\u5143\u7d20 */\nlet peekFirst = deque.first! // \u961f\u9996\u5143\u7d20\nlet peekLast = deque.last! // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\n// \u4f7f\u7528 Array \u6a21\u62df\u65f6 popFirst \u7684\u590d\u6742\u5ea6\u4e3a O(n)\nlet popFirst = deque.removeFirst() // \u961f\u9996\u5143\u7d20\u51fa\u961f\nlet popLast = deque.removeLast() // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.count\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = deque.isEmpty\n
        deque.js
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// JavaScript \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\uff0c\u53ea\u80fd\u628a Array \u5f53\u4f5c\u53cc\u7aef\u961f\u5217\u6765\u4f7f\u7528\nconst deque = [];\n/* \u5143\u7d20\u5165\u961f */\ndeque.push(2);\ndeque.push(5);\ndeque.push(4);\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cunshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndeque.unshift(3);\ndeque.unshift(1);\nconsole.log(\"\u53cc\u5411\u961f\u5217 deque = \", deque);\n/* \u8bbf\u95ee\u5143\u7d20 */\nconst peekFirst = deque[0];\nconsole.log(\"\u961f\u9996\u5143\u7d20 peekFirst = \" + peekFirst);\nconst peekLast = deque[deque.length - 1];\nconsole.log(\"\u961f\u5c3e\u5143\u7d20 peekLast = \" + peekLast);\n/* \u5143\u7d20\u51fa\u961f */\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst popFront = deque.shift();\nconsole.log(\"\u961f\u9996\u51fa\u961f\u5143\u7d20 popFront = \" + popFront + \"\uff0c\u961f\u9996\u51fa\u961f\u540e deque = \" + deque);\nconst popBack = deque.pop();\nconsole.log(\"\u961f\u5c3e\u51fa\u961f\u5143\u7d20 popBack = \" + popBack + \"\uff0c\u961f\u5c3e\u51fa\u961f\u540e deque = \" + deque);\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = deque.length;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u957f\u5ea6 size = \" + size);\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst isEmpty = size === 0;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a = \" + isEmpty);\n
        deque.ts
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// TypeScript \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\uff0c\u53ea\u80fd\u628a Array \u5f53\u4f5c\u53cc\u7aef\u961f\u5217\u6765\u4f7f\u7528\nconst deque: number[] = [];\n/* \u5143\u7d20\u5165\u961f */\ndeque.push(2);\ndeque.push(5);\ndeque.push(4);\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cunshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndeque.unshift(3);\ndeque.unshift(1);\nconsole.log(\"\u53cc\u5411\u961f\u5217 deque = \", deque);\n/* \u8bbf\u95ee\u5143\u7d20 */\nconst peekFirst: number = deque[0];\nconsole.log(\"\u961f\u9996\u5143\u7d20 peekFirst = \" + peekFirst);\nconst peekLast: number = deque[deque.length - 1];\nconsole.log(\"\u961f\u5c3e\u5143\u7d20 peekLast = \" + peekLast);\n/* \u5143\u7d20\u51fa\u961f */\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst popFront: number = deque.shift() as number;\nconsole.log(\"\u961f\u9996\u51fa\u961f\u5143\u7d20 popFront = \" + popFront + \"\uff0c\u961f\u9996\u51fa\u961f\u540e deque = \" + deque);\nconst popBack: number = deque.pop() as number;\nconsole.log(\"\u961f\u5c3e\u51fa\u961f\u5143\u7d20 popBack = \" + popBack + \"\uff0c\u961f\u5c3e\u51fa\u961f\u540e deque = \" + deque);\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nconst size: number = deque.length;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u957f\u5ea6 size = \" + size);\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst isEmpty: boolean = size === 0;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a = \" + isEmpty);\n
        deque.dart
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Dart \u4e2d\uff0cQueue \u88ab\u5b9a\u4e49\u4e3a\u53cc\u5411\u961f\u5217\nQueue<int> deque = Queue<int>();\n/* \u5143\u7d20\u5165\u961f */\ndeque.addLast(2);  // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.addLast(5);\ndeque.addLast(4);\ndeque.addFirst(3); // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.addFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.first; // \u961f\u9996\u5143\u7d20\nint peekLast = deque.last;   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\nint popFirst = deque.removeFirst(); // \u961f\u9996\u5143\u7d20\u51fa\u961f\nint popLast = deque.removeLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.length;\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = deque.isEmpty;W\n
        deque.rs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\nlet mut deque: VecDeque<u32> = VecDeque::new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(2);  // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.push_back(5);\ndeque.push_back(4);\ndeque.push_front(3); // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.push_front(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nif let Some(front) = deque.front() { // \u961f\u9996\u5143\u7d20\n}\nif let Some(rear) = deque.back() {   // \u961f\u5c3e\u5143\u7d20\n}\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop_front) = deque.pop_front() { // \u961f\u9996\u5143\u7d20\u51fa\u961f\n}\nif let Some(pop_rear) = deque.pop_back() {   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = deque.is_empty();\n
        deque.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u53cc\u5411\u961f\u5217\n
        deque.zig
        \n
        "},{"location":"chapter_stack_and_queue/deque/#532","title":"5.3.2 \u00a0 \u53cc\u5411\u961f\u5217\u5b9e\u73b0 *","text":"

        \u53cc\u5411\u961f\u5217\u7684\u5b9e\u73b0\u4e0e\u961f\u5217\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u9009\u62e9\u94fe\u8868\u6216\u6570\u7ec4\u4f5c\u4e3a\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002

        "},{"location":"chapter_stack_and_queue/deque/#1","title":"1. \u00a0 \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u56de\u987e\u4e0a\u4e00\u8282\u5185\u5bb9\uff0c\u6211\u4eec\u4f7f\u7528\u666e\u901a\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u961f\u5217\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u5220\u9664\u5934\u8282\u70b9\uff08\u5bf9\u5e94\u51fa\u961f\u64cd\u4f5c\uff09\u548c\u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0\u65b0\u8282\u70b9\uff08\u5bf9\u5e94\u5165\u961f\u64cd\u4f5c\uff09\u3002

        \u5bf9\u4e8e\u53cc\u5411\u961f\u5217\u800c\u8a00\uff0c\u5934\u90e8\u548c\u5c3e\u90e8\u90fd\u53ef\u4ee5\u6267\u884c\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u53cc\u5411\u961f\u5217\u9700\u8981\u5b9e\u73b0\u53e6\u4e00\u4e2a\u5bf9\u79f0\u65b9\u5411\u7684\u64cd\u4f5c\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u91c7\u7528\u201c\u53cc\u5411\u94fe\u8868\u201d\u4f5c\u4e3a\u53cc\u5411\u961f\u5217\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002

        \u5982\u56fe 5-8 \u6240\u793a\uff0c\u6211\u4eec\u5c06\u53cc\u5411\u94fe\u8868\u7684\u5934\u8282\u70b9\u548c\u5c3e\u8282\u70b9\u89c6\u4e3a\u53cc\u5411\u961f\u5217\u7684\u961f\u9996\u548c\u961f\u5c3e\uff0c\u540c\u65f6\u5b9e\u73b0\u5728\u4e24\u7aef\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u7684\u529f\u80fd\u3002

        LinkedListDequepushLast()pushFirst()popLast()popFirst()

        \u56fe 5-8 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_deque.py
        class ListNode:\n\"\"\"\u53cc\u5411\u94fe\u8868\u8282\u70b9\"\"\"\ndef __init__(self, val: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.val: int = val\nself.next: ListNode | None = None  # \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nself.prev: ListNode | None = None  # \u524d\u9a71\u8282\u70b9\u5f15\u7528\nclass LinkedListDeque:\n\"\"\"\u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._front: ListNode | None = None  # \u5934\u8282\u70b9 front\nself._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\nself._size: int = 0  # \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self.size() == 0\ndef push(self, num: int, is_front: bool):\n\"\"\"\u5165\u961f\u64cd\u4f5c\"\"\"\nnode = ListNode(num)\n# \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif self.is_empty():\nself._front = self._rear = node\n# \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelif is_front:\n# \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nself._front.prev = node\nnode.next = self._front\nself._front = node  # \u66f4\u65b0\u5934\u8282\u70b9\n# \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse:\n# \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nself._rear.next = node\nnode.prev = self._rear\nself._rear = node  # \u66f4\u65b0\u5c3e\u8282\u70b9\nself._size += 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\ndef push_first(self, num: int):\n\"\"\"\u961f\u9996\u5165\u961f\"\"\"\nself.push(num, True)\ndef push_last(self, num: int):\n\"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\nself.push(num, False)\ndef pop(self, is_front: bool) -> int:\n\"\"\"\u51fa\u961f\u64cd\u4f5c\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n# \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif is_front:\nval: int = self._front.val  # \u6682\u5b58\u5934\u8282\u70b9\u503c\n# \u5220\u9664\u5934\u8282\u70b9\nfnext: ListNode | None = self._front.next\nif fnext != None:\nfnext.prev = None\nself._front.next = None\nself._front = fnext  # \u66f4\u65b0\u5934\u8282\u70b9\n# \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse:\nval: int = self._rear.val  # \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n# \u5220\u9664\u5c3e\u8282\u70b9\nrprev: ListNode | None = self._rear.prev\nif rprev != None:\nrprev.next = None\nself._rear.prev = None\nself._rear = rprev  # \u66f4\u65b0\u5c3e\u8282\u70b9\nself._size -= 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val\ndef pop_first(self) -> int:\n\"\"\"\u961f\u9996\u51fa\u961f\"\"\"\nreturn self.pop(True)\ndef pop_last(self) -> int:\n\"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\nreturn self.pop(False)\ndef peek_first(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._front.val\ndef peek_last(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._rear.val\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\nnode = self._front\nres = [0] * self.size()\nfor i in range(self.size()):\nres[i] = node.val\nnode = node.next\nreturn res\n
        linkedlist_deque.cpp
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nstruct DoublyListNode {\nint val;              // \u8282\u70b9\u503c\nDoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\u6307\u9488\nDoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\u6307\u9488\nDoublyListNode(int val) : val(val), prev(nullptr), next(nullptr) {\n}\n};\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate:\nDoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize = 0;              // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nLinkedListDeque() : front(nullptr), rear(nullptr) {\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~LinkedListDeque() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nDoublyListNode *pre, *cur = front;\nwhile (cur != nullptr) {\npre = cur;\ncur = cur->next;\ndelete pre;\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid push(int num, bool isFront) {\nDoublyListNode *node = new DoublyListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (isEmpty())\nfront = rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront->prev = node;\nnode->next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear->next = node;\nnode->prev = rear;\nrear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int num) {\npush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int num) {\npush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint pop(bool isFront) {\nif (isEmpty())\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front->val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nDoublyListNode *fNext = front->next;\nif (fNext != nullptr) {\nfNext->prev = nullptr;\nfront->next = nullptr;\ndelete front;\n}\nfront = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = rear->val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nDoublyListNode *rPrev = rear->prev;\nif (rPrev != nullptr) {\nrPrev->next = nullptr;\nrear->prev = nullptr;\ndelete rear;\n}\nrear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn front->val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn rear->val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\nDoublyListNode *node = front;\nvector<int> res(size());\nfor (int i = 0; i < res.size(); i++) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_deque.java
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nListNode prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\nListNode(int val) {\nthis.val = val;\nprev = next = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nprivate int queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic LinkedListDeque() {\nfront = rear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nprivate void push(int num, boolean isFront) {\nListNode node = new ListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (isEmpty())\nfront = rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront.prev = node;\nnode.next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear.next = node;\nnode.prev = rear;\nrear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npublic void pushFirst(int num) {\npush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void pushLast(int num) {\npush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nprivate int pop(boolean isFront) {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode fNext = front.next;\nif (fNext != null) {\nfNext.prev = null;\nfront.next = null;\n}\nfront = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = rear.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode rPrev = rear.prev;\nif (rPrev != null) {\nrPrev.next = null;\nrear.prev = null;\n}\nrear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peekFirst() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn front.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int peekLast() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn rear.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] toArray() {\nListNode node = front;\nint[] res = new int[size()];\nfor (int i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.cs
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode(int val) {\npublic int val = val;       // \u8282\u70b9\u503c\npublic ListNode? next = null; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\npublic ListNode? prev = null; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nListNode? front, rear; // \u5934\u8282\u70b9 front, \u5c3e\u8282\u70b9 rear\nint queSize = 0;      // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic LinkedListDeque() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid Push(int num, bool isFront) {\nListNode node = new(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (IsEmpty()) {\nfront = node;\nrear = node;\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront!.prev = node;\nnode.next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9                           \n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear!.next = node;\nnode.prev = rear;\nrear = node;  // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npublic void PushFirst(int num) {\nPush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void PushLast(int num) {\nPush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint? Pop(bool isFront) {\nif (IsEmpty())\nthrow new Exception();\nint? val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front?.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode? fNext = front?.next;\nif (fNext != null) {\nfNext.prev = null;\nfront!.next = null;\n}\nfront = fNext;   // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = rear?.val;  // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode? rPrev = rear?.prev;\nif (rPrev != null) {\nrPrev.next = null;\nrear!.prev = null;\n}\nrear = rPrev;    // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int? PopFirst() {\nreturn Pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int? PopLast() {\nreturn Pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int? PeekFirst() {\nif (IsEmpty())\nthrow new Exception();\nreturn front?.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int? PeekLast() {\nif (IsEmpty())\nthrow new Exception();\nreturn rear?.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int?[] ToArray() {\nListNode? node = front;\nint?[] res = new int?[Size()];\nfor (int i = 0; i < res.Length; i++) {\nres[i] = node?.val;\nnode = node?.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.go
        /* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype linkedListDeque struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u53cc\u7aef\u961f\u5217 */\nfunc newLinkedListDeque() *linkedListDeque {\nreturn &linkedListDeque{\ndata: list.New(),\n}\n}\n/* \u961f\u9996\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushFirst(value any) {\ns.data.PushFront(value)\n}\n/* \u961f\u5c3e\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushLast(value any) {\ns.data.PushBack(value)\n}\n/* \u961f\u9996\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popFirst() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u961f\u5c3e\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popLast() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListDeque) peekFirst() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (s *linkedListDeque) peekLast() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\nreturn e.Value\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListDeque) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListDeque) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListDeque) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_deque.swift
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nweak var prev: ListNode? // \u524d\u9a71\u8282\u70b9\u5f15\u7528\ninit(val: Int) {\nself.val = val\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate var front: ListNode? // \u5934\u8282\u70b9 front\nprivate var rear: ListNode? // \u5c3e\u8282\u70b9 rear\nprivate var queSize: Int // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\ninit() {\nqueSize = 0\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u961f\u64cd\u4f5c */\nprivate func push(num: Int, isFront: Bool) {\nlet node = ListNode(val: num)\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif isEmpty() {\nfront = node\nrear = node\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if isFront {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront?.prev = node\nnode.next = front\nfront = node // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear?.next = node\nnode.prev = rear\nrear = node // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize += 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nfunc pushFirst(num: Int) {\npush(num: num, isFront: true)\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc pushLast(num: Int) {\npush(num: num, isFront: false)\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nprivate func pop(isFront: Bool) -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\nlet val: Int\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif isFront {\nval = front!.val // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet fNext = front?.next\nif fNext != nil {\nfNext?.prev = nil\nfront?.next = nil\n}\nfront = fNext // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = rear!.val // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet rPrev = rear?.prev\nif rPrev != nil {\nrPrev?.next = nil\nrear?.prev = nil\n}\nrear = rPrev // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize -= 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc popFirst() -> Int {\npop(isFront: true)\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc popLast() -> Int {\npop(isFront: false)\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peekFirst() -> Int? {\nisEmpty() ? nil : front?.val\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc peekLast() -> Int? {\nisEmpty() ? nil : rear?.val\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfunc toArray() -> [Int] {\nvar node = front\nvar res = Array(repeating: 0, count: size())\nfor i in res.indices {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_deque.js
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nprev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nnext; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nval; // \u8282\u70b9\u503c\nconstructor(val) {\nthis.val = val;\nthis.next = null;\nthis.prev = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n#front; // \u5934\u8282\u70b9 front\n#rear; // \u5c3e\u8282\u70b9 rear\n#queSize; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nconstructor() {\nthis.#front = null;\nthis.#rear = null;\nthis.#queSize = 0;\n}\n/* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\npushLast(val) {\nconst node = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.#queSize === 0) {\nthis.#front = node;\nthis.#rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nthis.#rear.next = node;\nnode.prev = this.#rear;\nthis.#rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nthis.#queSize++;\n}\n/* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\npushFirst(val) {\nconst node = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.#queSize === 0) {\nthis.#front = node;\nthis.#rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nthis.#front.prev = node;\nnode.next = this.#front;\nthis.#front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\nthis.#queSize++;\n}\n/* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\npopLast() {\nif (this.#queSize === 0) {\nreturn null;\n}\nconst value = this.#rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet temp = this.#rear.prev;\nif (temp !== null) {\ntemp.next = null;\nthis.#rear.prev = null;\n}\nthis.#rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\nthis.#queSize--;\nreturn value;\n}\n/* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\npopFirst() {\nif (this.#queSize === 0) {\nreturn null;\n}\nconst value = this.#front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet temp = this.#front.next;\nif (temp !== null) {\ntemp.prev = null;\nthis.#front.next = null;\n}\nthis.#front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\nthis.#queSize--;\nreturn value;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast() {\nreturn this.#queSize === 0 ? null : this.#rear.val;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst() {\nreturn this.#queSize === 0 ? null : this.#front.val;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u6253\u5370\u53cc\u5411\u961f\u5217 */\nprint() {\nconst arr = [];\nlet temp = this.#front;\nwhile (temp !== null) {\narr.push(temp.val);\ntemp = temp.next;\n}\nconsole.log('[' + arr.join(', ') + ']');\n}\n}\n
        linkedlist_deque.ts
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nprev: ListNode; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nnext: ListNode; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nval: number; // \u8282\u70b9\u503c\nconstructor(val: number) {\nthis.val = val;\nthis.next = null;\nthis.prev = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate front: ListNode; // \u5934\u8282\u70b9 front\nprivate rear: ListNode; // \u5c3e\u8282\u70b9 rear\nprivate queSize: number; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nconstructor() {\nthis.front = null;\nthis.rear = null;\nthis.queSize = 0;\n}\n/* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\npushLast(val: number): void {\nconst node: ListNode = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.queSize === 0) {\nthis.front = node;\nthis.rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nthis.rear.next = node;\nnode.prev = this.rear;\nthis.rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nthis.queSize++;\n}\n/* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\npushFirst(val: number): void {\nconst node: ListNode = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.queSize === 0) {\nthis.front = node;\nthis.rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nthis.front.prev = node;\nnode.next = this.front;\nthis.front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\nthis.queSize++;\n}\n/* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\npopLast(): number {\nif (this.queSize === 0) {\nreturn null;\n}\nconst value: number = this.rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet temp: ListNode = this.rear.prev;\nif (temp !== null) {\ntemp.next = null;\nthis.rear.prev = null;\n}\nthis.rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\nthis.queSize--;\nreturn value;\n}\n/* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\npopFirst(): number {\nif (this.queSize === 0) {\nreturn null;\n}\nconst value: number = this.front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet temp: ListNode = this.front.next;\nif (temp !== null) {\ntemp.prev = null;\nthis.front.next = null;\n}\nthis.front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\nthis.queSize--;\nreturn value;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast(): number {\nreturn this.queSize === 0 ? null : this.rear.val;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst(): number {\nreturn this.queSize === 0 ? null : this.front.val;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u6253\u5370\u53cc\u5411\u961f\u5217 */\nprint(): void {\nconst arr: number[] = [];\nlet temp: ListNode = this.front;\nwhile (temp !== null) {\narr.push(temp.val);\ntemp = temp.next;\n}\nconsole.log('[' + arr.join(', ') + ']');\n}\n}\n
        linkedlist_deque.dart
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode? next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nListNode? prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\nListNode(this.val, {this.next, this.prev});\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u5bf9\u5217 */\nclass LinkedListDeque {\nlate ListNode? _front; // \u5934\u8282\u70b9 _front\nlate ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\nint _queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nLinkedListDeque() {\nthis._front = null;\nthis._rear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u957f\u5ea6 */\nint size() {\nreturn this._queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid push(int _num, bool isFront) {\nfinal ListNode node = ListNode(_num);\nif (isEmpty()) {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 _front \u548c _rear \u90fd\u6307\u5411 node\n_front = _rear = node;\n} else if (isFront) {\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n_front!.prev = node;\nnode.next = _front;\n_front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n} else {\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n_rear!.next = node;\nnode.prev = _rear;\n_rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n_queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int _num) {\npush(_num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int _num) {\npush(_num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint? pop(bool isFront) {\n// \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de null\nif (isEmpty()) {\nreturn null;\n}\nfinal int val;\nif (isFront) {\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nval = _front!.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode? fNext = _front!.next;\nif (fNext != null) {\nfNext.prev = null;\n_front!.next = null;\n}\n_front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n} else {\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nval = _rear!.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode? rPrev = _rear!.prev;\nif (rPrev != null) {\nrPrev.next = null;\n_rear!.prev = null;\n}\n_rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n_queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint? popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint? popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint? peekFirst() {\nreturn _front?.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint? peekLast() {\nreturn _rear?.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nList<int> toArray() {\nListNode? node = _front;\nfinal List<int> res = [];\nfor (int i = 0; i < _queSize; i++) {\nres.add(node!.val);\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.rs
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\npub struct ListNode<T> {\npub val: T,                                 // \u8282\u70b9\u503c\npub next: Option<Rc<RefCell<ListNode<T>>>>, // \u540e\u7ee7\u8282\u70b9\u6307\u9488\npub prev: Option<Rc<RefCell<ListNode<T>>>>, // \u524d\u9a71\u8282\u70b9\u6307\u9488\n}\nimpl<T> ListNode<T> {\npub fn new(val: T) -> Rc<RefCell<ListNode<T>>> {\nRc::new(RefCell::new(ListNode {\nval,\nnext: None,\nprev: None,\n}))\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListDeque<T> {\nfront: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\nrear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \nque_size: usize,                            // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListDeque<T> {\npub fn new() -> Self {\nSelf {\nfront: None,\nrear: None,\nque_size: 0, }\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.que_size;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\npub fn push(&mut self, num: T, is_front: bool) {\nlet node = ListNode::new(num);\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nif is_front {\nmatch self.front.take() {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nNone => {\nself.rear = Some(node.clone());\nself.front = Some(node);\n}\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nSome(old_front) => {\nold_front.borrow_mut().prev = Some(node.clone());\nnode.borrow_mut().next = Some(old_front);\nself.front = Some(node); // \u66f4\u65b0\u5934\u8282\u70b9\n}\n}\n} // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\nmatch self.rear.take() {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nNone => {\nself.front = Some(node.clone());\nself.rear = Some(node);\n}\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nSome(old_rear) => {\nold_rear.borrow_mut().next = Some(node.clone());\nnode.borrow_mut().prev = Some(old_rear);\nself.rear = Some(node); // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n}\n}\nself.que_size += 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npub fn push_first(&mut self, num: T) {\nself.push(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npub fn push_last(&mut self, num: T) {\nself.push(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\npub fn pop(&mut self, is_front: bool) -> Option<T> {\n// \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de None\nif self.is_empty() { return None };\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif is_front {\nself.front.take().map(|old_front| {\nmatch old_front.borrow_mut().next.take() {\nSome(new_front) => {\nnew_front.borrow_mut().prev.take();\nself.front = Some(new_front);   // \u66f4\u65b0\u5934\u8282\u70b9\n}\nNone => {\nself.rear.take();\n}\n}\nself.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nRc::try_unwrap(old_front).ok().unwrap().into_inner().val\n})\n} // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nself.rear.take().map(|old_rear| {\nmatch old_rear.borrow_mut().prev.take() {\nSome(new_rear) => {\nnew_rear.borrow_mut().next.take();\nself.rear = Some(new_rear);     // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nNone => {\nself.front.take();\n}\n}\nself.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nRc::try_unwrap(old_rear).ok().unwrap().into_inner().val\n})\n}\n}\n/* \u961f\u9996\u51fa\u961f */\npub fn pop_first(&mut self) -> Option<T> {\nreturn self.pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npub fn pop_last(&mut self) -> Option<T> {\nreturn self.pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npub fn peek_first(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.front.as_ref()\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npub fn peek_last(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.rear.as_ref()\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.insert(0, node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_deque.c
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\ntypedef struct DoublyListNode {\nint val;                     // \u8282\u70b9\u503c\nstruct DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\nstruct DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\n} DoublyListNode;\n/* \u6784\u9020\u51fd\u6570 */\nDoublyListNode *newDoublyListNode(int num) {\nDoublyListNode *new = (DoublyListNode *)malloc(sizeof(DoublyListNode));\nnew->val = num;\nnew->next = NULL;\nnew->prev = NULL;\nreturn new;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delDoublyListNode(DoublyListNode *node) {\nfree(node);\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\nDoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize;                  // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n} LinkedListDeque;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListDeque *newLinkedListDeque() {\nLinkedListDeque *deque = (LinkedListDeque *)malloc(sizeof(LinkedListDeque));\ndeque->front = NULL;\ndeque->rear = NULL;\ndeque->queSize = 0;\nreturn deque;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListdeque(LinkedListDeque *deque) {\n// \u91ca\u653e\u6240\u6709\u8282\u70b9\nfor (int i = 0; i < deque->queSize && deque->front != NULL; i++) {\nDoublyListNode *tmp = deque->front;\ndeque->front = deque->front->next;\nfree(tmp);\n}\n// \u91ca\u653e deque \u7ed3\u6784\u4f53\nfree(deque);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListDeque *deque) {\nreturn deque->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListDeque *deque) {\nreturn (size(deque) == 0);\n}\n/* \u5165\u961f */\nvoid push(LinkedListDeque *deque, int num, bool isFront) {\nDoublyListNode *node = newDoublyListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411node\nif (empty(deque)) {\ndeque->front = deque->rear = node;\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\ndeque->front->prev = node;\nnode->next = deque->front;\ndeque->front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\ndeque->rear->next = node;\nnode->prev = deque->rear;\ndeque->rear = node;\n}\ndeque->queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(LinkedListDeque *deque, int num) {\npush(deque, num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(LinkedListDeque *deque, int num) {\npush(deque, num, false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(LinkedListDeque *deque) {\nassert(size(deque) && deque->front);\nreturn deque->front->val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(LinkedListDeque *deque) {\nassert(size(deque) && deque->rear);\nreturn deque->rear->val;\n}\n/* \u51fa\u961f */\nint pop(LinkedListDeque *deque, bool isFront) {\nif (empty(deque))\nreturn -1;\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = peekFirst(deque); // \u6682\u5b58\u5934\u8282\u70b9\u503c\nDoublyListNode *fNext = deque->front->next;\nif (fNext) {\nfNext->prev = NULL;\ndeque->front->next = NULL;\ndelDoublyListNode(deque->front);\n}\ndeque->front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = peekLast(deque); // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\nDoublyListNode *rPrev = deque->rear->prev;\nif (rPrev) {\nrPrev->next = NULL;\ndeque->rear->prev = NULL;\ndelDoublyListNode(deque->rear);\n}\ndeque->rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\ndeque->queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(LinkedListDeque *deque) {\nreturn pop(deque, true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(LinkedListDeque *deque) {\nreturn pop(deque, false);\n}\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListDeque(LinkedListDeque *deque) {\nint *arr = malloc(sizeof(int) * deque->queSize);\n// \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\nint i;\nDoublyListNode *node;\nfor (i = 0, node = deque->front; i < deque->queSize; i++) {\narr[i] = node->val;\nnode = node->next;\n}\nprintArray(arr, deque->queSize);\nfree(arr);\n}\n
        linkedlist_deque.zig
        // \u53cc\u5411\u94fe\u8868\u8282\u70b9\nfn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = undefined,     // \u8282\u70b9\u503c\nnext: ?*Self = null,    // \u540e\u7ee7\u8282\u70b9\u6307\u9488\nprev: ?*Self = null,    // \u524d\u9a71\u8282\u70b9\u6307\u9488\n// Initialize a list node with specific value\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\nself.prev = null;\n}\n};\n}\n// \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\nfn LinkedListDeque(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nfront: ?*ListNode(T) = null,                    // \u5934\u8282\u70b9 front\nrear: ?*ListNode(T) = null,                     // \u5c3e\u8282\u70b9 rear\nque_size: usize = 0,                             // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.front = null;\nself.rear = null;\nself.que_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.que_size;\n}\n// \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u5165\u961f\u64cd\u4f5c\npub fn push(self: *Self, num: T, is_front: bool) !void {\nvar node = try self.mem_allocator.create(ListNode(T));\nnode.init(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (self.isEmpty()) {\nself.front = node;\nself.rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\n} else if (is_front) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nself.front.?.prev = node;\nnode.next = self.front;\nself.front = node;  // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nself.rear.?.next = node;\nnode.prev = self.rear;\nself.rear = node;   // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nself.que_size += 1;      // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n} // \u961f\u9996\u5165\u961f\npub fn pushFirst(self: *Self, num: T) !void {\ntry self.push(num, true);\n} // \u961f\u5c3e\u5165\u961f\npub fn pushLast(self: *Self, num: T) !void {\ntry self.push(num, false);\n} // \u51fa\u961f\u64cd\u4f5c\npub fn pop(self: *Self, is_front: bool) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nvar val: T = undefined;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (is_front) {\nval = self.front.?.val;     // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nvar fNext = self.front.?.next;\nif (fNext != null) {\nfNext.?.prev = null;\nself.front.?.next = null;\n}\nself.front = fNext;         // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = self.rear.?.val;      // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nvar rPrev = self.rear.?.prev;\nif (rPrev != null) {\nrPrev.?.next = null;\nself.rear.?.prev = null;\n}\nself.rear = rPrev;          // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nself.que_size -= 1;              // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n} // \u961f\u9996\u51fa\u961f\npub fn popFirst(self: *Self) T {\nreturn self.pop(true);\n} // \u961f\u5c3e\u51fa\u961f\npub fn popLast(self: *Self) T {\nreturn self.pop(false);\n} // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peekFirst(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn self.front.?.val;\n}  // \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\npub fn peekLast(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn self.rear.?.val;\n}\n// \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\npub fn toArray(self: *Self) ![]T {\nvar node = self.front;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[i] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/deque/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u5982\u56fe 5-9 \u6240\u793a\uff0c\u4e0e\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u961f\u5217\u7c7b\u4f3c\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u73af\u5f62\u6570\u7ec4\u6765\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u3002

        ArrayDequepushLast()pushFirst()popLast()popFirst()

        \u56fe 5-9 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u5728\u961f\u5217\u7684\u5b9e\u73b0\u57fa\u7840\u4e0a\uff0c\u4ec5\u9700\u589e\u52a0\u201c\u961f\u9996\u5165\u961f\u201d\u548c\u201c\u961f\u5c3e\u51fa\u961f\u201d\u7684\u65b9\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_deque.py
        class ArrayDeque:\n\"\"\"\u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\ndef __init__(self, capacity: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._nums: list[int] = [0] * capacity\nself._front: int = 0\nself._size: int = 0\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\nreturn len(self._nums)\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._size == 0\ndef index(self, i: int) -> int:\n\"\"\"\u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15\"\"\"\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n# \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n# \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + self.capacity()) % self.capacity()\ndef push_first(self, num: int):\n\"\"\"\u961f\u9996\u5165\u961f\"\"\"\nif self._size == self.capacity():\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n# \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nself._front = self.index(self._front - 1)\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nself._nums[self._front] = num\nself._size += 1\ndef push_last(self, num: int):\n\"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\nif self._size == self.capacity():\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n# \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nrear = self.index(self._front + self._size)\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself._nums[rear] = num\nself._size += 1\ndef pop_first(self) -> int:\n\"\"\"\u961f\u9996\u51fa\u961f\"\"\"\nnum = self.peek_first()\n# \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nself._front = self.index(self._front + 1)\nself._size -= 1\nreturn num\ndef pop_last(self) -> int:\n\"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\nnum = self.peek_last()\nself._size -= 1\nreturn num\ndef peek_first(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._nums[self._front]\ndef peek_last(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n# \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlast = self.index(self._front + self._size - 1)\nreturn self._nums[last]\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\n# \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nres = []\nfor i in range(self._size):\nres.append(self._nums[self.index(self._front + i)])\nreturn res\n
        array_deque.cpp
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate:\nvector<int> nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;        // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;      // \u53cc\u5411\u961f\u5217\u957f\u5ea6\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayDeque(int capacity) {\nnums.resize(capacity);\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn nums.size();\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int num) {\nif (queSize == capacity()) {\ncout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int num) {\nif (queSize == capacity()) {\ncout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nint num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nint num = peekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> res(queSize);\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[index(j)];\n}\nreturn res;\n}\n};\n
        array_deque.java
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate int[] nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayDeque(int capacity) {\nthis.nums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\npublic int capacity() {\nreturn nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nprivate int index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npublic void pushFirst(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void pushLast(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int popFirst() {\nint num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int popLast() {\nint num = peekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peekFirst() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int peekLast() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.cs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nint[] nums;  // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayDeque(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint Capacity() {\nreturn nums.Length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint Index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + Capacity()) % Capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npublic void PushFirst(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = Index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void PushLast(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = Index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int PopFirst() {\nint num = PeekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = Index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int PopLast() {\nint num = PeekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int PeekFirst() {\nif (IsEmpty()) {\nthrow new InvalidOperationException();\n}\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int PeekLast() {\nif (IsEmpty()) {\nthrow new InvalidOperationException();\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = Index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[Index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.go
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype arrayDeque struct {\nnums        []int // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize     int   // \u53cc\u5411\u961f\u5217\u957f\u5ea6\nqueCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayDeque(queCapacity int) *arrayDeque {\nreturn &arrayDeque{\nnums:        make([]int, queCapacity),\nqueCapacity: queCapacity,\nfront:       0,\nqueSize:     0,\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayDeque) size() int {\nreturn q.queSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayDeque) isEmpty() bool {\nreturn q.queSize == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nfunc (q *arrayDeque) index(i int) int {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + q.queCapacity) % q.queCapacity\n}\n/* \u961f\u9996\u5165\u961f */\nfunc (q *arrayDeque) pushFirst(num int) {\nif q.queSize == q.queCapacity {\nfmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nq.front = q.index(q.front - 1)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nq.nums[q.front] = num\nq.queSize++\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc (q *arrayDeque) pushLast(num int) {\nif q.queSize == q.queCapacity {\nfmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nrear := q.index(q.front + q.queSize)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nq.nums[rear] = num\nq.queSize++\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc (q *arrayDeque) popFirst() any {\nnum := q.peekFirst()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nq.front = q.index(q.front + 1)\nq.queSize--\nreturn num\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc (q *arrayDeque) popLast() any {\nnum := q.peekLast()\nq.queSize--\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayDeque) peekFirst() any {\nif q.isEmpty() {\nreturn nil\n}\nreturn q.nums[q.front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (q *arrayDeque) peekLast() any {\nif q.isEmpty() {\nreturn nil\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlast := q.index(q.front + q.queSize - 1)\nreturn q.nums[last]\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayDeque) toSlice() []int {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nres := make([]int, q.queSize)\nfor i, j := 0, q.front; i < q.queSize; i++ {\nres[i] = q.nums[q.index(j)]\nj++\n}\nreturn res\n}\n
        array_deque.swift
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate var front: Int // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate var queSize: Int // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(capacity: Int) {\nnums = Array(repeating: 0, count: capacity)\nfront = 0\nqueSize = 0\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nfunc capacity() -> Int {\nnums.count\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nprivate func index(i: Int) -> Int {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\n(i + capacity()) % capacity()\n}\n/* \u961f\u9996\u5165\u961f */\nfunc pushFirst(num: Int) {\nif size() == capacity() {\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(i: front - 1)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num\nqueSize += 1\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc pushLast(num: Int) {\nif size() == capacity() {\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nlet rear = index(i: front + size())\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num\nqueSize += 1\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc popFirst() -> Int {\nlet num = peekFirst()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(i: front + 1)\nqueSize -= 1\nreturn num\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc popLast() -> Int {\nlet num = peekLast()\nqueSize -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peekFirst() -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn nums[front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc peekLast() -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlet last = index(i: front + size() - 1)\nreturn nums[last]\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfunc toArray() -> [Int] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = Array(repeating: 0, count: size())\nfor (i, j) in sequence(first: (0, front), next: { $0 < self.size() - 1 ? ($0 + 1, $1 + 1) : nil }) {\nres[i] = nums[index(i: j)]\n}\nreturn res\n}\n}\n
        array_deque.js
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n#nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n#front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n#queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(capacity) {\nthis.#nums = new Array(capacity);\nthis.#front = 0;\nthis.#queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\ncapacity() {\nreturn this.#nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nindex(i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + this.capacity()) % this.capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npushFirst(num) {\nif (this.#queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nthis.#front = this.index(this.#front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nthis.#nums[this.#front] = num;\nthis.#queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npushLast(num) {\nif (this.#queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nconst rear = this.index(this.#front + this.#queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.#nums[rear] = num;\nthis.#queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npopFirst() {\nconst num = this.peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nthis.#front = this.index(this.#front + 1);\nthis.#queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npopLast() {\nconst num = this.peekLast();\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst() {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\nreturn this.#nums[this.#front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast() {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nconst last = this.index(this.#front + this.#queSize - 1);\nreturn this.#nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\ntoArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst res = [];\nfor (let i = 0, j = this.#front; i < this.#queSize; i++, j++) {\nres[i] = this.#nums[this.index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.ts
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate queSize: number; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(capacity: number) {\nthis.nums = new Array(capacity);\nthis.front = 0;\nthis.queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\ncapacity(): number {\nreturn this.nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nindex(i: number): number {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + this.capacity()) % this.capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npushFirst(num: number): void {\nif (this.queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nthis.front = this.index(this.front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nthis.nums[this.front] = num;\nthis.queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npushLast(num: number): void {\nif (this.queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nconst rear: number = this.index(this.front + this.queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.nums[rear] = num;\nthis.queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npopFirst(): number {\nconst num: number = this.peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nthis.front = this.index(this.front + 1);\nthis.queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npopLast(): number {\nconst num: number = this.peekLast();\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst(): number {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\nreturn this.nums[this.front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast(): number {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nconst last = this.index(this.front + this.queSize - 1);\nreturn this.nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\ntoArray(): number[] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst res: number[] = [];\nfor (let i = 0, j = this.front; i < this.queSize; i++, j++) {\nres[i] = this.nums[this.index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.dart
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nlate List<int> _nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nlate int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nlate int _queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayDeque(int capacity) {\nthis._nums = List.filled(capacity, 0);\nthis._front = this._queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn _nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int _num) {\nif (_queSize == capacity()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 _front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n_front = index(_front - 1);\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u9996\n_nums[_front] = _num;\n_queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int _num) {\nif (_queSize == capacity()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(_front + _queSize);\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n_nums[rear] = _num;\n_queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nint _num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n_front = index(_front + 1);\n_queSize--;\nreturn _num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nint _num = peekLast();\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n}\nreturn _nums[_front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(_front + _queSize - 1);\nreturn _nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nList<int> toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nList<int> res = List.filled(_queSize, 0);\nfor (int i = 0, j = _front; i < _queSize; i++, j++) {\nres[i] = _nums[index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.rs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nstruct ArrayDeque {\nnums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront: usize,       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nque_size: usize,    // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n}\nimpl ArrayDeque {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(capacity: usize) -> Self {\nSelf {\nnums: vec![0; capacity],\nfront: 0,\nque_size: 0,\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\npub fn capacity(&self) -> usize {\nself.nums.len()\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nself.que_size\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nself.que_size == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nfn index(&self, i: i32) -> usize {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn ((i + self.capacity() as i32) % self.capacity() as i32) as usize;\n}\n/* \u961f\u9996\u5165\u961f */\npub fn push_first(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nself.front = self.index(self.front as i32 - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nself.nums[self.front] = num;\nself.que_size += 1;\n}\n/* \u961f\u5c3e\u5165\u961f */\npub fn push_last(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nlet rear = self.index(self.front as i32 + self.que_size as i32);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself.nums[rear] = num;\nself.que_size += 1;\n}\n/* \u961f\u9996\u51fa\u961f */\nfn pop_first(&mut self) -> i32 {\nlet num = self.peek_first();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nself.front = self.index(self.front as i32 + 1);\nself.que_size -= 1;\nnum\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfn pop_last(&mut self) -> i32 {\nlet num = self.peek_last();\nself.que_size -= 1;\nnum\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfn peek_first(&self) -> i32 {\nif self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\nself.nums[self.front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfn peek_last(&self) -> i32 {\nif self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlet last = self.index(self.front as i32 + self.que_size as i32 - 1);\nself.nums[last]\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfn to_array(&self) -> Vec<i32> {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nlet mut res = vec![0; self.que_size];\nlet mut j = self.front;\nfor i in 0..self.que_size {\nres[i] = self.nums[self.index(j as i32)];\nj += 1;\n}\nres\n}\n}\n
        array_deque.c
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayDeque;\n/* \u6784\u9020\u51fd\u6570 */\nArrayDeque *newArrayDeque(int capacity) {\nArrayDeque *deque = (ArrayDeque *)malloc(sizeof(ArrayDeque));\n// \u521d\u59cb\u5316\u6570\u7ec4\ndeque->queCapacity = capacity;\ndeque->nums = (int *)malloc(sizeof(int) * deque->queCapacity);\ndeque->front = deque->queSize = 0;\nreturn deque;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayDeque(ArrayDeque *deque) {\nfree(deque->nums);\nfree(deque);\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayDeque *deque) {\nreturn deque->queCapacity;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayDeque *deque) {\nreturn deque->queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayDeque *deque) {\nreturn deque->queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint dequeIndex(ArrayDeque *deque, int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn ((i + capacity(deque)) % capacity(deque));\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(ArrayDeque *deque, int num) {\nif (deque->queSize == capacity(deque)) {\nprintf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u56de\u5230\u5c3e\u90e8\ndeque->front = dequeIndex(deque, deque->front - 1);\n// \u5c06 num \u6dfb\u52a0\u5230\u961f\u9996\ndeque->nums[deque->front] = num;\ndeque->queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(ArrayDeque *deque, int num) {\nif (deque->queSize == capacity(deque)) {\nprintf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = dequeIndex(deque, deque->front + deque->queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque->nums[rear] = num;\ndeque->queSize++;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(ArrayDeque *deque) {\n// \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\nassert(empty(deque) == 0);\nreturn deque->nums[deque->front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(ArrayDeque *deque) {\n// \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\nassert(empty(deque) == 0);\nint last = dequeIndex(deque, deque->front + deque->queSize - 1);\nreturn deque->nums[last];\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(ArrayDeque *deque) {\nint num = peekFirst(deque);\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\ndeque->front = dequeIndex(deque, deque->front + 1);\ndeque->queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(ArrayDeque *deque) {\nint num = peekLast(deque);\ndeque->queSize--;\nreturn num;\n}\n
        array_deque.zig
        [class]{ArrayDeque}-[func]{}\n
        "},{"location":"chapter_stack_and_queue/deque/#533","title":"5.3.3 \u00a0 \u53cc\u5411\u961f\u5217\u5e94\u7528","text":"

        \u53cc\u5411\u961f\u5217\u517c\u5177\u6808\u4e0e\u961f\u5217\u7684\u903b\u8f91\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e24\u8005\u7684\u6240\u6709\u5e94\u7528\u573a\u666f\uff0c\u540c\u65f6\u63d0\u4f9b\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\u3002

        \u6211\u4eec\u77e5\u9053\uff0c\u8f6f\u4ef6\u7684\u201c\u64a4\u9500\u201d\u529f\u80fd\u901a\u5e38\u4f7f\u7528\u6808\u6765\u5b9e\u73b0\uff1a\u7cfb\u7edf\u5c06\u6bcf\u6b21\u66f4\u6539\u64cd\u4f5c push \u5230\u6808\u4e2d\uff0c\u7136\u540e\u901a\u8fc7 pop \u5b9e\u73b0\u64a4\u9500\u3002\u7136\u800c\uff0c\u8003\u8651\u5230\u7cfb\u7edf\u8d44\u6e90\u7684\u9650\u5236\uff0c\u8f6f\u4ef6\u901a\u5e38\u4f1a\u9650\u5236\u64a4\u9500\u7684\u6b65\u6570\uff08\u4f8b\u5982\u4ec5\u5141\u8bb8\u4fdd\u5b58 \\(50\\) \u6b65\uff09\u3002\u5f53\u6808\u7684\u957f\u5ea6\u8d85\u8fc7 \\(50\\) \u65f6\uff0c\u8f6f\u4ef6\u9700\u8981\u5728\u6808\u5e95\uff08\u961f\u9996\uff09\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002\u4f46\u6808\u65e0\u6cd5\u5b9e\u73b0\u8be5\u529f\u80fd\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u4f7f\u7528\u53cc\u5411\u961f\u5217\u6765\u66ff\u4ee3\u6808\u3002\u8bf7\u6ce8\u610f\uff0c\u201c\u64a4\u9500\u201d\u7684\u6838\u5fc3\u903b\u8f91\u4ecd\u7136\u9075\u5faa\u6808\u7684\u5148\u5165\u540e\u51fa\u539f\u5219\uff0c\u53ea\u662f\u53cc\u5411\u961f\u5217\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u5b9e\u73b0\u4e00\u4e9b\u989d\u5916\u903b\u8f91\u3002

        "},{"location":"chapter_stack_and_queue/queue/","title":"5.2 \u00a0 \u961f\u5217","text":"

        \u300c\u961f\u5217 queue\u300d\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u5148\u51fa\u89c4\u5219\u7684\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002\u987e\u540d\u601d\u4e49\uff0c\u961f\u5217\u6a21\u62df\u4e86\u6392\u961f\u73b0\u8c61\uff0c\u5373\u65b0\u6765\u7684\u4eba\u4e0d\u65ad\u52a0\u5165\u961f\u5217\u5c3e\u90e8\uff0c\u800c\u4f4d\u4e8e\u961f\u5217\u5934\u90e8\u7684\u4eba\u9010\u4e2a\u79bb\u5f00\u3002

        \u5982\u56fe 5-4 \u6240\u793a\uff0c\u6211\u4eec\u5c06\u961f\u5217\u5934\u90e8\u79f0\u4e3a\u201c\u961f\u9996\u201d\uff0c\u5c3e\u90e8\u79f0\u4e3a\u201c\u961f\u5c3e\u201d\uff0c\u5c06\u628a\u5143\u7d20\u52a0\u5165\u961f\u5c3e\u7684\u64cd\u4f5c\u79f0\u4e3a\u201c\u5165\u961f\u201d\uff0c\u5220\u9664\u961f\u9996\u5143\u7d20\u7684\u64cd\u4f5c\u79f0\u4e3a\u201c\u51fa\u961f\u201d\u3002

        \u56fe 5-4 \u00a0 \u961f\u5217\u7684\u5148\u5165\u5148\u51fa\u89c4\u5219

        "},{"location":"chapter_stack_and_queue/queue/#521","title":"5.2.1 \u00a0 \u961f\u5217\u5e38\u7528\u64cd\u4f5c","text":"

        \u961f\u5217\u7684\u5e38\u89c1\u64cd\u4f5c\u5982\u8868 5-2 \u6240\u793a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u7684\u65b9\u6cd5\u540d\u79f0\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u6211\u4eec\u5728\u6b64\u91c7\u7528\u4e0e\u6808\u76f8\u540c\u7684\u65b9\u6cd5\u547d\u540d\u3002

        \u8868 5-2 \u00a0 \u961f\u5217\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u961f\uff0c\u5373\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u5c3e \\(O(1)\\) pop() \u961f\u9996\u5143\u7d20\u51fa\u961f \\(O(1)\\) peek() \u8bbf\u95ee\u961f\u9996\u5143\u7d20 \\(O(1)\\)

        \u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u4e2d\u73b0\u6210\u7684\u961f\u5217\u7c7b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig queue.py
        from collections import deque\n# \u521d\u59cb\u5316\u961f\u5217\n# \u5728 Python \u4e2d\uff0c\u6211\u4eec\u4e00\u822c\u5c06\u53cc\u5411\u961f\u5217\u7c7b deque \u5f53\u4f5c\u961f\u5217\u4f7f\u7528\n# \u867d\u7136 queue.Queue() \u662f\u7eaf\u6b63\u7684\u961f\u5217\u7c7b\uff0c\u4f46\u4e0d\u592a\u597d\u7528\uff0c\u56e0\u6b64\u4e0d\u63a8\u8350\nque: deque[int] = deque()\n# \u5143\u7d20\u5165\u961f\nque.append(1)\nque.append(3)\nque.append(2)\nque.append(5)\nque.append(4)\n# \u8bbf\u95ee\u961f\u9996\u5143\u7d20\nfront: int = que[0];\n# \u5143\u7d20\u51fa\u961f\npop: int = que.popleft()\n# \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(que)\n# \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(que) == 0\n
        queue.cpp
        /* \u521d\u59cb\u5316\u961f\u5217 */\nqueue<int> queue;\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint front = queue.front();\n/* \u5143\u7d20\u51fa\u961f */\nqueue.pop();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty = queue.empty();\n
        queue.java
        /* \u521d\u59cb\u5316\u961f\u5217 */\nQueue<Integer> queue = new LinkedList<>();\n/* \u5143\u7d20\u5165\u961f */\nqueue.offer(1);\nqueue.offer(3);\nqueue.offer(2);\nqueue.offer(5);\nqueue.offer(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.peek();\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.poll();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = queue.isEmpty();\n
        queue.cs
        /* \u521d\u59cb\u5316\u961f\u5217 */\nQueue<int> queue = new();\n/* \u5143\u7d20\u5165\u961f */\nqueue.Enqueue(1);\nqueue.Enqueue(3);\nqueue.Enqueue(2);\nqueue.Enqueue(5);\nqueue.Enqueue(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.Peek();\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.Dequeue();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.Count;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = queue.Count == 0;\n
        queue_test.go
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// \u5728 Go \u4e2d\uff0c\u5c06 list \u4f5c\u4e3a\u961f\u5217\u6765\u4f7f\u7528\nqueue := list.New()\n/* \u5143\u7d20\u5165\u961f */\nqueue.PushBack(1)\nqueue.PushBack(3)\nqueue.PushBack(2)\nqueue.PushBack(5)\nqueue.PushBack(4)\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek := queue.Front()\n/* \u5143\u7d20\u51fa\u961f */\npop := queue.Front()\nqueue.Remove(pop)\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nsize := queue.Len()\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty := queue.Len() == 0\n
        queue.swift
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528\nvar queue: [Int] = []\n/* \u5143\u7d20\u5165\u961f */\nqueue.append(1)\nqueue.append(3)\nqueue.append(2)\nqueue.append(5)\nqueue.append(4)\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nlet peek = queue.first!\n/* \u5143\u7d20\u51fa\u961f */\n// \u7531\u4e8e\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 removeFirst \u7684\u590d\u6742\u5ea6\u4e3a O(n)\nlet pool = queue.removeFirst()\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = queue.count\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = queue.isEmpty\n
        queue.js
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// JavaScript \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528\nconst queue = [];\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n/* \u5143\u7d20\u51fa\u961f */\n// \u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 shift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst pop = queue.shift();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst empty = queue.length === 0;\n
        queue.ts
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// TypeScript \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528 \nconst queue: number[] = [];\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n/* \u5143\u7d20\u51fa\u961f */\n// \u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 shift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst pop = queue.shift();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst empty = queue.length === 0;\n
        queue.dart
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// \u5728 Dart \u4e2d\uff0c\u961f\u5217\u7c7b Qeque \u662f\u53cc\u5411\u961f\u5217\uff0c\u4e5f\u53ef\u4f5c\u4e3a\u961f\u5217\u4f7f\u7528\nQueue<int> queue = Queue();\n/* \u5143\u7d20\u5165\u961f */\nqueue.add(1);\nqueue.add(3);\nqueue.add(2);\nqueue.add(5);\nqueue.add(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.first;\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.removeFirst();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = queue.isEmpty;\n
        queue.rs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Rust \u4e2d\u4f7f\u7528\u53cc\u5411\u961f\u5217\u4f5c\u4e3a\u666e\u901a\u961f\u5217\u6765\u4f7f\u7528\nlet mut deque: VecDeque<u32> = VecDeque::new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(1);\ndeque.push_back(3);\ndeque.push_back(2);\ndeque.push_back(5);\ndeque.push_back(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nif let Some(front) = deque.front() {\n}\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop) = deque.pop_front() {\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = deque.is_empty();\n
        queue.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u961f\u5217\n
        queue.zig
        \n
        "},{"location":"chapter_stack_and_queue/queue/#522","title":"5.2.2 \u00a0 \u961f\u5217\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u961f\u5217\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u5728\u4e00\u7aef\u6dfb\u52a0\u5143\u7d20\uff0c\u5e76\u5728\u53e6\u4e00\u7aef\u5220\u9664\u5143\u7d20\u3002\u94fe\u8868\u548c\u6570\u7ec4\u90fd\u7b26\u5408\u8981\u6c42\u3002

        "},{"location":"chapter_stack_and_queue/queue/#1","title":"1. \u00a0 \u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u5982\u56fe 5-5 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u94fe\u8868\u7684\u201c\u5934\u8282\u70b9\u201d\u548c\u201c\u5c3e\u8282\u70b9\u201d\u5206\u522b\u89c6\u4e3a\u201c\u961f\u9996\u201d\u548c\u201c\u961f\u5c3e\u201d\uff0c\u89c4\u5b9a\u961f\u5c3e\u4ec5\u53ef\u6dfb\u52a0\u8282\u70b9\uff0c\u961f\u9996\u4ec5\u53ef\u5220\u9664\u8282\u70b9\u3002

        LinkedListQueuepush()pop()

        \u56fe 5-5 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u4ee5\u4e0b\u662f\u7528\u94fe\u8868\u5b9e\u73b0\u961f\u5217\u7684\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_queue.py
        class LinkedListQueue:\n\"\"\"\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._front: ListNode | None = None  # \u5934\u8282\u70b9 front\nself._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\nself._size: int = 0\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn not self._front\ndef push(self, num: int):\n\"\"\"\u5165\u961f\"\"\"\n# \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nnode = ListNode(num)\n# \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif self._front is None:\nself._front = node\nself._rear = node\n# \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse:\nself._rear.next = node\nself._rear = node\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u961f\"\"\"\nnum = self.peek()\n# \u5220\u9664\u5934\u8282\u70b9\nself._front = self._front.next\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\nreturn self._front.val\ndef to_list(self) -> list[int]:\n\"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nqueue = []\ntemp = self._front\nwhile temp:\nqueue.append(temp.val)\ntemp = temp.next\nreturn queue\n
        linkedlist_queue.cpp
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate:\nListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize;\npublic:\nLinkedListQueue() {\nfront = nullptr;\nrear = nullptr;\nqueSize = 0;\n}\n~LinkedListQueue() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nfreeMemoryLinkedList(front);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode *node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == nullptr) {\nfront = node;\nrear = node;\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nrear->next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\nvoid pop() {\nint num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\nListNode *tmp = front;\nfront = front->next;\n// \u91ca\u653e\u5185\u5b58\ndelete tmp;\nqueSize--;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (size() == 0)\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn front->val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\nvector<int> toVector() {\nListNode *node = front;\nvector<int> res(size());\nfor (int i = 0; i < res.size(); i++) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_queue.java
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nprivate int queSize = 0;\npublic LinkedListQueue() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f */\npublic void push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == null) {\nfront = node;\nrear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nrear.next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int pop() {\nint num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front.next;\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn front.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] toArray() {\nListNode node = front;\nint[] res = new int[size()];\nfor (int i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.cs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nListNode? front, rear;  // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear \nint queSize = 0;\npublic LinkedListQueue() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u961f */\npublic void Push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode node = new(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == null) {\nfront = node;\nrear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else if (rear != null) {\nrear.next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int Pop() {\nint num = Peek();\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front?.next;\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nif (front == null)\nreturn [];\nListNode? node = front;\nint[] res = new int[Size()];\nfor (int i = 0; i < res.Length; i++) {\nres[i] = node!.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.go
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntype linkedListQueue struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list \u6765\u5b9e\u73b0\u961f\u5217\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newLinkedListQueue() *linkedListQueue {\nreturn &linkedListQueue{\ndata: list.New(),\n}\n}\n/* \u5165\u961f */\nfunc (s *linkedListQueue) push(value any) {\ns.data.PushBack(value)\n}\n/* \u51fa\u961f */\nfunc (s *linkedListQueue) pop() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListQueue) peek() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\nreturn e.Value\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListQueue) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListQueue) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListQueue) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_queue.swift
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate var front: ListNode? // \u5934\u8282\u70b9\nprivate var rear: ListNode? // \u5c3e\u8282\u70b9\nprivate var _size = 0\ninit() {}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\n_size\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u961f */\nfunc push(num: Int) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nlet node = ListNode(x: num)\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif front == nil {\nfront = node\nrear = node\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nrear?.next = node\nrear = node\n}\n_size += 1\n}\n/* \u51fa\u961f */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front?.next\n_size -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn front!.val\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nvar node = front\nvar res = Array(repeating: 0, count: size())\nfor i in res.indices {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_queue.js
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n#front; // \u5934\u8282\u70b9 #front\n#rear; // \u5c3e\u8282\u70b9 #rear\n#queSize = 0;\nconstructor() {\nthis.#front = null;\nthis.#rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.size === 0;\n}\n/* \u5165\u961f */\npush(num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nconst node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (!this.#front) {\nthis.#front = node;\nthis.#rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nthis.#rear.next = node;\nthis.#rear = node;\n}\nthis.#queSize++;\n}\n/* \u51fa\u961f */\npop() {\nconst num = this.peek();\n// \u5220\u9664\u5934\u8282\u70b9\nthis.#front = this.#front.next;\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek() {\nif (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.#front.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray() {\nlet node = this.#front;\nconst res = new Array(this.size);\nfor (let i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.ts
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate front: ListNode | null; // \u5934\u8282\u70b9 front\nprivate rear: ListNode | null; // \u5c3e\u8282\u70b9 rear\nprivate queSize: number = 0;\nconstructor() {\nthis.front = null;\nthis.rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.size === 0;\n}\n/* \u5165\u961f */\npush(num: number): void {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nconst node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (!this.front) {\nthis.front = node;\nthis.rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nthis.rear!.next = node;\nthis.rear = node;\n}\nthis.queSize++;\n}\n/* \u51fa\u961f */\npop(): number {\nconst num = this.peek();\nif (!this.front) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n// \u5220\u9664\u5934\u8282\u70b9\nthis.front = this.front.next;\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek(): number {\nif (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray(): number[] {\nlet node = this.front;\nconst res = new Array<number>(this.size);\nfor (let i = 0; i < res.length; i++) {\nres[i] = node!.val;\nnode = node!.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.dart
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nListNode? _front; // \u5934\u8282\u70b9 _front\nListNode? _rear; // \u5c3e\u8282\u70b9 _rear\nint _queSize = 0; // \u961f\u5217\u957f\u5ea6\nLinkedListQueue() {\n_front = null;\n_rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int _num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 _num\nfinal node = ListNode(_num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (_front == null) {\n_front = node;\n_rear = node;\n} else {\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n_rear!.next = node;\n_rear = node;\n}\n_queSize++;\n}\n/* \u51fa\u961f */\nint pop() {\nfinal int _num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\n_front = _front!.next;\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (_queSize == 0) {\nthrow Exception('\u961f\u5217\u4e3a\u7a7a');\n}\nreturn _front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nList<int> toArray() {\nListNode? node = _front;\nfinal List<int> queue = [];\nwhile (node != null) {\nqueue.add(node.val);\nnode = node.next;\n}\nreturn queue;\n}\n}\n
        linkedlist_queue.rs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListQueue<T> {\nfront: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\nrear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \nque_size: usize,                            // \u961f\u5217\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListQueue<T> {\npub fn new() -> Self {\nSelf {\nfront: None,\nrear: None,\nque_size: 0, }\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.que_size;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u961f */\npub fn push(&mut self, num: T) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nlet new_rear = ListNode::new(num);\nmatch self.rear.take() {\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nSome(old_rear) => {\nold_rear.borrow_mut().next = Some(new_rear.clone());\nself.rear = Some(new_rear);\n}\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nNone => {\nself.front = Some(new_rear.clone());\nself.rear = Some(new_rear);\n}\n}\nself.que_size += 1;\n}\n/* \u51fa\u961f */\npub fn pop(&mut self) -> Option<T> {\nself.front.take().map(|old_front| {\nmatch old_front.borrow_mut().next.take() {\nSome(new_front) => {\nself.front = Some(new_front);\n}\nNone => {\nself.rear.take();\n}\n}\nself.que_size -= 1;\nRc::try_unwrap(old_front).ok().unwrap().into_inner().val\n})\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.front.as_ref()\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.insert(0, node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_queue.c
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\nListNode *front, *rear;\nint queSize;\n} LinkedListQueue;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListQueue *newLinkedListQueue() {\nLinkedListQueue *queue = (LinkedListQueue *)malloc(sizeof(LinkedListQueue));\nqueue->front = NULL;\nqueue->rear = NULL;\nqueue->queSize = 0;\nreturn queue;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListQueue(LinkedListQueue *queue) {\n// \u91ca\u653e\u6240\u6709\u8282\u70b9\nfor (int i = 0; i < queue->queSize && queue->front != NULL; i++) {\nListNode *tmp = queue->front;\nqueue->front = queue->front->next;\nfree(tmp);\n}\n// \u91ca\u653e queue \u7ed3\u6784\u4f53\nfree(queue);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListQueue *queue) {\nreturn queue->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListQueue *queue) {\nreturn (size(queue) == 0);\n}\n/* \u5165\u961f */\nvoid push(LinkedListQueue *queue, int num) {\n// \u5c3e\u8282\u70b9\u5904\u6dfb\u52a0 node\nListNode *node = newListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (queue->front == NULL) {\nqueue->front = node;\nqueue->rear = node;\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nqueue->rear->next = node;\nqueue->rear = node;\n}\nqueue->queSize++;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(LinkedListQueue *queue) {\nassert(size(queue) && queue->front);\nreturn queue->front->val;\n}\n/* \u51fa\u961f */\nvoid pop(LinkedListQueue *queue) {\nint num = peek(queue);\nListNode *tmp = queue->front;\nqueue->front = queue->front->next;\nfree(tmp);\nqueue->queSize--;\n}\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListQueue(LinkedListQueue *queue) {\nint *arr = malloc(sizeof(int) * queue->queSize);\n// \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\nint i;\nListNode *node;\nfor (i = 0, node = queue->front; i < queue->queSize; i++) {\narr[i] = node->val;\nnode = node->next;\n}\nprintArray(arr, queue->queSize);\nfree(arr);\n}\n
        linkedlist_queue.zig
        // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\nfn LinkedListQueue(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nfront: ?*inc.ListNode(T) = null,                // \u5934\u8282\u70b9 front\nrear: ?*inc.ListNode(T) = null,                 // \u5c3e\u8282\u70b9 rear\nque_size: usize = 0,                            // \u961f\u5217\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.front = null;\nself.rear = null;\nself.que_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.que_size;\n}\n// \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.size() == 0) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn self.front.?.val;\n}  // \u5165\u961f\npub fn push(self: *Self, num: T) !void {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nvar node = try self.mem_allocator.create(inc.ListNode(T));\nnode.init(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (self.front == null) {\nself.front = node;\nself.rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nself.rear.?.next = node;\nself.rear = node;\n}\nself.que_size += 1;\n} // \u51fa\u961f\npub fn pop(self: *Self) T {\nvar num = self.peek();\n// \u5220\u9664\u5934\u8282\u70b9\nself.front = self.front.?.next;\nself.que_size -= 1;\nreturn num;\n} // \u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\nvar node = self.front;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[i] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/queue/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u5728\u6570\u7ec4\u4e2d\u5220\u9664\u9996\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4f1a\u5bfc\u81f4\u51fa\u961f\u64cd\u4f5c\u6548\u7387\u8f83\u4f4e\u3002\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u5de7\u5999\u65b9\u6cd5\u6765\u907f\u514d\u8fd9\u4e2a\u95ee\u9898\u3002

        \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf front \u6307\u5411\u961f\u9996\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5e76\u7ef4\u62a4\u4e00\u4e2a\u53d8\u91cf size \u7528\u4e8e\u8bb0\u5f55\u961f\u5217\u957f\u5ea6\u3002\u5b9a\u4e49 rear = front + size \uff0c\u8fd9\u4e2a\u516c\u5f0f\u8ba1\u7b97\u51fa\u7684 rear \u6307\u5411\u961f\u5c3e\u5143\u7d20\u4e4b\u540e\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u3002

        \u57fa\u4e8e\u6b64\u8bbe\u8ba1\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u5143\u7d20\u7684\u6709\u6548\u533a\u95f4\u4e3a [front, rear - 1]\uff0c\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u65b9\u6cd5\u5982\u56fe 5-6 \u6240\u793a\u3002

        • \u5165\u961f\u64cd\u4f5c\uff1a\u5c06\u8f93\u5165\u5143\u7d20\u8d4b\u503c\u7ed9 rear \u7d22\u5f15\u5904\uff0c\u5e76\u5c06 size \u589e\u52a0 1 \u3002
        • \u51fa\u961f\u64cd\u4f5c\uff1a\u53ea\u9700\u5c06 front \u589e\u52a0 1 \uff0c\u5e76\u5c06 size \u51cf\u5c11 1 \u3002

        \u53ef\u4ee5\u770b\u5230\uff0c\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u90fd\u53ea\u9700\u8fdb\u884c\u4e00\u6b21\u64cd\u4f5c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(1)\\) \u3002

        ArrayQueuepush()pop()

        \u56fe 5-6 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff1a\u5728\u4e0d\u65ad\u8fdb\u884c\u5165\u961f\u548c\u51fa\u961f\u7684\u8fc7\u7a0b\u4e2d\uff0cfront \u548c rear \u90fd\u5728\u5411\u53f3\u79fb\u52a8\uff0c\u5f53\u5b83\u4eec\u5230\u8fbe\u6570\u7ec4\u5c3e\u90e8\u65f6\u5c31\u65e0\u6cd5\u7ee7\u7eed\u79fb\u52a8\u4e86\u3002\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u89c6\u4e3a\u9996\u5c3e\u76f8\u63a5\u7684\u201c\u73af\u5f62\u6570\u7ec4\u201d\u3002

        \u5bf9\u4e8e\u73af\u5f62\u6570\u7ec4\uff0c\u6211\u4eec\u9700\u8981\u8ba9 front \u6216 rear \u5728\u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u76f4\u63a5\u56de\u5230\u6570\u7ec4\u5934\u90e8\u7ee7\u7eed\u904d\u5386\u3002\u8fd9\u79cd\u5468\u671f\u6027\u89c4\u5f8b\u53ef\u4ee5\u901a\u8fc7\u201c\u53d6\u4f59\u64cd\u4f5c\u201d\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_queue.py
        class ArrayQueue:\n\"\"\"\u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\"\"\"\ndef __init__(self, size: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._nums: list[int] = [0] * size  # \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nself._front: int = 0  # \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nself._size: int = 0  # \u961f\u5217\u957f\u5ea6\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\nreturn len(self._nums)\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._size == 0\ndef push(self, num: int):\n\"\"\"\u5165\u961f\"\"\"\nif self._size == self.capacity():\nraise IndexError(\"\u961f\u5217\u5df2\u6ee1\")\n# \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nrear: int = (self._front + self._size) % self.capacity()\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself._nums[rear] = num\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u961f\"\"\"\nnum: int = self.peek()\n# \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself._front = (self._front + 1) % self.capacity()\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\nreturn self._nums[self._front]\ndef to_list(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nres = [0] * self.size()\nj: int = self._front\nfor i in range(self.size()):\nres[i] = self._nums[(j % self.capacity())]\nj += 1\nreturn res\n
        array_queue.cpp
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate:\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u961f\u5217\u957f\u5ea6\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\npublic:\nArrayQueue(int capacity) {\n// \u521d\u59cb\u5316\u6570\u7ec4\nnums = new int[capacity];\nqueCapacity = capacity;\nfront = queSize = 0;\n}\n~ArrayQueue() {\ndelete[] nums;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn queCapacity;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f */\nvoid push(int num) {\nif (queSize == queCapacity) {\ncout << \"\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % queCapacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\nvoid pop() {\nint num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % queCapacity;\nqueSize--;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (isEmpty())\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn nums[front];\n}\n/* \u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> arr(queSize);\nfor (int i = 0, j = front; i < queSize; i++, j++) {\narr[i] = nums[j % queCapacity];\n}\nreturn arr;\n}\n};\n
        array_queue.java
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate int[] nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate int queSize; // \u961f\u5217\u957f\u5ea6\npublic ArrayQueue(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\npublic int capacity() {\nreturn nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\npublic void push(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % capacity();\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int pop() {\nint num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % capacity();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn nums[front];\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\npublic int[] toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[j % capacity()];\n}\nreturn res;\n}\n}\n
        array_queue.cs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nint[] nums;  // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize; // \u961f\u5217\u957f\u5ea6\npublic ArrayQueue(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint Capacity() {\nreturn nums.Length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\npublic void Push(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % Capacity();\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int Pop() {\nint num = Peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % Capacity();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn nums[front];\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[j % this.Capacity()];\n}\nreturn res;\n}\n}\n
        array_queue.go
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntype arrayQueue struct {\nnums        []int // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize     int   // \u961f\u5217\u957f\u5ea6\nqueCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayQueue(queCapacity int) *arrayQueue {\nreturn &arrayQueue{\nnums:        make([]int, queCapacity),\nqueCapacity: queCapacity,\nfront:       0,\nqueSize:     0,\n}\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayQueue) size() int {\nreturn q.queSize\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayQueue) isEmpty() bool {\nreturn q.queSize == 0\n}\n/* \u5165\u961f */\nfunc (q *arrayQueue) push(num int) {\n// \u5f53 rear == queCapacity \u8868\u793a\u961f\u5217\u5df2\u6ee1\nif q.queSize == q.queCapacity {\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nrear := (q.front + q.queSize) % q.queCapacity\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nq.nums[rear] = num\nq.queSize++\n}\n/* \u51fa\u961f */\nfunc (q *arrayQueue) pop() any {\nnum := q.peek()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nq.front = (q.front + 1) % q.queCapacity\nq.queSize--\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayQueue) peek() any {\nif q.isEmpty() {\nreturn nil\n}\nreturn q.nums[q.front]\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayQueue) toSlice() []int {\nrear := (q.front + q.queSize)\nif rear >= q.queCapacity {\nrear %= q.queCapacity\nreturn append(q.nums[q.front:], q.nums[:rear]...)\n}\nreturn q.nums[q.front:rear]\n}\n
        array_queue.swift
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate var front = 0 // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate var queSize = 0 // \u961f\u5217\u957f\u5ea6\ninit(capacity: Int) {\n// \u521d\u59cb\u5316\u6570\u7ec4\nnums = Array(repeating: 0, count: capacity)\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nfunc capacity() -> Int {\nnums.count\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nqueSize == 0\n}\n/* \u5165\u961f */\nfunc push(num: Int) {\nif size() == capacity() {\nprint(\"\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nlet rear = (front + queSize) % capacity()\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num\nqueSize += 1\n}\n/* \u51fa\u961f */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % capacity()\nqueSize -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn nums[front]\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\nfunc toArray() -> [Int] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = Array(repeating: 0, count: queSize)\nfor (i, j) in sequence(first: (0, front), next: { $0 < self.queSize - 1 ? ($0 + 1, $1 + 1) : nil }) {\nres[i] = nums[j % capacity()]\n}\nreturn res\n}\n}\n
        array_queue.js
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n#nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n#front = 0; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n#queSize = 0; // \u961f\u5217\u957f\u5ea6\nconstructor(capacity) {\nthis.#nums = new Array(capacity);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nget capacity() {\nreturn this.#nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u5165\u961f */\npush(num) {\nif (this.size === this.capacity) {\nconsole.log('\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nconst rear = (this.#front + this.size) % this.capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.#nums[rear] = num;\nthis.#queSize++;\n}\n/* \u51fa\u961f */\npop() {\nconst num = this.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nthis.#front = (this.#front + 1) % this.capacity;\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek() {\nif (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.#nums[this.#front];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(this.size);\nfor (let i = 0, j = this.#front; i < this.size; i++, j++) {\narr[i] = this.#nums[j % this.capacity];\n}\nreturn arr;\n}\n}\n
        array_queue.ts
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate queSize: number; // \u961f\u5217\u957f\u5ea6\nconstructor(capacity: number) {\nthis.nums = new Array(capacity);\nthis.front = this.queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nget capacity(): number {\nreturn this.nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u5165\u961f */\npush(num: number): void {\nif (this.size === this.capacity) {\nconsole.log('\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nconst rear = (this.front + this.queSize) % this.capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.nums[rear] = num;\nthis.queSize++;\n}\n/* \u51fa\u961f */\npop(): number {\nconst num = this.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nthis.front = (this.front + 1) % this.capacity;\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek(): number {\nif (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.nums[this.front];\n}\n/* \u8fd4\u56de Array */\ntoArray(): number[] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(this.size);\nfor (let i = 0, j = this.front; i < this.size; i++, j++) {\narr[i] = this.nums[j % this.capacity];\n}\nreturn arr;\n}\n}\n
        array_queue.dart
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nlate List<int> _nums; // \u7528\u4e8e\u50a8\u5b58\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nlate int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nlate int _queSize; // \u961f\u5217\u957f\u5ea6\nArrayQueue(int capacity) {\n_nums = List.filled(capacity, 0);\n_front = _queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capaCity() {\nreturn _nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int _num) {\nif (_queSize == capaCity()) {\nthrow Exception(\"\u961f\u5217\u5df2\u6ee1\");\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (_front + _queSize) % capaCity();\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n_nums[rear] = _num;\n_queSize++;\n}\n/* \u51fa\u961f */\nint pop() {\nint _num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n_front = (_front + 1) % capaCity();\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (isEmpty()) {\nthrow Exception(\"\u961f\u5217\u4e3a\u7a7a\");\n}\nreturn _nums[_front];\n}\n/* \u8fd4\u56de Array */\nList<int> toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nfinal List<int> res = List.filled(_queSize, 0);\nfor (int i = 0, j = _front; i < _queSize; i++, j++) {\nres[i] = _nums[j % capaCity()];\n}\nreturn res;\n}\n}\n
        array_queue.rs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nstruct ArrayQueue {\nnums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront: i32,         // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nque_size: i32,      // \u961f\u5217\u957f\u5ea6\nque_capacity: i32,  // \u961f\u5217\u5bb9\u91cf\n}\nimpl ArrayQueue {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(capacity: i32) -> ArrayQueue {\nArrayQueue {\nnums: vec![0; capacity as usize],\nfront: 0,\nque_size: 0,\nque_capacity: capacity,\n}\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nfn capacity(&self) -> i32 {\nself.que_capacity\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfn size(&self) -> i32 {\nself.que_size\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfn is_empty(&self) -> bool {\nself.que_size == 0\n}\n/* \u5165\u961f */\nfn push(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nlet rear = (self.front + self.que_size) % self.que_capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself.nums[rear as usize] = num;\nself.que_size += 1;\n}\n/* \u51fa\u961f */\nfn pop(&mut self) -> i32 {\nlet num = self.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself.front = (self.front + 1) % self.que_capacity;\nself.que_size -= 1;\nnum\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfn peek(&self) -> i32 {\nif self.is_empty() {\npanic!(\"index out of bounds\");\n}\nself.nums[self.front as usize]\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\nfn to_vector(&self) -> Vec<i32> {\nlet cap = self.que_capacity;\nlet mut j = self.front;\nlet mut arr = vec![0; self.que_size as usize];\nfor i in 0..self.que_size {\narr[i as usize] = self.nums[(j % cap) as usize];\nj += 1;\n}\narr\n}\n}\n
        array_queue.c
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayQueue;\n/* \u6784\u9020\u51fd\u6570 */\nArrayQueue *newArrayQueue(int capacity) {\nArrayQueue *queue = (ArrayQueue *)malloc(sizeof(ArrayQueue));\n// \u521d\u59cb\u5316\u6570\u7ec4\nqueue->queCapacity = capacity;\nqueue->nums = (int *)malloc(sizeof(int) * queue->queCapacity);\nqueue->front = queue->queSize = 0;\nreturn queue;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayQueue(ArrayQueue *queue) {\nfree(queue->nums);\nfree(queue);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayQueue *queue) {\nreturn queue->queCapacity;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayQueue *queue) {\nreturn queue->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayQueue *queue) {\nreturn queue->queSize == 0;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(ArrayQueue *queue) {\nassert(size(queue) != 0);\nreturn queue->nums[queue->front];\n}\n/* \u5165\u961f */\nvoid push(ArrayQueue *queue, int num) {\nif (size(queue) == capacity(queue)) {\nprintf(\"\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (queue->front + queue->queSize) % queue->queCapacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nqueue->nums[rear] = num;\nqueue->queSize++;\n}\n/* \u51fa\u961f */\nvoid pop(ArrayQueue *queue) {\nint num = peek(queue);\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nqueue->front = (queue->front + 1) % queue->queCapacity;\nqueue->queSize--;\n}\n
        array_queue.zig
        // \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\nfn ArrayQueue(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nnums: []T = undefined,                          // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4     \ncap: usize = 0,                                 // \u961f\u5217\u5bb9\u91cf\nfront: usize = 0,                               // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize: usize = 0,                             // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6570\u7ec4\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator, cap: usize) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.cap = cap;\nself.nums = try self.mem_allocator.alloc(T, self.cap);\n@memset(self.nums, @as(T, 0));\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\npub fn capacity(self: *Self) usize {\nreturn self.cap;\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.queSize;\n}\n// \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.queSize == 0;\n}\n// \u5165\u961f\npub fn push(self: *Self, num: T) !void {\nif (self.size() == self.capacity()) {\nstd.debug.print(\"\u961f\u5217\u5df2\u6ee1\\n\", .{});\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nvar rear = (self.front + self.queSize) % self.capacity();\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nself.nums[rear] = num;\nself.queSize += 1;\n} // \u51fa\u961f\npub fn pop(self: *Self) T {\nvar num = self.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself.front = (self.front + 1) % self.capacity();\nself.queSize -= 1;\nreturn num;\n} // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn self.nums[self.front];\n} // \u8fd4\u56de\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nvar j: usize = self.front;\nwhile (i < self.size()) : ({ i += 1; j += 1; }) {\nres[i] = self.nums[j % self.capacity()];\n}\nreturn res;\n}\n};\n}\n

        \u4ee5\u4e0a\u5b9e\u73b0\u7684\u961f\u5217\u4ecd\u7136\u5177\u6709\u5c40\u9650\u6027\uff1a\u5176\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002\u7136\u800c\uff0c\u8fd9\u4e2a\u95ee\u9898\u4e0d\u96be\u89e3\u51b3\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u66ff\u6362\u4e3a\u52a8\u6001\u6570\u7ec4\uff0c\u4ece\u800c\u5f15\u5165\u6269\u5bb9\u673a\u5236\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u5c1d\u8bd5\u81ea\u884c\u5b9e\u73b0\u3002

        \u4e24\u79cd\u5b9e\u73b0\u7684\u5bf9\u6bd4\u7ed3\u8bba\u4e0e\u6808\u4e00\u81f4\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

        "},{"location":"chapter_stack_and_queue/queue/#523","title":"5.2.3 \u00a0 \u961f\u5217\u5178\u578b\u5e94\u7528","text":"
        • \u6dd8\u5b9d\u8ba2\u5355\u3002\u8d2d\u7269\u8005\u4e0b\u5355\u540e\uff0c\u8ba2\u5355\u5c06\u52a0\u5165\u961f\u5217\u4e2d\uff0c\u7cfb\u7edf\u968f\u540e\u4f1a\u6839\u636e\u987a\u5e8f\u5904\u7406\u961f\u5217\u4e2d\u7684\u8ba2\u5355\u3002\u5728\u53cc\u5341\u4e00\u671f\u95f4\uff0c\u77ed\u65f6\u95f4\u5185\u4f1a\u4ea7\u751f\u6d77\u91cf\u8ba2\u5355\uff0c\u9ad8\u5e76\u53d1\u6210\u4e3a\u5de5\u7a0b\u5e08\u4eec\u9700\u8981\u91cd\u70b9\u653b\u514b\u7684\u95ee\u9898\u3002
        • \u5404\u7c7b\u5f85\u529e\u4e8b\u9879\u3002\u4efb\u4f55\u9700\u8981\u5b9e\u73b0\u201c\u5148\u6765\u540e\u5230\u201d\u529f\u80fd\u7684\u573a\u666f\uff0c\u4f8b\u5982\u6253\u5370\u673a\u7684\u4efb\u52a1\u961f\u5217\u3001\u9910\u5385\u7684\u51fa\u9910\u961f\u5217\u7b49\uff0c\u961f\u5217\u5728\u8fd9\u4e9b\u573a\u666f\u4e2d\u53ef\u4ee5\u6709\u6548\u5730\u7ef4\u62a4\u5904\u7406\u987a\u5e8f\u3002
        "},{"location":"chapter_stack_and_queue/stack/","title":"5.1 \u00a0 \u6808","text":"

        \u300c\u6808 stack\u300d\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u540e\u51fa\u7684\u903b\u8f91\u7684\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002

        \u6211\u4eec\u53ef\u4ee5\u5c06\u6808\u7c7b\u6bd4\u4e3a\u684c\u9762\u4e0a\u7684\u4e00\u645e\u76d8\u5b50\uff0c\u5982\u679c\u60f3\u53d6\u51fa\u5e95\u90e8\u7684\u76d8\u5b50\uff0c\u5219\u9700\u8981\u5148\u5c06\u4e0a\u9762\u7684\u76d8\u5b50\u4f9d\u6b21\u79fb\u8d70\u3002\u6211\u4eec\u5c06\u76d8\u5b50\u66ff\u6362\u4e3a\u5404\u79cd\u7c7b\u578b\u7684\u5143\u7d20\uff08\u5982\u6574\u6570\u3001\u5b57\u7b26\u3001\u5bf9\u8c61\u7b49\uff09\uff0c\u5c31\u5f97\u5230\u4e86\u6808\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u3002

        \u5982\u56fe 5-1 \u6240\u793a\uff0c\u6211\u4eec\u628a\u5806\u53e0\u5143\u7d20\u7684\u9876\u90e8\u79f0\u4e3a\u201c\u6808\u9876\u201d\uff0c\u5e95\u90e8\u79f0\u4e3a\u201c\u6808\u5e95\u201d\u3002\u5c06\u628a\u5143\u7d20\u6dfb\u52a0\u5230\u6808\u9876\u7684\u64cd\u4f5c\u53eb\u4f5c\u201c\u5165\u6808\u201d\uff0c\u5220\u9664\u6808\u9876\u5143\u7d20\u7684\u64cd\u4f5c\u53eb\u4f5c\u201c\u51fa\u6808\u201d\u3002

        \u56fe 5-1 \u00a0 \u6808\u7684\u5148\u5165\u540e\u51fa\u89c4\u5219

        "},{"location":"chapter_stack_and_queue/stack/#511","title":"5.1.1 \u00a0 \u6808\u5e38\u7528\u64cd\u4f5c","text":"

        \u6808\u7684\u5e38\u7528\u64cd\u4f5c\u5982\u8868 5-1 \u6240\u793a\uff0c\u5177\u4f53\u7684\u65b9\u6cd5\u540d\u9700\u8981\u6839\u636e\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002\u5728\u6b64\uff0c\u6211\u4eec\u4ee5\u5e38\u89c1\u7684 push()\u3001pop()\u3001peek() \u547d\u540d\u4e3a\u4f8b\u3002

        \u8868 5-1 \u00a0 \u6808\u7684\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5 \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u6808\uff08\u6dfb\u52a0\u81f3\u6808\u9876\uff09 \\(O(1)\\) pop() \u6808\u9876\u5143\u7d20\u51fa\u6808 \\(O(1)\\) peek() \u8bbf\u95ee\u6808\u9876\u5143\u7d20 \\(O(1)\\)

        \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u7684\u6808\u7c7b\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u8bed\u8a00\u53ef\u80fd\u6ca1\u6709\u4e13\u95e8\u63d0\u4f9b\u6808\u7c7b\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u5c06\u8be5\u8bed\u8a00\u7684\u201c\u6570\u7ec4\u201d\u6216\u201c\u94fe\u8868\u201d\u5f53\u4f5c\u6808\u6765\u4f7f\u7528\uff0c\u5e76\u5728\u7a0b\u5e8f\u903b\u8f91\u4e0a\u5ffd\u7565\u4e0e\u6808\u65e0\u5173\u7684\u64cd\u4f5c\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig stack.py
        # \u521d\u59cb\u5316\u6808\n# Python \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a List \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nstack: list[int] = []\n# \u5143\u7d20\u5165\u6808\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n# \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npeek: int = stack[-1]\n# \u5143\u7d20\u51fa\u6808\npop: int = stack.pop()\n# \u83b7\u53d6\u6808\u7684\u957f\u5ea6\nsize: int = len(stack)\n# \u5224\u65ad\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(stack) == 0\n
        stack.cpp
        /* \u521d\u59cb\u5316\u6808 */\nstack<int> stack;\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top = stack.top();\n/* \u5143\u7d20\u51fa\u6808 */\nstack.pop(); // \u65e0\u8fd4\u56de\u503c\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool empty = stack.empty();\n
        stack.java
        /* \u521d\u59cb\u5316\u6808 */\nStack<Integer> stack = new Stack<>();\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.peek();\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = stack.isEmpty();\n
        stack.cs
        /* \u521d\u59cb\u5316\u6808 */\nStack<int> stack = new();\n/* \u5143\u7d20\u5165\u6808 */\nstack.Push(1);\nstack.Push(3);\nstack.Push(2);\nstack.Push(5);\nstack.Push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.Peek();\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.Pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.Count;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = stack.Count == 0;\n
        stack_test.go
        /* \u521d\u59cb\u5316\u6808 */\n// \u5728 Go \u4e2d\uff0c\u63a8\u8350\u5c06 Slice \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nvar stack []int\n/* \u5143\u7d20\u5165\u6808 */\nstack = append(stack, 1)\nstack = append(stack, 3)\nstack = append(stack, 2)\nstack = append(stack, 5)\nstack = append(stack, 4)\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek := stack[len(stack)-1]\n/* \u5143\u7d20\u51fa\u6808 */\npop := stack[len(stack)-1]\nstack = stack[:len(stack)-1]\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nsize := len(stack)\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nisEmpty := len(stack) == 0\n
        stack.swift
        /* \u521d\u59cb\u5316\u6808 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nvar stack: [Int] = []\n/* \u5143\u7d20\u5165\u6808 */\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet peek = stack.last!\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.removeLast()\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.count\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = stack.isEmpty\n
        stack.js
        /* \u521d\u59cb\u5316\u6808 */\n// Javascript \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nconst stack = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length-1];\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nconst is_empty = stack.length === 0;\n
        stack.ts
        /* \u521d\u59cb\u5316\u6808 */\n// Typescript \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nconst stack: number[] = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length - 1];\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nconst is_empty = stack.length === 0;\n
        stack.dart
        /* \u521d\u59cb\u5316\u6808 */\n// Dart \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a List \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nList<int> stack = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.add(1);\nstack.add(3);\nstack.add(2);\nstack.add(5);\nstack.add(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.last;\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.removeLast();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = stack.isEmpty;\n
        stack.rs
        /* \u521d\u59cb\u5316\u6808 */\n// \u628a Vec \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nlet mut stack: Vec<i32> = Vec::new();\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet top = stack.last().unwrap();\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.pop().unwrap();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.len();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = stack.is_empty();\n
        stack.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u6808\n
        stack.zig
        \n
        "},{"location":"chapter_stack_and_queue/stack/#512","title":"5.1.2 \u00a0 \u6808\u7684\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u6df1\u5165\u4e86\u89e3\u6808\u7684\u8fd0\u884c\u673a\u5236\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u81ea\u5df1\u5b9e\u73b0\u4e00\u4e2a\u6808\u7c7b\u3002

        \u6808\u9075\u5faa\u5148\u5165\u540e\u51fa\u7684\u539f\u5219\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u80fd\u5728\u6808\u9876\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u3002\u7136\u800c\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u90fd\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\uff0c\u56e0\u6b64\u6808\u53ef\u4ee5\u89c6\u4e3a\u4e00\u79cd\u53d7\u9650\u5236\u7684\u6570\u7ec4\u6216\u94fe\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u201c\u5c4f\u853d\u201d\u6570\u7ec4\u6216\u94fe\u8868\u7684\u90e8\u5206\u65e0\u5173\u64cd\u4f5c\uff0c\u4f7f\u5176\u5bf9\u5916\u8868\u73b0\u7684\u903b\u8f91\u7b26\u5408\u6808\u7684\u7279\u6027\u3002

        "},{"location":"chapter_stack_and_queue/stack/#1","title":"1. \u00a0 \u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\u6808\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u94fe\u8868\u7684\u5934\u8282\u70b9\u89c6\u4e3a\u6808\u9876\uff0c\u5c3e\u8282\u70b9\u89c6\u4e3a\u6808\u5e95\u3002

        \u5982\u56fe 5-2 \u6240\u793a\uff0c\u5bf9\u4e8e\u5165\u6808\u64cd\u4f5c\uff0c\u6211\u4eec\u53ea\u9700\u5c06\u5143\u7d20\u63d2\u5165\u94fe\u8868\u5934\u90e8\uff0c\u8fd9\u79cd\u8282\u70b9\u63d2\u5165\u65b9\u6cd5\u88ab\u79f0\u4e3a\u201c\u5934\u63d2\u6cd5\u201d\u3002\u800c\u5bf9\u4e8e\u51fa\u6808\u64cd\u4f5c\uff0c\u53ea\u9700\u5c06\u5934\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\u5373\u53ef\u3002

        LinkedListStackpush()pop()

        \u56fe 5-2 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u6808\u7684\u5165\u6808\u51fa\u6808\u64cd\u4f5c

        \u4ee5\u4e0b\u662f\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u6808\u7684\u793a\u4f8b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_stack.py
        class LinkedListStack:\n\"\"\"\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._peek: ListNode | None = None\nself._size: int = 0\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn not self._peek\ndef push(self, val: int):\n\"\"\"\u5165\u6808\"\"\"\nnode = ListNode(val)\nnode.next = self._peek\nself._peek = node\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u6808\"\"\"\nnum = self.peek()\nself._peek = self._peek.next\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._peek.val\ndef to_list(self) -> list[int]:\n\"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\narr = []\nnode = self._peek\nwhile node:\narr.append(node.val)\nnode = node.next\narr.reverse()\nreturn arr\n
        linkedlist_stack.cpp
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate:\nListNode *stackTop; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint stkSize;        // \u6808\u7684\u957f\u5ea6\npublic:\nLinkedListStack() {\nstackTop = nullptr;\nstkSize = 0;\n}\n~LinkedListStack() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nfreeMemoryLinkedList(stackTop);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\nvoid push(int num) {\nListNode *node = new ListNode(num);\nnode->next = stackTop;\nstackTop = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\nvoid pop() {\nint num = top();\nListNode *tmp = stackTop;\nstackTop = stackTop->next;\n// \u91ca\u653e\u5185\u5b58\ndelete tmp;\nstkSize--;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top() {\nif (isEmpty())\nthrow out_of_range(\"\u6808\u4e3a\u7a7a\");\nreturn stackTop->val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nvector<int> toVector() {\nListNode *node = stackTop;\nvector<int> res(size());\nfor (int i = res.size() - 1; i >= 0; i--) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_stack.java
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate ListNode stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate int stkSize = 0; // \u6808\u7684\u957f\u5ea6\npublic LinkedListStack() {\nstackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\npublic void push(int num) {\nListNode node = new ListNode(num);\nnode.next = stackPeek;\nstackPeek = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\npublic int pop() {\nint num = peek();\nstackPeek = stackPeek.next;\nstkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stackPeek.val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] toArray() {\nListNode node = stackPeek;\nint[] res = new int[size()];\nfor (int i = res.length - 1; i >= 0; i--) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.cs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nListNode? stackPeek;  // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint stkSize = 0;   // \u6808\u7684\u957f\u5ea6\npublic LinkedListStack() {\nstackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u6808 */\npublic void Push(int num) {\nListNode node = new(num) {\nnext = stackPeek\n};\nstackPeek = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\npublic int Pop() {\nint num = Peek();\nstackPeek = stackPeek!.next;\nstkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn stackPeek!.val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nif (stackPeek == null)\nreturn [];\nListNode? node = stackPeek;\nint[] res = new int[Size()];\nfor (int i = res.Length - 1; i >= 0; i--) {\nres[i] = node!.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.go
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntype linkedListStack struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list \u6765\u5b9e\u73b0\u6808\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u6808 */\nfunc newLinkedListStack() *linkedListStack {\nreturn &linkedListStack{\ndata: list.New(),\n}\n}\n/* \u5165\u6808 */\nfunc (s *linkedListStack) push(value int) {\ns.data.PushBack(value)\n}\n/* \u51fa\u6808 */\nfunc (s *linkedListStack) pop() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc (s *linkedListStack) peek() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\nreturn e.Value\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc (s *linkedListStack) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListStack) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListStack) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_stack.swift
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate var _peek: ListNode? // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate var _size = 0 // \u6808\u7684\u957f\u5ea6\ninit() {}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc size() -> Int {\n_size\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u6808 */\nfunc push(num: Int) {\nlet node = ListNode(x: num)\nnode.next = _peek\n_peek = node\n_size += 1\n}\n/* \u51fa\u6808 */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n_peek = _peek?.next\n_size -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn _peek!.val\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nvar node = _peek\nvar res = Array(repeating: 0, count: _size)\nfor i in sequence(first: res.count - 1, next: { $0 >= 0 + 1 ? $0 - 1 : nil }) {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_stack.js
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n#stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n#stkSize = 0; // \u6808\u7684\u957f\u5ea6\nconstructor() {\nthis.#stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.size === 0;\n}\n/* \u5165\u6808 */\npush(num) {\nconst node = new ListNode(num);\nnode.next = this.#stackPeek;\nthis.#stackPeek = node;\nthis.#stkSize++;\n}\n/* \u51fa\u6808 */\npop() {\nconst num = this.peek();\nthis.#stackPeek = this.#stackPeek.next;\nthis.#stkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek() {\nif (!this.#stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stackPeek.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray() {\nlet node = this.#stackPeek;\nconst res = new Array(this.size);\nfor (let i = res.length - 1; i >= 0; i--) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.ts
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate stackPeek: ListNode | null; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate stkSize: number = 0; // \u6808\u7684\u957f\u5ea6\nconstructor() {\nthis.stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.size === 0;\n}\n/* \u5165\u6808 */\npush(num: number): void {\nconst node = new ListNode(num);\nnode.next = this.stackPeek;\nthis.stackPeek = node;\nthis.stkSize++;\n}\n/* \u51fa\u6808 */\npop(): number {\nconst num = this.peek();\nif (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nthis.stackPeek = this.stackPeek.next;\nthis.stkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek(): number {\nif (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stackPeek.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray(): number[] {\nlet node = this.stackPeek;\nconst res = new Array<number>(this.size);\nfor (let i = res.length - 1; i >= 0; i--) {\nres[i] = node!.val;\nnode = node!.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.dart
        /* \u57fa\u4e8e\u94fe\u8868\u7c7b\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nListNode? _stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint _stkSize = 0; // \u6808\u7684\u957f\u5ea6\nLinkedListStack() {\n_stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn _stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _stkSize == 0;\n}\n/* \u5165\u6808 */\nvoid push(int _num) {\nfinal ListNode node = ListNode(_num);\nnode.next = _stackPeek;\n_stackPeek = node;\n_stkSize++;\n}\n/* \u51fa\u6808 */\nint pop() {\nfinal int _num = peek();\n_stackPeek = _stackPeek!.next;\n_stkSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek() {\nif (_stackPeek == null) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stackPeek!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a List \u5e76\u8fd4\u56de */\nList<int> toList() {\nListNode? node = _stackPeek;\nList<int> list = [];\nwhile (node != null) {\nlist.add(node.val);\nnode = node.next;\n}\nlist = list.reversed.toList();\nreturn list;\n}\n}\n
        linkedlist_stack.rs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\n#[allow(dead_code)]\npub struct LinkedListStack<T> {\nstack_peek: Option<Rc<RefCell<ListNode<T>>>>,   // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nstk_size: usize,                                // \u6808\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListStack<T> {\npub fn new() -> Self {\nSelf {\nstack_peek: None,\nstk_size: 0,\n}\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.stk_size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u6808 */\npub fn push(&mut self, num: T) {\nlet node = ListNode::new(num);\nnode.borrow_mut().next = self.stack_peek.take();\nself.stack_peek = Some(node);\nself.stk_size += 1;\n}\n/* \u51fa\u6808 */\npub fn pop(&mut self) -> Option<T> {\nself.stack_peek.take().map(|old_head| {\nmatch old_head.borrow_mut().next.take() {\nSome(new_head) => {\nself.stack_peek = Some(new_head);\n}\nNone => {\nself.stack_peek = None;\n}\n}\nself.stk_size -= 1;\nRc::try_unwrap(old_head).ok().unwrap().into_inner().val\n})\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.stack_peek.as_ref()\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.push(node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_stack.c
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\nListNode *top; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint size;      // \u6808\u7684\u957f\u5ea6\n} LinkedListStack;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListStack *newLinkedListStack() {\nLinkedListStack *s = malloc(sizeof(LinkedListStack));\ns->top = NULL;\ns->size = 0;\nreturn s;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListStack(LinkedListStack *s) {\nwhile (s->top) {\nListNode *n = s->top->next;\nfree(s->top);\ns->top = n;\n}\nfree(s);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(LinkedListStack *s) {\nassert(s);\nreturn s->size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(LinkedListStack *s) {\nassert(s);\nreturn size(s) == 0;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(LinkedListStack *s) {\nassert(s);\nassert(size(s) != 0);\nreturn s->top->val;\n}\n/* \u5165\u6808 */\nvoid push(LinkedListStack *s, int num) {\nassert(s);\nListNode *node = (ListNode *)malloc(sizeof(ListNode));\nnode->next = s->top; // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6307\u9488\u57df\nnode->val = num;     // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6570\u636e\u57df\ns->top = node;       // \u66f4\u65b0\u6808\u9876\ns->size++;           // \u66f4\u65b0\u6808\u5927\u5c0f\n}\n/* \u51fa\u6808 */\nint pop(LinkedListStack *s) {\nif (s->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nassert(s);\nint val = peek(s);\nListNode *tmp = s->top;\ns->top = s->top->next;\n// \u91ca\u653e\u5185\u5b58\nfree(tmp);\ns->size--;\nreturn val;\n}\n
        linkedlist_stack.zig
        // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\nfn LinkedListStack(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nstack_top: ?*inc.ListNode(T) = null,             // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nstk_size: usize = 0,                             // \u6808\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,    // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.stack_top = null;\nself.stk_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u6808\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.stk_size;\n}\n// \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.size() == 0) @panic(\"\u6808\u4e3a\u7a7a\");\nreturn self.stack_top.?.val;\n}  // \u5165\u6808\npub fn push(self: *Self, num: T) !void {\nvar node = try self.mem_allocator.create(inc.ListNode(T));\nnode.init(num);\nnode.next = self.stack_top;\nself.stack_top = node;\nself.stk_size += 1;\n} // \u51fa\u6808\npub fn pop(self: *Self) T {\nvar num = self.peek();\nself.stack_top = self.stack_top.?.next;\nself.stk_size -= 1;\nreturn num;\n} // \u5c06\u6808\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\nvar node = self.stack_top;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[res.len - i - 1] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/stack/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u6808\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u7684\u5c3e\u90e8\u4f5c\u4e3a\u6808\u9876\u3002\u5982\u56fe 5-3 \u6240\u793a\uff0c\u5165\u6808\u4e0e\u51fa\u6808\u64cd\u4f5c\u5206\u522b\u5bf9\u5e94\u5728\u6570\u7ec4\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u4e0e\u5220\u9664\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(1)\\) \u3002

        ArrayStackpush()pop()

        \u56fe 5-3 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u6808\u7684\u5165\u6808\u51fa\u6808\u64cd\u4f5c

        \u7531\u4e8e\u5165\u6808\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u6e90\u6e90\u4e0d\u65ad\u5730\u589e\u52a0\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u52a8\u6001\u6570\u7ec4\uff0c\u8fd9\u6837\u5c31\u65e0\u987b\u81ea\u884c\u5904\u7406\u6570\u7ec4\u6269\u5bb9\u95ee\u9898\u3002\u4ee5\u4e0b\u4e3a\u793a\u4f8b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_stack.py
        class ArrayStack:\n\"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._stack: list[int] = []\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\nreturn len(self._stack)\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._stack == []\ndef push(self, item: int):\n\"\"\"\u5165\u6808\"\"\"\nself._stack.append(item)\ndef pop(self) -> int:\n\"\"\"\u51fa\u6808\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._stack.pop()\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._stack[-1]\ndef to_list(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nreturn self._stack\n
        array_stack.cpp
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate:\nvector<int> stack;\npublic:\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn stack.size();\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn stack.size() == 0;\n}\n/* \u5165\u6808 */\nvoid push(int num) {\nstack.push_back(num);\n}\n/* \u51fa\u6808 */\nvoid pop() {\nint oldTop = top();\nstack.pop_back();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top() {\nif (isEmpty())\nthrow out_of_range(\"\u6808\u4e3a\u7a7a\");\nreturn stack.back();\n}\n/* \u8fd4\u56de Vector */\nvector<int> toVector() {\nreturn stack;\n}\n};\n
        array_stack.java
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate ArrayList<Integer> stack;\npublic ArrayStack() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = new ArrayList<>();\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int size() {\nreturn stack.size();\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\npublic void push(int num) {\nstack.add(num);\n}\n/* \u51fa\u6808 */\npublic int pop() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stack.remove(size() - 1);\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stack.get(size() - 1);\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic Object[] toArray() {\nreturn stack.toArray();\n}\n}\n
        array_stack.cs
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nList<int> stack;\npublic ArrayStack() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn stack.Count;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u6808 */\npublic void Push(int num) {\nstack.Add(num);\n}\n/* \u51fa\u6808 */\npublic int Pop() {\nif (IsEmpty())\nthrow new Exception();\nvar val = Peek();\nstack.RemoveAt(Size() - 1);\nreturn val;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn stack[Size() - 1];\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nreturn [.. stack];\n}\n}\n
        array_stack.go
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntype arrayStack struct {\ndata []int // \u6570\u636e\n}\n/* \u521d\u59cb\u5316\u6808 */\nfunc newArrayStack() *arrayStack {\nreturn &arrayStack{\n// \u8bbe\u7f6e\u6808\u7684\u957f\u5ea6\u4e3a 0\uff0c\u5bb9\u91cf\u4e3a 16\ndata: make([]int, 0, 16),\n}\n}\n/* \u6808\u7684\u957f\u5ea6 */\nfunc (s *arrayStack) size() int {\nreturn len(s.data)\n}\n/* \u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *arrayStack) isEmpty() bool {\nreturn s.size() == 0\n}\n/* \u5165\u6808 */\nfunc (s *arrayStack) push(v int) {\n// \u5207\u7247\u4f1a\u81ea\u52a8\u6269\u5bb9\ns.data = append(s.data, v)\n}\n/* \u51fa\u6808 */\nfunc (s *arrayStack) pop() any {\nval := s.peek()\ns.data = s.data[:len(s.data)-1]\nreturn val\n}\n/* \u83b7\u53d6\u6808\u9876\u5143\u7d20 */\nfunc (s *arrayStack) peek() any {\nif s.isEmpty() {\nreturn nil\n}\nval := s.data[len(s.data)-1]\nreturn val\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (s *arrayStack) toSlice() []int {\nreturn s.data\n}\n
        array_stack.swift
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate var stack: [Int]\ninit() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = []\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nstack.count\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nstack.isEmpty\n}\n/* \u5165\u6808 */\nfunc push(num: Int) {\nstack.append(num)\n}\n/* \u51fa\u6808 */\n@discardableResult\nfunc pop() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn stack.removeLast()\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn stack.last!\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nstack\n}\n}\n
        array_stack.js
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n#stack;\nconstructor() {\nthis.#stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#stack.length === 0;\n}\n/* \u5165\u6808 */\npush(num) {\nthis.#stack.push(num);\n}\n/* \u51fa\u6808 */\npop() {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stack.pop();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\ntop() {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stack[this.#stack.length - 1];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\nreturn this.#stack;\n}\n}\n
        array_stack.ts
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate stack: number[];\nconstructor() {\nthis.stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.stack.length === 0;\n}\n/* \u5165\u6808 */\npush(num: number): void {\nthis.stack.push(num);\n}\n/* \u51fa\u6808 */\npop(): number | undefined {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stack.pop();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\ntop(): number | undefined {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stack[this.stack.length - 1];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\nreturn this.stack;\n}\n}\n
        array_stack.dart
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nlate List<int> _stack;\nArrayStack() {\n_stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn _stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _stack.isEmpty;\n}\n/* \u5165\u6808 */\nvoid push(int _num) {\n_stack.add(_num);\n}\n/* \u51fa\u6808 */\nint pop() {\nif (isEmpty()) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stack.removeLast();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek() {\nif (isEmpty()) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stack.last;\n}\n/* \u5c06\u6808\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nList<int> toArray() => _stack;\n}\n
        array_stack.rs
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nstruct ArrayStack<T> {\nstack: Vec<T>,\n}\nimpl<T> ArrayStack<T> {\n/* \u521d\u59cb\u5316\u6808 */\nfn new() -> ArrayStack<T> {\nArrayStack::<T> { stack: Vec::<T>::new() }\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfn size(&self) -> usize {\nself.stack.len()\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfn is_empty(&self) -> bool {\nself.size() == 0\n}\n/* \u5165\u6808 */\nfn push(&mut self, num: T) {\nself.stack.push(num);\n}\n/* \u51fa\u6808 */\nfn pop(&mut self) -> Option<T> {\nmatch self.stack.pop() {\nSome(num) => Some(num),\nNone => None,\n}\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<&T> {\nif self.is_empty() { panic!(\"\u6808\u4e3a\u7a7a\") };\nself.stack.last()\n}\n/* \u8fd4\u56de &Vec */\nfn to_array(&self) -> &Vec<T> {\n&self.stack\n}\n}\n
        array_stack.c
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\nint *data;\nint size;\n} ArrayStack;\n/* \u6784\u9020\u51fd\u6570 */\nArrayStack *newArrayStack() {\nArrayStack *stack = malloc(sizeof(ArrayStack));\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5927\u5bb9\u91cf\uff0c\u907f\u514d\u6269\u5bb9\nstack->data = malloc(sizeof(int) * MAX_SIZE);\nstack->size = 0;\nreturn stack;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayStack(ArrayStack *stack) {\nfree(stack->data);\nfree(stack);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(ArrayStack *stack) {\nreturn stack->size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(ArrayStack *stack) {\nreturn stack->size == 0;\n}\n/* \u5165\u6808 */\nvoid push(ArrayStack *stack, int num) {\nif (stack->size == MAX_SIZE) {\nprintf(\"stack is full.\\n\");\nreturn;\n}\nstack->data[stack->size] = num;\nstack->size++;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(ArrayStack *stack) {\nif (stack->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nreturn stack->data[stack->size - 1];\n}\n/* \u51fa\u6808 */\nint pop(ArrayStack *stack) {\nif (stack->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nint val = peek(stack);\nstack->size--;\nreturn val;\n}\n
        array_stack.zig
        // \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\nfn ArrayStack(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nstack: ?std.ArrayList(T) = null,     // \u6784\u9020\u65b9\u6cd5\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) void {\nif (self.stack == null) {\nself.stack = std.ArrayList(T).init(allocator);\n}\n}\n// \u6790\u6784\u65b9\u6cd5\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.stack == null) return;\nself.stack.?.deinit();\n}\n// \u83b7\u53d6\u6808\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.stack.?.items.len;\n}\n// \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u6808\u4e3a\u7a7a\");\nreturn self.stack.?.items[self.size() - 1];\n}  // \u5165\u6808\npub fn push(self: *Self, num: T) !void {\ntry self.stack.?.append(num);\n} // \u51fa\u6808\npub fn pop(self: *Self) T {\nvar num = self.stack.?.pop();\nreturn num;\n} // \u8fd4\u56de ArrayList\npub fn toList(self: *Self) std.ArrayList(T) {\nreturn self.stack.?;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/stack/#513","title":"5.1.3 \u00a0 \u4e24\u79cd\u5b9e\u73b0\u5bf9\u6bd4","text":"

        \u652f\u6301\u64cd\u4f5c

        \u4e24\u79cd\u5b9e\u73b0\u90fd\u652f\u6301\u6808\u5b9a\u4e49\u4e2d\u7684\u5404\u9879\u64cd\u4f5c\u3002\u6570\u7ec4\u5b9e\u73b0\u989d\u5916\u652f\u6301\u968f\u673a\u8bbf\u95ee\uff0c\u4f46\u8fd9\u5df2\u8d85\u51fa\u4e86\u6808\u7684\u5b9a\u4e49\u8303\u7574\uff0c\u56e0\u6b64\u4e00\u822c\u4e0d\u4f1a\u7528\u5230\u3002

        \u65f6\u95f4\u6548\u7387

        \u5728\u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0\u4e2d\uff0c\u5165\u6808\u548c\u51fa\u6808\u64cd\u4f5c\u90fd\u5728\u9884\u5148\u5206\u914d\u597d\u7684\u8fde\u7eed\u5185\u5b58\u4e2d\u8fdb\u884c\uff0c\u5177\u6709\u5f88\u597d\u7684\u7f13\u5b58\u672c\u5730\u6027\uff0c\u56e0\u6b64\u6548\u7387\u8f83\u9ad8\u3002\u7136\u800c\uff0c\u5982\u679c\u5165\u6808\u65f6\u8d85\u51fa\u6570\u7ec4\u5bb9\u91cf\uff0c\u4f1a\u89e6\u53d1\u6269\u5bb9\u673a\u5236\uff0c\u5bfc\u81f4\u8be5\u6b21\u5165\u6808\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53d8\u4e3a \\(O(n)\\) \u3002

        \u5728\u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0\u4e2d\uff0c\u94fe\u8868\u7684\u6269\u5bb9\u975e\u5e38\u7075\u6d3b\uff0c\u4e0d\u5b58\u5728\u4e0a\u8ff0\u6570\u7ec4\u6269\u5bb9\u65f6\u6548\u7387\u964d\u4f4e\u7684\u95ee\u9898\u3002\u4f46\u662f\uff0c\u5165\u6808\u64cd\u4f5c\u9700\u8981\u521d\u59cb\u5316\u8282\u70b9\u5bf9\u8c61\u5e76\u4fee\u6539\u6307\u9488\uff0c\u56e0\u6b64\u6548\u7387\u76f8\u5bf9\u8f83\u4f4e\u3002\u4e0d\u8fc7\uff0c\u5982\u679c\u5165\u6808\u5143\u7d20\u672c\u8eab\u5c31\u662f\u8282\u70b9\u5bf9\u8c61\uff0c\u90a3\u4e48\u53ef\u4ee5\u7701\u53bb\u521d\u59cb\u5316\u6b65\u9aa4\uff0c\u4ece\u800c\u63d0\u9ad8\u6548\u7387\u3002

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u5f53\u5165\u6808\u4e0e\u51fa\u6808\u64cd\u4f5c\u7684\u5143\u7d20\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u65f6\uff0c\u4f8b\u5982 int \u6216 double \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4ee5\u4e0b\u7ed3\u8bba\u3002

        • \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\u5728\u89e6\u53d1\u6269\u5bb9\u65f6\u6548\u7387\u4f1a\u964d\u4f4e\uff0c\u4f46\u7531\u4e8e\u6269\u5bb9\u662f\u4f4e\u9891\u64cd\u4f5c\uff0c\u56e0\u6b64\u5e73\u5747\u6548\u7387\u66f4\u9ad8\u3002
        • \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\u53ef\u4ee5\u63d0\u4f9b\u66f4\u52a0\u7a33\u5b9a\u7684\u6548\u7387\u8868\u73b0\u3002

        \u7a7a\u95f4\u6548\u7387

        \u5728\u521d\u59cb\u5316\u5217\u8868\u65f6\uff0c\u7cfb\u7edf\u4f1a\u4e3a\u5217\u8868\u5206\u914d\u201c\u521d\u59cb\u5bb9\u91cf\u201d\uff0c\u8be5\u5bb9\u91cf\u53ef\u80fd\u8d85\u51fa\u5b9e\u9645\u9700\u6c42\uff1b\u5e76\u4e14\uff0c\u6269\u5bb9\u673a\u5236\u901a\u5e38\u662f\u6309\u7167\u7279\u5b9a\u500d\u7387\uff08\u4f8b\u5982 2 \u500d\uff09\u8fdb\u884c\u6269\u5bb9\u7684\uff0c\u6269\u5bb9\u540e\u7684\u5bb9\u91cf\u4e5f\u53ef\u80fd\u8d85\u51fa\u5b9e\u9645\u9700\u6c42\u3002\u56e0\u6b64\uff0c\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\u53ef\u80fd\u9020\u6210\u4e00\u5b9a\u7684\u7a7a\u95f4\u6d6a\u8d39\u3002

        \u7136\u800c\uff0c\u7531\u4e8e\u94fe\u8868\u8282\u70b9\u9700\u8981\u989d\u5916\u5b58\u50a8\u6307\u9488\uff0c\u56e0\u6b64\u94fe\u8868\u8282\u70b9\u5360\u7528\u7684\u7a7a\u95f4\u76f8\u5bf9\u8f83\u5927\u3002

        \u7efc\u4e0a\uff0c\u6211\u4eec\u4e0d\u80fd\u7b80\u5355\u5730\u786e\u5b9a\u54ea\u79cd\u5b9e\u73b0\u66f4\u52a0\u8282\u7701\u5185\u5b58\uff0c\u9700\u8981\u9488\u5bf9\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u5206\u6790\u3002

        "},{"location":"chapter_stack_and_queue/stack/#514","title":"5.1.4 \u00a0 \u6808\u5178\u578b\u5e94\u7528","text":"
        • \u6d4f\u89c8\u5668\u4e2d\u7684\u540e\u9000\u4e0e\u524d\u8fdb\u3001\u8f6f\u4ef6\u4e2d\u7684\u64a4\u9500\u4e0e\u53cd\u64a4\u9500\u3002\u6bcf\u5f53\u6211\u4eec\u6253\u5f00\u65b0\u7684\u7f51\u9875\uff0c\u6d4f\u89c8\u5668\u5c31\u4f1a\u5bf9\u4e0a\u4e00\u4e2a\u7f51\u9875\u6267\u884c\u5165\u6808\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u540e\u9000\u64cd\u4f5c\u56de\u5230\u4e0a\u4e00\u4e2a\u7f51\u9875\u3002\u540e\u9000\u64cd\u4f5c\u5b9e\u9645\u4e0a\u662f\u5728\u6267\u884c\u51fa\u6808\u3002\u5982\u679c\u8981\u540c\u65f6\u652f\u6301\u540e\u9000\u548c\u524d\u8fdb\uff0c\u90a3\u4e48\u9700\u8981\u4e24\u4e2a\u6808\u6765\u914d\u5408\u5b9e\u73b0\u3002
        • \u7a0b\u5e8f\u5185\u5b58\u7ba1\u7406\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u7cfb\u7edf\u90fd\u4f1a\u5728\u6808\u9876\u6dfb\u52a0\u4e00\u4e2a\u6808\u5e27\uff0c\u7528\u4e8e\u8bb0\u5f55\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u5728\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u5411\u4e0b\u9012\u63a8\u9636\u6bb5\u4f1a\u4e0d\u65ad\u6267\u884c\u5165\u6808\u64cd\u4f5c\uff0c\u800c\u5411\u4e0a\u56de\u6eaf\u9636\u6bb5\u5219\u4f1a\u4e0d\u65ad\u6267\u884c\u51fa\u6808\u64cd\u4f5c\u3002
        "},{"location":"chapter_stack_and_queue/summary/","title":"5.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_stack_and_queue/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6808\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u540e\u51fa\u539f\u5219\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u901a\u8fc7\u6570\u7ec4\u6216\u94fe\u8868\u6765\u5b9e\u73b0\u3002
        • \u5728\u65f6\u95f4\u6548\u7387\u65b9\u9762\uff0c\u6808\u7684\u6570\u7ec4\u5b9e\u73b0\u5177\u6709\u8f83\u9ad8\u7684\u5e73\u5747\u6548\u7387\uff0c\u4f46\u5728\u6269\u5bb9\u8fc7\u7a0b\u4e2d\uff0c\u5355\u6b21\u5165\u6808\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u52a3\u5316\u81f3 \\(O(n)\\) \u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u6808\u7684\u94fe\u8868\u5b9e\u73b0\u5177\u6709\u66f4\u4e3a\u7a33\u5b9a\u7684\u6548\u7387\u8868\u73b0\u3002
        • \u5728\u7a7a\u95f4\u6548\u7387\u65b9\u9762\uff0c\u6808\u7684\u6570\u7ec4\u5b9e\u73b0\u53ef\u80fd\u5bfc\u81f4\u4e00\u5b9a\u7a0b\u5ea6\u7684\u7a7a\u95f4\u6d6a\u8d39\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u94fe\u8868\u8282\u70b9\u6240\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u6bd4\u6570\u7ec4\u5143\u7d20\u66f4\u5927\u3002
        • \u961f\u5217\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u5148\u51fa\u539f\u5219\u7684\u6570\u636e\u7ed3\u6784\uff0c\u540c\u6837\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u6216\u94fe\u8868\u6765\u5b9e\u73b0\u3002\u5728\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u7684\u5bf9\u6bd4\u4e0a\uff0c\u961f\u5217\u7684\u7ed3\u8bba\u4e0e\u524d\u8ff0\u6808\u7684\u7ed3\u8bba\u76f8\u4f3c\u3002
        • \u53cc\u5411\u961f\u5217\u662f\u4e00\u79cd\u5177\u6709\u66f4\u9ad8\u81ea\u7531\u5ea6\u7684\u961f\u5217\uff0c\u5b83\u5141\u8bb8\u5728\u4e24\u7aef\u8fdb\u884c\u5143\u7d20\u7684\u6dfb\u52a0\u548c\u5220\u9664\u64cd\u4f5c\u3002
        "},{"location":"chapter_stack_and_queue/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6d4f\u89c8\u5668\u7684\u524d\u8fdb\u540e\u9000\u662f\u5426\u662f\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\uff1f

        \u6d4f\u89c8\u5668\u7684\u524d\u8fdb\u540e\u9000\u529f\u80fd\u672c\u8d28\u4e0a\u662f\u201c\u6808\u201d\u7684\u4f53\u73b0\u3002\u5f53\u7528\u6237\u8bbf\u95ee\u4e00\u4e2a\u65b0\u9875\u9762\u65f6\uff0c\u8be5\u9875\u9762\u4f1a\u88ab\u6dfb\u52a0\u5230\u6808\u9876\uff1b\u5f53\u7528\u6237\u70b9\u51fb\u540e\u9000\u6309\u94ae\u65f6\uff0c\u8be5\u9875\u9762\u4f1a\u4ece\u6808\u9876\u5f39\u51fa\u3002\u4f7f\u7528\u53cc\u5411\u961f\u5217\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u4e00\u4e9b\u989d\u5916\u64cd\u4f5c\uff0c\u8fd9\u4e2a\u5728\u201c\u53cc\u5411\u961f\u5217\u201d\u7ae0\u8282\u6709\u63d0\u5230\u3002

        \u5728\u51fa\u6808\u540e\uff0c\u662f\u5426\u9700\u8981\u91ca\u653e\u51fa\u6808\u8282\u70b9\u7684\u5185\u5b58\uff1f

        \u5982\u679c\u540e\u7eed\u4ecd\u9700\u8981\u4f7f\u7528\u5f39\u51fa\u8282\u70b9\uff0c\u5219\u4e0d\u9700\u8981\u91ca\u653e\u5185\u5b58\u3002\u82e5\u4e4b\u540e\u4e0d\u9700\u8981\u7528\u5230\uff0cJava \u548c Python \u7b49\u8bed\u8a00\u62e5\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\uff1b\u5728 C \u548c C++ \u4e2d\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\u3002

        \u53cc\u5411\u961f\u5217\u50cf\u662f\u4e24\u4e2a\u6808\u62fc\u63a5\u5728\u4e86\u4e00\u8d77\uff0c\u5b83\u7684\u7528\u9014\u662f\u4ec0\u4e48\uff1f

        \u53cc\u5411\u961f\u5217\u5c31\u50cf\u662f\u6808\u548c\u961f\u5217\u7684\u7ec4\u5408\uff0c\u6216\u4e24\u4e2a\u6808\u62fc\u5728\u4e86\u4e00\u8d77\u3002\u5b83\u8868\u73b0\u7684\u662f\u6808 + \u961f\u5217\u7684\u903b\u8f91\uff0c\u56e0\u6b64\u53ef\u4ee5\u5b9e\u73b0\u6808\u4e0e\u961f\u5217\u7684\u6240\u6709\u5e94\u7528\uff0c\u5e76\u4e14\u66f4\u52a0\u7075\u6d3b\u3002

        \u64a4\u9500\uff08undo\uff09\u548c\u53cd\u64a4\u9500\uff08redo\uff09\u5177\u4f53\u662f\u5982\u4f55\u5b9e\u73b0\u7684\uff1f

        \u4f7f\u7528\u4e24\u4e2a\u5806\u6808\uff0c\u6808 A \u7528\u4e8e\u64a4\u9500\uff0c\u6808 B \u7528\u4e8e\u53cd\u64a4\u9500\u3002

        1. \u6bcf\u5f53\u7528\u6237\u6267\u884c\u4e00\u4e2a\u64cd\u4f5c\uff0c\u5c06\u8fd9\u4e2a\u64cd\u4f5c\u538b\u5165\u6808 A \uff0c\u5e76\u6e05\u7a7a\u6808 B \u3002
        2. \u5f53\u7528\u6237\u6267\u884c\u201c\u64a4\u9500\u201d\u65f6\uff0c\u4ece\u6808 A \u4e2d\u5f39\u51fa\u6700\u8fd1\u7684\u64cd\u4f5c\uff0c\u5e76\u5c06\u5176\u538b\u5165\u6808 B \u3002
        3. \u5f53\u7528\u6237\u6267\u884c\u201c\u53cd\u64a4\u9500\u201d\u65f6\uff0c\u4ece\u6808 B \u4e2d\u5f39\u51fa\u6700\u8fd1\u7684\u64cd\u4f5c\uff0c\u5e76\u5c06\u5176\u538b\u5165\u6808 A \u3002
        "},{"location":"chapter_tree/","title":"\u7b2c 7 \u7ae0 \u00a0 \u6811","text":"

        Abstract

        \u53c2\u5929\u5927\u6811\u5145\u6ee1\u751f\u547d\u529b\uff0c\u6839\u6df1\u53f6\u8302\uff0c\u5206\u679d\u6276\u758f\u3002

        \u5b83\u4e3a\u6211\u4eec\u5c55\u73b0\u4e86\u6570\u636e\u5206\u6cbb\u7684\u751f\u52a8\u5f62\u6001\u3002

        "},{"location":"chapter_tree/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 7.1 \u00a0 \u4e8c\u53c9\u6811
        • 7.2 \u00a0 \u4e8c\u53c9\u6811\u904d\u5386
        • 7.3 \u00a0 \u4e8c\u53c9\u6811\u6570\u7ec4\u8868\u793a
        • 7.4 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811
        • 7.5 \u00a0 AVL \u6811 *
        • 7.6 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_tree/array_representation_of_tree/","title":"7.3 \u00a0 \u4e8c\u53c9\u6811\u6570\u7ec4\u8868\u793a","text":"

        \u5728\u94fe\u8868\u8868\u793a\u4e0b\uff0c\u4e8c\u53c9\u6811\u7684\u5b58\u50a8\u5355\u5143\u4e3a\u8282\u70b9 TreeNode \uff0c\u8282\u70b9\u4e4b\u95f4\u901a\u8fc7\u6307\u9488\u76f8\u8fde\u63a5\u3002\u4e0a\u4e00\u8282\u4ecb\u7ecd\u4e86\u94fe\u8868\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7684\u5404\u9879\u57fa\u672c\u64cd\u4f5c\u3002

        \u90a3\u4e48\uff0c\u6211\u4eec\u80fd\u5426\u7528\u6570\u7ec4\u6765\u8868\u793a\u4e8c\u53c9\u6811\u5462\uff1f\u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002

        "},{"location":"chapter_tree/array_representation_of_tree/#731","title":"7.3.1 \u00a0 \u8868\u793a\u5b8c\u7f8e\u4e8c\u53c9\u6811","text":"

        \u5148\u5206\u6790\u4e00\u4e2a\u7b80\u5355\u6848\u4f8b\u3002\u7ed9\u5b9a\u4e00\u68f5\u5b8c\u7f8e\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u5c06\u6240\u6709\u8282\u70b9\u6309\u7167\u5c42\u5e8f\u904d\u5386\u7684\u987a\u5e8f\u5b58\u50a8\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5219\u6bcf\u4e2a\u8282\u70b9\u90fd\u5bf9\u5e94\u552f\u4e00\u7684\u6570\u7ec4\u7d22\u5f15\u3002

        \u6839\u636e\u5c42\u5e8f\u904d\u5386\u7684\u7279\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u63a8\u5bfc\u51fa\u7236\u8282\u70b9\u7d22\u5f15\u4e0e\u5b50\u8282\u70b9\u7d22\u5f15\u4e4b\u95f4\u7684\u201c\u6620\u5c04\u516c\u5f0f\u201d\uff1a\u82e5\u67d0\u8282\u70b9\u7684\u7d22\u5f15\u4e3a \\(i\\) \uff0c\u5219\u8be5\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 2\\) \u3002\u56fe 7-12 \u5c55\u793a\u4e86\u5404\u4e2a\u8282\u70b9\u7d22\u5f15\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002

        \u56fe 7-12 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u6620\u5c04\u516c\u5f0f\u7684\u89d2\u8272\u76f8\u5f53\u4e8e\u94fe\u8868\u4e2d\u7684\u6307\u9488\u3002\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u8282\u70b9\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7\u6620\u5c04\u516c\u5f0f\u6765\u8bbf\u95ee\u5b83\u7684\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u3002

        "},{"location":"chapter_tree/array_representation_of_tree/#732","title":"7.3.2 \u00a0 \u8868\u793a\u4efb\u610f\u4e8c\u53c9\u6811","text":"

        \u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u4e00\u4e2a\u7279\u4f8b\uff0c\u5728\u4e8c\u53c9\u6811\u7684\u4e2d\u95f4\u5c42\u901a\u5e38\u5b58\u5728\u8bb8\u591a \\(\\text{None}\\) \u3002\u7531\u4e8e\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5e76\u4e0d\u5305\u542b\u8fd9\u4e9b \\(\\text{None}\\) \uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u6cd5\u4ec5\u51ed\u8be5\u5e8f\u5217\u6765\u63a8\u6d4b \\(\\text{None}\\) \u7684\u6570\u91cf\u548c\u5206\u5e03\u4f4d\u7f6e\u3002\u8fd9\u610f\u5473\u7740\u5b58\u5728\u591a\u79cd\u4e8c\u53c9\u6811\u7ed3\u6784\u90fd\u7b26\u5408\u8be5\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u3002

        \u5982\u56fe 7-13 \u6240\u793a\uff0c\u7ed9\u5b9a\u4e00\u68f5\u975e\u5b8c\u7f8e\u4e8c\u53c9\u6811\uff0c\u4e0a\u8ff0\u6570\u7ec4\u8868\u793a\u65b9\u6cd5\u5df2\u7ecf\u5931\u6548\u3002

        \u56fe 7-13 \u00a0 \u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5bf9\u5e94\u591a\u79cd\u4e8c\u53c9\u6811\u53ef\u80fd\u6027

        \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u5728\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u663e\u5f0f\u5730\u5199\u51fa\u6240\u6709 \\(\\text{None}\\) \u3002\u5982\u56fe 7-14 \u6240\u793a\uff0c\u8fd9\u6837\u5904\u7406\u540e\uff0c\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5c31\u53ef\u4ee5\u552f\u4e00\u8868\u793a\u4e8c\u53c9\u6811\u4e86\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a\n# \u4f7f\u7528 None \u6765\u8868\u793a\u7a7a\u4f4d\ntree = [1, 2, 3, 4, None, 6, 7, 8, 9, None, None, 12, None, None, 15]\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u6700\u5927\u503c INT_MAX \u6807\u8bb0\u7a7a\u4f4d\nvector<int> tree = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u7684\u5305\u88c5\u7c7b Integer \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nInteger[] tree = { 1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15 };\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nint?[] tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 any \u7c7b\u578b\u7684\u5207\u7247, \u5c31\u53ef\u4ee5\u4f7f\u7528 nil \u6765\u6807\u8bb0\u7a7a\u4f4d\ntree := []any{1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15}\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 Int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 nil \u6765\u6807\u8bb0\u7a7a\u4f4d\nlet tree: [Int?] = [1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15]\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 null \u6765\u8868\u793a\u7a7a\u4f4d\nlet tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 null \u6765\u8868\u793a\u7a7a\u4f4d\nlet tree: (number | null)[] = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nList<int?> tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 None \u6765\u6807\u8bb0\u7a7a\u4f4d\nlet tree = [Some(1), Some(2), Some(3), Some(4), None, Some(6), Some(7), Some(8), Some(9), None, None, Some(12), None, None, Some(15)];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u6700\u5927\u503c\u6807\u8bb0\u7a7a\u4f4d\uff0c\u56e0\u6b64\u8981\u6c42\u8282\u70b9\u503c\u4e0d\u80fd\u4e3a INT_MAX\nint tree[] = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};\n
        \n

        \u56fe 7-14 \u00a0 \u4efb\u610f\u7c7b\u578b\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u4f7f\u7528\u6570\u7ec4\u6765\u8868\u793a\u3002\u56de\u987e\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u5b9a\u4e49\uff0c\\(\\text{None}\\) \u53ea\u51fa\u73b0\u5728\u6700\u5e95\u5c42\u4e14\u9760\u53f3\u7684\u4f4d\u7f6e\uff0c\u56e0\u6b64\u6240\u6709 \\(\\text{None}\\) \u4e00\u5b9a\u51fa\u73b0\u5728\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u7684\u672b\u5c3e\u3002

        \u8fd9\u610f\u5473\u7740\u4f7f\u7528\u6570\u7ec4\u8868\u793a\u5b8c\u5168\u4e8c\u53c9\u6811\u65f6\uff0c\u53ef\u4ee5\u7701\u7565\u5b58\u50a8\u6240\u6709 \\(\\text{None}\\) \uff0c\u975e\u5e38\u65b9\u4fbf\u3002\u56fe 7-15 \u7ed9\u51fa\u4e86\u4e00\u4e2a\u4f8b\u5b50\u3002

        \u56fe 7-15 \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u68f5\u57fa\u4e8e\u6570\u7ec4\u8868\u793a\u7684\u4e8c\u53c9\u6811\uff0c\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u64cd\u4f5c\u3002

        • \u7ed9\u5b9a\u67d0\u8282\u70b9\uff0c\u83b7\u53d6\u5b83\u7684\u503c\u3001\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u3001\u7236\u8282\u70b9\u3002
        • \u83b7\u53d6\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u3001\u540e\u5e8f\u904d\u5386\u3001\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_binary_tree.py
        class ArrayBinaryTree:\n\"\"\"\u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b\"\"\"\ndef __init__(self, arr: list[int | None]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._tree = list(arr)\ndef size(self):\n\"\"\"\u8282\u70b9\u6570\u91cf\"\"\"\nreturn len(self._tree)\ndef val(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c\"\"\"\n# \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 or i >= self.size():\nreturn None\nreturn self._tree[i]\ndef left(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn 2 * i + 1\ndef right(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn 2 * i + 2\ndef parent(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn (i - 1) // 2\ndef level_order(self) -> list[int]:\n\"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\nself.res = []\n# \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in range(self.size()):\nif self.val(i) is not None:\nself.res.append(self.val(i))\nreturn self.res\ndef dfs(self, i: int, order: str):\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\nif self.val(i) is None:\nreturn\n# \u524d\u5e8f\u904d\u5386\nif order == \"pre\":\nself.res.append(self.val(i))\nself.dfs(self.left(i), order)\n# \u4e2d\u5e8f\u904d\u5386\nif order == \"in\":\nself.res.append(self.val(i))\nself.dfs(self.right(i), order)\n# \u540e\u5e8f\u904d\u5386\nif order == \"post\":\nself.res.append(self.val(i))\ndef pre_order(self) -> list[int]:\n\"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"pre\")\nreturn self.res\ndef in_order(self) -> list[int]:\n\"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"in\")\nreturn self.res\ndef post_order(self) -> list[int]:\n\"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"post\")\nreturn self.res\n
        array_binary_tree.cpp
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayBinaryTree(vector<int> arr) {\ntree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nint size() {\nreturn tree.size();\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size())\nreturn INT_MAX;\nreturn tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nvector<int> levelOrder() {\nvector<int> res;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\nif (val(i) != INT_MAX)\nres.push_back(val(i));\n}\nreturn res;\n}\n/* \u524d\u5e8f\u904d\u5386 */\nvector<int> preOrder() {\nvector<int> res;\ndfs(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvector<int> inOrder() {\nvector<int> res;\ndfs(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvector<int> postOrder() {\nvector<int> res;\ndfs(0, \"post\", res);\nreturn res;\n}\nprivate:\nvector<int> tree;\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(int i, string order, vector<int> &res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == INT_MAX)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (order == \"pre\")\nres.push_back(val(i));\ndfs(left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == \"in\")\nres.push_back(val(i));\ndfs(right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == \"post\")\nres.push_back(val(i));\n}\n};\n
        array_binary_tree.java
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nprivate List<Integer> tree;\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayBinaryTree(List<Integer> arr) {\ntree = new ArrayList<>(arr);\n}\n/* \u8282\u70b9\u6570\u91cf */\npublic int size() {\nreturn tree.size();\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\npublic Integer val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size())\nreturn null;\nreturn tree.get(i);\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\npublic List<Integer> levelOrder() {\nList<Integer> res = new ArrayList<>();\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\nif (val(i) != null)\nres.add(val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nprivate void dfs(Integer i, String order, List<Integer> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == null)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (\"pre\".equals(order))\nres.add(val(i));\ndfs(left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (\"in\".equals(order))\nres.add(val(i));\ndfs(right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (\"post\".equals(order))\nres.add(val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npublic List<Integer> preOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\npublic List<Integer> inOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npublic List<Integer> postOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"post\", res);\nreturn res;\n}\n}\n
        array_binary_tree.cs
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree(List<int?> arr) {\nList<int?> tree = new(arr);\n/* \u8282\u70b9\u6570\u91cf */\npublic int Size() {\nreturn tree.Count;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\npublic int? Val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= Size())\nreturn null;\nreturn tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\npublic List<int> LevelOrder() {\nList<int> res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < Size(); i++) {\nif (Val(i).HasValue)\nres.Add(Val(i)!.Value);\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid DFS(int i, string order, List<int> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (!Val(i).HasValue)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (order == \"pre\")\nres.Add(Val(i)!.Value);\nDFS(Left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == \"in\")\nres.Add(Val(i)!.Value);\nDFS(Right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == \"post\")\nres.Add(Val(i)!.Value);\n}\n/* \u524d\u5e8f\u904d\u5386 */\npublic List<int> PreOrder() {\nList<int> res = [];\nDFS(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\npublic List<int> InOrder() {\nList<int> res = [];\nDFS(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npublic List<int> PostOrder() {\nList<int> res = [];\nDFS(0, \"post\", res);\nreturn res;\n}\n}\n
        array_binary_tree.go
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\ntype arrayBinaryTree struct {\ntree []any\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newArrayBinaryTree(arr []any) *arrayBinaryTree {\nreturn &arrayBinaryTree{\ntree: arr,\n}\n}\n/* \u8282\u70b9\u6570\u91cf */\nfunc (abt *arrayBinaryTree) size() int {\nreturn len(abt.tree)\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfunc (abt *arrayBinaryTree) val(i int) any {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= abt.size() {\nreturn nil\n}\nreturn abt.tree[i]\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) left(i int) int {\nreturn 2*i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) right(i int) int {\nreturn 2*i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) parent(i int) int {\nreturn (i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) levelOrder() []any {\nvar res []any\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i := 0; i < abt.size(); i++ {\nif abt.val(i) != nil {\nres = append(res, abt.val(i))\n}\n}\nreturn res\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nfunc (abt *arrayBinaryTree) dfs(i int, order string, res *[]any) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif abt.val(i) == nil {\nreturn\n}\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\n*res = append(*res, abt.val(i))\n}\nabt.dfs(abt.left(i), order, res)\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\n*res = append(*res, abt.val(i))\n}\nabt.dfs(abt.right(i), order, res)\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\n*res = append(*res, abt.val(i))\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) preOrder() []any {\nvar res []any\nabt.dfs(0, \"pre\", &res)\nreturn res\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) inOrder() []any {\nvar res []any\nabt.dfs(0, \"in\", &res)\nreturn res\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) postOrder() []any {\nvar res []any\nabt.dfs(0, \"post\", &res)\nreturn res\n}\n
        array_binary_tree.swift
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nprivate var tree: [Int?]\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(arr: [Int?]) {\ntree = arr\n}\n/* \u8282\u70b9\u6570\u91cf */\nfunc size() -> Int {\ntree.count\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfunc val(i: Int) -> Int? {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= size() {\nreturn nil\n}\nreturn tree[i]\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n2 * i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc parent(i: Int) -> Int {\n(i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder() -> [Int] {\nvar res: [Int] = []\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in stride(from: 0, to: size(), by: 1) {\nif let val = val(i: i) {\nres.append(val)\n}\n}\nreturn res\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nprivate func dfs(i: Int, order: String, res: inout [Int]) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nguard let val = val(i: i) else {\nreturn\n}\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\nres.append(val)\n}\ndfs(i: left(i: i), order: order, res: &res)\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\nres.append(val)\n}\ndfs(i: right(i: i), order: order, res: &res)\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\nres.append(val)\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"pre\", res: &res)\nreturn res\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"in\", res: &res)\nreturn res\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"post\", res: &res)\nreturn res\n}\n}\n
        array_binary_tree.js
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n#tree;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(arr) {\nthis.#tree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nsize() {\nreturn this.#tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nval(i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= this.size()) return null;\nreturn this.#tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i) {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nlevelOrder() {\nlet res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < this.size(); i++) {\nif (this.val(i) !== null) res.push(this.val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n#dfs(i, order, res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (this.val(i) === null) return;\n// \u524d\u5e8f\u904d\u5386\nif (order === 'pre') res.push(this.val(i));\nthis.#dfs(this.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order === 'in') res.push(this.val(i));\nthis.#dfs(this.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order === 'post') res.push(this.val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npreOrder() {\nconst res = [];\nthis.#dfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\ninOrder() {\nconst res = [];\nthis.#dfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npostOrder() {\nconst res = [];\nthis.#dfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.ts
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n#tree: (number | null)[];\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(arr: (number | null)[]) {\nthis.#tree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.#tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nval(i: number): number | null {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= this.size()) return null;\nreturn this.#tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i: number): number {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i: number): number {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i: number): number {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nlevelOrder(): number[] {\nlet res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < this.size(); i++) {\nif (this.val(i) !== null) res.push(this.val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n#dfs(i: number, order: Order, res: (number | null)[]): void {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (this.val(i) === null) return;\n// \u524d\u5e8f\u904d\u5386\nif (order === 'pre') res.push(this.val(i));\nthis.#dfs(this.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order === 'in') res.push(this.val(i));\nthis.#dfs(this.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order === 'post') res.push(this.val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npreOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\ninOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npostOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.dart
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nlate List<int?> _tree;\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayBinaryTree(this._tree);\n/* \u8282\u70b9\u6570\u91cf */\nint size() {\nreturn _tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint? val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size()) {\nreturn null;\n}\nreturn _tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint? left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint? right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint? parent(int i) {\nreturn (i - 1) ~/ 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nList<int> levelOrder() {\nList<int> res = [];\nfor (int i = 0; i < size(); i++) {\nif (val(i) != null) {\nres.add(val(i)!);\n}\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(int i, String order, List<int?> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == null) {\nreturn;\n}\n// \u524d\u5e8f\u904d\u5386\nif (order == 'pre') {\nres.add(val(i));\n}\ndfs(left(i)!, order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == 'in') {\nres.add(val(i));\n}\ndfs(right(i)!, order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == 'post') {\nres.add(val(i));\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nList<int?> preOrder() {\nList<int?> res = [];\ndfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nList<int?> inOrder() {\nList<int?> res = [];\ndfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nList<int?> postOrder() {\nList<int?> res = [];\ndfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.rs
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nstruct ArrayBinaryTree {\ntree: Vec<Option<i32>>,\n}\nimpl ArrayBinaryTree {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(arr: Vec<Option<i32>>) -> Self {\nSelf { tree: arr }\n}\n/* \u8282\u70b9\u6570\u91cf */\nfn size(&self) -> i32 {\nself.tree.len() as i32\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfn val(&self, i: i32) -> Option<i32> {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= self.size() {\nNone\n} else {\nself.tree[i as usize]\n}\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn left(&self, i: i32) -> i32 {\n2 * i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn right(&self, i: i32) -> i32 {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfn parent(&self, i: i32) -> i32 {\n(i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfn level_order(&self) -> Vec<i32> {\nlet mut res = vec![];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in 0..self.size() {\nif let Some(val) = self.val(i) {\nres.push(val)\n}\n}\nres\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nfn dfs(&self, i: i32, order: &str, res: &mut Vec<i32>) {\nif self.val(i).is_none() {\nreturn;\n}\nlet val = self.val(i).unwrap();\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\nres.push(val);\n}\nself.dfs(self.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\nres.push(val);\n}\nself.dfs(self.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\nres.push(val);\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"pre\", &mut res);\nres\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"in\", &mut res);\nres\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"post\", &mut res);\nres\n}\n}\n
        array_binary_tree.c
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7ed3\u6784\u4f53 */\ntypedef struct {\nint *tree;\nint size;\n} ArrayBinaryTree;\n/* \u6784\u9020\u51fd\u6570 */\nArrayBinaryTree *newArrayBinaryTree(int *arr, int arrSize) {\nArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));\nabt->tree = malloc(sizeof(int) * arrSize);\nmemcpy(abt->tree, arr, sizeof(int) * arrSize);\nabt->size = arrSize;\nreturn abt;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayBinaryTree(ArrayBinaryTree *abt) {\nfree(abt->tree);\nfree(abt);\n}\n/* \u8282\u70b9\u6570\u91cf */\nint size(ArrayBinaryTree *abt) {\nreturn abt->size;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint val(ArrayBinaryTree *abt, int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size(abt))\nreturn INT_MAX;\nreturn abt->tree[i];\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(abt); i++) {\nif (val(abt, i) != INT_MAX)\nres[index++] = val(abt, i);\n}\n*returnSize = index;\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(ArrayBinaryTree *abt, int i, char *order, int *res, int *index) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(abt, i) == INT_MAX)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (strcmp(order, \"pre\") == 0)\nres[(*index)++] = val(abt, i);\ndfs(abt, left(i), order, res, index);\n// \u4e2d\u5e8f\u904d\u5386\nif (strcmp(order, \"in\") == 0)\nres[(*index)++] = val(abt, i);\ndfs(abt, right(i), order, res, index);\n// \u540e\u5e8f\u904d\u5386\nif (strcmp(order, \"post\") == 0)\nres[(*index)++] = val(abt, i);\n}\n/* \u524d\u5e8f\u904d\u5386 */\nint *preOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"pre\", res, &index);\n*returnSize = index;\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nint *inOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"in\", res, &index);\n*returnSize = index;\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nint *postOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"post\", res, &index);\n*returnSize = index;\nreturn res;\n}\n
        array_binary_tree.zig
        [class]{ArrayBinaryTree}-[func]{}\n
        "},{"location":"chapter_tree/array_representation_of_tree/#733","title":"7.3.3 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a\u4e3b\u8981\u6709\u4ee5\u4e0b\u4f18\u70b9\u3002

        • \u6570\u7ec4\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u5bf9\u7f13\u5b58\u53cb\u597d\uff0c\u8bbf\u95ee\u4e0e\u904d\u5386\u901f\u5ea6\u8f83\u5feb\u3002
        • \u4e0d\u9700\u8981\u5b58\u50a8\u6307\u9488\uff0c\u6bd4\u8f83\u8282\u7701\u7a7a\u95f4\u3002
        • \u5141\u8bb8\u968f\u673a\u8bbf\u95ee\u8282\u70b9\u3002

        \u7136\u800c\uff0c\u6570\u7ec4\u8868\u793a\u4e5f\u5b58\u5728\u4e00\u4e9b\u5c40\u9650\u6027\u3002

        • \u6570\u7ec4\u5b58\u50a8\u9700\u8981\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\uff0c\u56e0\u6b64\u4e0d\u9002\u5408\u5b58\u50a8\u6570\u636e\u91cf\u8fc7\u5927\u7684\u6811\u3002
        • \u589e\u5220\u8282\u70b9\u9700\u8981\u901a\u8fc7\u6570\u7ec4\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u5b9e\u73b0\uff0c\u6548\u7387\u8f83\u4f4e\u3002
        • \u5f53\u4e8c\u53c9\u6811\u4e2d\u5b58\u5728\u5927\u91cf \\(\\text{None}\\) \u65f6\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u7684\u8282\u70b9\u6570\u636e\u6bd4\u91cd\u8f83\u4f4e\uff0c\u7a7a\u95f4\u5229\u7528\u7387\u8f83\u4f4e\u3002
        "},{"location":"chapter_tree/avl_tree/","title":"7.5 \u00a0 AVL \u6811 *","text":"

        \u5728\u201c\u4e8c\u53c9\u641c\u7d22\u6811\u201d\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u63d0\u5230\uff0c\u5728\u591a\u6b21\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u80fd\u9000\u5316\u4e3a\u94fe\u8868\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4ece \\(O(\\log n)\\) \u6076\u5316\u4e3a \\(O(n)\\) \u3002

        \u5982\u56fe 7-24 \u6240\u793a\uff0c\u7ecf\u8fc7\u4e24\u6b21\u5220\u9664\u8282\u70b9\u64cd\u4f5c\uff0c\u8fd9\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4fbf\u4f1a\u9000\u5316\u4e3a\u94fe\u8868\u3002

        \u56fe 7-24 \u00a0 AVL \u6811\u5728\u5220\u9664\u8282\u70b9\u540e\u53d1\u751f\u9000\u5316

        \u518d\u4f8b\u5982\uff0c\u5728\u56fe 7-25 \u6240\u793a\u7684\u5b8c\u7f8e\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e24\u4e2a\u8282\u70b9\u540e\uff0c\u6811\u5c06\u4e25\u91cd\u5411\u5de6\u503e\u659c\uff0c\u67e5\u627e\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u968f\u4e4b\u6076\u5316\u3002

        \u56fe 7-25 \u00a0 AVL \u6811\u5728\u63d2\u5165\u8282\u70b9\u540e\u53d1\u751f\u9000\u5316

        1962 \u5e74 G. M. Adelson-Velsky \u548c E. M. Landis \u5728\u8bba\u6587 \"An algorithm for the organization of information\" \u4e2d\u63d0\u51fa\u4e86\u300cAVL \u6811\u300d\u3002\u8bba\u6587\u4e2d\u8be6\u7ec6\u63cf\u8ff0\u4e86\u4e00\u7cfb\u5217\u64cd\u4f5c\uff0c\u786e\u4fdd\u5728\u6301\u7eed\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u540e\uff0cAVL \u6811\u4e0d\u4f1a\u9000\u5316\uff0c\u4ece\u800c\u4f7f\u5f97\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4fdd\u6301\u5728 \\(O(\\log n)\\) \u7ea7\u522b\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728\u9700\u8981\u9891\u7e41\u8fdb\u884c\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u7684\u573a\u666f\u4e2d\uff0cAVL \u6811\u80fd\u59cb\u7ec8\u4fdd\u6301\u9ad8\u6548\u7684\u6570\u636e\u64cd\u4f5c\u6027\u80fd\uff0c\u5177\u6709\u5f88\u597d\u7684\u5e94\u7528\u4ef7\u503c\u3002

        "},{"location":"chapter_tree/avl_tree/#751-avl","title":"7.5.1 \u00a0 AVL \u6811\u5e38\u89c1\u672f\u8bed","text":"

        AVL \u6811\u65e2\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u4e5f\u662f\u5e73\u8861\u4e8c\u53c9\u6811\uff0c\u540c\u65f6\u6ee1\u8db3\u8fd9\u4e24\u7c7b\u4e8c\u53c9\u6811\u7684\u6240\u6709\u6027\u8d28\uff0c\u56e0\u6b64\u4e5f\u88ab\u79f0\u4e3a\u300c\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 balanced binary search tree\u300d\u3002

        "},{"location":"chapter_tree/avl_tree/#1","title":"1. \u00a0 \u8282\u70b9\u9ad8\u5ea6","text":"

        \u7531\u4e8e AVL \u6811\u7684\u76f8\u5173\u64cd\u4f5c\u9700\u8981\u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u4e3a\u8282\u70b9\u7c7b\u6dfb\u52a0 height \u53d8\u91cf\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class TreeNode:\n\"\"\"AVL \u6811\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                 # \u8282\u70b9\u503c\nself.height: int = 0                # \u8282\u70b9\u9ad8\u5ea6\nself.left: TreeNode | None = None   # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nself.right: TreeNode | None = None  # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nstruct TreeNode {\nint val{};          // \u8282\u70b9\u503c\nint height = 0;     // \u8282\u70b9\u9ad8\u5ea6\nTreeNode *left{};   // \u5de6\u5b50\u8282\u70b9\nTreeNode *right{};  // \u53f3\u5b50\u8282\u70b9\nTreeNode() = default;\nexplicit TreeNode(int x) : val(x){}\n};\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\npublic int val;        // \u8282\u70b9\u503c\npublic int height;     // \u8282\u70b9\u9ad8\u5ea6\npublic TreeNode left;  // \u5de6\u5b50\u8282\u70b9\npublic TreeNode right; // \u53f3\u5b50\u8282\u70b9\npublic TreeNode(int x) { val = x; }\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\npublic int? val = x;    // \u8282\u70b9\u503c\npublic int height;      // \u8282\u70b9\u9ad8\u5ea6\npublic TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\npublic TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\nVal    int       // \u8282\u70b9\u503c\nHeight int       // \u8282\u70b9\u9ad8\u5ea6\nLeft   *TreeNode // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nRight  *TreeNode // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nvar val: Int // \u8282\u70b9\u503c\nvar height: Int // \u8282\u70b9\u9ad8\u5ea6\nvar left: TreeNode? // \u5de6\u5b50\u8282\u70b9\nvar right: TreeNode? // \u53f3\u5b50\u8282\u70b9\ninit(x: Int) {\nval = x\nheight = 0\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval; // \u8282\u70b9\u503c\nheight; //\u8282\u70b9\u9ad8\u5ea6\nleft; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val, left, right, height) {\nthis.val = val === undefined ? 0 : val;\nthis.height = height === undefined ? 0 : height;\nthis.left = left === undefined ? null : left;\nthis.right = right === undefined ? null : right;\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval: number;            // \u8282\u70b9\u503c\nheight: number;         // \u8282\u70b9\u9ad8\u5ea6\nleft: TreeNode | null;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright: TreeNode | null; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {\nthis.val = val === undefined ? 0 : val;\nthis.height = height === undefined ? 0 : height; this.left = left === undefined ? null : left; this.right = right === undefined ? null : right; }\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nint height;      // \u8282\u70b9\u9ad8\u5ea6\nTreeNode? left;  // \u5de6\u5b50\u8282\u70b9\nTreeNode? right; // \u53f3\u5b50\u8282\u70b9\nTreeNode(this.val, [this.height = 0, this.left, this.right]);\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nval: i32,                               // \u8282\u70b9\u503c\nheight: i32,                            // \u8282\u70b9\u9ad8\u5ea6\nleft: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\nright: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\n}\nimpl TreeNode {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(val: i32) -> Rc<RefCell<Self>> {\nRc::new(RefCell::new(Self {\nval,\nheight: 0,\nleft: None,\nright: None\n}))\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nTreeNode struct TreeNode {\nint val;\nint height;\nstruct TreeNode *left;\nstruct TreeNode *right;\n} TreeNode;\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\nTreeNode *node;\nnode = (TreeNode *)malloc(sizeof(TreeNode));\nnode->val = val;\nnode->height = 0;\nnode->left = NULL;\nnode->right = NULL;\nreturn node;\n}\n
        \n

        \u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u662f\u6307\u4ece\u8be5\u8282\u70b9\u5230\u5176\u6700\u8fdc\u53f6\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u5373\u6240\u7ecf\u8fc7\u7684\u201c\u8fb9\u201d\u7684\u6570\u91cf\u3002\u9700\u8981\u7279\u522b\u6ce8\u610f\u7684\u662f\uff0c\u53f6\u8282\u70b9\u7684\u9ad8\u5ea6\u4e3a \\(0\\) \uff0c\u800c\u7a7a\u8282\u70b9\u7684\u9ad8\u5ea6\u4e3a \\(-1\\) \u3002\u6211\u4eec\u5c06\u521b\u5efa\u4e24\u4e2a\u5de5\u5177\u51fd\u6570\uff0c\u5206\u522b\u7528\u4e8e\u83b7\u53d6\u548c\u66f4\u65b0\u8282\u70b9\u7684\u9ad8\u5ea6\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def height(self, node: TreeNode | None) -> int:\n\"\"\"\u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\"\"\"\n# \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif node is not None:\nreturn node.height\nreturn -1\ndef update_height(self, node: TreeNode | None):\n\"\"\"\u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\"\"\"\n# \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = max([self.height(node.left), self.height(node.right)]) + 1\n
        avl_tree.cpp
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == nullptr ? -1 : node->height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode->height = max(height(node->left), height(node->right)) + 1;\n}\n
        avl_tree.java
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = Math.max(height(node.left), height(node.right)) + 1;\n}\n
        avl_tree.cs
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint Height(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid UpdateHeight(TreeNode node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = Math.Max(Height(node.left), Height(node.right)) + 1;\n}\n
        avl_tree.go
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) height(node *TreeNode) int {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif node != nil {\nreturn node.Height\n}\nreturn -1\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) updateHeight(node *TreeNode) {\nlh := t.height(node.Left)\nrh := t.height(node.Right)\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nif lh > rh {\nnode.Height = lh + 1\n} else {\nnode.Height = rh + 1\n}\n}\n
        avl_tree.swift
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfunc height(node: TreeNode?) -> Int {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nnode == nil ? -1 : node!.height\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc updateHeight(node: TreeNode?) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode?.height = max(height(node: node?.left), height(node: node?.right)) + 1\n}\n
        avl_tree.js
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nheight(node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node === null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\n#updateHeight(node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height =\nMath.max(this.height(node.left), this.height(node.right)) + 1;\n}\n
        avl_tree.ts
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nheight(node: TreeNode): number {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node === null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nupdateHeight(node: TreeNode): void {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height =\nMath.max(this.height(node.left), this.height(node.right)) + 1;\n}\n
        avl_tree.dart
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode? node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode!.height = max(height(node.left), height(node.right)) + 1;\n}\n
        avl_tree.rs
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfn height(node: OptionTreeNodeRc) -> i32 {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nmatch node {\nSome(node) => node.borrow().height,\nNone => -1,\n}\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfn update_height(node: OptionTreeNodeRc) {\nif let Some(node) = node {\nlet left = node.borrow().left.clone();\nlet right = node.borrow().right.clone();\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.borrow_mut().height = std::cmp::max(Self::height(left), Self::height(right)) + 1;\n}\n}\n
        avl_tree.c
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif (node != NULL) {\nreturn node->height;\n}\nreturn -1;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\nint lh = height(node->left);\nint rh = height(node->right);\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nif (lh > rh) {\nnode->height = lh + 1;\n} else {\nnode->height = rh + 1;\n}\n}\n
        avl_tree.zig
        // \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\nfn height(self: *Self, node: ?*inc.TreeNode(T)) i32 {\n_ = self;\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn if (node == null) -1 else node.?.height;\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nfn updateHeight(self: *Self, node: ?*inc.TreeNode(T)) void {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.?.height = @max(self.height(node.?.left), self.height(node.?.right)) + 1;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2","title":"2. \u00a0 \u8282\u70b9\u5e73\u8861\u56e0\u5b50","text":"

        \u8282\u70b9\u7684\u300c\u5e73\u8861\u56e0\u5b50 balance factor\u300d\u5b9a\u4e49\u4e3a\u8282\u70b9\u5de6\u5b50\u6811\u7684\u9ad8\u5ea6\u51cf\u53bb\u53f3\u5b50\u6811\u7684\u9ad8\u5ea6\uff0c\u540c\u65f6\u89c4\u5b9a\u7a7a\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u4e3a \\(0\\) \u3002\u6211\u4eec\u540c\u6837\u5c06\u83b7\u53d6\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u7684\u529f\u80fd\u5c01\u88c5\u6210\u51fd\u6570\uff0c\u65b9\u4fbf\u540e\u7eed\u4f7f\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def balance_factor(self, node: TreeNode | None) -> int:\n\"\"\"\u83b7\u53d6\u5e73\u8861\u56e0\u5b50\"\"\"\n# \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif node is None:\nreturn 0\n# \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn self.height(node.left) - self.height(node.right)\n
        avl_tree.cpp
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == nullptr)\nreturn 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node->left) - height(node->right);\n}\n
        avl_tree.java
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null)\nreturn 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node.left) - height(node.right);\n}\n
        avl_tree.cs
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint BalanceFactor(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn Height(node.left) - Height(node.right);\n}\n
        avl_tree.go
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfunc (t *aVLTree) balanceFactor(node *TreeNode) int {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif node == nil {\nreturn 0\n}\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn t.height(node.Left) - t.height(node.Right)\n}\n
        avl_tree.swift
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfunc balanceFactor(node: TreeNode?) -> Int {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nguard let node = node else { return 0 }\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node: node.left) - height(node: node.right)\n}\n
        avl_tree.js
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nbalanceFactor(node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node === null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn this.height(node.left) - this.height(node.right);\n}\n
        avl_tree.ts
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nbalanceFactor(node: TreeNode): number {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node === null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn this.height(node.left) - this.height(node.right);\n}\n
        avl_tree.dart
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node.left) - height(node.right);\n}\n
        avl_tree.rs
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfn balance_factor(node: OptionTreeNodeRc) -> i32 {\nmatch node {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nNone => 0,\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nSome(node) => {\nSelf::height(node.borrow().left.clone()) - Self::height(node.borrow().right.clone())\n}\n}\n}\n
        avl_tree.c
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == NULL) {\nreturn 0;\n}\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node->left) - height(node->right);\n}\n
        avl_tree.zig
        // \u83b7\u53d6\u5e73\u8861\u56e0\u5b50\nfn balanceFactor(self: *Self, node: ?*inc.TreeNode(T)) i32 {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn self.height(node.?.left) - self.height(node.?.right);\n}\n

        Note

        \u8bbe\u5e73\u8861\u56e0\u5b50\u4e3a \\(f\\) \uff0c\u5219\u4e00\u68f5 AVL \u6811\u7684\u4efb\u610f\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u7686\u6ee1\u8db3 \\(-1 \\le f \\le 1\\) \u3002

        "},{"location":"chapter_tree/avl_tree/#752-avl","title":"7.5.2 \u00a0 AVL \u6811\u65cb\u8f6c","text":"

        AVL \u6811\u7684\u7279\u70b9\u5728\u4e8e\u201c\u65cb\u8f6c\u201d\u64cd\u4f5c\uff0c\u5b83\u80fd\u591f\u5728\u4e0d\u5f71\u54cd\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u7684\u524d\u63d0\u4e0b\uff0c\u4f7f\u5931\u8861\u8282\u70b9\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u65cb\u8f6c\u64cd\u4f5c\u65e2\u80fd\u4fdd\u6301\u201c\u4e8c\u53c9\u641c\u7d22\u6811\u201d\u7684\u6027\u8d28\uff0c\u4e5f\u80fd\u4f7f\u6811\u91cd\u65b0\u53d8\u4e3a\u201c\u5e73\u8861\u4e8c\u53c9\u6811\u201d\u3002

        \u6211\u4eec\u5c06\u5e73\u8861\u56e0\u5b50\u7edd\u5bf9\u503c \\(> 1\\) \u7684\u8282\u70b9\u79f0\u4e3a\u201c\u5931\u8861\u8282\u70b9\u201d\u3002\u6839\u636e\u8282\u70b9\u5931\u8861\u60c5\u51b5\u7684\u4e0d\u540c\uff0c\u65cb\u8f6c\u64cd\u4f5c\u5206\u4e3a\u56db\u79cd\uff1a\u53f3\u65cb\u3001\u5de6\u65cb\u3001\u5148\u53f3\u65cb\u540e\u5de6\u65cb\u3001\u5148\u5de6\u65cb\u540e\u53f3\u65cb\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65cb\u8f6c\u64cd\u4f5c\u3002

        "},{"location":"chapter_tree/avl_tree/#1_1","title":"1. \u00a0 \u53f3\u65cb","text":"

        \u5982\u56fe 7-26 \u6240\u793a\uff0c\u8282\u70b9\u4e0b\u65b9\u4e3a\u5e73\u8861\u56e0\u5b50\u3002\u4ece\u5e95\u81f3\u9876\u770b\uff0c\u4e8c\u53c9\u6811\u4e2d\u9996\u4e2a\u5931\u8861\u8282\u70b9\u662f\u201c\u8282\u70b9 3\u201d\u3002\u6211\u4eec\u5173\u6ce8\u4ee5\u8be5\u5931\u8861\u8282\u70b9\u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\uff0c\u5c06\u8be5\u8282\u70b9\u8bb0\u4e3a node \uff0c\u5176\u5de6\u5b50\u8282\u70b9\u8bb0\u4e3a child \uff0c\u6267\u884c\u201c\u53f3\u65cb\u201d\u64cd\u4f5c\u3002\u5b8c\u6210\u53f3\u65cb\u540e\uff0c\u5b50\u6811\u6062\u590d\u5e73\u8861\uff0c\u5e76\u4e14\u4ecd\u7136\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u3002

        <1><2><3><4>

        \u56fe 7-26 \u00a0 \u53f3\u65cb\u64cd\u4f5c\u6b65\u9aa4

        \u5982\u56fe 7-27 \u6240\u793a\uff0c\u5f53\u8282\u70b9 child \u6709\u53f3\u5b50\u8282\u70b9\uff08\u8bb0\u4e3a grandChild \uff09\u65f6\uff0c\u9700\u8981\u5728\u53f3\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grandChild \u4f5c\u4e3a node \u7684\u5de6\u5b50\u8282\u70b9\u3002

        \u56fe 7-27 \u00a0 \u6709 grandChild \u7684\u53f3\u65cb\u64cd\u4f5c

        \u201c\u5411\u53f3\u65cb\u8f6c\u201d\u662f\u4e00\u79cd\u5f62\u8c61\u5316\u7684\u8bf4\u6cd5\uff0c\u5b9e\u9645\u4e0a\u9700\u8981\u901a\u8fc7\u4fee\u6539\u8282\u70b9\u6307\u9488\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def right_rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u53f3\u65cb\u64cd\u4f5c\"\"\"\nchild = node.left\ngrand_child = child.right\n# \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node\nnode.left = grand_child\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\nself.update_height(child)\n# \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n
        avl_tree.cpp
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\nTreeNode *child = node->left;\nTreeNode *grandChild = child->right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild->right = node;\nnode->left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.java
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode rightRotate(TreeNode node) {\nTreeNode child = node.left;\nTreeNode grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.cs
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? RightRotate(TreeNode? node) {\nTreeNode? child = node?.left;\nTreeNode? grandChild = child?.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nUpdateHeight(node);\nUpdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.go
        /* \u53f3\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) rightRotate(node *TreeNode) *TreeNode {\nchild := node.Left\ngrandChild := child.Right\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.Right = node\nnode.Left = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\nt.updateHeight(child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.swift
        /* \u53f3\u65cb\u64cd\u4f5c */\nfunc rightRotate(node: TreeNode?) -> TreeNode? {\nlet child = node?.left\nlet grandChild = child?.right\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild?.right = node\nnode?.left = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node: node)\nupdateHeight(node: child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.js
        /* \u53f3\u65cb\u64cd\u4f5c */\n#rightRotate(node) {\nconst child = node.left;\nconst grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.#updateHeight(node);\nthis.#updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.ts
        /* \u53f3\u65cb\u64cd\u4f5c */\nrightRotate(node: TreeNode): TreeNode {\nconst child = node.left;\nconst grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.updateHeight(node);\nthis.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.dart
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? rightRotate(TreeNode? node) {\nTreeNode? child = node!.left;\nTreeNode? grandChild = child!.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.rs
        /* \u53f3\u65cb\u64cd\u4f5c */\nfn right_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\nmatch node {\nSome(node) => {\nlet child = node.borrow().left.clone().unwrap();\nlet grand_child = child.borrow().right.clone();\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.borrow_mut().right = Some(node.clone());\nnode.borrow_mut().left = grand_child;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nSelf::update_height(Some(node));\nSelf::update_height(Some(child.clone()));\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(child)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\nTreeNode *child, *grandChild;\nchild = node->left;\ngrandChild = child->right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild->right = node;\nnode->left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.zig
        // \u53f3\u65cb\u64cd\u4f5c\nfn rightRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\nvar child = node.?.left;\nvar grandChild = child.?.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.?.right = node;\nnode.?.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.updateHeight(node);\nself.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2_1","title":"2. \u00a0 \u5de6\u65cb","text":"

        \u76f8\u5e94\u5730\uff0c\u5982\u679c\u8003\u8651\u4e0a\u8ff0\u5931\u8861\u4e8c\u53c9\u6811\u7684\u201c\u955c\u50cf\u201d\uff0c\u5219\u9700\u8981\u6267\u884c\u56fe 7-28 \u6240\u793a\u7684\u201c\u5de6\u65cb\u201d\u64cd\u4f5c\u3002

        \u56fe 7-28 \u00a0 \u5de6\u65cb\u64cd\u4f5c

        \u540c\u7406\uff0c\u5982\u56fe 7-29 \u6240\u793a\uff0c\u5f53\u8282\u70b9 child \u6709\u5de6\u5b50\u8282\u70b9\uff08\u8bb0\u4e3a grandChild \uff09\u65f6\uff0c\u9700\u8981\u5728\u5de6\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grandChild \u4f5c\u4e3a node \u7684\u53f3\u5b50\u8282\u70b9\u3002

        \u56fe 7-29 \u00a0 \u6709 grandChild \u7684\u5de6\u65cb\u64cd\u4f5c

        \u53ef\u4ee5\u89c2\u5bdf\u5230\uff0c\u53f3\u65cb\u548c\u5de6\u65cb\u64cd\u4f5c\u5728\u903b\u8f91\u4e0a\u662f\u955c\u50cf\u5bf9\u79f0\u7684\uff0c\u5b83\u4eec\u5206\u522b\u89e3\u51b3\u7684\u4e24\u79cd\u5931\u8861\u60c5\u51b5\u4e5f\u662f\u5bf9\u79f0\u7684\u3002\u57fa\u4e8e\u5bf9\u79f0\u6027\uff0c\u6211\u4eec\u53ea\u9700\u5c06\u53f3\u65cb\u7684\u5b9e\u73b0\u4ee3\u7801\u4e2d\u7684\u6240\u6709\u7684 left \u66ff\u6362\u4e3a right \uff0c\u5c06\u6240\u6709\u7684 right \u66ff\u6362\u4e3a left \uff0c\u5373\u53ef\u5f97\u5230\u5de6\u65cb\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def left_rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u5de6\u65cb\u64cd\u4f5c\"\"\"\nchild = node.right\ngrand_child = child.left\n# \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node\nnode.right = grand_child\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\nself.update_height(child)\n# \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n
        avl_tree.cpp
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\nTreeNode *child = node->right;\nTreeNode *grandChild = child->left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild->left = node;\nnode->right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.java
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode leftRotate(TreeNode node) {\nTreeNode child = node.right;\nTreeNode grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.cs
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? LeftRotate(TreeNode? node) {\nTreeNode? child = node?.right;\nTreeNode? grandChild = child?.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nUpdateHeight(node);\nUpdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.go
        /* \u5de6\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) leftRotate(node *TreeNode) *TreeNode {\nchild := node.Right\ngrandChild := child.Left\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.Left = node\nnode.Right = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\nt.updateHeight(child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.swift
        /* \u5de6\u65cb\u64cd\u4f5c */\nfunc leftRotate(node: TreeNode?) -> TreeNode? {\nlet child = node?.right\nlet grandChild = child?.left\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild?.left = node\nnode?.right = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node: node)\nupdateHeight(node: child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.js
        /* \u5de6\u65cb\u64cd\u4f5c */\n#leftRotate(node) {\nconst child = node.right;\nconst grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.#updateHeight(node);\nthis.#updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.ts
        /* \u5de6\u65cb\u64cd\u4f5c */\nleftRotate(node: TreeNode): TreeNode {\nconst child = node.right;\nconst grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.updateHeight(node);\nthis.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.dart
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? leftRotate(TreeNode? node) {\nTreeNode? child = node!.right;\nTreeNode? grandChild = child!.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.rs
        /* \u5de6\u65cb\u64cd\u4f5c */\nfn left_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\nmatch node {\nSome(node) => {\nlet child = node.borrow().right.clone().unwrap();\nlet grand_child = child.borrow().left.clone();\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.borrow_mut().left = Some(node.clone());\nnode.borrow_mut().right = grand_child;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nSelf::update_height(Some(node));\nSelf::update_height(Some(child.clone()));\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(child)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\nTreeNode *child, *grandChild;\nchild = node->right;\ngrandChild = child->left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild->left = node;\nnode->right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.zig
        // \u5de6\u65cb\u64cd\u4f5c\nfn leftRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\nvar child = node.?.right;\nvar grandChild = child.?.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.?.left = node;\nnode.?.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.updateHeight(node);\nself.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        "},{"location":"chapter_tree/avl_tree/#3","title":"3. \u00a0 \u5148\u5de6\u65cb\u540e\u53f3\u65cb","text":"

        \u5bf9\u4e8e\u56fe 7-30 \u4e2d\u7684\u5931\u8861\u8282\u70b9 3 \uff0c\u4ec5\u4f7f\u7528\u5de6\u65cb\u6216\u53f3\u65cb\u90fd\u65e0\u6cd5\u4f7f\u5b50\u6811\u6062\u590d\u5e73\u8861\u3002\u6b64\u65f6\u9700\u8981\u5148\u5bf9 child \u6267\u884c\u201c\u5de6\u65cb\u201d\uff0c\u518d\u5bf9 node \u6267\u884c\u201c\u53f3\u65cb\u201d\u3002

        \u56fe 7-30 \u00a0 \u5148\u5de6\u65cb\u540e\u53f3\u65cb

        "},{"location":"chapter_tree/avl_tree/#4","title":"4. \u00a0 \u5148\u53f3\u65cb\u540e\u5de6\u65cb","text":"

        \u5982\u56fe 7-31 \u6240\u793a\uff0c\u5bf9\u4e8e\u4e0a\u8ff0\u5931\u8861\u4e8c\u53c9\u6811\u7684\u955c\u50cf\u60c5\u51b5\uff0c\u9700\u8981\u5148\u5bf9 child \u6267\u884c\u201c\u53f3\u65cb\u201d\uff0c\u518d\u5bf9 node \u6267\u884c\u201c\u5de6\u65cb\u201d\u3002

        \u56fe 7-31 \u00a0 \u5148\u53f3\u65cb\u540e\u5de6\u65cb

        "},{"location":"chapter_tree/avl_tree/#5","title":"5. \u00a0 \u65cb\u8f6c\u7684\u9009\u62e9","text":"

        \u56fe 7-32 \u5c55\u793a\u7684\u56db\u79cd\u5931\u8861\u60c5\u51b5\u4e0e\u4e0a\u8ff0\u6848\u4f8b\u9010\u4e2a\u5bf9\u5e94\uff0c\u5206\u522b\u9700\u8981\u91c7\u7528\u53f3\u65cb\u3001\u5148\u5de6\u65cb\u540e\u53f3\u65cb\u3001\u5148\u53f3\u65cb\u540e\u5de6\u65cb\u3001\u5de6\u65cb\u7684\u64cd\u4f5c\u3002

        \u56fe 7-32 \u00a0 AVL \u6811\u7684\u56db\u79cd\u65cb\u8f6c\u60c5\u51b5

        \u5982\u4e0b\u8868\u6240\u793a\uff0c\u6211\u4eec\u901a\u8fc7\u5224\u65ad\u5931\u8861\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u4ee5\u53ca\u8f83\u9ad8\u4e00\u4fa7\u5b50\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u7684\u6b63\u8d1f\u53f7\uff0c\u6765\u786e\u5b9a\u5931\u8861\u8282\u70b9\u5c5e\u4e8e\u56fe 7-32 \u4e2d\u7684\u54ea\u79cd\u60c5\u51b5\u3002

        \u8868 7-3 \u00a0 \u56db\u79cd\u65cb\u8f6c\u60c5\u51b5\u7684\u9009\u62e9\u6761\u4ef6

        \u5931\u8861\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50 \u5b50\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50 \u5e94\u91c7\u7528\u7684\u65cb\u8f6c\u65b9\u6cd5 \\(> 1\\) \uff08\u5de6\u504f\u6811\uff09 \\(\\geq 0\\) \u53f3\u65cb \\(> 1\\) \uff08\u5de6\u504f\u6811\uff09 \\(<0\\) \u5148\u5de6\u65cb\u540e\u53f3\u65cb \\(< -1\\) \uff08\u53f3\u504f\u6811\uff09 \\(\\leq 0\\) \u5de6\u65cb \\(< -1\\) \uff08\u53f3\u504f\u6811\uff09 \\(>0\\) \u5148\u53f3\u65cb\u540e\u5de6\u65cb

        \u4e3a\u4e86\u4fbf\u4e8e\u4f7f\u7528\uff0c\u6211\u4eec\u5c06\u65cb\u8f6c\u64cd\u4f5c\u5c01\u88c5\u6210\u4e00\u4e2a\u51fd\u6570\u3002\u6709\u4e86\u8fd9\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u5c31\u80fd\u5bf9\u5404\u79cd\u5931\u8861\u60c5\u51b5\u8fdb\u884c\u65cb\u8f6c\uff0c\u4f7f\u5931\u8861\u8282\u70b9\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\"\"\"\n# \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nbalance_factor = self.balance_factor(node)\n# \u5de6\u504f\u6811\nif balance_factor > 1:\nif self.balance_factor(node.left) >= 0:\n# \u53f3\u65cb\nreturn self.right_rotate(node)\nelse:\n# \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = self.left_rotate(node.left)\nreturn self.right_rotate(node)\n# \u53f3\u504f\u6811\nelif balance_factor < -1:\nif self.balance_factor(node.right) <= 0:\n# \u5de6\u65cb\nreturn self.left_rotate(node)\nelse:\n# \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = self.right_rotate(node.right)\nreturn self.left_rotate(node)\n# \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n
        avl_tree.cpp
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode *rotate(TreeNode *node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint _balanceFactor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (_balanceFactor > 1) {\nif (balanceFactor(node->left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode->left = leftRotate(node->left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (_balanceFactor < -1) {\nif (balanceFactor(node->right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode->right = rightRotate(node->right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.java
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode rotate(TreeNode node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint balanceFactor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = leftRotate(node.left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = rightRotate(node.right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.cs
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode? Rotate(TreeNode? node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint balanceFactorInt = BalanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactorInt > 1) {\nif (BalanceFactor(node?.left) >= 0) {\n// \u53f3\u65cb\nreturn RightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode!.left = LeftRotate(node!.left);\nreturn RightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactorInt < -1) {\nif (BalanceFactor(node?.right) <= 0) {\n// \u5de6\u65cb\nreturn LeftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode!.right = RightRotate(node!.right);\nreturn LeftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.go
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfunc (t *aVLTree) rotate(node *TreeNode) *TreeNode {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\n// Go \u63a8\u8350\u77ed\u53d8\u91cf\uff0c\u8fd9\u91cc bf \u6307\u4ee3 t.balanceFactor\nbf := t.balanceFactor(node)\n// \u5de6\u504f\u6811\nif bf > 1 {\nif t.balanceFactor(node.Left) >= 0 {\n// \u53f3\u65cb\nreturn t.rightRotate(node)\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.Left = t.leftRotate(node.Left)\nreturn t.rightRotate(node)\n}\n}\n// \u53f3\u504f\u6811\nif bf < -1 {\nif t.balanceFactor(node.Right) <= 0 {\n// \u5de6\u65cb\nreturn t.leftRotate(node)\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.Right = t.rightRotate(node.Right)\nreturn t.leftRotate(node)\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n
        avl_tree.swift
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfunc rotate(node: TreeNode?) -> TreeNode? {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nlet balanceFactor = balanceFactor(node: node)\n// \u5de6\u504f\u6811\nif balanceFactor > 1 {\nif self.balanceFactor(node: node?.left) >= 0 {\n// \u53f3\u65cb\nreturn rightRotate(node: node)\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode?.left = leftRotate(node: node?.left)\nreturn rightRotate(node: node)\n}\n}\n// \u53f3\u504f\u6811\nif balanceFactor < -1 {\nif self.balanceFactor(node: node?.right) <= 0 {\n// \u5de6\u65cb\nreturn leftRotate(node: node)\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode?.right = rightRotate(node: node?.right)\nreturn leftRotate(node: node)\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n
        avl_tree.js
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n#rotate(node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nconst balanceFactor = this.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (this.balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn this.#rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = this.#leftRotate(node.left);\nreturn this.#rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (this.balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn this.#leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = this.#rightRotate(node.right);\nreturn this.#leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.ts
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nrotate(node: TreeNode): TreeNode {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nconst balanceFactor = this.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (this.balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn this.rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = this.leftRotate(node.left);\nreturn this.rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (this.balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn this.leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = this.rightRotate(node.right);\nreturn this.leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.dart
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode? rotate(TreeNode? node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint factor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (factor > 1) {\nif (balanceFactor(node!.left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = leftRotate(node.left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (factor < -1) {\nif (balanceFactor(node!.right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = rightRotate(node.right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.rs
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfn rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nlet balance_factor = Self::balance_factor(node.clone());\n// \u5de6\u504f\u6811\nif balance_factor > 1 {\nlet node = node.unwrap();\nif Self::balance_factor(node.borrow().left.clone()) >= 0 {\n// \u53f3\u65cb\nSelf::right_rotate(Some(node))\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::left_rotate(left);\nSelf::right_rotate(Some(node))\n}\n}\n// \u53f3\u504f\u6811\nelse if balance_factor < -1 {\nlet node = node.unwrap();\nif Self::balance_factor(node.borrow().right.clone()) <= 0 {\n// \u5de6\u65cb\nSelf::left_rotate(Some(node))\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::right_rotate(right);\nSelf::left_rotate(Some(node))\n}\n} else {\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nnode\n}\n}\n
        avl_tree.c
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode *rotate(TreeNode *node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint bf = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (bf > 1) {\nif (balanceFactor(node->left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode->left = leftRotate(node->left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (bf < -1) {\nif (balanceFactor(node->right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode->right = rightRotate(node->right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.zig
        // \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nfn rotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nvar balance_factor = self.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balance_factor > 1) {\nif (self.balanceFactor(node.?.left) >= 0) {\n// \u53f3\u65cb\nreturn self.rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.?.left = self.leftRotate(node.?.left);\nreturn self.rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balance_factor < -1) {\nif (self.balanceFactor(node.?.right) <= 0) {\n// \u5de6\u65cb\nreturn self.leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.?.right = self.rightRotate(node.?.right);\nreturn self.leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#753-avl","title":"7.5.3 \u00a0 AVL \u6811\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_tree/avl_tree/#1_2","title":"1. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        AVL \u6811\u7684\u8282\u70b9\u63d2\u5165\u64cd\u4f5c\u4e0e\u4e8c\u53c9\u641c\u7d22\u6811\u5728\u4e3b\u4f53\u4e0a\u7c7b\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u5728\u4e8e\uff0c\u5728 AVL \u6811\u4e2d\u63d2\u5165\u8282\u70b9\u540e\uff0c\u4ece\u8be5\u8282\u70b9\u5230\u6839\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e00\u7cfb\u5217\u5931\u8861\u8282\u70b9\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u4ece\u8fd9\u4e2a\u8282\u70b9\u5f00\u59cb\uff0c\u81ea\u5e95\u5411\u4e0a\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6240\u6709\u5931\u8861\u8282\u70b9\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def insert(self, val):\n\"\"\"\u63d2\u5165\u8282\u70b9\"\"\"\nself._root = self.insert_helper(self._root, val)\ndef insert_helper(self, node: TreeNode | None, val: int) -> TreeNode:\n\"\"\"\u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\nif node is None:\nreturn TreeNode(val)\n# 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9\nif val < node.val:\nnode.left = self.insert_helper(node.left, val)\nelif val > node.val:\nnode.right = self.insert_helper(node.right, val)\nelse:\n# \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\n# 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nreturn self.rotate(node)\n
        avl_tree.cpp
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\nif (node == nullptr)\nreturn new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node->val)\nnode->left = insertHelper(node->left, val);\nelse if (val > node->val)\nnode->right = insertHelper(node->right, val);\nelse\nreturn node;    // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.java
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode insertHelper(TreeNode node, int val) {\nif (node == null)\nreturn new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = insertHelper(node.right, val);\nelse\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.cs
        /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int val) {\nroot = InsertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? InsertHelper(TreeNode? node, int val) {\nif (node == null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = InsertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = InsertHelper(node.right, val);\nelse\nreturn node;     // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nUpdateHeight(node);  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.go
        /* \u63d2\u5165\u8282\u70b9 */\nfunc (t *aVLTree) insert(val int) {\nt.root = t.insertHelper(t.root, val)\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {\nif node == nil {\nreturn NewTreeNode(val)\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif val < node.Val.(int) {\nnode.Left = t.insertHelper(node.Left, val)\n} else if val > node.Val.(int) {\nnode.Right = t.insertHelper(node.Right, val)\n} else {\n// \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = t.rotate(node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.swift
        /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(val: Int) {\nroot = insertHelper(node: root, val: val)\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc insertHelper(node: TreeNode?, val: Int) -> TreeNode? {\nvar node = node\nif node == nil {\nreturn TreeNode(x: val)\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif val < node!.val {\nnode?.left = insertHelper(node: node?.left, val: val)\n} else if val > node!.val {\nnode?.right = insertHelper(node: node?.right, val: val)\n} else {\nreturn node // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nupdateHeight(node: node) // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node: node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.js
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(val) {\nthis.root = this.#insertHelper(this.root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#insertHelper(node, val) {\nif (node === null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val) node.left = this.#insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = this.#insertHelper(node.right, val);\nelse return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nthis.#updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.#rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.ts
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(val: number): void {\nthis.root = this.insertHelper(this.root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\ninsertHelper(node: TreeNode, val: number): TreeNode {\nif (node === null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val) {\nnode.left = this.insertHelper(node.left, val);\n} else if (val > node.val) {\nnode.right = this.insertHelper(node.right, val);\n} else {\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nthis.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.dart
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? insertHelper(TreeNode? node, int val) {\nif (node == null) return TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = insertHelper(node.right, val);\nelse\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.rs
        /* \u63d2\u5165\u8282\u70b9 */\nfn insert(&mut self, val: i32) {\nself.root = Self::insert_helper(self.root.clone(), val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn insert_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\nmatch node {\nSome(mut node) => {\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nmatch {\nlet node_val = node.borrow().val;\nnode_val\n}\n.cmp(&val)\n{\nOrdering::Greater => {\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::insert_helper(left, val);\n}\nOrdering::Less => {\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::insert_helper(right, val);\n}\nOrdering::Equal => {\nreturn Some(node); // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\n}\nSelf::update_height(Some(node.clone())); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Self::rotate(Some(node)).unwrap();\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(node)\n}\nNone => Some(TreeNode::new(val)),\n}\n}\n
        avl_tree.c
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(AVLTree *tree, int val) {\ntree->root = insertHelper(tree->root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\nif (node == NULL) {\nreturn newTreeNode(val);\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node->val) {\nnode->left = insertHelper(node->left, val);\n} else if (val > node->val) {\nnode->right = insertHelper(node->right, val);\n} else {\n// \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.zig
        // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, val: T) !void {\nself.root = (try self.insertHelper(self.root, val)).?;\n}\n// \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\nfn insertHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) !?*inc.TreeNode(T) {\nvar node = node_;\nif (node == null) {\nvar tmp_node = try self.mem_allocator.create(inc.TreeNode(T));\ntmp_node.init(val);\nreturn tmp_node;\n}\n// 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9\nif (val < node.?.val) {\nnode.?.left = try self.insertHelper(node.?.left, val);\n} else if (val > node.?.val) {\nnode.?.right = try self.insertHelper(node.?.right, val);\n} else {\nreturn node;            // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nself.updateHeight(node);    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n// 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nnode = self.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2_2","title":"2. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u7c7b\u4f3c\u5730\uff0c\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u8282\u70b9\u65b9\u6cd5\u7684\u57fa\u7840\u4e0a\uff0c\u9700\u8981\u4ece\u5e95\u81f3\u9876\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6240\u6709\u5931\u8861\u8282\u70b9\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def remove(self, val: int):\n\"\"\"\u5220\u9664\u8282\u70b9\"\"\"\nself._root = self.remove_helper(self._root, val)\ndef remove_helper(self, node: TreeNode | None, val: int) -> TreeNode | None:\n\"\"\"\u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\nif node is None:\nreturn None\n# 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b\nif val < node.val:\nnode.left = self.remove_helper(node.left, val)\nelif val > node.val:\nnode.right = self.remove_helper(node.right, val)\nelse:\nif node.left is None or node.right is None:\nchild = node.left or node.right\n# \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif child is None:\nreturn None\n# \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse:\nnode = child\nelse:\n# \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\ntemp = node.right\nwhile temp.left is not None:\ntemp = temp.left\nnode.right = self.remove_helper(node.right, temp.val)\nnode.val = temp.val\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\n# 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nreturn self.rotate(node)\n
        avl_tree.cpp
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\nif (node == nullptr)\nreturn nullptr;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node->val)\nnode->left = removeHelper(node->left, val);\nelse if (val > node->val)\nnode->right = removeHelper(node->right, val);\nelse {\nif (node->left == nullptr || node->right == nullptr) {\nTreeNode *child = node->left != nullptr ? node->left : node->right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == nullptr) {\ndelete node;\nreturn nullptr;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse {\ndelete node;\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode *temp = node->right;\nwhile (temp->left != nullptr) {\ntemp = temp->left;\n}\nint tempVal = temp->val;\nnode->right = removeHelper(node->right, temp->val);\nnode->val = tempVal;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.java
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode removeHelper(TreeNode node, int val) {\nif (node == null)\nreturn null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = removeHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode child = node.left != null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode temp = node.right;\nwhile (temp.left != null) {\ntemp = temp.left;\n}\nnode.right = removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.cs
        /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int val) {\nroot = RemoveHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? RemoveHelper(TreeNode? node, int val) {\nif (node == null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = RemoveHelper(node.left, val);\nelse if (val > node.val)\nnode.right = RemoveHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode? child = node.left ?? node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode? temp = node.right;\nwhile (temp.left != null) {\ntemp = temp.left;\n}\nnode.right = RemoveHelper(node.right, temp.val!.Value);\nnode.val = temp.val;\n}\n}\nUpdateHeight(node);  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.go
        /* \u5220\u9664\u8282\u70b9 */\nfunc (t *aVLTree) remove(val int) {\nt.root = t.removeHelper(t.root, val)\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {\nif node == nil {\nreturn nil\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node.Val.(int) {\nnode.Left = t.removeHelper(node.Left, val)\n} else if val > node.Val.(int) {\nnode.Right = t.removeHelper(node.Right, val)\n} else {\nif node.Left == nil || node.Right == nil {\nchild := node.Left\nif node.Right != nil {\nchild = node.Right\n}\nif child == nil {\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nreturn nil\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\ntemp := node.Right\nfor temp.Left != nil {\ntemp = temp.Left\n}\nnode.Right = t.removeHelper(node.Right, temp.Val.(int))\nnode.Val = temp.Val\n}\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = t.rotate(node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.swift
        /* \u5220\u9664\u8282\u70b9 */\nfunc remove(val: Int) {\nroot = removeHelper(node: root, val: val)\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc removeHelper(node: TreeNode?, val: Int) -> TreeNode? {\nvar node = node\nif node == nil {\nreturn nil\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node!.val {\nnode?.left = removeHelper(node: node?.left, val: val)\n} else if val > node!.val {\nnode?.right = removeHelper(node: node?.right, val: val)\n} else {\nif node?.left == nil || node?.right == nil {\nlet child = node?.left != nil ? node?.left : node?.right\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif child == nil {\nreturn nil\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse {\nnode = child\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nvar temp = node?.right\nwhile temp?.left != nil {\ntemp = temp?.left\n}\nnode?.right = removeHelper(node: node?.right, val: temp!.val)\nnode?.val = temp!.val\n}\n}\nupdateHeight(node: node) // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node: node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.js
        /* \u5220\u9664\u8282\u70b9 */\nremove(val) {\nthis.root = this.#removeHelper(this.root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#removeHelper(node, val) {\nif (node === null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val) node.left = this.#removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = this.#removeHelper(node.right, val);\nelse {\nif (node.left === null || node.right === null) {\nconst child = node.left !== null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child === null) return null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse node = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet temp = node.right;\nwhile (temp.left !== null) {\ntemp = temp.left;\n}\nnode.right = this.#removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nthis.#updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.#rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.ts
        /* \u5220\u9664\u8282\u70b9 */\nremove(val: number): void {\nthis.root = this.removeHelper(this.root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nremoveHelper(node: TreeNode, val: number): TreeNode {\nif (node === null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val) {\nnode.left = this.removeHelper(node.left, val);\n} else if (val > node.val) {\nnode.right = this.removeHelper(node.right, val);\n} else {\nif (node.left === null || node.right === null) {\nconst child = node.left !== null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child === null) {\nreturn null;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet temp = node.right;\nwhile (temp.left !== null) {\ntemp = temp.left;\n}\nnode.right = this.removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nthis.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.dart
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? removeHelper(TreeNode? node, int val) {\nif (node == null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = removeHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode? child = node.left ?? node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode? temp = node.right;\nwhile (temp!.left != null) {\ntemp = temp.left;\n}\nnode.right = removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.rs
        /* \u5220\u9664\u8282\u70b9 */\nfn remove(&self, val: i32) {\nSelf::remove_helper(self.root.clone(), val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn remove_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\nmatch node {\nSome(mut node) => {\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node.borrow().val {\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::remove_helper(left, val);\n} else if val > node.borrow().val {\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::remove_helper(right, val);\n} else if node.borrow().left.is_none() || node.borrow().right.is_none() {\nlet child = if node.borrow().left.is_some() {\nnode.borrow().left.clone()\n} else {\nnode.borrow().right.clone()\n};\nmatch child {\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nNone => {\nreturn None;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nSome(child) => node = child,\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet mut temp = node.borrow().right.clone().unwrap();\nloop {\nlet temp_left = temp.borrow().left.clone();\nif temp_left.is_none() {\nbreak;\n}\ntemp = temp_left.unwrap();\n}\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::remove_helper(right, temp.borrow().val);\nnode.borrow_mut().val = temp.borrow().val;\n}\nSelf::update_height(Some(node.clone())); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Self::rotate(Some(node)).unwrap();\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(node)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u5220\u9664\u8282\u70b9 */\n// \u7531\u4e8e\u5f15\u5165\u4e86 stdio.h \uff0c\u6b64\u5904\u65e0\u6cd5\u4f7f\u7528 remove \u5173\u952e\u8bcd\nvoid removeItem(AVLTree *tree, int val) {\nTreeNode *root = removeHelper(tree->root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\nTreeNode *child, *grandChild;\nif (node == NULL) {\nreturn NULL;\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node->val) {\nnode->left = removeHelper(node->left, val);\n} else if (val > node->val) {\nnode->right = removeHelper(node->right, val);\n} else {\nif (node->left == NULL || node->right == NULL) {\nchild = node->left;\nif (node->right != NULL) {\nchild = node->right;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == NULL) {\nreturn NULL;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode *temp = node->right;\nwhile (temp->left != NULL) {\ntemp = temp->left;\n}\nint tempVal = temp->val;\nnode->right = removeHelper(node->right, temp->val);\nnode->val = tempVal;\n}\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.zig
        // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, val: T) void {\nself.root = self.removeHelper(self.root, val).?;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\nfn removeHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) ?*inc.TreeNode(T) {\nvar node = node_;\nif (node == null) return null;\n// 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b\nif (val < node.?.val) {\nnode.?.left = self.removeHelper(node.?.left, val);\n} else if (val > node.?.val) {\nnode.?.right = self.removeHelper(node.?.right, val);\n} else {\nif (node.?.left == null or node.?.right == null) {\nvar child = if (node.?.left != null) node.?.left else node.?.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null) {\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n} else {\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nvar temp = node.?.right;\nwhile (temp.?.left != null) {\ntemp = temp.?.left;\n}\nnode.?.right = self.removeHelper(node.?.right, temp.?.val);\nnode.?.val = temp.?.val;\n}\n}\nself.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n// 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nnode = self.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#3_1","title":"3. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        AVL \u6811\u7684\u8282\u70b9\u67e5\u627e\u64cd\u4f5c\u4e0e\u4e8c\u53c9\u641c\u7d22\u6811\u4e00\u81f4\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

        "},{"location":"chapter_tree/avl_tree/#754-avl","title":"7.5.4 \u00a0 AVL \u6811\u5178\u578b\u5e94\u7528","text":"
        • \u7ec4\u7ec7\u548c\u5b58\u50a8\u5927\u578b\u6570\u636e\uff0c\u9002\u7528\u4e8e\u9ad8\u9891\u67e5\u627e\u3001\u4f4e\u9891\u589e\u5220\u7684\u573a\u666f\u3002
        • \u7528\u4e8e\u6784\u5efa\u6570\u636e\u5e93\u4e2d\u7684\u7d22\u5f15\u7cfb\u7edf\u3002
        • \u7ea2\u9ed1\u6811\u5728\u8bb8\u591a\u5e94\u7528\u4e2d\u6bd4 AVL \u6811\u66f4\u53d7\u6b22\u8fce\u3002\u8fd9\u662f\u56e0\u4e3a\u7ea2\u9ed1\u6811\u7684\u5e73\u8861\u6761\u4ef6\u76f8\u5bf9\u5bbd\u677e\uff0c\u5728\u7ea2\u9ed1\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\u6240\u9700\u7684\u65cb\u8f6c\u64cd\u4f5c\u76f8\u5bf9\u8f83\u5c11\uff0c\u5176\u8282\u70b9\u589e\u5220\u64cd\u4f5c\u7684\u5e73\u5747\u6548\u7387\u66f4\u9ad8\u3002
        "},{"location":"chapter_tree/binary_search_tree/","title":"7.4 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811","text":"

        \u5982\u56fe 7-16 \u6240\u793a\uff0c\u300c\u4e8c\u53c9\u641c\u7d22\u6811 binary search tree\u300d\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u3002

        1. \u5bf9\u4e8e\u6839\u8282\u70b9\uff0c\u5de6\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c \\(<\\) \u6839\u8282\u70b9\u7684\u503c \\(<\\) \u53f3\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u3002
        2. \u4efb\u610f\u8282\u70b9\u7684\u5de6\u3001\u53f3\u5b50\u6811\u4e5f\u662f\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5373\u540c\u6837\u6ee1\u8db3\u6761\u4ef6 1. \u3002

        \u56fe 7-16 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811

        "},{"location":"chapter_tree/binary_search_tree/#741","title":"7.4.1 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u64cd\u4f5c","text":"

        \u6211\u4eec\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u5c01\u88c5\u4e3a\u4e00\u4e2a\u7c7b BinarySearchTree \uff0c\u5e76\u58f0\u660e\u4e00\u4e2a\u6210\u5458\u53d8\u91cf root \uff0c\u6307\u5411\u6811\u7684\u6839\u8282\u70b9\u3002

        "},{"location":"chapter_tree/binary_search_tree/#1","title":"1. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        \u7ed9\u5b9a\u76ee\u6807\u8282\u70b9\u503c num \uff0c\u53ef\u4ee5\u6839\u636e\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u6765\u67e5\u627e\u3002\u5982\u56fe 7-17 \u6240\u793a\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u8282\u70b9 cur \uff0c\u4ece\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u51fa\u53d1\uff0c\u5faa\u73af\u6bd4\u8f83\u8282\u70b9\u503c cur.val \u548c num \u4e4b\u95f4\u7684\u5927\u5c0f\u5173\u7cfb\u3002

        • \u82e5 cur.val < num \uff0c\u8bf4\u660e\u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u6267\u884c cur = cur.right \u3002
        • \u82e5 cur.val > num \uff0c\u8bf4\u660e\u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u6267\u884c cur = cur.left \u3002
        • \u82e5 cur.val = num \uff0c\u8bf4\u660e\u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\u5e76\u8fd4\u56de\u8be5\u8282\u70b9\u3002
        <1><2><3><4>

        \u56fe 7-17 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u67e5\u627e\u8282\u70b9\u793a\u4f8b

        \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u64cd\u4f5c\u4e0e\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u4e00\u81f4\uff0c\u90fd\u662f\u6bcf\u8f6e\u6392\u9664\u4e00\u534a\u60c5\u51b5\u3002\u5faa\u73af\u6b21\u6570\u6700\u591a\u4e3a\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\uff0c\u5f53\u4e8c\u53c9\u6811\u5e73\u8861\u65f6\uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def search(self, num: int) -> TreeNode | None:\n\"\"\"\u67e5\u627e\u8282\u70b9\"\"\"\ncur = self._root\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur is not None:\n# \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelif cur.val > num:\ncur = cur.left\n# \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse:\nbreak\nreturn cur\n
        binary_search_tree.cpp
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(int num) {\nTreeNode *cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur->val > num)\ncur = cur->left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.java
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode search(int num) {\nTreeNode cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.cs
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? Search(int num) {\nTreeNode? cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur =\ncur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.go
        /* \u67e5\u627e\u8282\u70b9 */\nfunc (bst *binarySearchTree) search(num int) *TreeNode {\nnode := bst.root\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor node != nil {\nif node.Val.(int) < num {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nnode = node.Right\n} else if node.Val.(int) > num {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nnode = node.Left\n} else {\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn node\n}\n
        binary_search_tree.swift
        /* \u67e5\u627e\u8282\u70b9 */\nfunc search(num: Int) -> TreeNode? {\nvar cur = root\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if cur!.val > num {\ncur = cur?.left\n}\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse {\nbreak\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur\n}\n
        binary_search_tree.js
        /* \u67e5\u627e\u8282\u70b9 */\nsearch(num) {\nlet cur = this.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num) cur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse break;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.ts
        /* \u67e5\u627e\u8282\u70b9 */\nsearch(num: number): TreeNode | null {\nlet cur = this.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num) cur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse break;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.dart
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? search(int _num) {\nTreeNode? cur = _root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > _num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.rs
        /* \u67e5\u627e\u8282\u70b9 */\npub fn search(&self, num: i32) -> Option<TreeNodeRc> {\nlet mut cur = self.root.clone();\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if node.borrow().val > num {\ncur = node.borrow().left.clone();\n}\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse {\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\ncur\n}\n
        binary_search_tree.c
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(BinarySearchTree *bst, int num) {\nTreeNode *cur = bst->root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\nif (cur->val < num) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else if (cur->val > num) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n} else {\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.zig
        // \u67e5\u627e\u8282\u70b9\nfn search(self: *Self, num: T) ?*inc.TreeNode(T) {\nvar cur = self.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else if (cur.?.val > num) {\ncur = cur.?.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n} else {\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        "},{"location":"chapter_tree/binary_search_tree/#2","title":"2. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u5f85\u63d2\u5165\u5143\u7d20 num \uff0c\u4e3a\u4e86\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u201c\u5de6\u5b50\u6811 < \u6839\u8282\u70b9 < \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\uff0c\u63d2\u5165\u64cd\u4f5c\u6d41\u7a0b\u5982\u56fe 7-18 \u6240\u793a\u3002

        1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff1a\u4e0e\u67e5\u627e\u64cd\u4f5c\u76f8\u4f3c\uff0c\u4ece\u6839\u8282\u70b9\u51fa\u53d1\uff0c\u6839\u636e\u5f53\u524d\u8282\u70b9\u503c\u548c num \u7684\u5927\u5c0f\u5173\u7cfb\u5faa\u73af\u5411\u4e0b\u641c\u7d22\uff0c\u76f4\u5230\u8d8a\u8fc7\u53f6\u8282\u70b9\uff08\u904d\u5386\u81f3 \\(\\text{None}\\) \uff09\u65f6\u8df3\u51fa\u5faa\u73af\u3002
        2. \u5728\u8be5\u4f4d\u7f6e\u63d2\u5165\u8282\u70b9\uff1a\u521d\u59cb\u5316\u8282\u70b9 num \uff0c\u5c06\u8be5\u8282\u70b9\u7f6e\u4e8e \\(\\text{None}\\) \u7684\u4f4d\u7f6e\u3002

        \u56fe 7-18 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u63d2\u5165\u8282\u70b9

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e24\u70b9\u3002

        • \u4e8c\u53c9\u641c\u7d22\u6811\u4e0d\u5141\u8bb8\u5b58\u5728\u91cd\u590d\u8282\u70b9\uff0c\u5426\u5219\u5c06\u8fdd\u53cd\u5176\u5b9a\u4e49\u3002\u56e0\u6b64\uff0c\u82e5\u5f85\u63d2\u5165\u8282\u70b9\u5728\u6811\u4e2d\u5df2\u5b58\u5728\uff0c\u5219\u4e0d\u6267\u884c\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\u3002
        • \u4e3a\u4e86\u5b9e\u73b0\u63d2\u5165\u8282\u70b9\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u8282\u70b9 pre \u4fdd\u5b58\u4e0a\u4e00\u8f6e\u5faa\u73af\u7684\u8282\u70b9\u3002\u8fd9\u6837\u5728\u904d\u5386\u81f3 \\(\\text{None}\\) \u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u5230\u5176\u7236\u8282\u70b9\uff0c\u4ece\u800c\u5b8c\u6210\u8282\u70b9\u63d2\u5165\u64cd\u4f5c\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def insert(self, num: int):\n\"\"\"\u63d2\u5165\u8282\u70b9\"\"\"\n# \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif self._root is None:\nself._root = TreeNode(num)\nreturn\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\ncur, pre = self._root, None\nwhile cur is not None:\n# \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif cur.val == num:\nreturn\npre = cur\n# \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse:\ncur = cur.left\n# \u63d2\u5165\u8282\u70b9\nnode = TreeNode(num)\nif pre.val < num:\npre.right = node\nelse:\npre.left = node\n
        binary_search_tree.cpp
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == nullptr) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode *cur = root, *pre = nullptr;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur->val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur->left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode *node = new TreeNode(num);\nif (pre->val < num)\npre->right = node;\nelse\npre->left = node;\n}\n
        binary_search_tree.java
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == null) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode node = new TreeNode(num);\nif (pre.val < num)\npre.right = node;\nelse\npre.left = node;\n}\n
        binary_search_tree.cs
        /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == null) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode? cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode node = new(num);\nif (pre != null) {\nif (pre.val < num)\npre.right = node;\nelse\npre.left = node;\n}\n}\n
        binary_search_tree.go
        /* \u63d2\u5165\u8282\u70b9 */\nfunc (bst *binarySearchTree) insert(num int) {\ncur := bst.root\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif cur == nil {\nbst.root = NewTreeNode(num)\nreturn\n}\n// \u5f85\u63d2\u5165\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\nvar pre *TreeNode = nil\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor cur != nil {\nif cur.Val == num {\nreturn\n}\npre = cur\nif cur.Val.(int) < num {\ncur = cur.Right\n} else {\ncur = cur.Left\n}\n}\n// \u63d2\u5165\u8282\u70b9\nnode := NewTreeNode(num)\nif pre.Val.(int) < num {\npre.Right = node\n} else {\npre.Left = node\n}\n}\n
        binary_search_tree.swift
        /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(num: Int) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif root == nil {\nroot = TreeNode(x: num)\nreturn\n}\nvar cur = root\nvar pre: TreeNode?\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif cur!.val == num {\nreturn\n}\npre = cur\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = cur?.left\n}\n}\n// \u63d2\u5165\u8282\u70b9\nlet node = TreeNode(x: num)\nif pre!.val < num {\npre?.right = node\n} else {\npre?.left = node\n}\n}\n
        binary_search_tree.js
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (this.root === null) {\nthis.root = new TreeNode(num);\nreturn;\n}\nlet cur = this.root,\npre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val === num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nconst node = new TreeNode(num);\nif (pre.val < num) pre.right = node;\nelse pre.left = node;\n}\n
        binary_search_tree.ts
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(num: number): void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (this.root === null) {\nthis.root = new TreeNode(num);\nreturn;\n}\nlet cur: TreeNode | null = this.root,\npre: TreeNode | null = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val === num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nconst node = new TreeNode(num);\nif (pre!.val < num) pre!.right = node;\nelse pre!.left = node;\n}\n
        binary_search_tree.dart
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int _num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (_root == null) {\n_root = TreeNode(_num);\nreturn;\n}\nTreeNode? cur = _root;\nTreeNode? pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == _num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode? node = TreeNode(_num);\nif (pre!.val < _num)\npre.right = node;\nelse\npre.left = node;\n}\n
        binary_search_tree.rs
        /* \u63d2\u5165\u8282\u70b9 */\npub fn insert(&mut self, num: i32) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif self.root.is_none() {\nself.root = Some(TreeNode::new(num));\nreturn;\n}\nlet mut cur = self.root.clone();\nlet mut pre = None;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif node.borrow().val == num {\nreturn;\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\npre = cur.clone();\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = node.borrow().left.clone();\n}\n}\n// \u63d2\u5165\u8282\u70b9\nlet node = TreeNode::new(num);\nlet pre = pre.unwrap();\nif pre.borrow().val < num {\npre.borrow_mut().right = Some(Rc::clone(&node));\n} else {\npre.borrow_mut().left = Some(Rc::clone(&node));\n}\n}\n
        binary_search_tree.c
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(BinarySearchTree *bst, int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (bst->root == NULL) {\nbst->root = newTreeNode(num);\nreturn;\n}\nTreeNode *cur = bst->root, *pre = NULL;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur->val == num) {\nreturn;\n}\npre = cur;\nif (cur->val < num) {\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else {\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n}\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode *node = newTreeNode(num);\nif (pre->val < num) {\npre->right = node;\n} else {\npre->left = node;\n}\n}\n
        binary_search_tree.zig
        // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, num: T) !void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (self.root == null) {\nself.root = try self.mem_allocator.create(inc.TreeNode(T));\nreturn;\n}\nvar cur = self.root;\nvar pre: ?*inc.TreeNode(T) = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.?.val == num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else {\ncur = cur.?.left;\n}\n}\n// \u63d2\u5165\u8282\u70b9\nvar node = try self.mem_allocator.create(inc.TreeNode(T));\nnode.init(num);\nif (pre.?.val < num) {\npre.?.right = node;\n} else {\npre.?.left = node;\n}\n}\n

        \u4e0e\u67e5\u627e\u8282\u70b9\u76f8\u540c\uff0c\u63d2\u5165\u8282\u70b9\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\u3002

        "},{"location":"chapter_tree/binary_search_tree/#3","title":"3. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u5148\u5728\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u518d\u5c06\u5176\u5220\u9664\u3002

        \u4e0e\u63d2\u5165\u8282\u70b9\u7c7b\u4f3c\uff0c\u6211\u4eec\u9700\u8981\u4fdd\u8bc1\u5728\u5220\u9664\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u201c\u5de6\u5b50\u6811 < \u6839\u8282\u70b9 < \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\u4ecd\u7136\u6ee1\u8db3\u3002

        \u56e0\u6b64\uff0c\u6211\u4eec\u6839\u636e\u76ee\u6807\u8282\u70b9\u7684\u5b50\u8282\u70b9\u6570\u91cf\uff0c\u5206 0\u30011 \u548c 2 \u4e09\u79cd\u60c5\u51b5\uff0c\u6267\u884c\u5bf9\u5e94\u7684\u5220\u9664\u8282\u70b9\u64cd\u4f5c\u3002

        \u5982\u56fe 7-19 \u6240\u793a\uff0c\u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(0\\) \u65f6\uff0c\u8868\u793a\u8be5\u8282\u70b9\u662f\u53f6\u8282\u70b9\uff0c\u53ef\u4ee5\u76f4\u63a5\u5220\u9664\u3002

        \u56fe 7-19 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 0 \uff09

        \u5982\u56fe 7-20 \u6240\u793a\uff0c\u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(1\\) \u65f6\uff0c\u5c06\u5f85\u5220\u9664\u8282\u70b9\u66ff\u6362\u4e3a\u5176\u5b50\u8282\u70b9\u5373\u53ef\u3002

        \u56fe 7-20 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 1 \uff09

        \u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(2\\) \u65f6\uff0c\u6211\u4eec\u65e0\u6cd5\u76f4\u63a5\u5220\u9664\u5b83\uff0c\u800c\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u8282\u70b9\u66ff\u6362\u8be5\u8282\u70b9\u3002\u7531\u4e8e\u8981\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u201c\u5de6\u5b50\u6811 \\(<\\) \u6839\u8282\u70b9 \\(<\\) \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\uff0c\u56e0\u6b64\u8fd9\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u53f3\u5b50\u6811\u7684\u6700\u5c0f\u8282\u70b9\u6216\u5de6\u5b50\u6811\u7684\u6700\u5927\u8282\u70b9\u3002

        \u5047\u8bbe\u6211\u4eec\u9009\u62e9\u53f3\u5b50\u6811\u7684\u6700\u5c0f\u8282\u70b9\uff08\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\uff09\uff0c\u5219\u5220\u9664\u64cd\u4f5c\u6d41\u7a0b\u5982\u56fe 7-21 \u6240\u793a\u3002

        1. \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\u5728\u201c\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u201d\u4e2d\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\uff0c\u8bb0\u4e3a tmp \u3002
        2. \u7528 tmp \u7684\u503c\u8986\u76d6\u5f85\u5220\u9664\u8282\u70b9\u7684\u503c\uff0c\u5e76\u5728\u6811\u4e2d\u9012\u5f52\u5220\u9664\u8282\u70b9 tmp \u3002
        <1><2><3><4>

        \u56fe 7-21 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 2 \uff09

        \u5220\u9664\u8282\u70b9\u64cd\u4f5c\u540c\u6837\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\uff0c\u5176\u4e2d\u67e5\u627e\u5f85\u5220\u9664\u8282\u70b9\u9700\u8981 \\(O(\\log n)\\) \u65f6\u95f4\uff0c\u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u540e\u7ee7\u8282\u70b9\u9700\u8981 \\(O(\\log n)\\) \u65f6\u95f4\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def remove(self, num: int):\n\"\"\"\u5220\u9664\u8282\u70b9\"\"\"\n# \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif self._root is None:\nreturn\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\ncur, pre = self._root, None\nwhile cur is not None:\n# \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif cur.val == num:\nbreak\npre = cur\n# \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse:\ncur = cur.left\n# \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur is None:\nreturn\n# \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur.left is None or cur.right is None:\n# \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nchild = cur.left or cur.right\n# \u5220\u9664\u8282\u70b9 cur\nif cur != self._root:\nif pre.left == cur:\npre.left = child\nelse:\npre.right = child\nelse:\n# \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nself._root = child\n# \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse:\n# \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\ntmp: TreeNode = cur.right\nwhile tmp.left is not None:\ntmp = tmp.left\n# \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmp.val)\n# \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val\n
        binary_search_tree.cpp
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == nullptr)\nreturn;\nTreeNode *cur = root, *pre = nullptr;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur->val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur->left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == nullptr)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur->left == nullptr || cur->right == nullptr) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nTreeNode *child = cur->left != nullptr ? cur->left : cur->right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre->left == cur)\npre->left = child;\nelse\npre->right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n// \u91ca\u653e\u5185\u5b58\ndelete cur;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode *tmp = cur->right;\nwhile (tmp->left != nullptr) {\ntmp = tmp->left;\n}\nint tmpVal = tmp->val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp->val);\n// \u7528 tmp \u8986\u76d6 cur\ncur->val = tmpVal;\n}\n}\n
        binary_search_tree.java
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == null)\nreturn;\nTreeNode cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode child = cur.left != null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode tmp = cur.right;\nwhile (tmp.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.cs
        /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == null)\nreturn;\nTreeNode? cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode? child = cur.left ?? cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre!.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode? tmp = cur.right;\nwhile (tmp.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nRemove(tmp.val!.Value);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.go
        /* \u5220\u9664\u8282\u70b9 */\nfunc (bst *binarySearchTree) remove(num int) {\ncur := bst.root\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\nvar pre *TreeNode = nil\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor cur != nil {\nif cur.Val == num {\nbreak\n}\npre = cur\nif cur.Val.(int) < num {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728\u53f3\u5b50\u6811\u4e2d\ncur = cur.Right\n} else {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728\u5de6\u5b50\u6811\u4e2d\ncur = cur.Left\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5b50\u8282\u70b9\u6570\u4e3a 0 \u6216 1\nif cur.Left == nil || cur.Right == nil {\nvar child *TreeNode = nil\n// \u53d6\u51fa\u5f85\u5220\u9664\u8282\u70b9\u7684\u5b50\u8282\u70b9\nif cur.Left != nil {\nchild = cur.Left\n} else {\nchild = cur.Right\n}\n// \u5220\u9664\u8282\u70b9 cur\nif cur != bst.root {\nif pre.Left == cur {\npre.Left = child\n} else {\npre.Right = child\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nbst.root = child\n}\n// \u5b50\u8282\u70b9\u6570\u4e3a 2\n} else {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d\u5f85\u5220\u9664\u8282\u70b9 cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\ntmp := cur.Right\nfor tmp.Left != nil {\ntmp = tmp.Left\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nbst.remove(tmp.Val.(int))\n// \u7528 tmp \u8986\u76d6 cur\ncur.Val = tmp.Val\n}\n}\n
        binary_search_tree.swift
        /* \u5220\u9664\u8282\u70b9 */\nfunc remove(num: Int) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif root == nil {\nreturn\n}\nvar cur = root\nvar pre: TreeNode?\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif cur!.val == num {\nbreak\n}\npre = cur\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = cur?.left\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur?.left == nil || cur?.right == nil {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nlet child = cur?.left != nil ? cur?.left : cur?.right\n// \u5220\u9664\u8282\u70b9 cur\nif cur !== root {\nif pre?.left === cur {\npre?.left = child\n} else {\npre?.right = child\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nvar tmp = cur?.right\nwhile tmp?.left != nil {\ntmp = tmp?.left\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(num: tmp!.val)\n// \u7528 tmp \u8986\u76d6 cur\ncur?.val = tmp!.val\n}\n}\n
        binary_search_tree.js
        /* \u5220\u9664\u8282\u70b9 */\nremove(num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (this.root === null) return;\nlet cur = this.root,\npre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val === num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur === null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left === null || cur.right === null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nconst child = cur.left !== null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur !== this.root) {\nif (pre.left === cur) pre.left = child;\nelse pre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nthis.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet tmp = cur.right;\nwhile (tmp.left !== null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nthis.remove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.ts
        /* \u5220\u9664\u8282\u70b9 */\nremove(num: number): void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (this.root === null) return;\nlet cur: TreeNode | null = this.root,\npre: TreeNode | null = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val === num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur === null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left === null || cur.right === null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nconst child: TreeNode | null =\ncur.left !== null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur !== this.root) {\nif (pre!.left === cur) pre!.left = child;\nelse pre!.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nthis.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet tmp: TreeNode | null = cur.right;\nwhile (tmp!.left !== null) {\ntmp = tmp!.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nthis.remove(tmp!.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp!.val;\n}\n}\n
        binary_search_tree.dart
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int _num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (_root == null) return;\nTreeNode? cur = _root;\nTreeNode? pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == _num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur == null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode? child = cur.left ?? cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != _root) {\nif (pre!.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n_root = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode? tmp = cur.right;\nwhile (tmp!.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.rs
        /* \u5220\u9664\u8282\u70b9 */\npub fn remove(&mut self, num: i32) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif self.root.is_none() { return; }\nlet mut cur = self.root.clone();\nlet mut pre = None;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif node.borrow().val == num {\nbreak;\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\npre = cur.clone();\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = node.borrow().left.clone();\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur.is_none() {\nreturn;\n}\nlet cur = cur.unwrap();\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur.borrow().left.is_none() || cur.borrow().right.is_none() {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nlet child = cur.borrow().left.clone().or_else(|| cur.borrow().right.clone());\nlet pre = pre.unwrap();\nlet left = pre.borrow().left.clone().unwrap();\n// \u5220\u9664\u8282\u70b9 cur\nif !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) {\nif Rc::ptr_eq(&left, &cur) {\npre.borrow_mut().left = child;\n} else {\npre.borrow_mut().right = child;\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nself.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet mut tmp = cur.borrow().right.clone();\nwhile let Some(node) = tmp.clone() {\nif node.borrow().left.is_some() {\ntmp = node.borrow().left.clone();\n} else {\nbreak;\n}\n}\nlet tmpval = tmp.unwrap().borrow().val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmpval);\n// \u7528 tmp \u8986\u76d6 cur\ncur.borrow_mut().val = tmpval;\n}\n}\n
        binary_search_tree.c
        /* \u5220\u9664\u8282\u70b9 */\n// \u7531\u4e8e\u5f15\u5165\u4e86 stdio.h \uff0c\u6b64\u5904\u65e0\u6cd5\u4f7f\u7528 remove \u5173\u952e\u8bcd\nvoid removeItem(BinarySearchTree *bst, int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (bst->root == NULL)\nreturn;\nTreeNode *cur = bst->root, *pre = NULL;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur->val == num)\nbreak;\npre = cur;\nif (cur->val < num) {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == NULL)\nreturn;\n// \u5224\u65ad\u5f85\u5220\u9664\u8282\u70b9\u662f\u5426\u5b58\u5728\u5b50\u8282\u70b9\nif (cur->left == NULL || cur->right == NULL) {\n/* \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1 */\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nTreeNode *child = cur->left != NULL ? cur->left : cur->right;\n// \u5220\u9664\u8282\u70b9 cur\nif (pre->left == cur) {\npre->left = child;\n} else {\npre->right = child;\n}\n} else {\n/* \u5b50\u8282\u70b9\u6570\u91cf = 2 */\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode *tmp = cur->right;\nwhile (tmp->left != NULL) {\ntmp = tmp->left;\n}\nint tmpVal = tmp->val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremoveItem(bst, tmp->val);\n// \u7528 tmp \u8986\u76d6 cur\ncur->val = tmpVal;\n}\n}\n
        binary_search_tree.zig
        // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, num: T) void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (self.root == null) return;\nvar cur = self.root;\nvar pre: ?*inc.TreeNode(T) = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.?.val == num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else {\ncur = cur.?.left;\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.?.left == null or cur.?.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nvar child = if (cur.?.left != null) cur.?.left else cur.?.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (pre.?.left == cur) {\npre.?.left = child;\n} else {\npre.?.right = child;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\n} else {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nvar tmp = cur.?.right;\nwhile (tmp.?.left != null) {\ntmp = tmp.?.left;\n}\nvar tmp_val = tmp.?.val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmp.?.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.?.val = tmp_val;\n}\n}\n
        "},{"location":"chapter_tree/binary_search_tree/#4","title":"4. \u00a0 \u4e2d\u5e8f\u904d\u5386\u6709\u5e8f","text":"

        \u5982\u56fe 7-22 \u6240\u793a\uff0c\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u9075\u5faa\u201c\u5de6 \\(\\rightarrow\\) \u6839 \\(\\rightarrow\\) \u53f3\u201d\u7684\u904d\u5386\u987a\u5e8f\uff0c\u800c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u201c\u5de6\u5b50\u8282\u70b9 \\(<\\) \u6839\u8282\u70b9 \\(<\\) \u53f3\u5b50\u8282\u70b9\u201d\u7684\u5927\u5c0f\u5173\u7cfb\u3002

        \u8fd9\u610f\u5473\u7740\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u8fdb\u884c\u4e2d\u5e8f\u904d\u5386\u65f6\uff0c\u603b\u662f\u4f1a\u4f18\u5148\u904d\u5386\u4e0b\u4e00\u4e2a\u6700\u5c0f\u8282\u70b9\uff0c\u4ece\u800c\u5f97\u51fa\u4e00\u4e2a\u91cd\u8981\u6027\u8d28\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u662f\u5347\u5e8f\u7684\u3002

        \u5229\u7528\u4e2d\u5e8f\u904d\u5386\u5347\u5e8f\u7684\u6027\u8d28\uff0c\u6211\u4eec\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u83b7\u53d6\u6709\u5e8f\u6570\u636e\u4ec5\u9700 \\(O(n)\\) \u65f6\u95f4\uff0c\u65e0\u987b\u8fdb\u884c\u989d\u5916\u7684\u6392\u5e8f\u64cd\u4f5c\uff0c\u975e\u5e38\u9ad8\u6548\u3002

        \u56fe 7-22 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217

        "},{"location":"chapter_tree/binary_search_tree/#742","title":"7.4.2 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6548\u7387","text":"

        \u7ed9\u5b9a\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u8003\u8651\u4f7f\u7528\u6570\u7ec4\u6216\u4e8c\u53c9\u641c\u7d22\u6811\u5b58\u50a8\u3002\u89c2\u5bdf\u8868 7-2 \uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5404\u9879\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662f\u5bf9\u6570\u9636\uff0c\u5177\u6709\u7a33\u5b9a\u4e14\u9ad8\u6548\u7684\u6027\u80fd\u3002\u53ea\u6709\u5728\u9ad8\u9891\u6dfb\u52a0\u3001\u4f4e\u9891\u67e5\u627e\u5220\u9664\u6570\u636e\u7684\u573a\u666f\u4e0b\uff0c\u6570\u7ec4\u6bd4\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6548\u7387\u66f4\u9ad8\u3002

        \u8868 7-2 \u00a0 \u6570\u7ec4\u4e0e\u641c\u7d22\u6811\u7684\u6548\u7387\u5bf9\u6bd4

        \u65e0\u5e8f\u6570\u7ec4 \u4e8c\u53c9\u641c\u7d22\u6811 \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\) \u63d2\u5165\u5143\u7d20 \\(O(1)\\) \\(O(\\log n)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\)

        \u5728\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u201c\u5e73\u8861\u201d\u7684\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 \\(\\log n\\) \u8f6e\u5faa\u73af\u5185\u67e5\u627e\u4efb\u610f\u8282\u70b9\u3002

        \u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u4e0d\u65ad\u5730\u63d2\u5165\u548c\u5220\u9664\u8282\u70b9\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u56fe 7-23 \u6240\u793a\u7684\u94fe\u8868\uff0c\u8fd9\u65f6\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u4f1a\u9000\u5316\u4e3a \\(O(n)\\) \u3002

        \u56fe 7-23 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u9000\u5316

        "},{"location":"chapter_tree/binary_search_tree/#743","title":"7.4.3 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u5e38\u89c1\u5e94\u7528","text":"
        • \u7528\u4f5c\u7cfb\u7edf\u4e2d\u7684\u591a\u7ea7\u7d22\u5f15\uff0c\u5b9e\u73b0\u9ad8\u6548\u7684\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u3002
        • \u4f5c\u4e3a\u67d0\u4e9b\u641c\u7d22\u7b97\u6cd5\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002
        • \u7528\u4e8e\u5b58\u50a8\u6570\u636e\u6d41\uff0c\u4ee5\u4fdd\u6301\u5176\u6709\u5e8f\u72b6\u6001\u3002
        "},{"location":"chapter_tree/binary_tree/","title":"7.1 \u00a0 \u4e8c\u53c9\u6811","text":"

        \u300c\u4e8c\u53c9\u6811 binary tree\u300d\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u4ee3\u8868\u201c\u7956\u5148\u201d\u4e0e\u201c\u540e\u4ee3\u201d\u4e4b\u95f4\u7684\u6d3e\u751f\u5173\u7cfb\uff0c\u4f53\u73b0\u4e86\u201c\u4e00\u5206\u4e3a\u4e8c\u201d\u7684\u5206\u6cbb\u903b\u8f91\u3002\u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u4e8c\u53c9\u6811\u7684\u57fa\u672c\u5355\u5143\u662f\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u503c\u3001\u5de6\u5b50\u8282\u70b9\u5f15\u7528\u548c\u53f3\u5b50\u8282\u70b9\u5f15\u7528\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class TreeNode:\n\"\"\"\u4e8c\u53c9\u6811\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                # \u8282\u70b9\u503c\nself.left: TreeNode | None = None  # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nself.right: TreeNode | None = None # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nint val;          // \u8282\u70b9\u503c\nTreeNode *left;   // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nTreeNode *right;  // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nTreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nTreeNode left;   // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode right;  // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode(int x) { val = x; }\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\npublic int? val = x;    // \u8282\u70b9\u503c\npublic TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\npublic TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\nVal   int\nLeft  *TreeNode\nRight *TreeNode\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc NewTreeNode(v int) *TreeNode {\nreturn &TreeNode{\nLeft:  nil, // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nRight: nil, // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nVal:   v,   // \u8282\u70b9\u503c\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nvar val: Int // \u8282\u70b9\u503c\nvar left: TreeNode? // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nvar right: TreeNode? // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\ninit(x: Int) {\nval = x\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval; // \u8282\u70b9\u503c\nleft; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val, left, right) {\nthis.val = val === undefined ? 0 : val;\nthis.left = left === undefined ? null : left;\nthis.right = right === undefined ? null : right;\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval: number;\nleft: TreeNode | null;\nright: TreeNode | null;\nconstructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.left = left === undefined ? null : left; // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nthis.right = right === undefined ? null : right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nTreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode(this.val, [this.left, this.right]);\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nval: i32,                               // \u8282\u70b9\u503c\nleft: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nright: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\nimpl TreeNode {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(val: i32) -> Rc<RefCell<Self>> {\nRc::new(RefCell::new(Self {\nval,\nleft: None,\nright: None\n}))\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct TreeNode {\nint val;                // \u8282\u70b9\u503c\nint height;             // \u8282\u70b9\u9ad8\u5ea6\nstruct TreeNode *left;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nstruct TreeNode *right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n} TreeNode;\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\nTreeNode *node;\nnode = (TreeNode *)malloc(sizeof(TreeNode));\nnode->val = val;\nnode->height = 0;\nnode->left = NULL;\nnode->right = NULL;\nreturn node;\n}\n
        \n

        \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u5206\u522b\u6307\u5411\u300c\u5de6\u5b50\u8282\u70b9 left-child node\u300d\u548c\u300c\u53f3\u5b50\u8282\u70b9 right-child node\u300d\uff0c\u8be5\u8282\u70b9\u88ab\u79f0\u4e3a\u8fd9\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u300c\u7236\u8282\u70b9 parent node\u300d\u3002\u5f53\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u65f6\uff0c\u6211\u4eec\u5c06\u8be5\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u79f0\u4e3a\u8be5\u8282\u70b9\u7684\u300c\u5de6\u5b50\u6811 left subtree\u300d\uff0c\u540c\u7406\u53ef\u5f97\u300c\u53f3\u5b50\u6811 right subtree\u300d\u3002

        \u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u9664\u53f6\u8282\u70b9\u5916\uff0c\u5176\u4ed6\u6240\u6709\u8282\u70b9\u90fd\u5305\u542b\u5b50\u8282\u70b9\u548c\u975e\u7a7a\u5b50\u6811\u3002\u5982\u56fe 7-1 \u6240\u793a\uff0c\u5982\u679c\u5c06\u201c\u8282\u70b9 2\u201d\u89c6\u4e3a\u7236\u8282\u70b9\uff0c\u5219\u5176\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\u5206\u522b\u662f\u201c\u8282\u70b9 4\u201d\u548c\u201c\u8282\u70b9 5\u201d\uff0c\u5de6\u5b50\u6811\u662f\u201c\u8282\u70b9 4 \u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u201d\uff0c\u53f3\u5b50\u6811\u662f\u201c\u8282\u70b9 5 \u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u201d\u3002

        \u56fe 7-1 \u00a0 \u7236\u8282\u70b9\u3001\u5b50\u8282\u70b9\u3001\u5b50\u6811

        "},{"location":"chapter_tree/binary_tree/#711","title":"7.1.1 \u00a0 \u4e8c\u53c9\u6811\u5e38\u89c1\u672f\u8bed","text":"

        \u4e8c\u53c9\u6811\u7684\u5e38\u7528\u672f\u8bed\u5982\u56fe 7-2 \u6240\u793a\u3002

        • \u300c\u6839\u8282\u70b9 root node\u300d\uff1a\u4f4d\u4e8e\u4e8c\u53c9\u6811\u9876\u5c42\u7684\u8282\u70b9\uff0c\u6ca1\u6709\u7236\u8282\u70b9\u3002
        • \u300c\u53f6\u8282\u70b9 leaf node\u300d\uff1a\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff0c\u5176\u4e24\u4e2a\u6307\u9488\u5747\u6307\u5411 \\(\\text{None}\\) \u3002
        • \u300c\u8fb9 edge\u300d\uff1a\u8fde\u63a5\u4e24\u4e2a\u8282\u70b9\u7684\u7ebf\u6bb5\uff0c\u5373\u8282\u70b9\u5f15\u7528\uff08\u6307\u9488\uff09\u3002
        • \u8282\u70b9\u6240\u5728\u7684\u300c\u5c42 level\u300d\uff1a\u4ece\u9876\u81f3\u5e95\u9012\u589e\uff0c\u6839\u8282\u70b9\u6240\u5728\u5c42\u4e3a 1 \u3002
        • \u8282\u70b9\u7684\u300c\u5ea6 degree\u300d\uff1a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u7684\u6570\u91cf\u3002\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u5ea6\u7684\u53d6\u503c\u8303\u56f4\u662f 0\u30011\u30012 \u3002
        • \u4e8c\u53c9\u6811\u7684\u300c\u9ad8\u5ea6 height\u300d\uff1a\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002
        • \u8282\u70b9\u7684\u300c\u6df1\u5ea6 depth\u300d\uff1a\u4ece\u6839\u8282\u70b9\u5230\u8be5\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002
        • \u8282\u70b9\u7684\u300c\u9ad8\u5ea6 height\u300d\uff1a\u4ece\u8ddd\u79bb\u8be5\u8282\u70b9\u6700\u8fdc\u7684\u53f6\u8282\u70b9\u5230\u8be5\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002

        \u56fe 7-2 \u00a0 \u4e8c\u53c9\u6811\u7684\u5e38\u7528\u672f\u8bed

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u901a\u5e38\u5c06\u201c\u9ad8\u5ea6\u201d\u548c\u201c\u6df1\u5ea6\u201d\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u201d\uff0c\u4f46\u6709\u4e9b\u9898\u76ee\u6216\u6559\u6750\u53ef\u80fd\u4f1a\u5c06\u5176\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8282\u70b9\u7684\u6570\u91cf\u201d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9ad8\u5ea6\u548c\u6df1\u5ea6\u90fd\u9700\u8981\u52a0 1 \u3002

        "},{"location":"chapter_tree/binary_tree/#712","title":"7.1.2 \u00a0 \u4e8c\u53c9\u6811\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"chapter_tree/binary_tree/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u4e8c\u53c9\u6811","text":"

        \u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u9996\u5148\u521d\u59cb\u5316\u8282\u70b9\uff0c\u7136\u540e\u6784\u5efa\u5f15\u7528\uff08\u6307\u9488\uff09\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree.py
        # \u521d\u59cb\u5316\u4e8c\u53c9\u6811\n# \u521d\u59cb\u5316\u8282\u70b9\nn1 = TreeNode(val=1)\nn2 = TreeNode(val=2)\nn3 = TreeNode(val=3)\nn4 = TreeNode(val=4)\nn5 = TreeNode(val=5)\n# \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2\nn1.right = n3\nn2.left = n4\nn2.right = n5\n
        binary_tree.cpp
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode* n1 = new TreeNode(1);\nTreeNode* n2 = new TreeNode(2);\nTreeNode* n3 = new TreeNode(3);\nTreeNode* n4 = new TreeNode(4);\nTreeNode* n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1->left = n2;\nn1->right = n3;\nn2->left = n4;\nn2->right = n5;\n
        binary_tree.java
        // \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new TreeNode(1);\nTreeNode n2 = new TreeNode(2);\nTreeNode n3 = new TreeNode(3);\nTreeNode n4 = new TreeNode(4);\nTreeNode n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.cs
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new(1);\nTreeNode n2 = new(2);\nTreeNode n3 = new(3);\nTreeNode n4 = new(4);\nTreeNode n5 = new(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.go
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nn1 := NewTreeNode(1)\nn2 := NewTreeNode(2)\nn3 := NewTreeNode(3)\nn4 := NewTreeNode(4)\nn5 := NewTreeNode(5)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.Left = n2\nn1.Right = n3\nn2.Left = n4\nn2.Right = n5\n
        binary_tree.swift
        // \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = TreeNode(x: 1)\nlet n2 = TreeNode(x: 2)\nlet n3 = TreeNode(x: 3)\nlet n4 = TreeNode(x: 4)\nlet n5 = TreeNode(x: 5)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2\nn1.right = n3\nn2.left = n4\nn2.right = n5\n
        binary_tree.js
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\nn2 = new TreeNode(2),\nn3 = new TreeNode(3),\nn4 = new TreeNode(4),\nn5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.ts
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\nn2 = new TreeNode(2),\nn3 = new TreeNode(3),\nn4 = new TreeNode(4),\nn5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.dart
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new TreeNode(1);\nTreeNode n2 = new TreeNode(2);\nTreeNode n3 = new TreeNode(3);\nTreeNode n4 = new TreeNode(4);\nTreeNode n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.rs
        // \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = TreeNode::new(1);\nlet n2 = TreeNode::new(2);\nlet n3 = TreeNode::new(3);\nlet n4 = TreeNode::new(4);\nlet n5 = TreeNode::new(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.borrow_mut().left = Some(n2.clone());\nn1.borrow_mut().right = Some(n3);\nn2.borrow_mut().left = Some(n4);\nn2.borrow_mut().right = Some(n5);\n
        binary_tree.c
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode *n1 = newTreeNode(1);\nTreeNode *n2 = newTreeNode(2);\nTreeNode *n3 = newTreeNode(3);\nTreeNode *n4 = newTreeNode(4);\nTreeNode *n5 = newTreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1->left = n2;\nn1->right = n3;\nn2->left = n4;\nn2->right = n5;\n
        binary_tree.zig
        \n
        "},{"location":"chapter_tree/binary_tree/#2","title":"2. \u00a0 \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9","text":"

        \u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u5728\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u6307\u9488\u6765\u5b9e\u73b0\u3002\u56fe 7-3 \u7ed9\u51fa\u4e86\u4e00\u4e2a\u793a\u4f8b\u3002

        \u56fe 7-3 \u00a0 \u5728\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree.py
        # \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\np = TreeNode(0)\n# \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = p\np.left = n2\n# \u5220\u9664\u8282\u70b9 P\nn1.left = n2\n
        binary_tree.cpp
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode* P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1->left = P;\nP->left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1->left = n2;\n
        binary_tree.java
        TreeNode P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.cs
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode P = new(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.go
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\np := NewTreeNode(0)\nn1.Left = p\np.Left = n2\n// \u5220\u9664\u8282\u70b9 P\nn1.Left = n2\n
        binary_tree.swift
        let P = TreeNode(x: 0)\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P\nP.left = n2\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2\n
        binary_tree.js
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nlet P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.ts
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nconst P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.dart
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.rs
        let p = TreeNode::new(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.borrow_mut().left = Some(p.clone());\np.borrow_mut().left = Some(n2.clone());\n// \u5220\u9664\u8282\u70b9 p\nn1.borrow_mut().left = Some(n2);\n
        binary_tree.c
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode *P = newTreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1->left = P;\nP->left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1->left = n2;\n
        binary_tree.zig
        \n

        Note

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u63d2\u5165\u8282\u70b9\u53ef\u80fd\u4f1a\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u539f\u6709\u903b\u8f91\u7ed3\u6784\uff0c\u800c\u5220\u9664\u8282\u70b9\u901a\u5e38\u610f\u5473\u7740\u5220\u9664\u8be5\u8282\u70b9\u53ca\u5176\u6240\u6709\u5b50\u6811\u3002\u56e0\u6b64\uff0c\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u63d2\u5165\u4e0e\u5220\u9664\u901a\u5e38\u662f\u7531\u4e00\u5957\u64cd\u4f5c\u914d\u5408\u5b8c\u6210\u7684\uff0c\u4ee5\u5b9e\u73b0\u6709\u5b9e\u9645\u610f\u4e49\u7684\u64cd\u4f5c\u3002

        "},{"location":"chapter_tree/binary_tree/#713","title":"7.1.3 \u00a0 \u5e38\u89c1\u4e8c\u53c9\u6811\u7c7b\u578b","text":""},{"location":"chapter_tree/binary_tree/#1_1","title":"1. \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-4 \u6240\u793a\uff0c\u300c\u5b8c\u7f8e\u4e8c\u53c9\u6811 perfect binary tree\u300d\u6240\u6709\u5c42\u7684\u8282\u70b9\u90fd\u88ab\u5b8c\u5168\u586b\u6ee1\u3002\u5728\u5b8c\u7f8e\u4e8c\u53c9\u6811\u4e2d\uff0c\u53f6\u8282\u70b9\u7684\u5ea6\u4e3a \\(0\\) \uff0c\u5176\u4f59\u6240\u6709\u8282\u70b9\u7684\u5ea6\u90fd\u4e3a \\(2\\) \uff1b\u82e5\u6811\u7684\u9ad8\u5ea6\u4e3a \\(h\\) \uff0c\u5219\u8282\u70b9\u603b\u6570\u4e3a \\(2^{h+1} - 1\\) \uff0c\u5448\u73b0\u6807\u51c6\u7684\u6307\u6570\u7ea7\u5173\u7cfb\uff0c\u53cd\u6620\u4e86\u81ea\u7136\u754c\u4e2d\u5e38\u89c1\u7684\u7ec6\u80de\u5206\u88c2\u73b0\u8c61\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u5728\u4e2d\u6587\u793e\u533a\u4e2d\uff0c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u5e38\u88ab\u79f0\u4e3a\u300c\u6ee1\u4e8c\u53c9\u6811\u300d\u3002

        \u56fe 7-4 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#2_1","title":"2. \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-5 \u6240\u793a\uff0c\u300c\u5b8c\u5168\u4e8c\u53c9\u6811 complete binary tree\u300d\u53ea\u6709\u6700\u5e95\u5c42\u7684\u8282\u70b9\u672a\u88ab\u586b\u6ee1\uff0c\u4e14\u6700\u5e95\u5c42\u8282\u70b9\u5c3d\u91cf\u9760\u5de6\u586b\u5145\u3002

        \u56fe 7-5 \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#3","title":"3. \u00a0 \u5b8c\u6ee1\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-6 \u6240\u793a\uff0c\u300c\u5b8c\u6ee1\u4e8c\u53c9\u6811 full binary tree\u300d\u9664\u4e86\u53f6\u8282\u70b9\u4e4b\u5916\uff0c\u5176\u4f59\u6240\u6709\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u3002

        \u56fe 7-6 \u00a0 \u5b8c\u6ee1\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#4","title":"4. \u00a0 \u5e73\u8861\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-7 \u6240\u793a\uff0c\u300c\u5e73\u8861\u4e8c\u53c9\u6811 balanced binary tree\u300d\u4e2d\u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u7684\u9ad8\u5ea6\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u3002

        \u56fe 7-7 \u00a0 \u5e73\u8861\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#714","title":"7.1.4 \u00a0 \u4e8c\u53c9\u6811\u7684\u9000\u5316","text":"

        \u56fe 7-8 \u5c55\u793a\u4e86\u4e8c\u53c9\u6811\u7684\u7406\u60f3\u7ed3\u6784\u4e0e\u9000\u5316\u7ed3\u6784\u3002\u5f53\u4e8c\u53c9\u6811\u7684\u6bcf\u5c42\u8282\u70b9\u90fd\u88ab\u586b\u6ee1\u65f6\uff0c\u8fbe\u5230\u201c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u201d\uff1b\u800c\u5f53\u6240\u6709\u8282\u70b9\u90fd\u504f\u5411\u4e00\u4fa7\u65f6\uff0c\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u201c\u94fe\u8868\u201d\u3002

        • \u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u7406\u60f3\u60c5\u51b5\uff0c\u53ef\u4ee5\u5145\u5206\u53d1\u6325\u4e8c\u53c9\u6811\u201c\u5206\u6cbb\u201d\u7684\u4f18\u52bf\u3002
        • \u94fe\u8868\u5219\u662f\u53e6\u4e00\u4e2a\u6781\u7aef\uff0c\u5404\u9879\u64cd\u4f5c\u90fd\u53d8\u4e3a\u7ebf\u6027\u64cd\u4f5c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u9000\u5316\u81f3 \\(O(n)\\) \u3002

        \u56fe 7-8 \u00a0 \u4e8c\u53c9\u6811\u7684\u6700\u4f73\u7ed3\u6784\u4e0e\u6700\u5dee\u7ed3\u6784

        \u5982\u8868 7-1 \u6240\u793a\uff0c\u5728\u6700\u4f73\u7ed3\u6784\u548c\u6700\u5dee\u7ed3\u6784\u4e0b\uff0c\u4e8c\u53c9\u6811\u7684\u53f6\u8282\u70b9\u6570\u91cf\u3001\u8282\u70b9\u603b\u6570\u3001\u9ad8\u5ea6\u7b49\u8fbe\u5230\u6781\u5927\u503c\u6216\u6781\u5c0f\u503c\u3002

        \u8868 7-1 \u00a0 \u4e8c\u53c9\u6811\u7684\u6700\u4f73\u7ed3\u6784\u4e0e\u6700\u5dee\u7ed3\u6784

        \u5b8c\u7f8e\u4e8c\u53c9\u6811 \u94fe\u8868 \u7b2c \\(i\\) \u5c42\u7684\u8282\u70b9\u6570\u91cf \\(2^{i-1}\\) \\(1\\) \u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u6811\u7684\u53f6\u8282\u70b9\u6570\u91cf \\(2^h\\) \\(1\\) \u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u6811\u7684\u8282\u70b9\u603b\u6570 \\(2^{h+1} - 1\\) \\(h + 1\\) \u8282\u70b9\u603b\u6570\u4e3a \\(n\\) \u7684\u6811\u7684\u9ad8\u5ea6 \\(\\log_2 (n+1) - 1\\) \\(n - 1\\)"},{"location":"chapter_tree/binary_tree_traversal/","title":"7.2 \u00a0 \u4e8c\u53c9\u6811\u904d\u5386","text":"

        \u4ece\u7269\u7406\u7ed3\u6784\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u6811\u662f\u4e00\u79cd\u57fa\u4e8e\u94fe\u8868\u7684\u6570\u636e\u7ed3\u6784\uff0c\u56e0\u6b64\u5176\u904d\u5386\u65b9\u5f0f\u662f\u901a\u8fc7\u6307\u9488\u9010\u4e2a\u8bbf\u95ee\u8282\u70b9\u3002\u7136\u800c\uff0c\u6811\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u8fd9\u4f7f\u5f97\u904d\u5386\u6811\u6bd4\u904d\u5386\u94fe\u8868\u66f4\u52a0\u590d\u6742\uff0c\u9700\u8981\u501f\u52a9\u641c\u7d22\u7b97\u6cd5\u6765\u5b9e\u73b0\u3002

        \u4e8c\u53c9\u6811\u5e38\u89c1\u7684\u904d\u5386\u65b9\u5f0f\u5305\u62ec\u5c42\u5e8f\u904d\u5386\u3001\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u548c\u540e\u5e8f\u904d\u5386\u7b49\u3002

        "},{"location":"chapter_tree/binary_tree_traversal/#721","title":"7.2.1 \u00a0 \u5c42\u5e8f\u904d\u5386","text":"

        \u5982\u56fe 7-9 \u6240\u793a\uff0c\u300c\u5c42\u5e8f\u904d\u5386 level-order traversal\u300d\u4ece\u9876\u90e8\u5230\u5e95\u90e8\u9010\u5c42\u904d\u5386\u4e8c\u53c9\u6811\uff0c\u5e76\u5728\u6bcf\u4e00\u5c42\u6309\u7167\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u8bbf\u95ee\u8282\u70b9\u3002

        \u5c42\u5e8f\u904d\u5386\u672c\u8d28\u4e0a\u5c5e\u4e8e\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal, BFS\u300d\uff0c\u5b83\u4f53\u73b0\u4e86\u4e00\u79cd\u201c\u4e00\u5708\u4e00\u5708\u5411\u5916\u6269\u5c55\u201d\u7684\u9010\u5c42\u904d\u5386\u65b9\u5f0f\u3002

        \u56fe 7-9 \u00a0 \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386

        "},{"location":"chapter_tree/binary_tree_traversal/#1","title":"1. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u901a\u5e38\u501f\u52a9\u201c\u961f\u5217\u201d\u6765\u5b9e\u73b0\u3002\u961f\u5217\u9075\u5faa\u201c\u5148\u8fdb\u5148\u51fa\u201d\u7684\u89c4\u5219\uff0c\u800c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u5219\u9075\u5faa\u201c\u9010\u5c42\u63a8\u8fdb\u201d\u7684\u89c4\u5219\uff0c\u4e24\u8005\u80cc\u540e\u7684\u601d\u60f3\u662f\u4e00\u81f4\u7684\u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree_bfs.py
        def level_order(root: TreeNode | None) -> list[int]:\n\"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\n# \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue: deque[TreeNode] = deque()\nqueue.append(root)\n# \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nres = []\nwhile queue:\nnode: TreeNode = queue.popleft()  # \u961f\u5217\u51fa\u961f\nres.append(node.val)  # \u4fdd\u5b58\u8282\u70b9\u503c\nif node.left is not None:\nqueue.append(node.left)  # \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif node.right is not None:\nqueue.append(node.right)  # \u53f3\u5b50\u8282\u70b9\u5165\u961f\nreturn res\n
        binary_tree_bfs.cpp
        /* \u5c42\u5e8f\u904d\u5386 */\nvector<int> levelOrder(TreeNode *root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue<TreeNode *> queue;\nqueue.push(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvector<int> vec;\nwhile (!queue.empty()) {\nTreeNode *node = queue.front();\nqueue.pop();              // \u961f\u5217\u51fa\u961f\nvec.push_back(node->val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node->left != nullptr)\nqueue.push(node->left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node->right != nullptr)\nqueue.push(node->right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn vec;\n}\n
        binary_tree_bfs.java
        /* \u5c42\u5e8f\u904d\u5386 */\nList<Integer> levelOrder(TreeNode root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode> queue = new LinkedList<>();\nqueue.add(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<Integer> list = new ArrayList<>();\nwhile (!queue.isEmpty()) {\nTreeNode node = queue.poll(); // \u961f\u5217\u51fa\u961f\nlist.add(node.val);           // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null)\nqueue.offer(node.left);   // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null)\nqueue.offer(node.right);  // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.cs
        /* \u5c42\u5e8f\u904d\u5386 */\nList<int> LevelOrder(TreeNode root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode> queue = new();\nqueue.Enqueue(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<int> list = [];\nwhile (queue.Count != 0) {\nTreeNode node = queue.Dequeue(); // \u961f\u5217\u51fa\u961f\nlist.Add(node.val!.Value);       // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null)\nqueue.Enqueue(node.left);    // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null)\nqueue.Enqueue(node.right);   // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.go
        /* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder(root *TreeNode) []any {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue := list.New()\nqueue.PushBack(root)\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5207\u7247\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nnums := make([]any, 0)\nfor queue.Len() > 0 {\n// \u961f\u5217\u51fa\u961f\nnode := queue.Remove(queue.Front()).(*TreeNode)\n// \u4fdd\u5b58\u8282\u70b9\u503c\nnums = append(nums, node.Val)\nif node.Left != nil {\n// \u5de6\u5b50\u8282\u70b9\u5165\u961f\nqueue.PushBack(node.Left)\n}\nif node.Right != nil {\n// \u53f3\u5b50\u8282\u70b9\u5165\u961f\nqueue.PushBack(node.Right)\n}\n}\nreturn nums\n}\n
        binary_tree_bfs.swift
        /* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder(root: TreeNode) -> [Int] {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nvar queue: [TreeNode] = [root]\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvar list: [Int] = []\nwhile !queue.isEmpty {\nlet node = queue.removeFirst() // \u961f\u5217\u51fa\u961f\nlist.append(node.val) // \u4fdd\u5b58\u8282\u70b9\u503c\nif let left = node.left {\nqueue.append(left) // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif let right = node.right {\nqueue.append(right) // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\n}\nreturn list\n}\n
        binary_tree_bfs.js
        /* \u5c42\u5e8f\u904d\u5386 */\nfunction levelOrder(root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst queue = [root];\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nconst list = [];\nwhile (queue.length) {\nlet node = queue.shift(); // \u961f\u5217\u51fa\u961f\nlist.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left) queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right) queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.ts
        /* \u5c42\u5e8f\u904d\u5386 */\nfunction levelOrder(root: TreeNode | null): number[] {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst queue = [root];\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nconst list: number[] = [];\nwhile (queue.length) {\nlet node = queue.shift() as TreeNode; // \u961f\u5217\u51fa\u961f\nlist.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left) {\nqueue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif (node.right) {\nqueue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\n}\nreturn list;\n}\n
        binary_tree_bfs.dart
        /* \u5c42\u5e8f\u904d\u5386 */\nList<int> levelOrder(TreeNode? root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode?> queue = Queue();\nqueue.add(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<int> res = [];\nwhile (queue.isNotEmpty) {\nTreeNode? node = queue.removeFirst(); // \u961f\u5217\u51fa\u961f\nres.add(node!.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null) queue.add(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null) queue.add(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn res;\n}\n
        binary_tree_bfs.rs
        /* \u5c42\u5e8f\u904d\u5386 */\nfn level_order(root: &Rc<RefCell<TreeNode>>) -> Vec<i32> {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nlet mut que = VecDeque::new();\nque.push_back(Rc::clone(&root));\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nlet mut vec = Vec::new();\nwhile let Some(node) = que.pop_front() {                 // \u961f\u5217\u51fa\u961f\nvec.push(node.borrow().val);                         // \u4fdd\u5b58\u8282\u70b9\u503c\nif let Some(left) = node.borrow().left.as_ref() {\nque.push_back(Rc::clone(left));                  // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif let Some(right) = node.borrow().right.as_ref() {\nque.push_back(Rc::clone(right));                 // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n};\n}\nvec\n}\n
        binary_tree_bfs.c
        /* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(TreeNode *root, int *size) {\n/* \u8f85\u52a9\u961f\u5217 */\nint front, rear;\nint index, *arr;\nTreeNode *node;\nTreeNode **queue;\n/* \u8f85\u52a9\u961f\u5217 */\nqueue = (TreeNode **)malloc(sizeof(TreeNode *) * MAX_SIZE);\n// \u961f\u5217\u6307\u9488\nfront = 0, rear = 0;\n// \u52a0\u5165\u6839\u8282\u70b9\nqueue[rear++] = root;\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n/* \u8f85\u52a9\u6570\u7ec4 */\narr = (int *)malloc(sizeof(int) * MAX_SIZE);\n// \u6570\u7ec4\u6307\u9488\nindex = 0;\nwhile (front < rear) {\n// \u961f\u5217\u51fa\u961f\nnode = queue[front++];\n// \u4fdd\u5b58\u8282\u70b9\u503c\narr[index++] = node->val;\nif (node->left != NULL) {\n// \u5de6\u5b50\u8282\u70b9\u5165\u961f\nqueue[rear++] = node->left;\n}\nif (node->right != NULL) {\n// \u53f3\u5b50\u8282\u70b9\u5165\u961f\nqueue[rear++] = node->right;\n}\n}\n// \u66f4\u65b0\u6570\u7ec4\u957f\u5ea6\u7684\u503c\n*size = index;\narr = realloc(arr, sizeof(int) * (*size));\n// \u91ca\u653e\u8f85\u52a9\u6570\u7ec4\u7a7a\u95f4\nfree(queue);\nreturn arr;\n}\n
        binary_tree_bfs.zig
        // \u5c42\u5e8f\u904d\u5386\nfn levelOrder(comptime T: type, mem_allocator: std.mem.Allocator, root: *inc.TreeNode(T)) !std.ArrayList(T) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst L = std.TailQueue(*inc.TreeNode(T));\nvar queue = L{};\nvar root_node = try mem_allocator.create(L.Node);\nroot_node.data = root;\nqueue.append(root_node); // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvar list = std.ArrayList(T).init(std.heap.page_allocator);\nwhile (queue.len > 0) {\nvar queue_node = queue.popFirst().?;    // \u961f\u5217\u51fa\u961f\nvar node = queue_node.data;\ntry list.append(node.val);              // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null) {\nvar tmp_node = try mem_allocator.create(L.Node);\ntmp_node.data = node.left.?;\nqueue.append(tmp_node);             // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif (node.right != null) {\nvar tmp_node = try mem_allocator.create(L.Node);\ntmp_node.data = node.right.?;\nqueue.append(tmp_node);             // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}        }\nreturn list;\n}\n
        "},{"location":"chapter_tree/binary_tree_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u6240\u6709\u8282\u70b9\u88ab\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\uff0c\u5176\u4e2d \\(n\\) \u4e3a\u8282\u70b9\u6570\u91cf\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u6ee1\u4e8c\u53c9\u6811\u65f6\uff0c\u904d\u5386\u5230\u6700\u5e95\u5c42\u4e4b\u524d\uff0c\u961f\u5217\u4e2d\u6700\u591a\u540c\u65f6\u5b58\u5728 \\((n + 1) / 2\\) \u4e2a\u8282\u70b9\uff0c\u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002
        "},{"location":"chapter_tree/binary_tree_traversal/#722","title":"7.2.2 \u00a0 \u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386","text":"

        \u76f8\u5e94\u5730\uff0c\u524d\u5e8f\u3001\u4e2d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u90fd\u5c5e\u4e8e\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal, DFS\u300d\uff0c\u5b83\u4f53\u73b0\u4e86\u4e00\u79cd\u201c\u5148\u8d70\u5230\u5c3d\u5934\uff0c\u518d\u56de\u6eaf\u7ee7\u7eed\u201d\u7684\u904d\u5386\u65b9\u5f0f\u3002

        \u56fe 7-10 \u5c55\u793a\u4e86\u5bf9\u4e8c\u53c9\u6811\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5de5\u4f5c\u539f\u7406\u3002\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u5c31\u50cf\u662f\u7ed5\u7740\u6574\u68f5\u4e8c\u53c9\u6811\u7684\u5916\u56f4\u201c\u8d70\u201d\u4e00\u5708\uff0c\u5728\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u9047\u5230\u4e09\u4e2a\u4f4d\u7f6e\uff0c\u5206\u522b\u5bf9\u5e94\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u548c\u540e\u5e8f\u904d\u5386\u3002

        \u56fe 7-10 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386

        "},{"location":"chapter_tree/binary_tree_traversal/#1_1","title":"1. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree_dfs.py
        def pre_order(root: TreeNode | None):\n\"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nres.append(root.val)\npre_order(root=root.left)\npre_order(root=root.right)\ndef in_order(root: TreeNode | None):\n\"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nin_order(root=root.left)\nres.append(root.val)\nin_order(root=root.right)\ndef post_order(root: TreeNode | None):\n\"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npost_order(root=root.left)\npost_order(root=root.right)\nres.append(root.val)\n
        binary_tree_dfs.cpp
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nvec.push_back(root->val);\npreOrder(root->left);\npreOrder(root->right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root->left);\nvec.push_back(root->val);\ninOrder(root->right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root->left);\npostOrder(root->right);\nvec.push_back(root->val);\n}\n
        binary_tree_dfs.java
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.add(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.add(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.add(root.val);\n}\n
        binary_tree_dfs.cs
        /* \u524d\u5e8f\u904d\u5386 */\nvoid PreOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.Add(root.val!.Value);\nPreOrder(root.left);\nPreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid InOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nInOrder(root.left);\nlist.Add(root.val!.Value);\nInOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid PostOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\nPostOrder(root.left);\nPostOrder(root.right);\nlist.Add(root.val!.Value);\n}\n
        binary_tree_dfs.go
        /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nnums = append(nums, node.Val)\npreOrder(node.Left)\npreOrder(node.Right)\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(node.Left)\nnums = append(nums, node.Val)\ninOrder(node.Right)\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(node.Left)\npostOrder(node.Right)\nnums = append(nums, node.Val)\n}\n
        binary_tree_dfs.swift
        /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.append(root.val)\npreOrder(root: root.left)\npreOrder(root: root.right)\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root: root.left)\nlist.append(root.val)\ninOrder(root: root.right)\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root: root.left)\npostOrder(root: root.right)\nlist.append(root.val)\n}\n
        binary_tree_dfs.js
        /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.push(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.push(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.push(root.val);\n}\n
        binary_tree_dfs.ts
        /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.push(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.push(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.push(root.val);\n}\n
        binary_tree_dfs.dart
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.add(node.val);\npreOrder(node.left);\npreOrder(node.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(node.left);\nlist.add(node.val);\ninOrder(node.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(node.left);\npostOrder(node.right);\nlist.add(node.val);\n}\n
        binary_tree_dfs.rs
        /* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nresult.push(node.borrow().val);\nresult.append(&mut pre_order(node.borrow().left.as_ref()));\nresult.append(&mut pre_order(node.borrow().right.as_ref()));\n}\nresult\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nresult.append(&mut in_order(node.borrow().left.as_ref()));\nresult.push(node.borrow().val);\nresult.append(&mut in_order(node.borrow().right.as_ref()));\n}\nresult\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\nresult.append(&mut post_order(node.borrow().left.as_ref()));\nresult.append(&mut post_order(node.borrow().right.as_ref()));\nresult.push(node.borrow().val);\n}\nresult\n}\n
        binary_tree_dfs.c
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\narr[(*size)++] = root->val;\npreOrder(root->left, size);\npreOrder(root->right, size);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root->left, size);\narr[(*size)++] = root->val;\ninOrder(root->right, size);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root->left, size);\npostOrder(root->right, size);\narr[(*size)++] = root->val;\n}\n
        binary_tree_dfs.zig
        // \u524d\u5e8f\u904d\u5386\nfn preOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\ntry list.append(root.?.val);\ntry preOrder(T, root.?.left);\ntry preOrder(T, root.?.right);\n}\n// \u4e2d\u5e8f\u904d\u5386\nfn inOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ntry inOrder(T, root.?.left);\ntry list.append(root.?.val);\ntry inOrder(T, root.?.right);\n}\n// \u540e\u5e8f\u904d\u5386\nfn postOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\ntry postOrder(T, root.?.left);\ntry postOrder(T, root.?.right);\ntry list.append(root.?.val);\n}\n

        Tip

        \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u4e5f\u53ef\u4ee5\u57fa\u4e8e\u8fed\u4ee3\u5b9e\u73b0\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u7814\u7a76\u3002

        \u56fe 7-11 \u5c55\u793a\u4e86\u524d\u5e8f\u904d\u5386\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b\uff0c\u5176\u53ef\u5206\u4e3a\u201c\u9012\u201d\u548c\u201c\u5f52\u201d\u4e24\u4e2a\u9006\u5411\u7684\u90e8\u5206\u3002

        1. \u201c\u9012\u201d\u8868\u793a\u5f00\u542f\u65b0\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u5728\u6b64\u8fc7\u7a0b\u4e2d\u8bbf\u95ee\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002
        2. \u201c\u5f52\u201d\u8868\u793a\u51fd\u6570\u8fd4\u56de\uff0c\u4ee3\u8868\u5f53\u524d\u8282\u70b9\u5df2\u7ecf\u8bbf\u95ee\u5b8c\u6bd5\u3002
        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 7-11 \u00a0 \u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u8fc7\u7a0b

        "},{"location":"chapter_tree/binary_tree_traversal/#2_1","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u6240\u6709\u8282\u70b9\u88ab\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u9012\u5f52\u6df1\u5ea6\u8fbe\u5230 \\(n\\) \uff0c\u7cfb\u7edf\u5360\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002
        "},{"location":"chapter_tree/summary/","title":"7.6 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_tree/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u4e8c\u53c9\u6811\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u4f53\u73b0\u201c\u4e00\u5206\u4e3a\u4e8c\u201d\u7684\u5206\u6cbb\u903b\u8f91\u3002\u6bcf\u4e2a\u4e8c\u53c9\u6811\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u503c\u4ee5\u53ca\u4e24\u4e2a\u6307\u9488\uff0c\u5206\u522b\u6307\u5411\u5176\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\u3002
        • \u5bf9\u4e8e\u4e8c\u53c9\u6811\u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\uff0c\u5176\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u53ca\u5176\u4ee5\u4e0b\u5f62\u6210\u7684\u6811\u88ab\u79f0\u4e3a\u8be5\u8282\u70b9\u7684\u5de6\uff08\u53f3\uff09\u5b50\u6811\u3002
        • \u4e8c\u53c9\u6811\u7684\u76f8\u5173\u672f\u8bed\u5305\u62ec\u6839\u8282\u70b9\u3001\u53f6\u8282\u70b9\u3001\u5c42\u3001\u5ea6\u3001\u8fb9\u3001\u9ad8\u5ea6\u548c\u6df1\u5ea6\u7b49\u3002
        • \u4e8c\u53c9\u6811\u7684\u521d\u59cb\u5316\u3001\u8282\u70b9\u63d2\u5165\u548c\u8282\u70b9\u5220\u9664\u64cd\u4f5c\u4e0e\u94fe\u8868\u64cd\u4f5c\u65b9\u6cd5\u7c7b\u4f3c\u3002
        • \u5e38\u89c1\u7684\u4e8c\u53c9\u6811\u7c7b\u578b\u6709\u5b8c\u7f8e\u4e8c\u53c9\u6811\u3001\u5b8c\u5168\u4e8c\u53c9\u6811\u3001\u5b8c\u6ee1\u4e8c\u53c9\u6811\u548c\u5e73\u8861\u4e8c\u53c9\u6811\u3002\u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u6700\u7406\u60f3\u7684\u72b6\u6001\uff0c\u800c\u94fe\u8868\u662f\u9000\u5316\u540e\u7684\u6700\u5dee\u72b6\u6001\u3002
        • \u4e8c\u53c9\u6811\u53ef\u4ee5\u7528\u6570\u7ec4\u8868\u793a\uff0c\u65b9\u6cd5\u662f\u5c06\u8282\u70b9\u503c\u548c\u7a7a\u4f4d\u6309\u5c42\u5e8f\u904d\u5386\u987a\u5e8f\u6392\u5217\uff0c\u5e76\u6839\u636e\u7236\u8282\u70b9\u4e0e\u5b50\u8282\u70b9\u4e4b\u95f4\u7684\u7d22\u5f15\u6620\u5c04\u5173\u7cfb\u6765\u5b9e\u73b0\u6307\u9488\u3002
        • \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386\u662f\u4e00\u79cd\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u65b9\u6cd5\uff0c\u5b83\u4f53\u73b0\u4e86\u201c\u4e00\u5708\u4e00\u5708\u5411\u5916\u6269\u5c55\u201d\u7684\u9010\u5c42\u904d\u5386\u65b9\u5f0f\uff0c\u901a\u5e38\u901a\u8fc7\u961f\u5217\u6765\u5b9e\u73b0\u3002
        • \u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\u7686\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff0c\u5b83\u4eec\u4f53\u73b0\u4e86\u201c\u5148\u8d70\u5230\u5c3d\u5934\uff0c\u518d\u56de\u6eaf\u7ee7\u7eed\u201d\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u901a\u5e38\u4f7f\u7528\u9012\u5f52\u6765\u5b9e\u73b0\u3002
        • \u4e8c\u53c9\u641c\u7d22\u6811\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u5143\u7d20\u67e5\u627e\u6570\u636e\u7ed3\u6784\uff0c\u5176\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log n)\\) \u3002\u5f53\u4e8c\u53c9\u641c\u7d22\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u5404\u9879\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u52a3\u5316\u81f3 \\(O(n)\\) \u3002
        • AVL \u6811\uff0c\u4e5f\u79f0\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5b83\u901a\u8fc7\u65cb\u8f6c\u64cd\u4f5c\u786e\u4fdd\u5728\u4e0d\u65ad\u63d2\u5165\u548c\u5220\u9664\u8282\u70b9\u540e\u6811\u4ecd\u7136\u4fdd\u6301\u5e73\u8861\u3002
        • AVL \u6811\u7684\u65cb\u8f6c\u64cd\u4f5c\u5305\u62ec\u53f3\u65cb\u3001\u5de6\u65cb\u3001\u5148\u53f3\u65cb\u518d\u5de6\u65cb\u3001\u5148\u5de6\u65cb\u518d\u53f3\u65cb\u3002\u5728\u63d2\u5165\u6216\u5220\u9664\u8282\u70b9\u540e\uff0cAVL \u6811\u4f1a\u4ece\u5e95\u5411\u9876\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002
        "},{"location":"chapter_tree/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u5bf9\u4e8e\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u6811\u7684\u9ad8\u5ea6\u548c\u6839\u8282\u70b9\u7684\u6df1\u5ea6\u90fd\u662f \\(0\\) \u5417\uff1f

        \u662f\u7684\uff0c\u56e0\u4e3a\u9ad8\u5ea6\u548c\u6df1\u5ea6\u901a\u5e38\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u201d\u3002

        \u4e8c\u53c9\u6811\u4e2d\u7684\u63d2\u5165\u4e0e\u5220\u9664\u4e00\u822c\u7531\u4e00\u5957\u64cd\u4f5c\u914d\u5408\u5b8c\u6210\uff0c\u8fd9\u91cc\u7684\u201c\u4e00\u5957\u64cd\u4f5c\u201d\u6307\u4ec0\u4e48\u5462\uff1f\u53ef\u4ee5\u7406\u89e3\u4e3a\u8d44\u6e90\u7684\u5b50\u8282\u70b9\u7684\u8d44\u6e90\u91ca\u653e\u5417\uff1f

        \u62ff\u4e8c\u53c9\u641c\u7d22\u6811\u6765\u4e3e\u4f8b\uff0c\u5220\u9664\u8282\u70b9\u64cd\u4f5c\u8981\u5206\u4e09\u79cd\u60c5\u51b5\u5904\u7406\uff0c\u5176\u4e2d\u6bcf\u79cd\u60c5\u51b5\u90fd\u9700\u8981\u8fdb\u884c\u591a\u4e2a\u6b65\u9aa4\u7684\u8282\u70b9\u64cd\u4f5c\u3002

        \u4e3a\u4ec0\u4e48 DFS \u904d\u5386\u4e8c\u53c9\u6811\u6709\u524d\u3001\u4e2d\u3001\u540e\u4e09\u79cd\u987a\u5e8f\uff0c\u5206\u522b\u6709\u4ec0\u4e48\u7528\u5462\uff1f

        \u4e0e\u987a\u5e8f\u548c\u9006\u5e8f\u904d\u5386\u6570\u7ec4\u7c7b\u4f3c\uff0c\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\u662f\u4e09\u79cd\u4e8c\u53c9\u6811\u904d\u5386\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b83\u4eec\u5f97\u5230\u4e00\u4e2a\u7279\u5b9a\u987a\u5e8f\u7684\u904d\u5386\u7ed3\u679c\u3002\u4f8b\u5982\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\uff0c\u7531\u4e8e\u8282\u70b9\u5927\u5c0f\u6ee1\u8db3 \u5de6\u5b50\u8282\u70b9\u503c < \u6839\u8282\u70b9\u503c < \u53f3\u5b50\u8282\u70b9\u503c \uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u8981\u6309\u7167 \u5de6 $\\rightarrow$ \u6839 $\\rightarrow$ \u53f3 \u7684\u4f18\u5148\u7ea7\u904d\u5386\u6811\uff0c\u5c31\u53ef\u4ee5\u83b7\u5f97\u6709\u5e8f\u7684\u8282\u70b9\u5e8f\u5217\u3002

        \u53f3\u65cb\u64cd\u4f5c\u662f\u5904\u7406\u5931\u8861\u8282\u70b9 node\u3001child\u3001grand_child \u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u90a3 node \u7684\u7236\u8282\u70b9\u548c node \u539f\u6765\u7684\u8fde\u63a5\u4e0d\u9700\u8981\u7ef4\u62a4\u5417\uff1f\u53f3\u65cb\u64cd\u4f5c\u540e\u5c82\u4e0d\u662f\u65ad\u6389\u4e86\uff1f

        \u6211\u4eec\u9700\u8981\u4ece\u9012\u5f52\u7684\u89c6\u89d2\u6765\u770b\u8fd9\u4e2a\u95ee\u9898\u3002\u53f3\u65cb\u64cd\u4f5c right_rotate(root) \u4f20\u5165\u7684\u662f\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u6700\u7ec8 return child \u8fd4\u56de\u65cb\u8f6c\u4e4b\u540e\u7684\u5b50\u6811\u7684\u6839\u8282\u70b9\u3002\u5b50\u6811\u7684\u6839\u8282\u70b9\u548c\u5176\u7236\u8282\u70b9\u7684\u8fde\u63a5\u662f\u5728\u8be5\u51fd\u6570\u8fd4\u56de\u540e\u5b8c\u6210\u7684\uff0c\u4e0d\u5c5e\u4e8e\u53f3\u65cb\u64cd\u4f5c\u7684\u7ef4\u62a4\u8303\u56f4\u3002

        \u5728 C++ \u4e2d\uff0c\u51fd\u6570\u88ab\u5212\u5206\u5230 private \u548c public \u4e2d\uff0c\u8fd9\u65b9\u9762\u6709\u4ec0\u4e48\u8003\u91cf\u5417\uff1f\u4e3a\u4ec0\u4e48\u8981\u5c06 height() \u51fd\u6570\u548c updateHeight() \u51fd\u6570\u5206\u522b\u653e\u5728 public \u548c private \u4e2d\u5462\uff1f

        \u4e3b\u8981\u770b\u65b9\u6cd5\u7684\u4f7f\u7528\u8303\u56f4\uff0c\u5982\u679c\u65b9\u6cd5\u53ea\u5728\u7c7b\u5185\u90e8\u4f7f\u7528\uff0c\u90a3\u4e48\u5c31\u8bbe\u8ba1\u4e3a private \u3002\u4f8b\u5982\uff0c\u7528\u6237\u5355\u72ec\u8c03\u7528 updateHeight() \u662f\u6ca1\u6709\u610f\u4e49\u7684\uff0c\u5b83\u53ea\u662f\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u4e2d\u7684\u4e00\u6b65\u3002\u800c height() \u662f\u8bbf\u95ee\u8282\u70b9\u9ad8\u5ea6\uff0c\u7c7b\u4f3c\u4e8e vector.size() \uff0c\u56e0\u6b64\u8bbe\u7f6e\u6210 public \u4ee5\u4fbf\u4f7f\u7528\u3002

        \u5982\u4f55\u4ece\u4e00\u7ec4\u8f93\u5165\u6570\u636e\u6784\u5efa\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff1f\u6839\u8282\u70b9\u7684\u9009\u62e9\u662f\u4e0d\u662f\u5f88\u91cd\u8981\uff1f

        \u662f\u7684\uff0c\u6784\u5efa\u6811\u7684\u65b9\u6cd5\u5df2\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4ee3\u7801\u4e2d\u7684 build_tree() \u65b9\u6cd5\u4e2d\u7ed9\u51fa\u3002\u81f3\u4e8e\u6839\u8282\u70b9\u7684\u9009\u62e9\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u8f93\u5165\u6570\u636e\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u4e2d\u70b9\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u518d\u9012\u5f52\u5730\u6784\u5efa\u5de6\u53f3\u5b50\u6811\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u6700\u5927\u7a0b\u5ea6\u4fdd\u8bc1\u6811\u7684\u5e73\u8861\u6027\u3002

        \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u5bf9\u6bd4\u662f\u5426\u4e00\u5b9a\u8981\u7528 equals() \u65b9\u6cd5\uff1f

        \u5728 Java \u4e2d\uff0c\u5bf9\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c== \u7528\u4e8e\u5bf9\u6bd4\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002\u5bf9\u4e8e\u5f15\u7528\u7c7b\u578b\uff0c\u4e24\u79cd\u7b26\u53f7\u7684\u5de5\u4f5c\u539f\u7406\u662f\u4e0d\u540c\u7684\u3002

        • == \uff1a\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5373\u5b83\u4eec\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u662f\u5426\u76f8\u540c\u3002
        • equals()\uff1a\u7528\u6765\u5bf9\u6bd4\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002

        \u56e0\u6b64\uff0c\u5982\u679c\u8981\u5bf9\u6bd4\u503c\uff0c\u6211\u4eec\u5e94\u8be5\u4f7f\u7528 equals() \u3002\u7136\u800c\uff0c\u901a\u8fc7 String a = \"hi\"; String b = \"hi\"; \u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u90fd\u5b58\u50a8\u5728\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u4e2d\uff0c\u5b83\u4eec\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u56e0\u6b64\u4e5f\u53ef\u4ee5\u7528 a == b \u6765\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u3002

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u5230\u6700\u5e95\u5c42\u4e4b\u524d\uff0c\u961f\u5217\u4e2d\u7684\u8282\u70b9\u6570\u91cf\u662f \\(2^h\\) \u5417\uff1f

        \u662f\u7684\uff0c\u4f8b\u5982\u9ad8\u5ea6 \\(h = 2\\) \u7684\u6ee1\u4e8c\u53c9\u6811\uff0c\u5176\u8282\u70b9\u603b\u6570 \\(n = 7\\) \uff0c\u5219\u5e95\u5c42\u8282\u70b9\u6570\u91cf \\(4 = 2^h = (n + 1) / 2\\) \u3002

        "}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\u200b\\u3000\\-\u3001\u3002\uff0c\uff0e\uff1f\uff01\uff1b]+","pipeline":["stemmer"]},"docs":[{"location":"","title":"Home","text":"\u300a Hello \u7b97\u6cd5 \u300b

        \u52a8\u753b\u56fe\u89e3\u3001\u4e00\u952e\u8fd0\u884c\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6559\u7a0b

        \u63a8\u8350\u8bed

        Quote

        \u201c\u4e00\u672c\u901a\u4fd7\u6613\u61c2\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5165\u95e8\u4e66\uff0c\u5f15\u5bfc\u8bfb\u8005\u624b\u8111\u5e76\u7528\u5730\u5b66\u4e60\uff0c\u5f3a\u70c8\u63a8\u8350\u7b97\u6cd5\u521d\u5b66\u8005\u9605\u8bfb\u3002\u201d

        \u2014\u2014 \u9093\u4fca\u8f89\uff0c\u6e05\u534e\u5927\u5b66\u8ba1\u7b97\u673a\u7cfb\u6559\u6388

        Quote

        \u201c\u5982\u679c\u6211\u5f53\u5e74\u5b66\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u65f6\u5019\u6709\u300aHello \u7b97\u6cd5\u300b\uff0c\u5b66\u8d77\u6765\u5e94\u8be5\u4f1a\u7b80\u5355 10 \u500d\uff01\u201d

        \u2014\u2014 \u674e\u6c90\uff0c\u4e9a\u9a6c\u900a\u8d44\u6df1\u9996\u5e2d\u79d1\u5b66\u5bb6

        \u5168\u4e66\u52a8\u753b\u56fe\u89e3

        \u5185\u5bb9\u6e05\u6670\u6613\u61c2\u3001\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1\u7535\u8111\u3001\u5e73\u677f\u3001\u624b\u673a\u5168\u7ec8\u7aef\u9605\u8bfb

        \"A picture is worth a thousand words.\"

        \u201c\u4e00\u56fe\u80dc\u5343\u8a00\u201d

        \u4ee3\u7801\u4e00\u952e\u8fd0\u884c

        \u63d0\u4f9b\u5404\u4e2a\u7b97\u6cd5\u4e0e\u6570\u636e\u7ed3\u6784\u7684\u7b80\u6d01\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u6837\u4f8b\uff0c\u7686\u53ef\u76f4\u63a5\u8fd0\u884c\u652f\u6301 Python\u3001C++\u3001Java\u3001C#\u3001Go\u3001Swift\u3001JS\u3001TS\u3001Dart\u3001Rust\u3001C\u3001Zig \u7b49\u8bed\u8a00

        \"Talk is cheap. Show me the code.\"

        \u201c\u5c11\u5439\u725b\uff0c\u770b\u4ee3\u7801\u201d

        \u53ef\u8ba8\u8bba\u4e0e\u63d0\u95ee

        \u9f13\u52b1\u5c0f\u4f19\u4f34\u4eec\u4e92\u5e2e\u4e92\u52a9\u3001\u5171\u540c\u6210\u957f\u63d0\u95ee\u4e0e\u8bc4\u8bba\u4e00\u822c\u80fd\u5728\u4e24\u65e5\u5185\u5f97\u5230\u56de\u590d

        \u201c\u8ffd\u98ce\u8d76\u6708\u83ab\u505c\u7559\uff0c\u5e73\u829c\u5c3d\u5904\u662f\u6625\u5c71\u201d

        \u4e00\u8d77\u52a0\u6cb9\uff01

        \u5e8f

        \u4e24\u5e74\u524d\uff0c\u6211\u5728\u529b\u6263\u4e0a\u5206\u4eab\u4e86\u201c\u5251\u6307 Offer\u201d\u7cfb\u5217\u9898\u89e3\uff0c\u53d7\u5230\u4e86\u8bb8\u591a\u540c\u5b66\u7684\u559c\u7231\u548c\u652f\u6301\u3002\u5728\u4e0e\u8bfb\u8005\u4ea4\u6d41\u671f\u95f4\uff0c\u6211\u6700\u5e38\u6536\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u201c\u5982\u4f55\u5165\u95e8\u7b97\u6cd5\u201d\u3002\u9010\u6e10\u5730\uff0c\u6211\u5bf9\u8fd9\u4e2a\u95ee\u9898\u4ea7\u751f\u4e86\u6d53\u539a\u7684\u5174\u8da3\u3002

        \u4e24\u773c\u4e00\u62b9\u9ed1\u5730\u5237\u9898\u4f3c\u4e4e\u662f\u6700\u53d7\u6b22\u8fce\u7684\u65b9\u6cd5\uff0c\u7b80\u5355\u76f4\u63a5\u4e14\u6709\u6548\u3002\u7136\u800c\u5237\u9898\u5c31\u5982\u540c\u73a9\u201c\u626b\u96f7\u201d\u6e38\u620f\uff0c\u81ea\u5b66\u80fd\u529b\u5f3a\u7684\u540c\u5b66\u80fd\u591f\u987a\u5229\u5c06\u5730\u96f7\u9010\u4e2a\u6392\u6389\uff0c\u800c\u57fa\u7840\u4e0d\u8db3\u7684\u540c\u5b66\u5f88\u53ef\u80fd\u88ab\u70b8\u7684\u6ee1\u5934\u662f\u5305\uff0c\u5e76\u5728\u632b\u6298\u4e2d\u6b65\u6b65\u9000\u7f29\u3002\u901a\u8bfb\u6559\u6750\u4e5f\u662f\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\uff0c\u4f46\u5bf9\u4e8e\u9762\u5411\u6c42\u804c\u7684\u540c\u5b66\u6765\u8bf4\uff0c\u6bd5\u4e1a\u5b63\u3001\u6295\u9012\u7b80\u5386\u3001\u51c6\u5907\u7b14\u8bd5\u9762\u8bd5\u5df2\u7ecf\u6d88\u8017\u4e86\u5927\u90e8\u5206\u7cbe\u529b\uff0c\u5543\u539a\u91cd\u7684\u4e66\u5f80\u5f80\u53d8\u6210\u4e86\u4e00\u9879\u8270\u5de8\u7684\u6311\u6218\u3002

        \u5982\u679c\u4f60\u4e5f\u9762\u4e34\u7c7b\u4f3c\u7684\u56f0\u6270\uff0c\u90a3\u4e48\u5f88\u5e78\u8fd0\u8fd9\u672c\u4e66\u627e\u5230\u4e86\u4f60\u3002\u672c\u4e66\u662f\u6211\u5bf9\u8fd9\u4e2a\u95ee\u9898\u7ed9\u51fa\u7684\u7b54\u6848\uff0c\u5373\u4f7f\u4e0d\u662f\u6700\u4f18\u89e3\uff0c\u4e5f\u81f3\u5c11\u662f\u4e00\u6b21\u79ef\u6781\u7684\u5c1d\u8bd5\u3002\u672c\u4e66\u867d\u7136\u4e0d\u8db3\u4ee5\u8ba9\u4f60\u76f4\u63a5\u62ff\u5230 Offer \uff0c\u4f46\u4f1a\u5f15\u5bfc\u4f60\u63a2\u7d22\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u201c\u77e5\u8bc6\u5730\u56fe\u201d\uff0c\u5e26\u4f60\u4e86\u89e3\u4e0d\u540c\u201c\u5730\u96f7\u201d\u7684\u5f62\u72b6\u3001\u5927\u5c0f\u548c\u5206\u5e03\u4f4d\u7f6e\uff0c\u8ba9\u4f60\u638c\u63e1\u5404\u79cd\u201c\u6392\u96f7\u65b9\u6cd5\u201d\u3002\u6709\u4e86\u8fd9\u4e9b\u672c\u9886\uff0c\u76f8\u4fe1\u4f60\u53ef\u4ee5\u66f4\u52a0\u81ea\u5982\u5730\u5237\u9898\u548c\u9605\u8bfb\u6587\u732e\uff0c\u9010\u6b65\u6784\u5efa\u8d77\u5b8c\u6574\u7684\u77e5\u8bc6\u4f53\u7cfb\u3002

        \u6211\u6df1\u6df1\u8d5e\u540c\u8d39\u66fc\u6559\u6388\u6240\u8a00\uff1a\u201cKnowledge isn't free. You have to pay attention.\u201d\u4ece\u8fd9\u4e2a\u610f\u4e49\u4e0a\u770b\uff0c\u8fd9\u672c\u4e66\u5e76\u975e\u5b8c\u5168\u201c\u514d\u8d39\u201d\u3002\u4e3a\u4e86\u4e0d\u8f9c\u8d1f\u4f60\u4e3a\u672c\u4e66\u6240\u4ed8\u51fa\u7684\u5b9d\u8d35\u201c\u6ce8\u610f\u529b\u201d\uff0c\u6211\u4f1a\u5c3d\u6211\u6240\u80fd\uff0c\u6295\u5165\u6700\u5927\u7684\u201c\u6ce8\u610f\u529b\u201d\u6765\u5b8c\u6210\u8fd9\u672c\u4e66\u7684\u521b\u4f5c\u3002

        \u4f5c\u8005\u7b80\u4ecb

        \u9773\u5b87\u680b (Krahets)\uff0c\u5927\u5382\u9ad8\u7ea7\u7b97\u6cd5\u5de5\u7a0b\u5e08\uff0c\u4e0a\u6d77\u4ea4\u901a\u5927\u5b66\u7855\u58eb\u3002\u529b\u6263\uff08LeetCode\uff09\u5168\u7f51\u9605\u8bfb\u91cf\u6700\u9ad8\u535a\u4e3b\uff0c\u53d1\u8868\u7684\u300a\u56fe\u89e3\u7b97\u6cd5\u6570\u636e\u7ed3\u6784\u300b\u5df2\u88ab\u8ba2\u9605 27 \u4e07\u672c\u3002

        \u81f4\u8c22

        \u672c\u4e66\u5728\u5f00\u6e90\u793e\u533a\u4f17\u591a\u8d21\u732e\u8005\u7684\u5171\u540c\u52aa\u529b\u4e0b\u4e0d\u65ad\u5b8c\u5584\u3002\u611f\u8c22\u6bcf\u4e00\u4f4d\u6295\u5165\u65f6\u95f4\u4e0e\u7cbe\u529b\u7684\u64b0\u7a3f\u4eba\uff0c\u4ed6\u4eec\u662f\uff08\u6309\u7167 GitHub \u81ea\u52a8\u751f\u6210\u7684\u987a\u5e8f\u6392\u5217\uff09\uff1a

        \u672c\u4e66\u7684\u4ee3\u7801\u5ba1\u9605\u5de5\u4f5c\u7531 Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1\u3001Reanon \u548c sjinzh \u5b8c\u6210\uff08\u6309\u7167\u9996\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\uff09\u3002\u611f\u8c22\u4ed6\u4eec\u4ed8\u51fa\u7684\u65f6\u95f4\u4e0e\u7cbe\u529b\uff0c\u6b63\u662f\u4ed6\u4eec\u786e\u4fdd\u4e86\u5404\u8bed\u8a00\u4ee3\u7801\u7684\u89c4\u8303\u4e0e\u7edf\u4e00\u3002

        GongljaC, C++ gvenusleoDart hpstoryC# justin-tseJS, TS krahetsJava, Python night-cruiseRust nuomi1Swift ReanonGo, C sjinzhRust, Zig"},{"location":"chapter_appendix/","title":"\u7b2c 16 \u7ae0 \u00a0 \u9644\u5f55","text":""},{"location":"chapter_appendix/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 16.1 \u00a0 \u7f16\u7a0b\u73af\u5883\u5b89\u88c5
        • 16.2 \u00a0 \u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c
        • 16.3 \u00a0 \u672f\u8bed\u8868
        "},{"location":"chapter_appendix/contribution/","title":"16.2 \u00a0 \u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c","text":"

        \u7531\u4e8e\u7b14\u8005\u80fd\u529b\u6709\u9650\uff0c\u4e66\u4e2d\u96be\u514d\u5b58\u5728\u4e00\u4e9b\u9057\u6f0f\u548c\u9519\u8bef\uff0c\u8bf7\u60a8\u8c05\u89e3\u3002\u5982\u679c\u60a8\u53d1\u73b0\u4e86\u7b14\u8bef\u3001\u94fe\u63a5\u5931\u6548\u3001\u5185\u5bb9\u7f3a\u5931\u3001\u6587\u5b57\u6b67\u4e49\u3001\u89e3\u91ca\u4e0d\u6e05\u6670\u6216\u884c\u6587\u7ed3\u6784\u4e0d\u5408\u7406\u7b49\u95ee\u9898\uff0c\u8bf7\u534f\u52a9\u6211\u4eec\u8fdb\u884c\u4fee\u6b63\uff0c\u4ee5\u7ed9\u8bfb\u8005\u63d0\u4f9b\u66f4\u4f18\u8d28\u7684\u5b66\u4e60\u8d44\u6e90\u3002

        \u6240\u6709\u64b0\u7a3f\u4eba\u7684 GitHub ID \u5c06\u5728\u672c\u4e66\u4ed3\u5e93\u3001\u7f51\u9875\u7248\u548c PDF \u7248\u7684\u4e3b\u9875\u4e0a\u8fdb\u884c\u5c55\u793a\uff0c\u4ee5\u611f\u8c22\u4ed6\u4eec\u5bf9\u5f00\u6e90\u793e\u533a\u7684\u65e0\u79c1\u5949\u732e\u3002

        \u5f00\u6e90\u7684\u9b45\u529b

        \u7eb8\u8d28\u56fe\u4e66\u7684\u4e24\u6b21\u5370\u5237\u7684\u95f4\u9694\u65f6\u95f4\u5f80\u5f80\u8f83\u4e45\uff0c\u5185\u5bb9\u66f4\u65b0\u975e\u5e38\u4e0d\u65b9\u4fbf\u3002

        \u800c\u5728\u672c\u5f00\u6e90\u4e66\u4e2d\uff0c\u5185\u5bb9\u66f4\u8fed\u7684\u65f6\u95f4\u88ab\u7f29\u77ed\u81f3\u6570\u65e5\u751a\u81f3\u51e0\u4e2a\u5c0f\u65f6\u3002

        "},{"location":"chapter_appendix/contribution/#1","title":"1. \u00a0 \u5185\u5bb9\u5fae\u8c03","text":"

        \u5982\u56fe 16-3 \u6240\u793a\uff0c\u6bcf\u4e2a\u9875\u9762\u7684\u53f3\u4e0a\u89d2\u90fd\u6709\u201c\u7f16\u8f91\u56fe\u6807\u201d\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u4fee\u6539\u6587\u672c\u6216\u4ee3\u7801\u3002

        1. \u70b9\u51fb\u201c\u7f16\u8f91\u56fe\u6807\u201d\uff0c\u5982\u679c\u9047\u5230\u201c\u9700\u8981 Fork \u6b64\u4ed3\u5e93\u201d\u7684\u63d0\u793a\uff0c\u8bf7\u540c\u610f\u8be5\u64cd\u4f5c\u3002
        2. \u4fee\u6539 Markdown \u6e90\u6587\u4ef6\u5185\u5bb9\uff0c\u68c0\u67e5\u5185\u5bb9\u7684\u6b63\u786e\u6027\uff0c\u5e76\u5c3d\u91cf\u4fdd\u6301\u6392\u7248\u683c\u5f0f\u7684\u7edf\u4e00\u3002
        3. \u5728\u9875\u9762\u5e95\u90e8\u586b\u5199\u4fee\u6539\u8bf4\u660e\uff0c\u7136\u540e\u70b9\u51fb\u201cPropose file change\u201d\u6309\u94ae\u3002\u9875\u9762\u8df3\u8f6c\u540e\uff0c\u70b9\u51fb\u201cCreate pull request\u201d\u6309\u94ae\u5373\u53ef\u53d1\u8d77\u62c9\u53d6\u8bf7\u6c42\u3002

        \u56fe 16-3 \u00a0 \u9875\u9762\u7f16\u8f91\u6309\u952e

        \u56fe\u7247\u65e0\u6cd5\u76f4\u63a5\u4fee\u6539\uff0c\u9700\u8981\u901a\u8fc7\u65b0\u5efa Issue \u6216\u8bc4\u8bba\u7559\u8a00\u6765\u63cf\u8ff0\u95ee\u9898\uff0c\u6211\u4eec\u4f1a\u5c3d\u5feb\u91cd\u65b0\u7ed8\u5236\u5e76\u66ff\u6362\u56fe\u7247\u3002

        "},{"location":"chapter_appendix/contribution/#2","title":"2. \u00a0 \u5185\u5bb9\u521b\u4f5c","text":"

        \u5982\u679c\u60a8\u6709\u5174\u8da3\u53c2\u4e0e\u6b64\u5f00\u6e90\u9879\u76ee\uff0c\u5305\u62ec\u5c06\u4ee3\u7801\u7ffb\u8bd1\u6210\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u3001\u6269\u5c55\u6587\u7ae0\u5185\u5bb9\u7b49\uff0c\u90a3\u4e48\u9700\u8981\u5b9e\u65bd\u4ee5\u4e0b Pull Request \u5de5\u4f5c\u6d41\u7a0b\u3002

        1. \u767b\u5f55 GitHub \uff0c\u5c06\u672c\u4e66\u7684\u4ee3\u7801\u4ed3\u5e93 Fork \u5230\u4e2a\u4eba\u8d26\u53f7\u4e0b\u3002
        2. \u8fdb\u5165\u60a8\u7684 Fork \u4ed3\u5e93\u7f51\u9875\uff0c\u4f7f\u7528 git clone \u547d\u4ee4\u5c06\u4ed3\u5e93\u514b\u9686\u81f3\u672c\u5730\u3002
        3. \u5728\u672c\u5730\u8fdb\u884c\u5185\u5bb9\u521b\u4f5c\uff0c\u5e76\u8fdb\u884c\u5b8c\u6574\u6d4b\u8bd5\uff0c\u9a8c\u8bc1\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002
        4. \u5c06\u672c\u5730\u6240\u505a\u66f4\u6539 Commit \uff0c\u7136\u540e Push \u81f3\u8fdc\u7a0b\u4ed3\u5e93\u3002
        5. \u5237\u65b0\u4ed3\u5e93\u7f51\u9875\uff0c\u70b9\u51fb\u201cCreate pull request\u201d\u6309\u94ae\u5373\u53ef\u53d1\u8d77\u62c9\u53d6\u8bf7\u6c42\u3002
        "},{"location":"chapter_appendix/contribution/#3-docker","title":"3. \u00a0 Docker \u90e8\u7f72","text":"

        \u5728 hello-algo \u6839\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b Docker \u811a\u672c\uff0c\u5373\u53ef\u5728 http://localhost:8000 \u8bbf\u95ee\u672c\u9879\u76ee\uff1a

        docker-compose up -d\n

        \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5220\u9664\u90e8\u7f72\uff1a

        docker-compose down\n
        "},{"location":"chapter_appendix/installation/","title":"16.1 \u00a0 \u7f16\u7a0b\u73af\u5883\u5b89\u88c5","text":""},{"location":"chapter_appendix/installation/#1611-ide","title":"16.1.1 \u00a0 \u5b89\u88c5 IDE","text":"

        \u63a8\u8350\u4f7f\u7528\u5f00\u6e90\u3001\u8f7b\u91cf\u7684 VSCode \u4f5c\u4e3a\u672c\u5730\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u8bbf\u95ee VSCode \u5b98\u7f51\uff0c\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u76f8\u5e94\u7248\u672c\u7684 VSCode \u8fdb\u884c\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002

        \u56fe 16-1 \u00a0 \u4ece\u5b98\u7f51\u4e0b\u8f7d VSCode

        VSCode \u62e5\u6709\u5f3a\u5927\u7684\u6269\u5c55\u5305\u751f\u6001\u7cfb\u7edf\uff0c\u652f\u6301\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u7684\u8fd0\u884c\u548c\u8c03\u8bd5\u3002\u4ee5 Python \u4e3a\u4f8b\uff0c\u5b89\u88c5\u201cPython Extension Pack\u201d\u6269\u5c55\u5305\u4e4b\u540e\uff0c\u5373\u53ef\u8fdb\u884c Python \u4ee3\u7801\u8c03\u8bd5\u3002\u5b89\u88c5\u6b65\u9aa4\u5982\u56fe 16-2 \u6240\u793a\u3002

        \u56fe 16-2 \u00a0 \u5b89\u88c5 VSCode \u6269\u5c55\u5305

        "},{"location":"chapter_appendix/installation/#1612","title":"16.1.2 \u00a0 \u5b89\u88c5\u8bed\u8a00\u73af\u5883","text":""},{"location":"chapter_appendix/installation/#1-python","title":"1. \u00a0 Python \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Miniconda3 \uff0c\u9700\u8981 Python 3.10 \u6216\u66f4\u65b0\u7248\u672c\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 python \uff0c\u5b89\u88c5 Python Extension Pack \u3002
        3. \uff08\u53ef\u9009\uff09\u5728\u547d\u4ee4\u884c\u8f93\u5165 pip install black \uff0c\u5b89\u88c5\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u3002
        "},{"location":"chapter_appendix/installation/#2-cc","title":"2. \u00a0 C/C++ \u73af\u5883","text":"
        1. Windows \u7cfb\u7edf\u9700\u8981\u5b89\u88c5 MinGW\uff08\u914d\u7f6e\u6559\u7a0b\uff09\uff1bMacOS \u81ea\u5e26 Clang \uff0c\u65e0\u987b\u5b89\u88c5\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 c++ \uff0c\u5b89\u88c5 C/C++ Extension Pack \u3002
        3. \uff08\u53ef\u9009\uff09\u6253\u5f00 Settings \u9875\u9762\uff0c\u641c\u7d22 Clang_format_fallback Style \u4ee3\u7801\u683c\u5f0f\u5316\u9009\u9879\uff0c\u8bbe\u7f6e\u4e3a { BasedOnStyle: Microsoft, BreakBeforeBraces: Attach } \u3002
        "},{"location":"chapter_appendix/installation/#3-java","title":"3. \u00a0 Java \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 OpenJDK\uff08\u7248\u672c\u9700\u6ee1\u8db3 > JDK 9\uff09\u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 java \uff0c\u5b89\u88c5 Extension Pack for Java \u3002
        "},{"location":"chapter_appendix/installation/#4-c","title":"4. \u00a0 C# \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 .Net 8.0 \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 C# Dev Kit \uff0c\u5b89\u88c5 C# Dev Kit \uff08\u914d\u7f6e\u6559\u7a0b\uff09\u3002
        3. \u4e5f\u53ef\u4f7f\u7528 Visual Studio\uff08\u5b89\u88c5\u6559\u7a0b\uff09\u3002
        "},{"location":"chapter_appendix/installation/#5-go","title":"5. \u00a0 Go \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 go \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 go \uff0c\u5b89\u88c5 Go \u3002
        3. \u6309\u5feb\u6377\u952e Ctrl + Shift + P \u547c\u51fa\u547d\u4ee4\u680f\uff0c\u8f93\u5165 go \uff0c\u9009\u62e9 Go: Install/Update Tools \uff0c\u5168\u90e8\u52fe\u9009\u5e76\u5b89\u88c5\u5373\u53ef\u3002
        "},{"location":"chapter_appendix/installation/#6-swift","title":"6. \u00a0 Swift \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Swift \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 swift \uff0c\u5b89\u88c5 Swift for Visual Studio Code \u3002
        "},{"location":"chapter_appendix/installation/#7-javascript","title":"7. \u00a0 JavaScript \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 node.js \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 javascript \uff0c\u5b89\u88c5 JavaScript (ES6) code snippets \u3002
        3. \uff08\u53ef\u9009\uff09\u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 Prettier \uff0c\u5b89\u88c5\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u3002
        "},{"location":"chapter_appendix/installation/#8-dart","title":"8. \u00a0 Dart \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Dart \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 dart \uff0c\u5b89\u88c5 Dart \u3002
        "},{"location":"chapter_appendix/installation/#9-rust","title":"9. \u00a0 Rust \u73af\u5883","text":"
        1. \u4e0b\u8f7d\u5e76\u5b89\u88c5 Rust \u3002
        2. \u5728 VSCode \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 rust \uff0c\u5b89\u88c5 rust-analyzer \u3002
        "},{"location":"chapter_appendix/terminology/","title":"16.3 \u00a0 \u672f\u8bed\u8868","text":"

        \u8868 16-1 \u5217\u51fa\u4e86\u4e66\u4e2d\u51fa\u73b0\u7684\u91cd\u8981\u672f\u8bed\u3002\u5efa\u8bae\u4f60\u540c\u65f6\u8bb0\u4f4f\u5b83\u4eec\u7684\u4e2d\u82f1\u6587\u53eb\u6cd5\uff0c\u4ee5\u4fbf\u9605\u8bfb\u82f1\u6587\u6587\u732e\u3002

        \u8868 16-1 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u91cd\u8981\u540d\u8bcd

        \u4e2d\u6587 English \u4e2d\u6587 English \u7b97\u6cd5 algorithm \u5c42\u5e8f\u904d\u5386 level-order traversal \u6570\u636e\u7ed3\u6784 data structure \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal \u6e10\u8fd1\u590d\u6742\u5ea6\u5206\u6790 asymptotic complexity analysis \u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal \u65f6\u95f4\u590d\u6742\u5ea6 time complexity \u4e8c\u53c9\u641c\u7d22\u6811 binary search tree \u7a7a\u95f4\u590d\u6742\u5ea6 space complexity \u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 balanced binary search tree \u8fed\u4ee3 iteration \u5e73\u8861\u56e0\u5b50 balance factor \u9012\u5f52 recursion \u5806 heap \u5c3e\u9012\u5f52 tail recursion \u5927\u9876\u5806 max heap \u9012\u5f52\u6811 recursion tree \u5c0f\u9876\u5806 min heap \u5927 big- \u4f18\u5148\u961f\u5217 priority queue \u8bb0\u53f7 notation \u6e10\u8fd1\u4e0a\u754c asymptotic upper bound \u5806\u5316 heapify \u539f\u7801 sign\u2013magnitude \u56fe graph \u53cd\u7801 1\u2019s complement \u9876\u70b9 vertex \u8865\u7801 2\u2019s complement \u65e0\u5411\u56fe undirected graph \u6570\u7ec4 array \u6709\u5411\u56fe directed graph \u7d22\u5f15 index \u8fde\u901a\u56fe connected graph \u94fe\u8868 linked list \u975e\u8fde\u901a\u56fe disconnected graph \u94fe\u8868\u8282\u70b9 linked list node, list node \u6709\u6743\u56fe weighted graph \u5217\u8868 list \u90bb\u63a5 adjacency \u52a8\u6001\u6570\u7ec4 dynamic array \u8def\u5f84 path \u786c\u76d8 hard disk \u5165\u5ea6 in-degree \u5185\u5b58 random-access memory (RAM) \u51fa\u5ea6 out-degree \u7f13\u5b58 cache memory \u90bb\u63a5\u77e9\u9635 adjacency matrix \u7f13\u5b58\u672a\u547d\u4e2d cache miss \u90bb\u63a5\u8868 adjacency list \u7f13\u5b58\u547d\u4e2d\u7387 cache hit rate \u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search \u6808 stack \u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search \u961f\u5217 queue \u4e8c\u5206\u67e5\u627e binary search \u53cc\u5411\u961f\u5217 double-ended queue \u641c\u7d22\u7b97\u6cd5 searching algorithm \u54c8\u5e0c\u8868 hash table \u6392\u5e8f\u7b97\u6cd5 sorting algorithm \u6876 bucket \u9009\u62e9\u6392\u5e8f selection sort \u54c8\u5e0c\u51fd\u6570 hash function \u5192\u6ce1\u6392\u5e8f bubble sort \u54c8\u5e0c\u51b2\u7a81 hash collision \u63d2\u5165\u6392\u5e8f insertion sort \u8d1f\u8f7d\u56e0\u5b50 load factor \u5feb\u901f\u6392\u5e8f quick sort \u94fe\u5f0f\u5730\u5740 separate chaining \u5f52\u5e76\u6392\u5e8f merge sort \u5f00\u653e\u5bfb\u5740 open addressing \u5806\u6392\u5e8f heap sort \u7ebf\u6027\u63a2\u6d4b linear probing \u6876\u6392\u5e8f bucket sort \u61d2\u5220\u9664 lazy deletion \u8ba1\u6570\u6392\u5e8f counting sort \u4e8c\u53c9\u6811 binary tree \u57fa\u6570\u6392\u5e8f radix sort \u6811\u8282\u70b9 tree node \u5206\u6cbb divide and conquer \u5de6\u5b50\u8282\u70b9 left-child node \u6c49\u8bfa\u5854\u95ee\u9898 hanota problem \u53f3\u5b50\u8282\u70b9 right-child node \u56de\u6eaf\u7b97\u6cd5 backtracking algorithm \u7236\u8282\u70b9 parent node \u7ea6\u675f constraint \u5de6\u5b50\u6811 left subtree \u89e3 solution \u53f3\u5b50\u6811 right subtree \u72b6\u6001 state \u6839\u8282\u70b9 root node \u526a\u679d pruning \u53f6\u8282\u70b9 leaf node \u5168\u6392\u5217\u95ee\u9898 permutations problem \u8fb9 edge \u5b50\u96c6\u548c\u95ee\u9898 subset-sum problem \u5c42 level N \u7687\u540e\u95ee\u9898 N-queens problem \u5ea6 degree \u52a8\u6001\u89c4\u5212 dynamic programming \u9ad8\u5ea6 height \u521d\u59cb\u72b6\u6001 initial state \u6df1\u5ea6 depth \u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b state-trasition equation \u5b8c\u7f8e\u4e8c\u53c9\u6811 perfect binary tree \u80cc\u5305\u95ee\u9898 knapsack problem \u5b8c\u5168\u4e8c\u53c9\u6811 complete binary tree \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898 edit distance problem \u5b8c\u6ee1\u4e8c\u53c9\u6811 full binary tree \u8d2a\u5fc3\u7b97\u6cd5 greedy algorithm \u5e73\u8861\u4e8c\u53c9\u6811 balanced binary tree AVL \u6811 AVL tree \u7ea2\u9ed1\u6811 red-black tree"},{"location":"chapter_array_and_linkedlist/","title":"\u7b2c 4 \u7ae0 \u00a0 \u6570\u7ec4\u4e0e\u94fe\u8868","text":"

        Abstract

        \u6570\u636e\u7ed3\u6784\u7684\u4e16\u754c\u5982\u540c\u4e00\u5835\u539a\u5b9e\u7684\u7816\u5899\u3002

        \u6570\u7ec4\u7684\u7816\u5757\u6574\u9f50\u6392\u5217\uff0c\u9010\u4e2a\u7d27\u8d34\u3002\u94fe\u8868\u7684\u7816\u5757\u5206\u6563\u5404\u5904\uff0c\u8fde\u63a5\u7684\u85e4\u8513\u81ea\u7531\u5730\u7a7f\u68ad\u4e8e\u7816\u7f1d\u4e4b\u95f4\u3002

        "},{"location":"chapter_array_and_linkedlist/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 4.1 \u00a0 \u6570\u7ec4
        • 4.2 \u00a0 \u94fe\u8868
        • 4.3 \u00a0 \u5217\u8868
        • 4.4 \u00a0 \u5185\u5b58\u4e0e\u7f13\u5b58 *
        • 4.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_array_and_linkedlist/array/","title":"4.1 \u00a0 \u6570\u7ec4","text":"

        \u300c\u6570\u7ec4 array\u300d\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u5c06\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\u3002\u6211\u4eec\u5c06\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u79f0\u4e3a\u8be5\u5143\u7d20\u7684\u300c\u7d22\u5f15 index\u300d\u3002\u56fe 4-1 \u5c55\u793a\u4e86\u6570\u7ec4\u7684\u4e3b\u8981\u672f\u8bed\u548c\u6982\u5ff5\u3002

        \u56fe 4-1 \u00a0 \u6570\u7ec4\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f

        "},{"location":"chapter_array_and_linkedlist/array/#411","title":"4.1.1 \u00a0 \u6570\u7ec4\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/array/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u6570\u7ec4","text":"

        \u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u7528\u6570\u7ec4\u7684\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u5f0f\uff1a\u65e0\u521d\u59cb\u503c\u3001\u7ed9\u5b9a\u521d\u59cb\u503c\u3002\u5728\u672a\u6307\u5b9a\u521d\u59cb\u503c\u7684\u60c5\u51b5\u4e0b\uff0c\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4f1a\u5c06\u6570\u7ec4\u5143\u7d20\u521d\u59cb\u5316\u4e3a \\(0\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        # \u521d\u59cb\u5316\u6570\u7ec4\narr: list[int] = [0] * 5  # [ 0, 0, 0, 0, 0 ]\nnums: list[int] = [1, 3, 2, 5, 4]  \n
        array.cpp
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\n// \u5b58\u50a8\u5728\u6808\u4e0a\nint arr[5];\nint nums[5] = { 1, 3, 2, 5, 4 };\n// \u5b58\u50a8\u5728\u5806\u4e0a\uff08\u9700\u8981\u624b\u52a8\u91ca\u653e\u7a7a\u95f4\uff09\nint* arr1 = new int[5];\nint* nums1 = new int[5] { 1, 3, 2, 5, 4 };\n
        array.java
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint[] arr = new int[5]; // { 0, 0, 0, 0, 0 }\nint[] nums = { 1, 3, 2, 5, 4 };\n
        array.cs
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint[] arr = new int[5]; // { 0, 0, 0, 0, 0 }\nint[] nums = [1, 3, 2, 5, 4];\n
        array.go
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nvar arr [5]int\n// \u5728 Go \u4e2d\uff0c\u6307\u5b9a\u957f\u5ea6\u65f6\uff08[5]int\uff09\u4e3a\u6570\u7ec4\uff0c\u4e0d\u6307\u5b9a\u957f\u5ea6\u65f6\uff08[]int\uff09\u4e3a\u5207\u7247\n// \u7531\u4e8e Go \u7684\u6570\u7ec4\u88ab\u8bbe\u8ba1\u4e3a\u5728\u7f16\u8bd1\u671f\u786e\u5b9a\u957f\u5ea6\uff0c\u56e0\u6b64\u53ea\u80fd\u4f7f\u7528\u5e38\u91cf\u6765\u6307\u5b9a\u957f\u5ea6\n// \u4e3a\u4e86\u65b9\u4fbf\u5b9e\u73b0\u6269\u5bb9 extend() \u65b9\u6cd5\uff0c\u4ee5\u4e0b\u5c06\u5207\u7247\uff08Slice\uff09\u770b\u4f5c\u6570\u7ec4\uff08Array\uff09\nnums := []int{1, 3, 2, 5, 4}\n
        array.swift
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr = Array(repeating: 0, count: 5) // [0, 0, 0, 0, 0]\nlet nums = [1, 3, 2, 5, 4]\n
        array.js
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nvar arr = new Array(5).fill(0);\nvar nums = [1, 3, 2, 5, 4];\n
        array.ts
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr: number[] = new Array(5).fill(0);\nlet nums: number[] = [1, 3, 2, 5, 4];\n
        array.dart
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nList<int> arr = List.filled(5, 0); // [0, 0, 0, 0, 0]\nList<int> nums = [1, 3, 2, 5, 4];\n
        array.rs
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nlet arr: Vec<i32> = vec![0; 5]; // [0, 0, 0, 0, 0]\nlet nums: Vec<i32> = vec![1, 3, 2, 5, 4];\n
        array.c
        /* \u521d\u59cb\u5316\u6570\u7ec4 */\nint arr[5] = { 0 }; // { 0, 0, 0, 0, 0 }\nint nums[5] = { 1, 3, 2, 5, 4 };\n
        array.zig
        // \u521d\u59cb\u5316\u6570\u7ec4\nvar arr = [_]i32{0} ** 5; // { 0, 0, 0, 0, 0 }\nvar nums = [_]i32{ 1, 3, 2, 5, 4 };\n
        "},{"location":"chapter_array_and_linkedlist/array/#2","title":"2. \u00a0 \u8bbf\u95ee\u5143\u7d20","text":"

        \u6570\u7ec4\u5143\u7d20\u88ab\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u8ba1\u7b97\u6570\u7ec4\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\u975e\u5e38\u5bb9\u6613\u3002\u7ed9\u5b9a\u6570\u7ec4\u5185\u5b58\u5730\u5740\uff08\u9996\u5143\u7d20\u5185\u5b58\u5730\u5740\uff09\u548c\u67d0\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u56fe 4-2 \u6240\u793a\u7684\u516c\u5f0f\u8ba1\u7b97\u5f97\u5230\u8be5\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\uff0c\u4ece\u800c\u76f4\u63a5\u8bbf\u95ee\u8be5\u5143\u7d20\u3002

        \u56fe 4-2 \u00a0 \u6570\u7ec4\u5143\u7d20\u7684\u5185\u5b58\u5730\u5740\u8ba1\u7b97

        \u89c2\u5bdf\u56fe 4-2 \uff0c\u6211\u4eec\u53d1\u73b0\u6570\u7ec4\u9996\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4e3a \\(0\\) \uff0c\u8fd9\u4f3c\u4e4e\u6709\u4e9b\u53cd\u76f4\u89c9\uff0c\u56e0\u4e3a\u4ece \\(1\\) \u5f00\u59cb\u8ba1\u6570\u4f1a\u66f4\u81ea\u7136\u3002\u4f46\u4ece\u5730\u5740\u8ba1\u7b97\u516c\u5f0f\u7684\u89d2\u5ea6\u770b\uff0c\u7d22\u5f15\u672c\u8d28\u4e0a\u662f\u5185\u5b58\u5730\u5740\u7684\u504f\u79fb\u91cf\u3002\u9996\u4e2a\u5143\u7d20\u7684\u5730\u5740\u504f\u79fb\u91cf\u662f \\(0\\) \uff0c\u56e0\u6b64\u5b83\u7684\u7d22\u5f15\u4e3a \\(0\\) \u662f\u5408\u7406\u7684\u3002

        \u5728\u6570\u7ec4\u4e2d\u8bbf\u95ee\u5143\u7d20\u975e\u5e38\u9ad8\u6548\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u968f\u673a\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5143\u7d20\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def random_access(nums: list[int]) -> int:\n\"\"\"\u968f\u673a\u8bbf\u95ee\u5143\u7d20\"\"\"\n# \u5728\u533a\u95f4 [0, len(nums)-1] \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nrandom_index = random.randint(0, len(nums) - 1)\n# \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nrandom_num = nums[random_index]\nreturn random_num\n
        array.cpp
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int *nums, int size) {\n// \u5728\u533a\u95f4 [0, size) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = rand() % size;\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.java
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int[] nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = ThreadLocalRandom.current().nextInt(0, nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.cs
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint RandomAccess(int[] nums) {\nRandom random = new();\n// \u5728\u533a\u95f4 [0, nums.Length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = random.Next(nums.Length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.go
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunc randomAccess(nums []int) (randomNum int) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nrandomIndex := rand.Intn(len(nums))\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nrandomNum = nums[randomIndex]\nreturn\n}\n
        array.swift
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunc randomAccess(nums: [Int]) -> Int {\n// \u5728\u533a\u95f4 [0, nums.count) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nlet randomIndex = nums.indices.randomElement()!\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nlet randomNum = nums[randomIndex]\nreturn randomNum\n}\n
        array.js
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunction randomAccess(nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nconst random_index = Math.floor(Math.random() * nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nconst random_num = nums[random_index];\nreturn random_num;\n}\n
        array.ts
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfunction randomAccess(nums: number[]): number {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nconst random_index = Math.floor(Math.random() * nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nconst random_num = nums[random_index];\nreturn random_num;\n}\n
        array.dart
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(List<int> nums) {\n// \u5728\u533a\u95f4 [0, nums.length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = Random().nextInt(nums.length);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.rs
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nfn random_access(nums: &[i32]) -> i32 {\n// \u5728\u533a\u95f4 [0, nums.len()) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nlet random_index = rand::thread_rng().gen_range(0..nums.len());\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nlet random_num = nums[random_index];\nrandom_num\n}\n
        array.c
        /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint randomAccess(int *nums, int size) {\n// \u5728\u533a\u95f4 [0, size) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\nint randomIndex = rand() % size;\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nint randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        array.zig
        // \u968f\u673a\u8bbf\u95ee\u5143\u7d20\nfn randomAccess(nums: []i32) i32 {\n// \u5728\u533a\u95f4 [0, nums.len) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6574\u6570\nvar randomIndex = std.crypto.random.intRangeLessThan(usize, 0, nums.len);\n// \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\nvar randomNum = nums[randomIndex];\nreturn randomNum;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#3","title":"3. \u00a0 \u63d2\u5165\u5143\u7d20","text":"

        \u6570\u7ec4\u5143\u7d20\u5728\u5185\u5b58\u4e2d\u662f\u201c\u7d27\u6328\u7740\u7684\u201d\uff0c\u5b83\u4eec\u4e4b\u95f4\u6ca1\u6709\u7a7a\u95f4\u518d\u5b58\u653e\u4efb\u4f55\u6570\u636e\u3002\u5982\u56fe 4-3 \u6240\u793a\uff0c\u5982\u679c\u60f3\u5728\u6570\u7ec4\u4e2d\u95f4\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u5219\u9700\u8981\u5c06\u8be5\u5143\u7d20\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u4e4b\u540e\u518d\u628a\u5143\u7d20\u8d4b\u503c\u7ed9\u8be5\u7d22\u5f15\u3002

        \u56fe 4-3 \u00a0 \u6570\u7ec4\u63d2\u5165\u5143\u7d20\u793a\u4f8b

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u56e0\u6b64\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u4f1a\u5bfc\u81f4\u6570\u7ec4\u5c3e\u90e8\u5143\u7d20\u201c\u4e22\u5931\u201d\u3002\u6211\u4eec\u5c06\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u7559\u5728\u201c\u5217\u8868\u201d\u7ae0\u8282\u4e2d\u8ba8\u8bba\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def insert(nums: list[int], num: int, index: int):\n\"\"\"\u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num\"\"\"\n# \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in range(len(nums) - 1, index, -1):\nnums[i] = nums[i - 1]\n# \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n
        array.cpp
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int *nums, int size, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = size - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.java
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int[] nums, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.cs
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid Insert(int[] nums, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = nums.Length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.go
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunc insert(nums []int, num int, index int) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i := len(nums) - 1; i > index; i-- {\nnums[i] = nums[i-1]\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n}\n
        array.swift
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunc insert(nums: inout [Int], num: Int, index: Int) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in nums.indices.dropFirst(index).reversed() {\nnums[i] = nums[i - 1]\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num\n}\n
        array.js
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunction insert(nums, num, index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.ts
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfunction insert(nums: number[], num: number, index: number): void {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.dart
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 _num */\nvoid insert(List<int> nums, int _num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (var i = nums.length - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 _num \u8d4b\u7ed9 index \u5904\u5143\u7d20\nnums[index] = _num;\n}\n
        array.rs
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nfn insert(nums: &mut Vec<i32>, num: i32, index: usize) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor i in (index + 1..nums.len()).rev() {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.c
        /* \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num */\nvoid insert(int *nums, int size, int num, int index) {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int i = size - 1; i > index; i--) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        array.zig
        // \u5728\u6570\u7ec4\u7684\u7d22\u5f15 index \u5904\u63d2\u5165\u5143\u7d20 num\nfn insert(nums: []i32, num: i32, index: usize) void {\n// \u628a\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nvar i = nums.len - 1;\nwhile (i > index) : (i -= 1) {\nnums[i] = nums[i - 1];\n}\n// \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\nnums[index] = num;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#4","title":"4. \u00a0 \u5220\u9664\u5143\u7d20","text":"

        \u540c\u7406\uff0c\u5982\u56fe 4-4 \u6240\u793a\uff0c\u82e5\u60f3\u5220\u9664\u7d22\u5f15 \\(i\\) \u5904\u7684\u5143\u7d20\uff0c\u5219\u9700\u8981\u628a\u7d22\u5f15 \\(i\\) \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\u3002

        \u56fe 4-4 \u00a0 \u6570\u7ec4\u5220\u9664\u5143\u7d20\u793a\u4f8b

        \u8bf7\u6ce8\u610f\uff0c\u5220\u9664\u5143\u7d20\u5b8c\u6210\u540e\uff0c\u539f\u5148\u672b\u5c3e\u7684\u5143\u7d20\u53d8\u5f97\u201c\u65e0\u610f\u4e49\u201d\u4e86\uff0c\u6240\u4ee5\u6211\u4eec\u65e0\u987b\u7279\u610f\u53bb\u4fee\u6539\u5b83\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def remove(nums: list[int], index: int):\n\"\"\"\u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\"\"\"\n# \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in range(index, len(nums) - 1):\nnums[i] = nums[i + 1]\n
        array.cpp
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(int *nums, int size, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < size - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.java
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(int[] nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.cs
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid Remove(int[] nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < nums.Length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.go
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunc remove(nums []int, index int) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i := index; i < len(nums)-1; i++ {\nnums[i] = nums[i+1]\n}\n}\n
        array.swift
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunc remove(nums: inout [Int], index: Int) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in nums.indices.dropFirst(index).dropLast() {\nnums[i] = nums[i + 1]\n}\n}\n
        array.js
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunction remove(nums, index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.ts
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfunction remove(nums: number[], index: number): void {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.dart
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nvoid remove(List<int> nums, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (var i = index; i < nums.length - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.rs
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\nfn remove(nums: &mut Vec<i32>, index: usize) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor i in index..nums.len() - 1 {\nnums[i] = nums[i + 1];\n}\n}\n
        array.c
        /* \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nvoid removeItem(int *nums, int size, int index) {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int i = index; i < size - 1; i++) {\nnums[i] = nums[i + 1];\n}\n}\n
        array.zig
        // \u5220\u9664\u7d22\u5f15 index \u5904\u7684\u5143\u7d20\nfn remove(nums: []i32, index: usize) void {\n// \u628a\u7d22\u5f15 index \u4e4b\u540e\u7684\u6240\u6709\u5143\u7d20\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nvar i = index;\nwhile (i < nums.len - 1) : (i += 1) {\nnums[i] = nums[i + 1];\n}\n}\n

        \u603b\u7684\u6765\u770b\uff0c\u6570\u7ec4\u7684\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u6709\u4ee5\u4e0b\u7f3a\u70b9\u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6\u9ad8\uff1a\u6570\u7ec4\u7684\u63d2\u5165\u548c\u5220\u9664\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u6570\u7ec4\u957f\u5ea6\u3002
        • \u4e22\u5931\u5143\u7d20\uff1a\u7531\u4e8e\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u53ef\u53d8\uff0c\u56e0\u6b64\u5728\u63d2\u5165\u5143\u7d20\u540e\uff0c\u8d85\u51fa\u6570\u7ec4\u957f\u5ea6\u8303\u56f4\u7684\u5143\u7d20\u4f1a\u4e22\u5931\u3002
        • \u5185\u5b58\u6d6a\u8d39\uff1a\u6211\u4eec\u53ef\u4ee5\u521d\u59cb\u5316\u4e00\u4e2a\u6bd4\u8f83\u957f\u7684\u6570\u7ec4\uff0c\u53ea\u7528\u524d\u9762\u4e00\u90e8\u5206\uff0c\u8fd9\u6837\u5728\u63d2\u5165\u6570\u636e\u65f6\uff0c\u4e22\u5931\u7684\u672b\u5c3e\u5143\u7d20\u90fd\u662f\u201c\u65e0\u610f\u4e49\u201d\u7684\uff0c\u4f46\u8fd9\u6837\u505a\u4f1a\u9020\u6210\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u3002
        "},{"location":"chapter_array_and_linkedlist/array/#5","title":"5. \u00a0 \u904d\u5386\u6570\u7ec4","text":"

        \u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u65e2\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u904d\u5386\u83b7\u53d6\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def traverse(nums: list[int]):\n\"\"\"\u904d\u5386\u6570\u7ec4\"\"\"\ncount = 0\n# \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in range(len(nums)):\ncount += nums[i]\n# \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums:\ncount += num\n# \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\nfor i, num in enumerate(nums):\ncount += nums[i]\ncount += num\n
        array.cpp
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\ncount += nums[i];\n}\n}\n
        array.java
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int[] nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (int num : nums) {\ncount += num;\n}\n}\n
        array.cs
        /* \u904d\u5386\u6570\u7ec4 */\nvoid Traverse(int[] nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < nums.Length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nforeach (int num in nums) {\ncount += num;\n}\n}\n
        array.go
        /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums []int) {\ncount := 0\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i := 0; i < len(nums); i++ {\ncount += nums[i]\n}\ncount = 0\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor _, num := range nums {\ncount += num\n}\n// \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\nfor i, num := range nums {\ncount += nums[i]\ncount += num\n}\n}\n
        array.swift
        /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums: [Int]) {\nvar count = 0\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in nums.indices {\ncount += nums[i]\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums {\ncount += num\n}\n}\n
        array.js
        /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums) {\nlet count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (const num of nums) {\ncount += num;\n}\n}\n
        array.ts
        /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums: number[]): void {\nlet count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (const num of nums) {\ncount += num;\n}\n}\n
        array.dart
        /* \u904d\u5386\u6570\u7ec4\u5143\u7d20 */\nvoid traverse(List<int> nums) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (var i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (int _num in nums) {\ncount += _num;\n}\n// \u901a\u8fc7 forEach \u65b9\u6cd5\u904d\u5386\u6570\u7ec4\nnums.forEach((_num) {\ncount += _num;\n});\n}\n
        array.rs
        /* \u904d\u5386\u6570\u7ec4 */\nfn traverse(nums: &[i32]) {\nlet mut _count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor i in 0..nums.len() {\n_count += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor num in nums {\n_count += num;\n}\n}\n
        array.c
        /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\nint count = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\ncount += nums[i];\n}\n}\n
        array.zig
        // \u904d\u5386\u6570\u7ec4\nfn traverse(nums: []i32) void {\nvar count: i32 = 0;\n// \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\nvar i: i32 = 0;\nwhile (i < nums.len) : (i += 1) {\ncount += nums[i];\n}\ncount = 0;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\nfor (nums) |num| {\ncount += num;\n}\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#6","title":"6. \u00a0 \u67e5\u627e\u5143\u7d20","text":"

        \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\u9700\u8981\u904d\u5386\u6570\u7ec4\uff0c\u6bcf\u8f6e\u5224\u65ad\u5143\u7d20\u503c\u662f\u5426\u5339\u914d\uff0c\u82e5\u5339\u914d\u5219\u8f93\u51fa\u5bf9\u5e94\u7d22\u5f15\u3002

        \u56e0\u4e3a\u6570\u7ec4\u662f\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u6240\u4ee5\u4e0a\u8ff0\u67e5\u627e\u64cd\u4f5c\u88ab\u79f0\u4e3a\u201c\u7ebf\u6027\u67e5\u627e\u201d\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def find(nums: list[int], target: int) -> int:\n\"\"\"\u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\"\"\"\nfor i in range(len(nums)):\nif nums[i] == target:\nreturn i\nreturn -1\n
        array.cpp
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\nfor (int i = 0; i < size; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.java
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int[] nums, int target) {\nfor (int i = 0; i < nums.length; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.cs
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint Find(int[] nums, int target) {\nfor (int i = 0; i < nums.Length; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.go
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums []int, target int) (index int) {\nindex = -1\nfor i := 0; i < len(nums); i++ {\nif nums[i] == target {\nindex = i\nbreak\n}\n}\nreturn\n}\n
        array.swift
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums: [Int], target: Int) -> Int {\nfor i in nums.indices {\nif nums[i] == target {\nreturn i\n}\n}\nreturn -1\n}\n
        array.js
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums, target) {\nfor (let i = 0; i < nums.length; i++) {\nif (nums[i] === target) return i;\n}\nreturn -1;\n}\n
        array.ts
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums: number[], target: number): number {\nfor (let i = 0; i < nums.length; i++) {\nif (nums[i] === target) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        array.dart
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(List<int> nums, int target) {\nfor (var i = 0; i < nums.length; i++) {\nif (nums[i] == target) return i;\n}\nreturn -1;\n}\n
        array.rs
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfn find(nums: &[i32], target: i32) -> Option<usize> {\nfor i in 0..nums.len() {\nif nums[i] == target {\nreturn Some(i);\n}\n}\nNone\n}\n
        array.c
        /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\nfor (int i = 0; i < size; i++) {\nif (nums[i] == target)\nreturn i;\n}\nreturn -1;\n}\n
        array.zig
        // \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\nfn find(nums: []i32, target: i32) i32 {\nfor (nums, 0..) |num, i| {\nif (num == target) return @intCast(i);\n}\nreturn -1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#7","title":"7. \u00a0 \u6269\u5bb9\u6570\u7ec4","text":"

        \u5728\u590d\u6742\u7684\u7cfb\u7edf\u73af\u5883\u4e2d\uff0c\u7a0b\u5e8f\u96be\u4ee5\u4fdd\u8bc1\u6570\u7ec4\u4e4b\u540e\u7684\u5185\u5b58\u7a7a\u95f4\u662f\u53ef\u7528\u7684\uff0c\u4ece\u800c\u65e0\u6cd5\u5b89\u5168\u5730\u6269\u5c55\u6570\u7ec4\u5bb9\u91cf\u3002\u56e0\u6b64\u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u662f\u4e0d\u53ef\u53d8\u7684\u3002

        \u5982\u679c\u6211\u4eec\u5e0c\u671b\u6269\u5bb9\u6570\u7ec4\uff0c\u5219\u9700\u91cd\u65b0\u5efa\u7acb\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u7136\u540e\u628a\u539f\u6570\u7ec4\u5143\u7d20\u4f9d\u6b21\u590d\u5236\u5230\u65b0\u6570\u7ec4\u3002\u8fd9\u662f\u4e00\u4e2a \\(O(n)\\) \u7684\u64cd\u4f5c\uff0c\u5728\u6570\u7ec4\u5f88\u5927\u7684\u60c5\u51b5\u4e0b\u975e\u5e38\u8017\u65f6\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array.py
        def extend(nums: list[int], enlarge: int) -> list[int]:\n\"\"\"\u6269\u5c55\u6570\u7ec4\u957f\u5ea6\"\"\"\n# \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nres = [0] * (len(nums) + enlarge)\n# \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i in range(len(nums)):\nres[i] = nums[i]\n# \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n
        array.cpp
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint *extend(int *nums, int size, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint *res = new int[size + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\nres[i] = nums[i];\n}\n// \u91ca\u653e\u5185\u5b58\ndelete[] nums;\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.java
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint[] extend(int[] nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint[] res = new int[nums.length + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.cs
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint[] Extend(int[] nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint[] res = new int[nums.Length + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < nums.Length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.go
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfunc extend(nums []int, enlarge int) []int {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nres := make([]int, len(nums)+enlarge)\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i, num := range nums {\nres[i] = num\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n}\n
        array.swift
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfunc extend(nums: [Int], enlarge: Int) -> [Int] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nvar res = Array(repeating: 0, count: nums.count + enlarge)\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor i in nums.indices {\nres[i] = nums[i]\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res\n}\n
        array.js
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\n// \u8bf7\u6ce8\u610f\uff0cJavaScript \u7684 Array \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u76f4\u63a5\u6269\u5c55\n// \u4e3a\u4e86\u65b9\u4fbf\u5b66\u4e60\uff0c\u672c\u51fd\u6570\u5c06 Array \u770b\u4f5c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6570\u7ec4\nfunction extend(nums, enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nconst res = new Array(nums.length + enlarge).fill(0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.ts
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\n// \u8bf7\u6ce8\u610f\uff0cTypeScript \u7684 Array \u662f\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u76f4\u63a5\u6269\u5c55\n// \u4e3a\u4e86\u65b9\u4fbf\u5b66\u4e60\uff0c\u672c\u51fd\u6570\u5c06 Array \u770b\u4f5c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6570\u7ec4\nfunction extend(nums: number[], enlarge: number): number[] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nconst res = new Array(nums.length + enlarge).fill(0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (let i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.dart
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nList<int> extend(List<int> nums, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nList<int> res = List.filled(nums.length + enlarge, 0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (var i = 0; i < nums.length; i++) {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.rs
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nfn extend(nums: Vec<i32>, enlarge: usize) -> Vec<i32> {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nlet mut res: Vec<i32> = vec![0; nums.len() + enlarge];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\nfor i in 0..nums.len() {\nres[i] = nums[i];\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nres\n}\n
        array.c
        /* \u6269\u5c55\u6570\u7ec4\u957f\u5ea6 */\nint *extend(int *nums, int size, int enlarge) {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nint *res = (int *)malloc(sizeof(int) * (size + enlarge));\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size; i++) {\nres[i] = nums[i];\n}\n// \u521d\u59cb\u5316\u6269\u5c55\u540e\u7684\u7a7a\u95f4\nfor (int i = size; i < size + enlarge; i++) {\nres[i] = 0;\n}\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        array.zig
        // \u6269\u5c55\u6570\u7ec4\u957f\u5ea6\nfn extend(mem_allocator: std.mem.Allocator, nums: []i32, enlarge: usize) ![]i32 {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u6269\u5c55\u957f\u5ea6\u540e\u7684\u6570\u7ec4\nvar res = try mem_allocator.alloc(i32, nums.len + enlarge);\n@memset(res, 0);\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nstd.mem.copy(i32, res, nums);\n// \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\nreturn res;\n}\n
        "},{"location":"chapter_array_and_linkedlist/array/#412","title":"4.1.2 \u00a0 \u6570\u7ec4\u7684\u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u6570\u7ec4\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u5185\uff0c\u4e14\u5143\u7d20\u7c7b\u578b\u76f8\u540c\u3002\u8fd9\u79cd\u505a\u6cd5\u5305\u542b\u4e30\u5bcc\u7684\u5148\u9a8c\u4fe1\u606f\uff0c\u7cfb\u7edf\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u4fe1\u606f\u6765\u4f18\u5316\u6570\u636e\u7ed3\u6784\u7684\u64cd\u4f5c\u6548\u7387\u3002

        • \u7a7a\u95f4\u6548\u7387\u9ad8\uff1a\u6570\u7ec4\u4e3a\u6570\u636e\u5206\u914d\u4e86\u8fde\u7eed\u7684\u5185\u5b58\u5757\uff0c\u65e0\u987b\u989d\u5916\u7684\u7ed3\u6784\u5f00\u9500\u3002
        • \u652f\u6301\u968f\u673a\u8bbf\u95ee\uff1a\u6570\u7ec4\u5141\u8bb8\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u8bbf\u95ee\u4efb\u4f55\u5143\u7d20\u3002
        • \u7f13\u5b58\u5c40\u90e8\u6027\uff1a\u5f53\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u65f6\uff0c\u8ba1\u7b97\u673a\u4e0d\u4ec5\u4f1a\u52a0\u8f7d\u5b83\uff0c\u8fd8\u4f1a\u7f13\u5b58\u5176\u5468\u56f4\u7684\u5176\u4ed6\u6570\u636e\uff0c\u4ece\u800c\u501f\u52a9\u9ad8\u901f\u7f13\u5b58\u6765\u63d0\u5347\u540e\u7eed\u64cd\u4f5c\u7684\u6267\u884c\u901f\u5ea6\u3002

        \u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u662f\u4e00\u628a\u53cc\u5203\u5251\uff0c\u5176\u5b58\u5728\u4ee5\u4e0b\u5c40\u9650\u6027\u3002

        • \u63d2\u5165\u4e0e\u5220\u9664\u6548\u7387\u4f4e\uff1a\u5f53\u6570\u7ec4\u4e2d\u5143\u7d20\u8f83\u591a\u65f6\uff0c\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u9700\u8981\u79fb\u52a8\u5927\u91cf\u7684\u5143\u7d20\u3002
        • \u957f\u5ea6\u4e0d\u53ef\u53d8\uff1a\u6570\u7ec4\u5728\u521d\u59cb\u5316\u540e\u957f\u5ea6\u5c31\u56fa\u5b9a\u4e86\uff0c\u6269\u5bb9\u6570\u7ec4\u9700\u8981\u5c06\u6240\u6709\u6570\u636e\u590d\u5236\u5230\u65b0\u6570\u7ec4\uff0c\u5f00\u9500\u5f88\u5927\u3002
        • \u7a7a\u95f4\u6d6a\u8d39\uff1a\u5982\u679c\u6570\u7ec4\u5206\u914d\u7684\u5927\u5c0f\u8d85\u8fc7\u5b9e\u9645\u6240\u9700\uff0c\u90a3\u4e48\u591a\u4f59\u7684\u7a7a\u95f4\u5c31\u88ab\u6d6a\u8d39\u4e86\u3002
        "},{"location":"chapter_array_and_linkedlist/array/#413","title":"4.1.3 \u00a0 \u6570\u7ec4\u5178\u578b\u5e94\u7528","text":"

        \u6570\u7ec4\u662f\u4e00\u79cd\u57fa\u7840\u4e14\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\uff0c\u65e2\u9891\u7e41\u5e94\u7528\u5728\u5404\u7c7b\u7b97\u6cd5\u4e4b\u4e2d\uff0c\u4e5f\u53ef\u7528\u4e8e\u5b9e\u73b0\u5404\u79cd\u590d\u6742\u6570\u636e\u7ed3\u6784\u3002

        • \u968f\u673a\u8bbf\u95ee\uff1a\u5982\u679c\u6211\u4eec\u60f3\u968f\u673a\u62bd\u53d6\u4e00\u4e9b\u6837\u672c\uff0c\u90a3\u4e48\u53ef\u4ee5\u7528\u6570\u7ec4\u5b58\u50a8\uff0c\u5e76\u751f\u6210\u4e00\u4e2a\u968f\u673a\u5e8f\u5217\uff0c\u6839\u636e\u7d22\u5f15\u5b9e\u73b0\u968f\u673a\u62bd\u6837\u3002
        • \u6392\u5e8f\u548c\u641c\u7d22\uff1a\u6570\u7ec4\u662f\u6392\u5e8f\u548c\u641c\u7d22\u7b97\u6cd5\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u4e8c\u5206\u67e5\u627e\u7b49\u90fd\u4e3b\u8981\u5728\u6570\u7ec4\u4e0a\u8fdb\u884c\u3002
        • \u67e5\u627e\u8868\uff1a\u5f53\u9700\u8981\u5feb\u901f\u67e5\u627e\u4e00\u4e2a\u5143\u7d20\u6216\u5176\u5bf9\u5e94\u5173\u7cfb\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a\u67e5\u627e\u8868\u3002\u5047\u5982\u6211\u4eec\u60f3\u5b9e\u73b0\u5b57\u7b26\u5230 ASCII \u7801\u7684\u6620\u5c04\uff0c\u5219\u53ef\u4ee5\u5c06\u5b57\u7b26\u7684 ASCII \u7801\u503c\u4f5c\u4e3a\u7d22\u5f15\uff0c\u5bf9\u5e94\u7684\u5143\u7d20\u5b58\u653e\u5728\u6570\u7ec4\u4e2d\u7684\u5bf9\u5e94\u4f4d\u7f6e\u3002
        • \u673a\u5668\u5b66\u4e60\uff1a\u795e\u7ecf\u7f51\u7edc\u4e2d\u5927\u91cf\u4f7f\u7528\u4e86\u5411\u91cf\u3001\u77e9\u9635\u3001\u5f20\u91cf\u4e4b\u95f4\u7684\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97\uff0c\u8fd9\u4e9b\u6570\u636e\u90fd\u662f\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u6784\u5efa\u7684\u3002\u6570\u7ec4\u662f\u795e\u7ecf\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6700\u5e38\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff1a\u6570\u7ec4\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u5806\u3001\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u3002\u4f8b\u5982\uff0c\u56fe\u7684\u90bb\u63a5\u77e9\u9635\u8868\u793a\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002
        "},{"location":"chapter_array_and_linkedlist/linked_list/","title":"4.2 \u00a0 \u94fe\u8868","text":"

        \u5185\u5b58\u7a7a\u95f4\u662f\u6240\u6709\u7a0b\u5e8f\u7684\u516c\u5171\u8d44\u6e90\uff0c\u5728\u4e00\u4e2a\u590d\u6742\u7684\u7cfb\u7edf\u8fd0\u884c\u73af\u5883\u4e0b\uff0c\u7a7a\u95f2\u7684\u5185\u5b58\u7a7a\u95f4\u53ef\u80fd\u6563\u843d\u5728\u5185\u5b58\u5404\u5904\u3002\u6211\u4eec\u77e5\u9053\uff0c\u5b58\u50a8\u6570\u7ec4\u7684\u5185\u5b58\u7a7a\u95f4\u5fc5\u987b\u662f\u8fde\u7eed\u7684\uff0c\u800c\u5f53\u6570\u7ec4\u975e\u5e38\u5927\u65f6\uff0c\u5185\u5b58\u53ef\u80fd\u65e0\u6cd5\u63d0\u4f9b\u5982\u6b64\u5927\u7684\u8fde\u7eed\u7a7a\u95f4\u3002\u6b64\u65f6\u94fe\u8868\u7684\u7075\u6d3b\u6027\u4f18\u52bf\u5c31\u4f53\u73b0\u51fa\u6765\u4e86\u3002

        \u300c\u94fe\u8868 linked list\u300d\u662f\u4e00\u79cd\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u8282\u70b9\u5bf9\u8c61\uff0c\u5404\u4e2a\u8282\u70b9\u901a\u8fc7\u201c\u5f15\u7528\u201d\u76f8\u8fde\u63a5\u3002\u5f15\u7528\u8bb0\u5f55\u4e86\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u5185\u5b58\u5730\u5740\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u4ece\u5f53\u524d\u8282\u70b9\u8bbf\u95ee\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002

        \u94fe\u8868\u7684\u8bbe\u8ba1\u4f7f\u5f97\u5404\u4e2a\u8282\u70b9\u53ef\u4ee5\u5206\u6563\u5b58\u50a8\u5728\u5185\u5b58\u5404\u5904\uff0c\u5b83\u4eec\u7684\u5185\u5b58\u5730\u5740\u65e0\u987b\u8fde\u7eed\u3002

        \u56fe 4-5 \u00a0 \u94fe\u8868\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f

        \u89c2\u5bdf\u56fe 4-5 \uff0c\u94fe\u8868\u7684\u7ec4\u6210\u5355\u4f4d\u662f\u300c\u8282\u70b9 node\u300d\u5bf9\u8c61\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u542b\u4e24\u9879\u6570\u636e\uff1a\u8282\u70b9\u7684\u201c\u503c\u201d\u548c\u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u201c\u5f15\u7528\u201d\u3002

        • \u94fe\u8868\u7684\u9996\u4e2a\u8282\u70b9\u88ab\u79f0\u4e3a\u201c\u5934\u8282\u70b9\u201d\uff0c\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u88ab\u79f0\u4e3a\u201c\u5c3e\u8282\u70b9\u201d\u3002
        • \u5c3e\u8282\u70b9\u6307\u5411\u7684\u662f\u201c\u7a7a\u201d\uff0c\u5b83\u5728 Java\u3001C++ \u548c Python \u4e2d\u5206\u522b\u88ab\u8bb0\u4e3a \\(\\text{null}\\)\u3001\\(\\text{nullptr}\\) \u548c \\(\\text{None}\\) \u3002
        • \u5728 C\u3001C++\u3001Go \u548c Rust \u7b49\u652f\u6301\u6307\u9488\u7684\u8bed\u8a00\u4e2d\uff0c\u4e0a\u8ff0\u7684\u201c\u5f15\u7528\u201d\u5e94\u88ab\u66ff\u6362\u4e3a\u201c\u6307\u9488\u201d\u3002

        \u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u94fe\u8868\u8282\u70b9 ListNode \u9664\u4e86\u5305\u542b\u503c\uff0c\u8fd8\u9700\u989d\u5916\u4fdd\u5b58\u4e00\u4e2a\u5f15\u7528\uff08\u6307\u9488\uff09\u3002\u56e0\u6b64\u5728\u76f8\u540c\u6570\u636e\u91cf\u4e0b\uff0c\u94fe\u8868\u6bd4\u6570\u7ec4\u5360\u7528\u66f4\u591a\u7684\u5185\u5b58\u7a7a\u95f4\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class ListNode:\n\"\"\"\u94fe\u8868\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val               # \u8282\u70b9\u503c\nself.next: ListNode | None = None # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\nint val;         // \u8282\u70b9\u503c\nListNode *next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\nListNode(int x) : val(x), next(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\nListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  //\u6784\u9020\u51fd\u6570\nint val = x;         // \u8282\u70b9\u503c\nListNode? next;      // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype ListNode struct {\nVal  int       // \u8282\u70b9\u503c\nNext *ListNode // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n// NewListNode \u6784\u9020\u51fd\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\nfunc NewListNode(val int) *ListNode {\nreturn &ListNode{\nVal:  val,\nNext: nil,\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\ninit(x: Int) { // \u6784\u9020\u51fd\u6570\nval = x\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nconstructor(val, next) {\nthis.val = (val === undefined ? 0 : val);       // \u8282\u70b9\u503c\nthis.next = (next === undefined ? null : next); // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nval: number;\nnext: ListNode | null;\nconstructor(val?: number, next?: ListNode | null) {\nthis.val = val === undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next === undefined ? null : next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode? next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\nListNode(this.val, [this.next]); // \u6784\u9020\u51fd\u6570\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u94fe\u8868\u8282\u70b9\u7c7b */\n#[derive(Debug)]\nstruct ListNode {\nval: i32, // \u8282\u70b9\u503c\nnext: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n
        /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\nint val;               // \u8282\u70b9\u503c\nstruct ListNode *next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\nListNode *node;\nnode = (ListNode *) malloc(sizeof(ListNode));\nnode->val = val;\nnode->next = NULL;\nreturn node;\n}\n
        // \u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = 0, // \u8282\u70b9\u503c\nnext: ?*Self = null, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\n}\n};\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#421","title":"4.2.1 \u00a0 \u94fe\u8868\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/linked_list/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u94fe\u8868","text":"

        \u5efa\u7acb\u94fe\u8868\u5206\u4e3a\u4e24\u6b65\uff0c\u7b2c\u4e00\u6b65\u662f\u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\u5bf9\u8c61\uff0c\u7b2c\u4e8c\u6b65\u662f\u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\u5173\u7cfb\u3002\u521d\u59cb\u5316\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4ece\u94fe\u8868\u7684\u5934\u8282\u70b9\u51fa\u53d1\uff0c\u901a\u8fc7\u5f15\u7528\u6307\u5411 next \u4f9d\u6b21\u8bbf\u95ee\u6240\u6709\u8282\u70b9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        # \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4\n# \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nn0 = ListNode(1)\nn1 = ListNode(3)\nn2 = ListNode(2)\nn3 = ListNode(5)\nn4 = ListNode(4)\n# \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1\nn1.next = n2\nn2.next = n3\nn3.next = n4\n
        linked_list.cpp
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode* n0 = new ListNode(1);\nListNode* n1 = new ListNode(3);\nListNode* n2 = new ListNode(2);\nListNode* n3 = new ListNode(5);\nListNode* n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0->next = n1;\nn1->next = n2;\nn2->next = n3;\nn3->next = n4;\n
        linked_list.java
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = new ListNode(1);\nListNode n1 = new ListNode(3);\nListNode n2 = new ListNode(2);\nListNode n3 = new ListNode(5);\nListNode n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.cs
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = new(1);\nListNode n1 = new(3);\nListNode n2 = new(2);\nListNode n3 = new(5);\nListNode n4 = new(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.go
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nn0 := NewListNode(1)\nn1 := NewListNode(3)\nn2 := NewListNode(2)\nn3 := NewListNode(5)\nn4 := NewListNode(4)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.Next = n1\nn1.Next = n2\nn2.Next = n3\nn3.Next = n4\n
        linked_list.swift
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nlet n0 = ListNode(x: 1)\nlet n1 = ListNode(x: 3)\nlet n2 = ListNode(x: 2)\nlet n3 = ListNode(x: 5)\nlet n4 = ListNode(x: 4)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1\nn1.next = n2\nn2.next = n3\nn3.next = n4\n
        linked_list.js
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nconst n0 = new ListNode(1);\nconst n1 = new ListNode(3);\nconst n2 = new ListNode(2);\nconst n3 = new ListNode(5);\nconst n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.ts
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nconst n0 = new ListNode(1);\nconst n1 = new ListNode(3);\nconst n2 = new ListNode(2);\nconst n3 = new ListNode(5);\nconst n4 = new ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.dart
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\\\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode n0 = ListNode(1);\nListNode n1 = ListNode(3);\nListNode n2 = ListNode(2);\nListNode n3 = ListNode(5);\nListNode n4 = ListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = n1;\nn1.next = n2;\nn2.next = n3;\nn3.next = n4;\n
        linked_list.rs
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nlet n0 = Rc::new(RefCell::new(ListNode { val: 1, next: None }));\nlet n1 = Rc::new(RefCell::new(ListNode { val: 3, next: None }));\nlet n2 = Rc::new(RefCell::new(ListNode { val: 2, next: None }));\nlet n3 = Rc::new(RefCell::new(ListNode { val: 5, next: None }));\nlet n4 = Rc::new(RefCell::new(ListNode { val: 4, next: None }));\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.borrow_mut().next = Some(n1.clone());\nn1.borrow_mut().next = Some(n2.clone());\nn2.borrow_mut().next = Some(n3.clone());\nn3.borrow_mut().next = Some(n4.clone());\n
        linked_list.c
        /* \u521d\u59cb\u5316\u94fe\u8868 1 -> 3 -> 2 -> 5 -> 4 */\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nListNode* n0 = newListNode(1);\nListNode* n1 = newListNode(3);\nListNode* n2 = newListNode(2);\nListNode* n3 = newListNode(5);\nListNode* n4 = newListNode(4);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0->next = n1;\nn1->next = n2;\nn2->next = n3;\nn3->next = n4;\n
        linked_list.zig
        // \u521d\u59cb\u5316\u94fe\u8868\n// \u521d\u59cb\u5316\u5404\u4e2a\u8282\u70b9\nvar n0 = inc.ListNode(i32){.val = 1};\nvar n1 = inc.ListNode(i32){.val = 3};\nvar n2 = inc.ListNode(i32){.val = 2};\nvar n3 = inc.ListNode(i32){.val = 5};\nvar n4 = inc.ListNode(i32){.val = 4};\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\nn0.next = &n1;\nn1.next = &n2;\nn2.next = &n3;\nn3.next = &n4;\n

        \u6570\u7ec4\u6574\u4f53\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u6bd4\u5982\u6570\u7ec4 nums \u5305\u542b\u5143\u7d20 nums[0] \u548c nums[1] \u7b49\uff0c\u800c\u94fe\u8868\u662f\u7531\u591a\u4e2a\u72ec\u7acb\u7684\u8282\u70b9\u5bf9\u8c61\u7ec4\u6210\u7684\u3002\u6211\u4eec\u901a\u5e38\u5c06\u5934\u8282\u70b9\u5f53\u4f5c\u94fe\u8868\u7684\u4ee3\u79f0\uff0c\u6bd4\u5982\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u7684\u94fe\u8868\u53ef\u8bb0\u4f5c\u94fe\u8868 n0 \u3002

        "},{"location":"chapter_array_and_linkedlist/linked_list/#2","title":"2. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        \u5728\u94fe\u8868\u4e2d\u63d2\u5165\u8282\u70b9\u975e\u5e38\u5bb9\u6613\u3002\u5982\u56fe 4-6 \u6240\u793a\uff0c\u5047\u8bbe\u6211\u4eec\u60f3\u5728\u76f8\u90bb\u7684\u4e24\u4e2a\u8282\u70b9 n0 \u548c n1 \u4e4b\u95f4\u63d2\u5165\u4e00\u4e2a\u65b0\u8282\u70b9 P \uff0c\u5219\u53ea\u9700\u6539\u53d8\u4e24\u4e2a\u8282\u70b9\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        \u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5728\u6570\u7ec4\u4e2d\u63d2\u5165\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5728\u5927\u6570\u636e\u91cf\u4e0b\u7684\u6548\u7387\u8f83\u4f4e\u3002

        \u56fe 4-6 \u00a0 \u94fe\u8868\u63d2\u5165\u8282\u70b9\u793a\u4f8b

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def insert(n0: ListNode, P: ListNode):\n\"\"\"\u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P\"\"\"\nn1 = n0.next\nP.next = n1\nn0.next = P\n
        linked_list.cpp
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode *n0, ListNode *P) {\nListNode *n1 = n0->next;\nP->next = n1;\nn0->next = P;\n}\n
        linked_list.java
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode n0, ListNode P) {\nListNode n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.cs
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid Insert(ListNode n0, ListNode P) {\nListNode? n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.go
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunc insertNode(n0 *ListNode, P *ListNode) {\nn1 := n0.Next\nP.Next = n1\nn0.Next = P\n}\n
        linked_list.swift
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunc insert(n0: ListNode, P: ListNode) {\nlet n1 = n0.next\nP.next = n1\nn0.next = P\n}\n
        linked_list.js
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunction insert(n0, P) {\nconst n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.ts
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nfunction insert(n0: ListNode, P: ListNode): void {\nconst n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.dart
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode n0, ListNode P) {\nListNode? n1 = n0.next;\nP.next = n1;\nn0.next = P;\n}\n
        linked_list.rs
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\n#[allow(non_snake_case)]\npub fn insert<T>(n0: &Rc<RefCell<ListNode<T>>>, P: Rc<RefCell<ListNode<T>>>) {\nlet n1 =  n0.borrow_mut().next.take();\nP.borrow_mut().next = n1;\nn0.borrow_mut().next = Some(P);\n}\n
        linked_list.c
        /* \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P */\nvoid insert(ListNode *n0, ListNode *P) {\nListNode *n1 = n0->next;\nP->next = n1;\nn0->next = P;\n}\n
        linked_list.zig
        // \u5728\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u63d2\u5165\u8282\u70b9 P\nfn insert(n0: ?*inc.ListNode(i32), P: ?*inc.ListNode(i32)) void {\nvar n1 = n0.?.next;\nP.?.next = n1;\nn0.?.next = P;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#3","title":"3. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u5982\u56fe 4-7 \u6240\u793a\uff0c\u5728\u94fe\u8868\u4e2d\u5220\u9664\u8282\u70b9\u4e5f\u975e\u5e38\u65b9\u4fbf\uff0c\u53ea\u9700\u6539\u53d8\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\u3002

        \u8bf7\u6ce8\u610f\uff0c\u5c3d\u7ba1\u5728\u5220\u9664\u64cd\u4f5c\u5b8c\u6210\u540e\u8282\u70b9 P \u4ecd\u7136\u6307\u5411 n1 \uff0c\u4f46\u5b9e\u9645\u4e0a\u904d\u5386\u6b64\u94fe\u8868\u5df2\u7ecf\u65e0\u6cd5\u8bbf\u95ee\u5230 P \uff0c\u8fd9\u610f\u5473\u7740 P \u5df2\u7ecf\u4e0d\u518d\u5c5e\u4e8e\u8be5\u94fe\u8868\u4e86\u3002

        \u56fe 4-7 \u00a0 \u94fe\u8868\u5220\u9664\u8282\u70b9

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def remove(n0: ListNode):\n\"\"\"\u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9\"\"\"\nif not n0.next:\nreturn\n# n0 -> P -> n1\nP = n0.next\nn1 = P.next\nn0.next = n1\n
        linked_list.cpp
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode *n0) {\nif (n0->next == nullptr)\nreturn;\n// n0 -> P -> n1\nListNode *P = n0->next;\nListNode *n1 = P->next;\nn0->next = n1;\n// \u91ca\u653e\u5185\u5b58\ndelete P;\n}\n
        linked_list.java
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode n0) {\nif (n0.next == null)\nreturn;\n// n0 -> P -> n1\nListNode P = n0.next;\nListNode n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.cs
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid Remove(ListNode n0) {\nif (n0.next == null)\nreturn;\n// n0 -> P -> n1\nListNode P = n0.next;\nListNode? n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.go
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunc removeItem(n0 *ListNode) {\nif n0.Next == nil {\nreturn\n}\n// n0 -> P -> n1\nP := n0.Next\nn1 := P.Next\nn0.Next = n1\n}\n
        linked_list.swift
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunc remove(n0: ListNode) {\nif n0.next == nil {\nreturn\n}\n// n0 -> P -> n1\nlet P = n0.next\nlet n1 = P?.next\nn0.next = n1\nP?.next = nil\n}\n
        linked_list.js
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunction remove(n0) {\nif (!n0.next) return;\n// n0 -> P -> n1\nconst P = n0.next;\nconst n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.ts
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nfunction remove(n0: ListNode): void {\nif (!n0.next) {\nreturn;\n}\n// n0 -> P -> n1\nconst P = n0.next;\nconst n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.dart
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\nvoid remove(ListNode n0) {\nif (n0.next == null) return;\n// n0 -> P -> n1\nListNode P = n0.next!;\nListNode? n1 = P.next;\nn0.next = n1;\n}\n
        linked_list.rs
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\n#[allow(non_snake_case)]\npub fn remove<T>(n0: &Rc<RefCell<ListNode<T>>>) {\nif n0.borrow().next.is_none() {return};\n// n0 -> P -> n1\nlet P = n0.borrow_mut().next.take();\nif let Some(node) = P {\nlet n1 = node.borrow_mut().next.take();\nn0.borrow_mut().next = n1;\n}\n}\n
        linked_list.c
        /* \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nvoid removeItem(ListNode *n0) {\nif (!n0->next)\nreturn;\n// n0 -> P -> n1\nListNode *P = n0->next;\nListNode *n1 = P->next;\nn0->next = n1;\n// \u91ca\u653e\u5185\u5b58\nfree(P);\n}\n
        linked_list.zig
        // \u5220\u9664\u94fe\u8868\u7684\u8282\u70b9 n0 \u4e4b\u540e\u7684\u9996\u4e2a\u8282\u70b9\nfn remove(n0: ?*inc.ListNode(i32)) void {\nif (n0.?.next == null) return;\n// n0 -> P -> n1\nvar P = n0.?.next;\nvar n1 = P.?.next;\nn0.?.next = n1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#4","title":"4. \u00a0 \u8bbf\u95ee\u8282\u70b9","text":"

        \u5728\u94fe\u8868\u4e2d\u8bbf\u95ee\u8282\u70b9\u7684\u6548\u7387\u8f83\u4f4e\u3002\u5982\u4e0a\u4e00\u8282\u6240\u8ff0\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u4e0b\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u5143\u7d20\u3002\u94fe\u8868\u5219\u4e0d\u7136\uff0c\u7a0b\u5e8f\u9700\u8981\u4ece\u5934\u8282\u70b9\u51fa\u53d1\uff0c\u9010\u4e2a\u5411\u540e\u904d\u5386\uff0c\u76f4\u81f3\u627e\u5230\u76ee\u6807\u8282\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8bbf\u95ee\u94fe\u8868\u7684\u7b2c \\(i\\) \u4e2a\u8282\u70b9\u9700\u8981\u5faa\u73af \\(i - 1\\) \u8f6e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def access(head: ListNode, index: int) -> ListNode | None:\n\"\"\"\u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9\"\"\"\nfor _ in range(index):\nif not head:\nreturn None\nhead = head.next\nreturn head\n
        linked_list.cpp
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == nullptr)\nreturn nullptr;\nhead = head->next;\n}\nreturn head;\n}\n
        linked_list.java
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode access(ListNode head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == null)\nreturn null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.cs
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? Access(ListNode? head, int index) {\nfor (int i = 0; i < index; i++) {\nif (head == null)\nreturn null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.go
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunc access(head *ListNode, index int) *ListNode {\nfor i := 0; i < index; i++ {\nif head == nil {\nreturn nil\n}\nhead = head.Next\n}\nreturn head\n}\n
        linked_list.swift
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunc access(head: ListNode, index: Int) -> ListNode? {\nvar head: ListNode? = head\nfor _ in 0 ..< index {\nif head == nil {\nreturn nil\n}\nhead = head?.next\n}\nreturn head\n}\n
        linked_list.js
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head, index) {\nfor (let i = 0; i < index; i++) {\nif (!head) {\nreturn null;\n}\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.ts
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head: ListNode | null, index: number): ListNode | null {\nfor (let i = 0; i < index; i++) {\nif (!head) {\nreturn null;\n}\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.dart
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? access(ListNode? head, int index) {\nfor (var i = 0; i < index; i++) {\nif (head == null) return null;\nhead = head.next;\n}\nreturn head;\n}\n
        linked_list.rs
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\npub fn access<T>(head: Rc<RefCell<ListNode<T>>>, index: i32) -> Rc<RefCell<ListNode<T>>> {\nif index <= 0 {return head};\nif let Some(node) = &head.borrow_mut().next {\nreturn access(node.clone(), index - 1);\n}\nreturn head;\n}\n
        linked_list.c
        /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\nwhile (head && head->next && index) {\nhead = head->next;\nindex--;\n}\nreturn head;\n}\n
        linked_list.zig
        // \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9\nfn access(node: ?*inc.ListNode(i32), index: i32) ?*inc.ListNode(i32) {\nvar head = node;\nvar i: i32 = 0;\nwhile (i < index) : (i += 1) {\nhead = head.?.next;\nif (head == null) return null;\n}\nreturn head;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#5","title":"5. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        \u904d\u5386\u94fe\u8868\uff0c\u67e5\u627e\u5176\u4e2d\u503c\u4e3a target \u7684\u8282\u70b9\uff0c\u8f93\u51fa\u8be5\u8282\u70b9\u5728\u94fe\u8868\u4e2d\u7684\u7d22\u5f15\u3002\u6b64\u8fc7\u7a0b\u4e5f\u5c5e\u4e8e\u7ebf\u6027\u67e5\u627e\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linked_list.py
        def find(head: ListNode, target: int) -> int:\n\"\"\"\u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9\"\"\"\nindex = 0\nwhile head:\nif head.val == target:\nreturn index\nhead = head.next\nindex += 1\nreturn -1\n
        linked_list.cpp
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode *head, int target) {\nint index = 0;\nwhile (head != nullptr) {\nif (head->val == target)\nreturn index;\nhead = head->next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.java
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target)\nreturn index;\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.cs
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint Find(ListNode? head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target)\nreturn index;\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.go
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunc findNode(head *ListNode, target int) int {\nindex := 0\nfor head != nil {\nif head.Val == target {\nreturn index\n}\nhead = head.Next\nindex++\n}\nreturn -1\n}\n
        linked_list.swift
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunc find(head: ListNode, target: Int) -> Int {\nvar head: ListNode? = head\nvar index = 0\nwhile head != nil {\nif head?.val == target {\nreturn index\n}\nhead = head?.next\nindex += 1\n}\nreturn -1\n}\n
        linked_list.js
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head, target) {\nlet index = 0;\nwhile (head !== null) {\nif (head.val === target) {\nreturn index;\n}\nhead = head.next;\nindex += 1;\n}\nreturn -1;\n}\n
        linked_list.ts
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head: ListNode | null, target: number): number {\nlet index = 0;\nwhile (head !== null) {\nif (head.val === target) {\nreturn index;\n}\nhead = head.next;\nindex += 1;\n}\nreturn -1;\n}\n
        linked_list.dart
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode? head, int target) {\nint index = 0;\nwhile (head != null) {\nif (head.val == target) {\nreturn index;\n}\nhead = head.next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.rs
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\npub fn find<T: PartialEq>(head: Rc<RefCell<ListNode<T>>>, target: T, index: i32) -> i32 {\nif head.borrow().val == target {return index};\nif let Some(node) = &head.borrow_mut().next {\nreturn find(node.clone(), target, index + 1);\n}\nreturn -1;\n}\n
        linked_list.c
        /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nint find(ListNode *head, int target) {\nint index = 0;\nwhile (head) {\nif (head->val == target)\nreturn index;\nhead = head->next;\nindex++;\n}\nreturn -1;\n}\n
        linked_list.zig
        // \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9\nfn find(node: ?*inc.ListNode(i32), target: i32) i32 {\nvar head = node;\nvar index: i32 = 0;\nwhile (head != null) {\nif (head.?.val == target) return index;\nhead = head.?.next;\nindex += 1;\n}\nreturn -1;\n}\n
        "},{"location":"chapter_array_and_linkedlist/linked_list/#422-vs","title":"4.2.2 \u00a0 \u6570\u7ec4 vs. \u94fe\u8868","text":"

        \u8868 4-1 \u603b\u7ed3\u4e86\u6570\u7ec4\u548c\u94fe\u8868\u7684\u5404\u9879\u7279\u70b9\u5e76\u5bf9\u6bd4\u4e86\u64cd\u4f5c\u6548\u7387\u3002\u7531\u4e8e\u5b83\u4eec\u91c7\u7528\u4e24\u79cd\u76f8\u53cd\u7684\u5b58\u50a8\u7b56\u7565\uff0c\u56e0\u6b64\u5404\u79cd\u6027\u8d28\u548c\u64cd\u4f5c\u6548\u7387\u4e5f\u5448\u73b0\u5bf9\u7acb\u7684\u7279\u70b9\u3002

        \u8868 4-1 \u00a0 \u6570\u7ec4\u4e0e\u94fe\u8868\u7684\u6548\u7387\u5bf9\u6bd4

        \u6570\u7ec4 \u94fe\u8868 \u5b58\u50a8\u65b9\u5f0f \u8fde\u7eed\u5185\u5b58\u7a7a\u95f4 \u5206\u6563\u5185\u5b58\u7a7a\u95f4 \u5bb9\u91cf\u6269\u5c55 \u957f\u5ea6\u4e0d\u53ef\u53d8 \u53ef\u7075\u6d3b\u6269\u5c55 \u5185\u5b58\u6548\u7387 \u5143\u7d20\u5360\u7528\u5185\u5b58\u5c11\u3001\u4f46\u53ef\u80fd\u6d6a\u8d39\u7a7a\u95f4 \u5143\u7d20\u5360\u7528\u5185\u5b58\u591a \u8bbf\u95ee\u5143\u7d20 \\(O(1)\\) \\(O(n)\\) \u6dfb\u52a0\u5143\u7d20 \\(O(n)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(1)\\)"},{"location":"chapter_array_and_linkedlist/linked_list/#423","title":"4.2.3 \u00a0 \u5e38\u89c1\u94fe\u8868\u7c7b\u578b","text":"

        \u5982\u56fe 4-8 \u6240\u793a\uff0c\u5e38\u89c1\u7684\u94fe\u8868\u7c7b\u578b\u5305\u62ec\u4e09\u79cd\u3002

        • \u5355\u5411\u94fe\u8868\uff1a\u5373\u524d\u9762\u4ecb\u7ecd\u7684\u666e\u901a\u94fe\u8868\u3002\u5355\u5411\u94fe\u8868\u7684\u8282\u70b9\u5305\u542b\u503c\u548c\u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\u4e24\u9879\u6570\u636e\u3002\u6211\u4eec\u5c06\u9996\u4e2a\u8282\u70b9\u79f0\u4e3a\u5934\u8282\u70b9\uff0c\u5c06\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u79f0\u4e3a\u5c3e\u8282\u70b9\uff0c\u5c3e\u8282\u70b9\u6307\u5411\u7a7a \\(\\text{None}\\) \u3002
        • \u73af\u5f62\u94fe\u8868\uff1a\u5982\u679c\u6211\u4eec\u4ee4\u5355\u5411\u94fe\u8868\u7684\u5c3e\u8282\u70b9\u6307\u5411\u5934\u8282\u70b9\uff08\u9996\u5c3e\u76f8\u63a5\uff09\uff0c\u5219\u5f97\u5230\u4e00\u4e2a\u73af\u5f62\u94fe\u8868\u3002\u5728\u73af\u5f62\u94fe\u8868\u4e2d\uff0c\u4efb\u610f\u8282\u70b9\u90fd\u53ef\u4ee5\u89c6\u4f5c\u5934\u8282\u70b9\u3002
        • \u53cc\u5411\u94fe\u8868\uff1a\u4e0e\u5355\u5411\u94fe\u8868\u76f8\u6bd4\uff0c\u53cc\u5411\u94fe\u8868\u8bb0\u5f55\u4e86\u4e24\u4e2a\u65b9\u5411\u7684\u5f15\u7528\u3002\u53cc\u5411\u94fe\u8868\u7684\u8282\u70b9\u5b9a\u4e49\u540c\u65f6\u5305\u542b\u6307\u5411\u540e\u7ee7\u8282\u70b9\uff08\u4e0b\u4e00\u4e2a\u8282\u70b9\uff09\u548c\u524d\u9a71\u8282\u70b9\uff08\u4e0a\u4e00\u4e2a\u8282\u70b9\uff09\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\u3002\u76f8\u8f83\u4e8e\u5355\u5411\u94fe\u8868\uff0c\u53cc\u5411\u94fe\u8868\u66f4\u5177\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u671d\u4e24\u4e2a\u65b9\u5411\u904d\u5386\u94fe\u8868\uff0c\u4f46\u76f8\u5e94\u5730\u4e5f\u9700\u8981\u5360\u7528\u66f4\u591a\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class ListNode:\n\"\"\"\u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                # \u8282\u70b9\u503c\nself.next: ListNode | None = None  # \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nself.prev: ListNode | None = None  # \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\nint val;         // \u8282\u70b9\u503c\nListNode *next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nListNode *prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\nListNode(int x) : val(x), next(nullptr), prev(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\nListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  // \u6784\u9020\u51fd\u6570\nint val = x;    // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype DoublyListNode struct {\nVal  int             // \u8282\u70b9\u503c\nNext *DoublyListNode // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nPrev *DoublyListNode // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n// NewDoublyListNode \u521d\u59cb\u5316\nfunc NewDoublyListNode(val int) *DoublyListNode {\nreturn &DoublyListNode{\nVal:  val,\nNext: nil,\nPrev: nil,\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nvar prev: ListNode? // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\ninit(x: Int) { // \u6784\u9020\u51fd\u6570\nval = x\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nconstructor(val, next, prev) {\nthis.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nthis.prev = prev  ===  undefined ? null : prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nval: number;\nnext: ListNode | null;\nprev: ListNode | null;\nconstructor(val?: number, next?: ListNode | null, prev?: ListNode | null) {\nthis.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\nthis.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nthis.prev = prev  ===  undefined ? null : prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\nint val;        // \u8282\u70b9\u503c\nListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\nListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\nListNode(this.val, [this.next, this.prev]);  // \u6784\u9020\u51fd\u6570\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\u578b */\n#[derive(Debug)]\nstruct ListNode {\nval: i32, // \u8282\u70b9\u503c\nnext: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nprev: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n/* \u6784\u9020\u51fd\u6570 */\nimpl ListNode {\nfn new(val: i32) -> Self {\nListNode {\nval,\nnext: None,\nprev: None,\n}\n}\n}\n
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\nint val;               // \u8282\u70b9\u503c\nstruct ListNode *next; // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nstruct ListNode *prev; // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\nListNode *node;\nnode = (ListNode *) malloc(sizeof(ListNode));\nnode->val = val;\nnode->next = NULL;\nnode->prev = NULL;\nreturn node;\n}\n
        // \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = 0, // \u8282\u70b9\u503c\nnext: ?*Self = null, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\nprev: ?*Self = null, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\nself.prev = null;\n}\n};\n}\n

        \u56fe 4-8 \u00a0 \u5e38\u89c1\u94fe\u8868\u79cd\u7c7b

        "},{"location":"chapter_array_and_linkedlist/linked_list/#424","title":"4.2.4 \u00a0 \u94fe\u8868\u5178\u578b\u5e94\u7528","text":"

        \u5355\u5411\u94fe\u8868\u901a\u5e38\u7528\u4e8e\u5b9e\u73b0\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u548c\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u3002

        • \u6808\u4e0e\u961f\u5217\uff1a\u5f53\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u90fd\u5728\u94fe\u8868\u7684\u4e00\u7aef\u8fdb\u884c\u65f6\uff0c\u5b83\u8868\u73b0\u51fa\u5148\u8fdb\u540e\u51fa\u7684\u7279\u6027\uff0c\u5bf9\u5e94\u6808\uff1b\u5f53\u63d2\u5165\u64cd\u4f5c\u5728\u94fe\u8868\u7684\u4e00\u7aef\u8fdb\u884c\uff0c\u5220\u9664\u64cd\u4f5c\u5728\u94fe\u8868\u7684\u53e6\u4e00\u7aef\u8fdb\u884c\uff0c\u5b83\u8868\u73b0\u51fa\u5148\u8fdb\u5148\u51fa\u7684\u7279\u6027\uff0c\u5bf9\u5e94\u961f\u5217\u3002
        • \u54c8\u5e0c\u8868\uff1a\u94fe\u5f0f\u5730\u5740\u662f\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81\u7684\u4e3b\u6d41\u65b9\u6848\u4e4b\u4e00\uff0c\u5728\u8be5\u65b9\u6848\u4e2d\uff0c\u6240\u6709\u51b2\u7a81\u7684\u5143\u7d20\u90fd\u4f1a\u88ab\u653e\u5230\u4e00\u4e2a\u94fe\u8868\u4e2d\u3002
        • \u56fe\uff1a\u90bb\u63a5\u8868\u662f\u8868\u793a\u56fe\u7684\u4e00\u79cd\u5e38\u7528\u65b9\u5f0f\uff0c\u5176\u4e2d\u56fe\u7684\u6bcf\u4e2a\u9876\u70b9\u90fd\u4e0e\u4e00\u4e2a\u94fe\u8868\u76f8\u5173\u8054\uff0c\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u4ee3\u8868\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u5176\u4ed6\u9876\u70b9\u3002

        \u53cc\u5411\u94fe\u8868\u5e38\u7528\u4e8e\u9700\u8981\u5feb\u901f\u67e5\u627e\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u573a\u666f\u3002

        • \u9ad8\u7ea7\u6570\u636e\u7ed3\u6784\uff1a\u6bd4\u5982\u5728\u7ea2\u9ed1\u6811\u3001B \u6811\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u8bbf\u95ee\u8282\u70b9\u7684\u7236\u8282\u70b9\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728\u8282\u70b9\u4e2d\u4fdd\u5b58\u4e00\u4e2a\u6307\u5411\u7236\u8282\u70b9\u7684\u5f15\u7528\u6765\u5b9e\u73b0\uff0c\u7c7b\u4f3c\u4e8e\u53cc\u5411\u94fe\u8868\u3002
        • \u6d4f\u89c8\u5668\u5386\u53f2\uff1a\u5728\u7f51\u9875\u6d4f\u89c8\u5668\u4e2d\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u524d\u8fdb\u6216\u540e\u9000\u6309\u94ae\u65f6\uff0c\u6d4f\u89c8\u5668\u9700\u8981\u77e5\u9053\u7528\u6237\u8bbf\u95ee\u8fc7\u7684\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u7f51\u9875\u3002\u53cc\u5411\u94fe\u8868\u7684\u7279\u6027\u4f7f\u5f97\u8fd9\u79cd\u64cd\u4f5c\u53d8\u5f97\u7b80\u5355\u3002
        • LRU \u7b97\u6cd5\uff1a\u5728\u7f13\u5b58\u6dd8\u6c70\uff08LRU\uff09\u7b97\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5feb\u901f\u627e\u5230\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7684\u6570\u636e\uff0c\u4ee5\u53ca\u652f\u6301\u5feb\u901f\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u3002\u8fd9\u65f6\u5019\u4f7f\u7528\u53cc\u5411\u94fe\u8868\u5c31\u975e\u5e38\u5408\u9002\u3002

        \u73af\u5f62\u94fe\u8868\u5e38\u7528\u4e8e\u9700\u8981\u5468\u671f\u6027\u64cd\u4f5c\u7684\u573a\u666f\uff0c\u6bd4\u5982\u64cd\u4f5c\u7cfb\u7edf\u7684\u8d44\u6e90\u8c03\u5ea6\u3002

        • \u65f6\u95f4\u7247\u8f6e\u8f6c\u8c03\u5ea6\u7b97\u6cd5\uff1a\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u65f6\u95f4\u7247\u8f6e\u8f6c\u8c03\u5ea6\u7b97\u6cd5\u662f\u4e00\u79cd\u5e38\u89c1\u7684 CPU \u8c03\u5ea6\u7b97\u6cd5\uff0c\u5b83\u9700\u8981\u5bf9\u4e00\u7ec4\u8fdb\u7a0b\u8fdb\u884c\u5faa\u73af\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u88ab\u8d4b\u4e88\u4e00\u4e2a\u65f6\u95f4\u7247\uff0c\u5f53\u65f6\u95f4\u7247\u7528\u5b8c\u65f6\uff0cCPU \u5c06\u5207\u6362\u5230\u4e0b\u4e00\u4e2a\u8fdb\u7a0b\u3002\u8fd9\u79cd\u5faa\u73af\u64cd\u4f5c\u53ef\u4ee5\u901a\u8fc7\u73af\u5f62\u94fe\u8868\u6765\u5b9e\u73b0\u3002
        • \u6570\u636e\u7f13\u51b2\u533a\uff1a\u5728\u67d0\u4e9b\u6570\u636e\u7f13\u51b2\u533a\u7684\u5b9e\u73b0\u4e2d\uff0c\u4e5f\u53ef\u80fd\u4f1a\u4f7f\u7528\u73af\u5f62\u94fe\u8868\u3002\u6bd4\u5982\u5728\u97f3\u9891\u3001\u89c6\u9891\u64ad\u653e\u5668\u4e2d\uff0c\u6570\u636e\u6d41\u53ef\u80fd\u4f1a\u88ab\u5206\u6210\u591a\u4e2a\u7f13\u51b2\u5757\u5e76\u653e\u5165\u4e00\u4e2a\u73af\u5f62\u94fe\u8868\uff0c\u4ee5\u4fbf\u5b9e\u73b0\u65e0\u7f1d\u64ad\u653e\u3002
        "},{"location":"chapter_array_and_linkedlist/list/","title":"4.3 \u00a0 \u5217\u8868","text":"

        \u300c\u5217\u8868 list\u300d\u662f\u4e00\u4e2a\u62bd\u8c61\u7684\u6570\u636e\u7ed3\u6784\u6982\u5ff5\uff0c\u5b83\u8868\u793a\u5143\u7d20\u7684\u6709\u5e8f\u96c6\u5408\uff0c\u652f\u6301\u5143\u7d20\u8bbf\u95ee\u3001\u4fee\u6539\u3001\u6dfb\u52a0\u3001\u5220\u9664\u548c\u904d\u5386\u7b49\u64cd\u4f5c\uff0c\u65e0\u987b\u4f7f\u7528\u8005\u8003\u8651\u5bb9\u91cf\u9650\u5236\u7684\u95ee\u9898\u3002\u5217\u8868\u53ef\u4ee5\u57fa\u4e8e\u94fe\u8868\u6216\u6570\u7ec4\u5b9e\u73b0\u3002

        • \u94fe\u8868\u5929\u7136\u53ef\u4ee5\u88ab\u770b\u4f5c\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u652f\u6301\u5143\u7d20\u589e\u5220\u67e5\u6539\u64cd\u4f5c\uff0c\u5e76\u4e14\u53ef\u4ee5\u7075\u6d3b\u52a8\u6001\u6269\u5bb9\u3002
        • \u6570\u7ec4\u4e5f\u652f\u6301\u5143\u7d20\u589e\u5220\u67e5\u6539\uff0c\u4f46\u7531\u4e8e\u5176\u957f\u5ea6\u4e0d\u53ef\u53d8\uff0c\u56e0\u6b64\u53ea\u80fd\u88ab\u770b\u4f5c\u4e00\u4e2a\u5177\u6709\u957f\u5ea6\u9650\u5236\u7684\u5217\u8868\u3002

        \u5f53\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u5217\u8868\u65f6\uff0c\u957f\u5ea6\u4e0d\u53ef\u53d8\u7684\u6027\u8d28\u4f1a\u5bfc\u81f4\u5217\u8868\u7684\u5b9e\u7528\u6027\u964d\u4f4e\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u901a\u5e38\u65e0\u6cd5\u4e8b\u5148\u786e\u5b9a\u9700\u8981\u5b58\u50a8\u591a\u5c11\u6570\u636e\uff0c\u4ece\u800c\u96be\u4ee5\u9009\u62e9\u5408\u9002\u7684\u5217\u8868\u957f\u5ea6\u3002\u82e5\u957f\u5ea6\u8fc7\u5c0f\uff0c\u5219\u5f88\u53ef\u80fd\u65e0\u6cd5\u6ee1\u8db3\u4f7f\u7528\u9700\u6c42\uff1b\u82e5\u957f\u5ea6\u8fc7\u5927\uff0c\u5219\u4f1a\u9020\u6210\u5185\u5b58\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002

        \u4e3a\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u300c\u52a8\u6001\u6570\u7ec4 dynamic array\u300d\u6765\u5b9e\u73b0\u5217\u8868\u3002\u5b83\u7ee7\u627f\u4e86\u6570\u7ec4\u7684\u5404\u9879\u4f18\u70b9\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u52a8\u6001\u6269\u5bb9\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u6807\u51c6\u5e93\u63d0\u4f9b\u7684\u5217\u8868\u90fd\u662f\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\u5b9e\u73b0\u7684\uff0c\u4f8b\u5982 Python \u4e2d\u7684 list \u3001Java \u4e2d\u7684 ArrayList \u3001C++ \u4e2d\u7684 vector \u548c C# \u4e2d\u7684 List \u7b49\u3002\u5728\u63a5\u4e0b\u6765\u7684\u8ba8\u8bba\u4e2d\uff0c\u6211\u4eec\u5c06\u628a\u201c\u5217\u8868\u201d\u548c\u201c\u52a8\u6001\u6570\u7ec4\u201d\u89c6\u4e3a\u7b49\u540c\u7684\u6982\u5ff5\u3002

        "},{"location":"chapter_array_and_linkedlist/list/#431","title":"4.3.1 \u00a0 \u5217\u8868\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_array_and_linkedlist/list/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u5217\u8868","text":"

        \u6211\u4eec\u901a\u5e38\u4f7f\u7528\u201c\u65e0\u521d\u59cb\u503c\u201d\u548c\u201c\u6709\u521d\u59cb\u503c\u201d\u8fd9\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u521d\u59cb\u5316\u5217\u8868\n# \u65e0\u521d\u59cb\u503c\nnums1: list[int] = []\n# \u6709\u521d\u59cb\u503c\nnums: list[int] = [1, 3, 2, 5, 4]\n
        list.cpp
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u9700\u6ce8\u610f\uff0cC++ \u4e2d vector \u5373\u662f\u672c\u6587\u63cf\u8ff0\u7684 nums\n// \u65e0\u521d\u59cb\u503c\nvector<int> nums1;\n// \u6709\u521d\u59cb\u503c\nvector<int> nums = { 1, 3, 2, 5, 4 };\n
        list.java
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<Integer> nums1 = new ArrayList<>();\n// \u6709\u521d\u59cb\u503c\uff08\u6ce8\u610f\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u9700\u4e3a int[] \u7684\u5305\u88c5\u7c7b Integer[]\uff09\nInteger[] numbers = new Integer[] { 1, 3, 2, 5, 4 };\nList<Integer> nums = new ArrayList<>(Arrays.asList(numbers));\n
        list.cs
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<int> nums1 = [];\n// \u6709\u521d\u59cb\u503c\nint[] numbers = [1, 3, 2, 5, 4];\nList<int> nums = [.. numbers];\n
        list_test.go
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nnums1 := []int{}\n// \u6709\u521d\u59cb\u503c\nnums := []int{1, 3, 2, 5, 4}\n
        list.swift
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nlet nums1: [Int] = []\n// \u6709\u521d\u59cb\u503c\nvar nums = [1, 3, 2, 5, 4]\n
        list.js
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nconst nums1 = [];\n// \u6709\u521d\u59cb\u503c\nconst nums = [1, 3, 2, 5, 4];\n
        list.ts
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nconst nums1: number[] = [];\n// \u6709\u521d\u59cb\u503c\nconst nums: number[] = [1, 3, 2, 5, 4];\n
        list.dart
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nList<int> nums1 = [];\n// \u6709\u521d\u59cb\u503c\nList<int> nums = [1, 3, 2, 5, 4];\n
        list.rs
        /* \u521d\u59cb\u5316\u5217\u8868 */\n// \u65e0\u521d\u59cb\u503c\nlet nums1: Vec<i32> = Vec::new();\n// \u6709\u521d\u59cb\u503c\nlet nums: Vec<i32> = vec![1, 3, 2, 5, 4];\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u521d\u59cb\u5316\u5217\u8868\nvar nums = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nums.deinit();\ntry nums.appendSlice(&[_]i32{ 1, 3, 2, 5, 4 });\n
        "},{"location":"chapter_array_and_linkedlist/list/#2","title":"2. \u00a0 \u8bbf\u95ee\u5143\u7d20","text":"

        \u5217\u8868\u672c\u8d28\u4e0a\u662f\u6570\u7ec4\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u8bbf\u95ee\u548c\u66f4\u65b0\u5143\u7d20\uff0c\u6548\u7387\u5f88\u9ad8\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u8bbf\u95ee\u5143\u7d20\nnum: int = nums[1]  # \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n# \u66f4\u65b0\u5143\u7d20\nnums[1] = 0    # \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.cpp
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.java
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums.get(1);  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums.set(1, 0);  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.cs
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list_test.go
        /* \u8bbf\u95ee\u5143\u7d20 */\nnum := nums[1]  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0     // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.swift
        /* \u8bbf\u95ee\u5143\u7d20 */\nlet num = nums[1] // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0 // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.js
        /* \u8bbf\u95ee\u5143\u7d20 */\nconst num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.ts
        /* \u8bbf\u95ee\u5143\u7d20 */\nconst num: number = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.dart
        /* \u8bbf\u95ee\u5143\u7d20 */\nint num = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;  // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.rs
        /* \u8bbf\u95ee\u5143\u7d20 */\nlet num: i32 = nums[1];  // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n/* \u66f4\u65b0\u5143\u7d20 */\nnums[1] = 0;             // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u8bbf\u95ee\u5143\u7d20\nvar num = nums.items[1]; // \u8bbf\u95ee\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\n// \u66f4\u65b0\u5143\u7d20\nnums.items[1] = 0; // \u5c06\u7d22\u5f15 1 \u5904\u7684\u5143\u7d20\u66f4\u65b0\u4e3a 0  \n
        "},{"location":"chapter_array_and_linkedlist/list/#3","title":"3. \u00a0 \u63d2\u5165\u4e0e\u5220\u9664\u5143\u7d20","text":"

        \u76f8\u8f83\u4e8e\u6570\u7ec4\uff0c\u5217\u8868\u53ef\u4ee5\u81ea\u7531\u5730\u6dfb\u52a0\u4e0e\u5220\u9664\u5143\u7d20\u3002\u5728\u5217\u8868\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff0c\u4f46\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u7684\u6548\u7387\u4ecd\u4e0e\u6570\u7ec4\u76f8\u540c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u6e05\u7a7a\u5217\u8868\nnums.clear()\n# \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n# \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\nnums.insert(3, 6)  # \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n# \u5220\u9664\u5143\u7d20\nnums.pop(3)        # \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.cpp
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push_back(1);\nnums.push_back(3);\nnums.push_back(2);\nnums.push_back(5);\nnums.push_back(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(nums.begin() + 3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.erase(nums.begin() + 3);      // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.java
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.add(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(3);  // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.cs
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.Clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.Add(1);\nnums.Add(3);\nnums.Add(2);\nnums.Add(5);\nnums.Add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.Insert(3, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.RemoveAt(3);\n
        list_test.go
        /* \u6e05\u7a7a\u5217\u8868 */\nnums = nil\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums = append(nums, 1)\nnums = append(nums, 3)\nnums = append(nums, 2)\nnums = append(nums, 5)\nnums = append(nums, 4)\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums = append(nums[:3], append([]int{6}, nums[3:]...)...) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums = append(nums[:3], nums[4:]...) // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.swift
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.removeAll()\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(6, at: 3) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(at: 3) // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.js
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
        list.ts
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
        list.dart
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.removeAt(3); // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.rs
        /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n/* \u5220\u9664\u5143\u7d20 */\nnums.remove(3);    // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u6e05\u7a7a\u5217\u8868\nnums.clearRetainingCapacity();\n// \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\ntry nums.append(1);\ntry nums.append(3);\ntry nums.append(2);\ntry nums.append(5);\ntry nums.append(4);\n// \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\ntry nums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n// \u5220\u9664\u5143\u7d20\n_ = nums.orderedRemove(3); // \u5220\u9664\u7d22\u5f15 3 \u5904\u7684\u5143\u7d20\n
        "},{"location":"chapter_array_and_linkedlist/list/#4","title":"4. \u00a0 \u904d\u5386\u5217\u8868","text":"

        \u4e0e\u6570\u7ec4\u4e00\u6837\uff0c\u5217\u8868\u53ef\u4ee5\u6839\u636e\u7d22\u5f15\u904d\u5386\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u904d\u5386\u5404\u5143\u7d20\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\ncount = 0\nfor i in range(len(nums)):\ncount += nums[i]\n# \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\nfor num in nums:\ncount += num\n
        list.cpp
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (int num : nums) {\ncount += num;\n}\n
        list.java
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\ncount += nums.get(i);\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\nfor (int num : nums) {\ncount += num;\n}\n
        list.cs
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.Count; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nforeach (int num in nums) {\ncount += num;\n}\n
        list_test.go
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\ncount := 0\nfor i := 0; i < len(nums); i++ {\ncount += nums[i]\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor _, num := range nums {\ncount += num\n}\n
        list.swift
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nvar count = 0\nfor i in nums.indices {\ncount += nums[i]\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor num in nums {\ncount += num\n}\n
        list.js
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\ncount += num;\n}\n
        list.ts
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\ncount += num;\n}\n
        list.dart
        /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (var i = 0; i < nums.length; i++) {\ncount += nums[i];\n}\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (var num in nums) {\ncount += num;\n}\n
        list.rs
        // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\nlet mut _count = 0;\nfor i in 0..nums.len() {\n_count += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\n_count = 0;\nfor num in &nums {\n_count += num;\n}\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868\nvar count: i32 = 0;\nvar i: i32 = 0;\nwhile (i < nums.items.len) : (i += 1) {\ncount += nums[i];\n}\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\ncount = 0;\nfor (nums.items) |num| {\ncount += num;\n}\n
        "},{"location":"chapter_array_and_linkedlist/list/#5","title":"5. \u00a0 \u62fc\u63a5\u5217\u8868","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u65b0\u5217\u8868 nums1 \uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u62fc\u63a5\u5230\u539f\u5217\u8868\u7684\u5c3e\u90e8\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u62fc\u63a5\u4e24\u4e2a\u5217\u8868\nnums1: list[int] = [6, 8, 7, 10, 9]\nnums += nums1  # \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.cpp
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nvector<int> nums1 = { 6, 8, 7, 10, 9 };\n// \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\nnums.insert(nums.end(), nums1.begin(), nums1.end());\n
        list.java
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<Integer> nums1 = new ArrayList<>(Arrays.asList(new Integer[] { 6, 8, 7, 10, 9 }));\nnums.addAll(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.cs
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<int> nums1 = [6, 8, 7, 10, 9];\nnums.AddRange(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list_test.go
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nnums1 := []int{6, 8, 7, 10, 9}\nnums = append(nums, nums1...)  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.swift
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nlet nums1 = [6, 8, 7, 10, 9]\nnums.append(contentsOf: nums1) // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.js
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nconst nums1 = [6, 8, 7, 10, 9];\nnums.push(...nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.ts
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nconst nums1: number[] = [6, 8, 7, 10, 9];\nnums.push(...nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.dart
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nList<int> nums1 = [6, 8, 7, 10, 9];\nnums.addAll(nums1);  // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        list.rs
        /* \u62fc\u63a5\u4e24\u4e2a\u5217\u8868 */\nlet nums1: Vec<i32> = vec![6, 8, 7, 10, 9];\nnums.extend(nums1);\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u62fc\u63a5\u4e24\u4e2a\u5217\u8868\nvar nums1 = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nums1.deinit();\ntry nums1.appendSlice(&[_]i32{ 6, 8, 7, 10, 9 });\ntry nums.insertSlice(nums.items.len, nums1.items); // \u5c06\u5217\u8868 nums1 \u62fc\u63a5\u5230 nums \u4e4b\u540e\n
        "},{"location":"chapter_array_and_linkedlist/list/#6","title":"6. \u00a0 \u6392\u5e8f\u5217\u8868","text":"

        \u5b8c\u6210\u5217\u8868\u6392\u5e8f\u540e\uff0c\u6211\u4eec\u4fbf\u53ef\u4ee5\u4f7f\u7528\u5728\u6570\u7ec4\u7c7b\u7b97\u6cd5\u9898\u4e2d\u7ecf\u5e38\u8003\u67e5\u7684\u201c\u4e8c\u5206\u67e5\u627e\u201d\u548c\u201c\u53cc\u6307\u9488\u201d\u7b97\u6cd5\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig list.py
        # \u6392\u5e8f\u5217\u8868\nnums.sort()  # \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.cpp
        /* \u6392\u5e8f\u5217\u8868 */\nsort(nums.begin(), nums.end());  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.java
        /* \u6392\u5e8f\u5217\u8868 */\nCollections.sort(nums);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.cs
        /* \u6392\u5e8f\u5217\u8868 */\nnums.Sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list_test.go
        /* \u6392\u5e8f\u5217\u8868 */\nsort.Ints(nums)  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.swift
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort() // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.js
        /* \u6392\u5e8f\u5217\u8868 */  nums.sort((a, b) => a - b);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.ts
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort((a, b) => a - b);  // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.dart
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.rs
        /* \u6392\u5e8f\u5217\u8868 */\nnums.sort(); // \u6392\u5e8f\u540e\uff0c\u5217\u8868\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217\n
        list.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u52a8\u6001\u6570\u7ec4\n
        list.zig
        // \u6392\u5e8f\u5217\u8868\nstd.sort.sort(i32, nums.items, {}, comptime std.sort.asc(i32));\n
        "},{"location":"chapter_array_and_linkedlist/list/#432","title":"4.3.2 \u00a0 \u5217\u8868\u5b9e\u73b0","text":"

        \u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u4e86\u5217\u8868\uff0c\u4f8b\u5982 Java\u3001C++\u3001Python \u7b49\u3002\u5b83\u4eec\u7684\u5b9e\u73b0\u6bd4\u8f83\u590d\u6742\uff0c\u5404\u4e2a\u53c2\u6570\u7684\u8bbe\u5b9a\u4e5f\u975e\u5e38\u8003\u7a76\uff0c\u4f8b\u5982\u521d\u59cb\u5bb9\u91cf\u3001\u6269\u5bb9\u500d\u6570\u7b49\u3002\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u67e5\u9605\u6e90\u7801\u8fdb\u884c\u5b66\u4e60\u3002

        \u4e3a\u4e86\u52a0\u6df1\u5bf9\u5217\u8868\u5de5\u4f5c\u539f\u7406\u7684\u7406\u89e3\uff0c\u6211\u4eec\u5c1d\u8bd5\u5b9e\u73b0\u4e00\u4e2a\u7b80\u6613\u7248\u5217\u8868\uff0c\u5305\u62ec\u4ee5\u4e0b\u4e09\u4e2a\u91cd\u70b9\u8bbe\u8ba1\u3002

        • \u521d\u59cb\u5bb9\u91cf\uff1a\u9009\u53d6\u4e00\u4e2a\u5408\u7406\u7684\u6570\u7ec4\u521d\u59cb\u5bb9\u91cf\u3002\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9009\u62e9 10 \u4f5c\u4e3a\u521d\u59cb\u5bb9\u91cf\u3002
        • \u6570\u91cf\u8bb0\u5f55\uff1a\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf size \uff0c\u7528\u4e8e\u8bb0\u5f55\u5217\u8868\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff0c\u5e76\u968f\u7740\u5143\u7d20\u63d2\u5165\u548c\u5220\u9664\u5b9e\u65f6\u66f4\u65b0\u3002\u6839\u636e\u6b64\u53d8\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4f4d\u5217\u8868\u5c3e\u90e8\uff0c\u4ee5\u53ca\u5224\u65ad\u662f\u5426\u9700\u8981\u6269\u5bb9\u3002
        • \u6269\u5bb9\u673a\u5236\uff1a\u82e5\u63d2\u5165\u5143\u7d20\u65f6\u5217\u8868\u5bb9\u91cf\u5df2\u6ee1\uff0c\u5219\u9700\u8981\u8fdb\u884c\u6269\u5bb9\u3002\u5148\u6839\u636e\u6269\u5bb9\u500d\u6570\u521b\u5efa\u4e00\u4e2a\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u518d\u5c06\u5f53\u524d\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u4f9d\u6b21\u79fb\u52a8\u81f3\u65b0\u6570\u7ec4\u3002\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u89c4\u5b9a\u6bcf\u6b21\u5c06\u6570\u7ec4\u6269\u5bb9\u81f3\u4e4b\u524d\u7684 2 \u500d\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_list.py
        class MyList:\n\"\"\"\u5217\u8868\u7c7b\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._capacity: int = 10  # \u5217\u8868\u5bb9\u91cf\nself._arr: list[int] = [0] * self._capacity  # \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nself._size: int = 0  # \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nself._extend_ratio: int = 2  # \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\"\"\"\nreturn self._size\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u5217\u8868\u5bb9\u91cf\"\"\"\nreturn self._capacity\ndef get(self, index: int) -> int:\n\"\"\"\u8bbf\u95ee\u5143\u7d20\"\"\"\n# \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nreturn self._arr[index]\ndef set(self, num: int, index: int):\n\"\"\"\u66f4\u65b0\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nself._arr[index] = num\ndef add(self, num: int):\n\"\"\"\u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\"\"\"\n# \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size() == self.capacity():\nself.extend_capacity()\nself._arr[self._size] = num\nself._size += 1\ndef insert(self, num: int, index: int):\n\"\"\"\u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n# \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self._size == self.capacity():\nself.extend_capacity()\n# \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in range(self._size - 1, index - 1, -1):\nself._arr[j + 1] = self._arr[j]\nself._arr[index] = num\n# \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself._size += 1\ndef remove(self, index: int) -> int:\n\"\"\"\u5220\u9664\u5143\u7d20\"\"\"\nif index < 0 or index >= self._size:\nraise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\nnum = self._arr[index]\n# \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in range(index, self._size - 1):\nself._arr[j] = self._arr[j + 1]\n# \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself._size -= 1\n# \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\ndef extend_capacity(self):\n\"\"\"\u5217\u8868\u6269\u5bb9\"\"\"\n# \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 __extend_ratio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nself._arr = self._arr + [0] * self.capacity() * (self._extend_ratio - 1)\n# \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself._capacity = len(self._arr)\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868\"\"\"\nreturn self._arr[: self._size]\n
        my_list.cpp
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate:\nint *arr;             // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint arrCapacity = 10; // \u5217\u8868\u5bb9\u91cf\nint arrSize = 0;      // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nint extendRatio = 2;   // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nMyList() {\narr = new int[arrCapacity];\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~MyList() {\ndelete[] arr;\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nint size() {\nreturn arrSize;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity() {\nreturn arrCapacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(int index, int num) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size() == capacity())\nextendCapacity();\narr[size()] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(int index, int num) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size() == capacity())\nextendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = size() - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nint remove(int index) {\nif (index < 0 || index >= size())\nthrow out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < size() - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\nint newCapacity = capacity() * extendRatio;\nint *tmp = arr;\narr = new int[newCapacity];\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\narr[i] = tmp[i];\n}\n// \u91ca\u653e\u5185\u5b58\ndelete[] tmp;\narrCapacity = newCapacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Vector \u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> vec(size());\nfor (int i = 0; i < size(); i++) {\nvec[i] = arr[i];\n}\nreturn vec;\n}\n};\n
        my_list.java
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate int[] arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate int capacity = 10; // \u5217\u8868\u5bb9\u91cf\nprivate int size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate int extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\npublic MyList() {\narr = new int[capacity];\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\npublic int size() {\nreturn size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic int capacity() {\nreturn capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic int get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic void set(int index, int num) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic void add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size == capacity())\nextendCapacity();\narr[size] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic void insert(int index, int num) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size == capacity())\nextendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = size - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic int remove(int index) {\nif (index < 0 || index >= size)\nthrow new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < size - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nsize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic void extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\narr = Arrays.copyOf(arr, capacity() * extendRatio);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\ncapacity = arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic int[] toArray() {\nint size = size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] arr = new int[size];\nfor (int i = 0; i < size; i++) {\narr[i] = get(i);\n}\nreturn arr;\n}\n}\n
        my_list.cs
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate int[] arr;           // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate int arrCapacity = 10;    // \u5217\u8868\u5bb9\u91cf\nprivate int arrSize = 0;         // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate readonly int extendRatio = 2;  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\npublic MyList() {\narr = new int[arrCapacity];\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npublic int Size() {\nreturn arrSize;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic int Capacity() {\nreturn arrCapacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic int Get(int index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic void Set(int index, int num) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\narr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic void Add(int num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (arrSize == arrCapacity)\nExtendCapacity();\narr[arrSize] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic void Insert(int index, int num) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (arrSize == arrCapacity)\nExtendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (int j = arrSize - 1; j >= index; j--) {\narr[j + 1] = arr[j];\n}\narr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic int Remove(int index) {\nif (index < 0 || index >= arrSize)\nthrow new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\nint num = arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (int j = index; j < arrSize - 1; j++) {\narr[j] = arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\narrSize--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic void ExtendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a arrCapacity * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nArray.Resize(ref arr, arrCapacity * extendRatio);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\narrCapacity = arr.Length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] arr = new int[arrSize];\nfor (int i = 0; i < arrSize; i++) {\narr[i] = Get(i);\n}\nreturn arr;\n}\n}\n
        my_list.go
        /* \u5217\u8868\u7c7b */\ntype myList struct {\narrCapacity int\narr         []int\narrSize     int\nextendRatio int\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newMyList() *myList {\nreturn &myList{\narrCapacity: 10,              // \u5217\u8868\u5bb9\u91cf\narr:         make([]int, 10), // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\narrSize:     0,               // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextendRatio: 2,               // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\nfunc (l *myList) size() int {\nreturn l.arrSize\n}\n/*  \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc (l *myList) capacity() int {\nreturn l.arrCapacity\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc (l *myList) get(index int) int {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nreturn l.arr[index]\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc (l *myList) set(num, index int) {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nl.arr[index] = num\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nfunc (l *myList) add(num int) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif l.arrSize == l.arrCapacity {\nl.extendCapacity()\n}\nl.arr[l.arrSize] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize++\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc (l *myList) insert(num, index int) {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif l.arrSize == l.arrCapacity {\nl.extendCapacity()\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j := l.arrSize - 1; j >= index; j-- {\nl.arr[j+1] = l.arr[j]\n}\nl.arr[index] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize++\n}\n/* \u5220\u9664\u5143\u7d20 */\nfunc (l *myList) remove(index int) int {\nif index < 0 || index >= l.arrSize {\npanic(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nnum := l.arr[index]\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j := index; j < l.arrSize-1; j++ {\nl.arr[j] = l.arr[j+1]\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nl.arrSize--\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\n}\n/* \u5217\u8868\u6269\u5bb9 */\nfunc (l *myList) extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nl.arr = append(l.arr, make([]int, l.arrCapacity*(l.extendRatio-1))...)\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nl.arrCapacity = len(l.arr)\n}\n/* \u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868 */\nfunc (l *myList) toArray() []int {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nreturn l.arr[:l.arrSize]\n}\n
        my_list.swift
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate var arr: [Int] // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate var _capacity = 10 // \u5217\u8868\u5bb9\u91cf\nprivate var _size = 0 // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate let extendRatio = 2 // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\narr = Array(repeating: 0, count: _capacity)\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nfunc size() -> Int {\n_size\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc capacity() -> Int {\n_capacity\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc get(index: Int) -> Int {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u9519\u8bef\uff0c\u4e0b\u540c\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nreturn arr[index]\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc set(index: Int, num: Int) {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\narr[index] = num\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nfunc add(num: Int) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif _size == _capacity {\nextendCapacity()\n}\narr[_size] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size += 1\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc insert(index: Int, num: Int) {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif _size == _capacity {\nextendCapacity()\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in sequence(first: _size - 1, next: { $0 >= index + 1 ? $0 - 1 : nil }) {\narr[j + 1] = arr[j]\n}\narr[index] = num\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size += 1\n}\n/* \u5220\u9664\u5143\u7d20 */\n@discardableResult\nfunc remove(index: Int) -> Int {\nif index < 0 || index >= _size {\nfatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n}\nlet num = arr[index]\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in index ..< (_size - 1) {\narr[j] = arr[j + 1]\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size -= 1\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num\n}\n/* \u5217\u8868\u6269\u5bb9 */\nfunc extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\narr = arr + Array(repeating: 0, count: _capacity * (extendRatio - 1))\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n_capacity = arr.count\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\nfunc toArray() -> [Int] {\nvar arr = Array(repeating: 0, count: _size)\nfor i in 0 ..< _size {\narr[i] = get(index: i)\n}\nreturn arr\n}\n}\n
        my_list.js
        /* \u5217\u8868\u7c7b */\nclass MyList {\n#arr = new Array(); // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n#capacity = 10; // \u5217\u8868\u5bb9\u91cf\n#size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n#extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#arr = new Array(this.#capacity);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nsize() {\nreturn this.#size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\ncapacity() {\nreturn this.#capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nget(index) {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nreturn this.#arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nset(index, num) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nthis.#arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nadd(num) {\n// \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\nif (this.#size === this.#capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\nthis.#arr[this.#size] = num;\nthis.#size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\ninsert(index, num) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (this.#size === this.#capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let j = this.#size - 1; j >= index; j--) {\nthis.#arr[j + 1] = this.#arr[j];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.#arr[index] = num;\nthis.#size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nremove(index) {\nif (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nlet num = this.#arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let j = index; j < this.#size - 1; j++) {\nthis.#arr[j] = this.#arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.#size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nextendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nthis.#arr = this.#arr.concat(\nnew Array(this.capacity() * (this.#extendRatio - 1))\n);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nthis.#capacity = this.#arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\ntoArray() {\nlet size = this.size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(size);\nfor (let i = 0; i < size; i++) {\narr[i] = this.get(i);\n}\nreturn arr;\n}\n}\n
        my_list.ts
        /* \u5217\u8868\u7c7b */\nclass MyList {\nprivate arr: Array<number>; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nprivate _capacity: number = 10; // \u5217\u8868\u5bb9\u91cf\nprivate _size: number = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nprivate extendRatio: number = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.arr = new Array(this._capacity);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npublic size(): number {\nreturn this._size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npublic capacity(): number {\nreturn this._capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npublic get(index: number): number {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nreturn this.arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npublic set(index: number, num: number): void {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nthis.arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npublic add(num: number): void {\n// \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\nif (this._size === this._capacity) this.extendCapacity();\n// \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\nthis.arr[this._size] = num;\nthis._size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npublic insert(index: number, num: number): void {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (this._size === this._capacity) {\nthis.extendCapacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (let j = this._size - 1; j >= index; j--) {\nthis.arr[j + 1] = this.arr[j];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis.arr[index] = num;\nthis._size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\npublic remove(index: number): number {\nif (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\nlet num = this.arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (let j = index; j < this._size - 1; j++) {\nthis.arr[j] = this.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nthis._size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npublic extendCapacity(): void {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nthis.arr = this.arr.concat(\nnew Array(this.capacity() * (this.extendRatio - 1))\n);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nthis._capacity = this.arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npublic toArray(): number[] {\nlet size = this.size();\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(size);\nfor (let i = 0; i < size; i++) {\narr[i] = this.get(i);\n}\nreturn arr;\n}\n}\n
        my_list.dart
        /* \u5217\u8868\u7c7b */\nclass MyList {\nlate List<int> _arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint _capacity = 10; // \u5217\u8868\u5bb9\u91cf\nint _size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nint _extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n/* \u6784\u9020\u65b9\u6cd5 */\nMyList() {\n_arr = List.filled(_capacity, 0);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\nint size() => _size;\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity() => _capacity;\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(int index) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\nreturn _arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(int index, int _num) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n_arr[index] = _num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(int _num) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (_size == _capacity) extendCapacity();\n_arr[_size] = _num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(int index, int _num) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (_size == _capacity) extendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor (var j = _size - 1; j >= index; j--) {\n_arr[j + 1] = _arr[j];\n}\n_arr[index] = _num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\nint remove(int index) {\nif (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\nint _num = _arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor (var j = index; j < _size - 1; j++) {\n_arr[j] = _arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n_size--;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn _num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity() {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 _extendRatio \u500d\u7684\u65b0\u6570\u7ec4\nfinal _newNums = List.filled(_capacity * _extendRatio, 0);\n// \u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nList.copyRange(_newNums, 0, _arr);\n// \u66f4\u65b0 _arr \u7684\u5f15\u7528\n_arr = _newNums;\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n_capacity = _arr.length;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\nList<int> toArray() {\nList<int> arr = [];\nfor (var i = 0; i < _size; i++) {\narr.add(get(i));\n}\nreturn arr;\n}\n}\n
        my_list.rs
        /* \u5217\u8868\u7c7b */\n#[allow(dead_code)]\nstruct MyList {\narr: Vec<i32>,       // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\ncapacity: usize,      // \u5217\u8868\u5bb9\u91cf\nsize: usize,          // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextend_ratio: usize,  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n#[allow(unused,unused_comparisons)]\nimpl MyList {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(capacity: usize) -> Self {\nlet mut vec = Vec::new(); vec.resize(capacity, 0);\nSelf {\narr: vec,\ncapacity,\nsize: 0,\nextend_ratio: 2,\n}\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\npub fn size(&self) -> usize {\nreturn self.size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\npub fn capacity(&self) -> usize {\nreturn self.capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\npub fn get(&self, index: usize) -> i32 {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nreturn self.arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\npub fn set(&mut self, index: usize, num: i32) {\nif index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nself.arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\npub fn add(&mut self, num: i32) {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size == self.capacity() {\nself.extend_capacity();\n}\nself.arr[self.size] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size += 1;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\npub fn insert(&mut self, index: usize, num: i32) {\nif index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif self.size == self.capacity() {\nself.extend_capacity();\n}\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfor j in (index..self.size).rev() {\nself.arr[j + 1] = self.arr[j];\n}\nself.arr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size += 1;\n}\n/* \u5220\u9664\u5143\u7d20 */\npub fn remove(&mut self, index: usize) -> i32 {\nif index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\nlet num = self.arr[index];\n// \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nfor j in (index..self.size - 1) {\nself.arr[j] = self.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.size -= 1;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\npub fn extend_capacity(&mut self) {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extend_ratio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nlet new_capacity = self.capacity * self.extend_ratio;\nself.arr.resize(new_capacity, 0);\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself.capacity = new_capacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\npub fn to_array(&mut self) -> Vec<i32> {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nlet mut arr = Vec::new();\nfor i in 0..self.size {\narr.push(self.get(i));\n}\narr\n}\n}\n
        my_list.c
        /* \u5217\u8868\u7c7b */\ntypedef struct {\nint *arr;        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\nint capacity;    // \u5217\u8868\u5bb9\u91cf\nint size;        // \u5217\u8868\u5927\u5c0f\nint extendRatio; // \u5217\u8868\u6bcf\u6b21\u6269\u5bb9\u7684\u500d\u6570\n} MyList;\n/* \u6784\u9020\u51fd\u6570 */\nMyList *newMyList() {\nMyList *nums = malloc(sizeof(MyList));\nnums->capacity = 10;\nnums->arr = malloc(sizeof(int) * nums->capacity);\nnums->size = 0;\nnums->extendRatio = 2;\nreturn nums;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delMyList(MyList *nums) {\nfree(nums->arr);\nfree(nums);\n}\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6 */\nint size(MyList *nums) {\nreturn nums->size;\n}\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity(MyList *nums) {\nreturn nums->capacity;\n}\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(MyList *nums, int index) {\nassert(index >= 0 && index < nums->size);\nreturn nums->arr[index];\n}\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(MyList *nums, int index, int num) {\nassert(index >= 0 && index < nums->size);\nnums->arr[index] = num;\n}\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(MyList *nums, int num) {\nif (size(nums) == capacity(nums)) {\nextendCapacity(nums); // \u6269\u5bb9\n}\nnums->arr[size(nums)] = num;\nnums->size++;\n}\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(MyList *nums, int index, int num) {\nassert(index >= 0 && index < size(nums));\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (size(nums) == capacity(nums)) {\nextendCapacity(nums); // \u6269\u5bb9\n}\nfor (int i = size(nums); i > index; --i) {\nnums->arr[i] = nums->arr[i - 1];\n}\nnums->arr[index] = num;\nnums->size++;\n}\n/* \u5220\u9664\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nint removeItem(MyList *nums, int index) {\nassert(index >= 0 && index < size(nums));\nint num = nums->arr[index];\nfor (int i = index; i < size(nums) - 1; i++) {\nnums->arr[i] = nums->arr[i + 1];\n}\nnums->size--;\nreturn num;\n}\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity(MyList *nums) {\n// \u5148\u5206\u914d\u7a7a\u95f4\nint newCapacity = capacity(nums) * nums->extendRatio;\nint *extend = (int *)malloc(sizeof(int) * newCapacity);\nint *temp = nums->arr;\n// \u62f7\u8d1d\u65e7\u6570\u636e\u5230\u65b0\u6570\u636e\nfor (int i = 0; i < size(nums); i++)\nextend[i] = nums->arr[i];\n// \u91ca\u653e\u65e7\u6570\u636e\nfree(temp);\n// \u66f4\u65b0\u65b0\u6570\u636e\nnums->arr = extend;\nnums->capacity = newCapacity;\n}\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Array \u7528\u4e8e\u6253\u5370 */\nint *toArray(MyList *nums) {\nreturn nums->arr;\n}\n
        my_list.zig
        // \u5217\u8868\u7c7b\nfn MyList(comptime T: type) type {\nreturn struct {\nconst Self = @This();\narr: []T = undefined,                        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\narrCapacity: usize = 10,                     // \u5217\u8868\u5bb9\u91cf\nnumSize: usize = 0,                           // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\nextendRatio: usize = 2,                       // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined, // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u5217\u8868\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.arr = try self.mem_allocator.alloc(T, self.arrCapacity);\n@memset(self.arr, @as(T, 0));\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\npub fn size(self: *Self) usize {\nreturn self.numSize;\n}\n// \u83b7\u53d6\u5217\u8868\u5bb9\u91cf\npub fn capacity(self: *Self) usize {\nreturn self.arrCapacity;\n}\n// \u8bbf\u95ee\u5143\u7d20\npub fn get(self: *Self, index: usize) T {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nreturn self.arr[index];\n}  // \u66f4\u65b0\u5143\u7d20\npub fn set(self: *Self, index: usize, num: T) void {\n// \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nself.arr[index] = num;\n}  // \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\npub fn add(self: *Self, num: T) !void {\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (self.size() == self.capacity()) try self.extendCapacity();\nself.arr[self.size()] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize += 1;\n}  // \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\npub fn insert(self: *Self, index: usize, num: T) !void {\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n// \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\nif (self.size() == self.capacity()) try self.extendCapacity();\n// \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nvar j = self.size() - 1;\nwhile (j >= index) : (j -= 1) {\nself.arr[j + 1] = self.arr[j];\n}\nself.arr[index] = num;\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize += 1;\n}\n// \u5220\u9664\u5143\u7d20\npub fn remove(self: *Self, index: usize) T {\nif (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\nvar num = self.arr[index];\n// \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\nvar j = index;\nwhile (j < self.size() - 1) : (j += 1) {\nself.arr[j] = self.arr[j + 1];\n}\n// \u66f4\u65b0\u5143\u7d20\u6570\u91cf\nself.numSize -= 1;\n// \u8fd4\u56de\u88ab\u5220\u9664\u5143\u7d20\nreturn num;\n}\n// \u5217\u8868\u6269\u5bb9\npub fn extendCapacity(self: *Self) !void {\n// \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u62f7\u8d1d\u5230\u65b0\u6570\u7ec4\nvar newCapacity = self.capacity() * self.extendRatio;\nvar extend = try self.mem_allocator.alloc(T, newCapacity);\n@memset(extend, @as(T, 0));\n// \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\nstd.mem.copy(T, extend, self.arr);\nself.arr = extend;\n// \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\nself.arrCapacity = newCapacity;\n}\n// \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar arr = try self.mem_allocator.alloc(T, self.size());\n@memset(arr, @as(T, 0));\nfor (arr, 0..) |*num, i| {\nnum.* = self.get(i);\n}\nreturn arr;\n}\n};\n}\n
        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/","title":"4.4 \u00a0 \u5185\u5b58\u4e0e\u7f13\u5b58 *","text":"

        \u5728\u672c\u7ae0\u7684\u524d\u4e24\u8282\u4e2d\uff0c\u6211\u4eec\u63a2\u8ba8\u4e86\u6570\u7ec4\u548c\u94fe\u8868\u8fd9\u4e24\u79cd\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u4eec\u5206\u522b\u4ee3\u8868\u4e86\u201c\u8fde\u7eed\u5b58\u50a8\u201d\u548c\u201c\u5206\u6563\u5b58\u50a8\u201d\u8fd9\u4e24\u79cd\u4e0d\u540c\u7684\u7269\u7406\u7ed3\u6784\u3002

        \u5b9e\u9645\u4e0a\uff0c\u7269\u7406\u7ed3\u6784\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u51b3\u5b9a\u4e86\u7a0b\u5e8f\u5bf9\u5185\u5b58\u548c\u7f13\u5b58\u7684\u4f7f\u7528\u6548\u7387\uff0c\u8fdb\u800c\u5f71\u54cd\u7b97\u6cd5\u7a0b\u5e8f\u7684\u6574\u4f53\u6027\u80fd\u3002

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#441","title":"4.4.1 \u00a0 \u8ba1\u7b97\u673a\u5b58\u50a8\u8bbe\u5907","text":"

        \u8ba1\u7b97\u673a\u4e2d\u5305\u62ec\u4e09\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u5b58\u50a8\u8bbe\u5907\uff1a\u300c\u786c\u76d8 hard disk\u300d\u3001\u300c\u5185\u5b58 random-access memory, RAM\u300d\u3001\u300c\u7f13\u5b58 cache memory\u300d\u3002\u8868 4-2 \u5c55\u793a\u4e86\u5b83\u4eec\u5728\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u4e0d\u540c\u89d2\u8272\u548c\u6027\u80fd\u7279\u70b9\u3002

        \u8868 4-2 \u00a0 \u8ba1\u7b97\u673a\u7684\u5b58\u50a8\u8bbe\u5907

        \u786c\u76d8 \u5185\u5b58 \u7f13\u5b58 \u7528\u9014 \u957f\u671f\u5b58\u50a8\u6570\u636e\uff0c\u5305\u62ec\u64cd\u4f5c\u7cfb\u7edf\u3001\u7a0b\u5e8f\u3001\u6587\u4ef6\u7b49 \u4e34\u65f6\u5b58\u50a8\u5f53\u524d\u8fd0\u884c\u7684\u7a0b\u5e8f\u548c\u6b63\u5728\u5904\u7406\u7684\u6570\u636e \u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u548c\u6307\u4ee4\uff0c\u51cf\u5c11 CPU \u8bbf\u95ee\u5185\u5b58\u7684\u6b21\u6570 \u6613\u5931\u6027 \u65ad\u7535\u540e\u6570\u636e\u4e0d\u4f1a\u4e22\u5931 \u65ad\u7535\u540e\u6570\u636e\u4f1a\u4e22\u5931 \u65ad\u7535\u540e\u6570\u636e\u4f1a\u4e22\u5931 \u5bb9\u91cf \u8f83\u5927\uff0cTB \u7ea7\u522b \u8f83\u5c0f\uff0cGB \u7ea7\u522b \u975e\u5e38\u5c0f\uff0cMB \u7ea7\u522b \u901f\u5ea6 \u8f83\u6162\uff0c\u51e0\u767e\u5230\u51e0\u5343 MB/s \u8f83\u5feb\uff0c\u51e0\u5341 GB/s \u975e\u5e38\u5feb\uff0c\u51e0\u5341\u5230\u51e0\u767e GB/s \u4ef7\u683c \u8f83\u4fbf\u5b9c\uff0c\u51e0\u6bdb\u5230\u51e0\u5143 / GB \u8f83\u8d35\uff0c\u51e0\u5341\u5230\u51e0\u767e\u5143 / GB \u975e\u5e38\u8d35\uff0c\u968f CPU \u6253\u5305\u8ba1\u4ef7

        \u6211\u4eec\u53ef\u4ee5\u5c06\u8ba1\u7b97\u673a\u5b58\u50a8\u7cfb\u7edf\u60f3\u8c61\u4e3a\u56fe 4-9 \u6240\u793a\u7684\u91d1\u5b57\u5854\u7ed3\u6784\u3002\u8d8a\u9760\u8fd1\u91d1\u5b57\u5854\u9876\u7aef\u7684\u5b58\u50a8\u8bbe\u5907\u7684\u901f\u5ea6\u8d8a\u5feb\u3001\u5bb9\u91cf\u8d8a\u5c0f\u3001\u6210\u672c\u8d8a\u9ad8\u3002\u8fd9\u79cd\u591a\u5c42\u7ea7\u7684\u8bbe\u8ba1\u5e76\u975e\u5076\u7136\uff0c\u800c\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u5bb6\u548c\u5de5\u7a0b\u5e08\u4eec\u7ecf\u8fc7\u6df1\u601d\u719f\u8651\u7684\u7ed3\u679c\u3002

        • \u786c\u76d8\u96be\u4ee5\u88ab\u5185\u5b58\u53d6\u4ee3\u3002\u9996\u5148\uff0c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5728\u65ad\u7535\u540e\u4f1a\u4e22\u5931\uff0c\u56e0\u6b64\u5b83\u4e0d\u9002\u5408\u957f\u671f\u5b58\u50a8\u6570\u636e\uff1b\u5176\u6b21\uff0c\u5185\u5b58\u7684\u6210\u672c\u5927\u7ea6\u662f\u786c\u76d8\u7684\u51e0\u5341\u500d\uff0c\u8fd9\u4f7f\u5f97\u5b83\u96be\u4ee5\u5728\u6d88\u8d39\u8005\u5e02\u573a\u666e\u53ca\u3002
        • \u7f13\u5b58\u7684\u5927\u5bb9\u91cf\u548c\u9ad8\u901f\u5ea6\u96be\u4ee5\u517c\u5f97\u3002\u968f\u7740 L1\u3001L2\u3001L3 \u7f13\u5b58\u7684\u5bb9\u91cf\u9010\u6b65\u589e\u5927\uff0c\u5176\u7269\u7406\u5c3a\u5bf8\u4f1a\u53d8\u5927\uff0c\u4e0e CPU \u6838\u5fc3\u4e4b\u95f4\u7684\u7269\u7406\u8ddd\u79bb\u4f1a\u53d8\u8fdc\uff0c\u4ece\u800c\u5bfc\u81f4\u6570\u636e\u4f20\u8f93\u65f6\u95f4\u589e\u52a0\uff0c\u5143\u7d20\u8bbf\u95ee\u5ef6\u8fdf\u53d8\u9ad8\u3002\u5728\u5f53\u524d\u6280\u672f\u4e0b\uff0c\u591a\u5c42\u7ea7\u7684\u7f13\u5b58\u7ed3\u6784\u662f\u5bb9\u91cf\u3001\u901f\u5ea6\u548c\u6210\u672c\u4e4b\u95f4\u7684\u6700\u4f73\u5e73\u8861\u70b9\u3002

        \u56fe 4-9 \u00a0 \u8ba1\u7b97\u673a\u5b58\u50a8\u7cfb\u7edf

        Note

        \u8ba1\u7b97\u673a\u7684\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\u4f53\u73b0\u4e86\u901f\u5ea6\u3001\u5bb9\u91cf\u548c\u6210\u672c\u4e09\u8005\u4e4b\u95f4\u7684\u7cbe\u5999\u5e73\u8861\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u79cd\u6743\u8861\u666e\u904d\u5b58\u5728\u4e8e\u6240\u6709\u5de5\u4e1a\u9886\u57df\uff0c\u5b83\u8981\u6c42\u6211\u4eec\u5728\u4e0d\u540c\u7684\u4f18\u52bf\u548c\u9650\u5236\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u7684\u5e73\u8861\u70b9\u3002

        \u603b\u7684\u6765\u8bf4\uff0c\u786c\u76d8\u7528\u4e8e\u957f\u671f\u5b58\u50a8\u5927\u91cf\u6570\u636e\uff0c\u5185\u5b58\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u6b63\u5728\u5904\u7406\u7684\u6570\u636e\uff0c\u800c\u7f13\u5b58\u5219\u7528\u4e8e\u5b58\u50a8\u7ecf\u5e38\u8bbf\u95ee\u7684\u6570\u636e\u548c\u6307\u4ee4\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\u3002\u8fd9\u4e09\u8005\u5171\u540c\u534f\u4f5c\uff0c\u786e\u4fdd\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u9ad8\u6548\u8fd0\u884c\u3002

        \u5982\u56fe 4-10 \u6240\u793a\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u4f1a\u4ece\u786c\u76d8\u4e2d\u88ab\u8bfb\u53d6\u5230\u5185\u5b58\u4e2d\uff0c\u4f9b\u7ed9 CPU \u8ba1\u7b97\u4f7f\u7528\u3002\u7f13\u5b58\u53ef\u4ee5\u770b\u4f5c CPU \u7684\u4e00\u90e8\u5206\uff0c\u5b83\u901a\u8fc7\u667a\u80fd\u5730\u4ece\u5185\u5b58\u52a0\u8f7d\u6570\u636e\uff0c\u7ed9 CPU \u63d0\u4f9b\u9ad8\u901f\u7684\u6570\u636e\u8bfb\u53d6\uff0c\u4ece\u800c\u663e\u8457\u63d0\u5347\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u51cf\u5c11\u5bf9\u8f83\u6162\u7684\u5185\u5b58\u7684\u4f9d\u8d56\u3002

        \u56fe 4-10 \u00a0 \u786c\u76d8\u3001\u5185\u5b58\u548c\u7f13\u5b58\u4e4b\u95f4\u7684\u6570\u636e\u6d41\u901a

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#442","title":"4.4.2 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u5185\u5b58\u6548\u7387","text":"

        \u5728\u5185\u5b58\u7a7a\u95f4\u5229\u7528\u65b9\u9762\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u5177\u6709\u5404\u81ea\u7684\u4f18\u52bf\u548c\u5c40\u9650\u3002

        \u4e00\u65b9\u9762\uff0c\u5185\u5b58\u662f\u6709\u9650\u7684\uff0c\u4e14\u540c\u4e00\u5757\u5185\u5b58\u4e0d\u80fd\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5171\u4eab\uff0c\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u6570\u636e\u7ed3\u6784\u80fd\u591f\u5c3d\u53ef\u80fd\u9ad8\u6548\u5730\u5229\u7528\u7a7a\u95f4\u3002\u6570\u7ec4\u7684\u5143\u7d20\u7d27\u5bc6\u6392\u5217\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684\u7a7a\u95f4\u6765\u5b58\u50a8\u94fe\u8868\u8282\u70b9\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u56e0\u6b64\u7a7a\u95f4\u6548\u7387\u66f4\u9ad8\u3002\u7136\u800c\uff0c\u6570\u7ec4\u9700\u8981\u4e00\u6b21\u6027\u5206\u914d\u8db3\u591f\u7684\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u7684\u6d6a\u8d39\uff0c\u6570\u7ec4\u6269\u5bb9\u4e5f\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u6210\u672c\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u94fe\u8868\u4ee5\u201c\u8282\u70b9\u201d\u4e3a\u5355\u4f4d\u8fdb\u884c\u52a8\u6001\u5185\u5b58\u5206\u914d\u548c\u56de\u6536\uff0c\u8fd9\u79cd\u65b9\u5f0f\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u7075\u6d3b\u6027\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u968f\u7740\u53cd\u590d\u7533\u8bf7\u4e0e\u91ca\u653e\u5185\u5b58\uff0c\u7a7a\u95f2\u5185\u5b58\u7684\u788e\u7247\u5316\u7a0b\u5ea6\u4f1a\u8d8a\u6765\u8d8a\u9ad8\uff0c\u4ece\u800c\u5bfc\u81f4\u5185\u5b58\u7684\u5229\u7528\u6548\u7387\u964d\u4f4e\u3002\u6570\u7ec4\u7531\u4e8e\u5176\u8fde\u7eed\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u76f8\u5bf9\u4e0d\u5bb9\u6613\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u5316\u3002\u76f8\u53cd\uff0c\u94fe\u8868\u7684\u5143\u7d20\u662f\u5206\u6563\u5b58\u50a8\u7684\uff0c\u5728\u9891\u7e41\u7684\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u4e2d\uff0c\u66f4\u5bb9\u6613\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u5316\u3002

        "},{"location":"chapter_array_and_linkedlist/ram_and_cache/#443","title":"4.4.3 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u7f13\u5b58\u6548\u7387","text":"

        \u7f13\u5b58\u867d\u7136\u5728\u7a7a\u95f4\u5bb9\u91cf\u4e0a\u8fdc\u5c0f\u4e8e\u5185\u5b58\uff0c\u4f46\u5b83\u6bd4\u5185\u5b58\u5feb\u5f97\u591a\uff0c\u5728\u7a0b\u5e8f\u6267\u884c\u901f\u5ea6\u4e0a\u8d77\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\u3002\u7531\u4e8e\u7f13\u5b58\u7684\u5bb9\u91cf\u6709\u9650\uff0c\u5b83\u53ea\u80fd\u5b58\u50a8\u4e00\u5c0f\u90e8\u5206\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u3002\u56e0\u6b64\uff0c\u5f53 CPU \u5c1d\u8bd5\u8bbf\u95ee\u7684\u6570\u636e\u4e0d\u5728\u7f13\u5b58\u4e2d\u65f6\uff0c\u5c31\u4f1a\u53d1\u751f\u300c\u7f13\u5b58\u672a\u547d\u4e2d cache miss\u300d\uff0c\u6b64\u65f6 CPU \u4e0d\u5f97\u4e0d\u4ece\u901f\u5ea6\u8f83\u6162\u7684\u5185\u5b58\u4e2d\u52a0\u8f7d\u6240\u9700\u6570\u636e\u3002

        \u663e\u7136\uff0c\u201c\u7f13\u5b58\u672a\u547d\u4e2d\u201d\u8d8a\u5c11\uff0cCPU \u8bfb\u5199\u6570\u636e\u7684\u6548\u7387\u5c31\u8d8a\u9ad8\uff0c\u7a0b\u5e8f\u6027\u80fd\u4e5f\u5c31\u8d8a\u597d\u3002\u6211\u4eec\u5c06 CPU \u4ece\u7f13\u5b58\u4e2d\u6210\u529f\u83b7\u53d6\u6570\u636e\u7684\u6bd4\u4f8b\u79f0\u4e3a\u300c\u7f13\u5b58\u547d\u4e2d\u7387 cache hit rate\u300d\uff0c\u8fd9\u4e2a\u6307\u6807\u901a\u5e38\u7528\u6765\u8861\u91cf\u7f13\u5b58\u6548\u7387\u3002

        \u4e3a\u4e86\u5c3d\u53ef\u80fd\u8fbe\u5230\u66f4\u9ad8\u6548\u7387\uff0c\u7f13\u5b58\u4f1a\u91c7\u53d6\u4ee5\u4e0b\u6570\u636e\u52a0\u8f7d\u673a\u5236\u3002

        • \u7f13\u5b58\u884c\uff1a\u7f13\u5b58\u4e0d\u662f\u5355\u4e2a\u5b57\u8282\u5730\u5b58\u50a8\u4e0e\u52a0\u8f7d\u6570\u636e\uff0c\u800c\u662f\u4ee5\u7f13\u5b58\u884c\u4e3a\u5355\u4f4d\u3002\u76f8\u6bd4\u4e8e\u5355\u4e2a\u5b57\u8282\u7684\u4f20\u8f93\uff0c\u7f13\u5b58\u884c\u7684\u4f20\u8f93\u5f62\u5f0f\u66f4\u52a0\u9ad8\u6548\u3002
        • \u9884\u53d6\u673a\u5236\uff1a\u5904\u7406\u5668\u4f1a\u5c1d\u8bd5\u9884\u6d4b\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\uff08\u4f8b\u5982\u987a\u5e8f\u8bbf\u95ee\u3001\u56fa\u5b9a\u6b65\u957f\u8df3\u8dc3\u8bbf\u95ee\u7b49\uff09\uff0c\u5e76\u6839\u636e\u7279\u5b9a\u6a21\u5f0f\u5c06\u6570\u636e\u52a0\u8f7d\u81f3\u7f13\u5b58\u4e4b\u4e2d\uff0c\u4ece\u800c\u63d0\u5347\u547d\u4e2d\u7387\u3002
        • \u7a7a\u95f4\u5c40\u90e8\u6027\uff1a\u5982\u679c\u4e00\u4e2a\u6570\u636e\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u5b83\u9644\u8fd1\u7684\u6570\u636e\u53ef\u80fd\u4e5f\u4f1a\u8fd1\u671f\u88ab\u8bbf\u95ee\u3002\u56e0\u6b64\uff0c\u7f13\u5b58\u5728\u52a0\u8f7d\u67d0\u4e00\u6570\u636e\u65f6\uff0c\u4e5f\u4f1a\u5c06\u5176\u9644\u8fd1\u7684\u6570\u636e\u52a0\u8f7d\u8fdb\u6765\uff0c\u4ee5\u63d0\u9ad8\u547d\u4e2d\u7387\u3002
        • \u65f6\u95f4\u5c40\u90e8\u6027\uff1a\u5982\u679c\u4e00\u4e2a\u6570\u636e\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u5b83\u5728\u4e0d\u4e45\u7684\u5c06\u6765\u5f88\u53ef\u80fd\u518d\u6b21\u88ab\u8bbf\u95ee\u3002\u7f13\u5b58\u5229\u7528\u8fd9\u4e00\u539f\u7406\uff0c\u901a\u8fc7\u4fdd\u7559\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684\u6570\u636e\u6765\u63d0\u9ad8\u547d\u4e2d\u7387\u3002

        \u5b9e\u9645\u4e0a\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u5bf9\u7f13\u5b58\u7684\u5229\u7528\u6548\u7387\u4e5f\u662f\u4e0d\u540c\u7684\uff0c\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u3002

        • \u5360\u7528\u7a7a\u95f4\uff1a\u94fe\u8868\u5143\u7d20\u6bd4\u6570\u7ec4\u5143\u7d20\u5360\u7528\u7a7a\u95f4\u66f4\u591a\uff0c\u5bfc\u81f4\u7f13\u5b58\u4e2d\u5bb9\u7eb3\u7684\u6709\u6548\u6570\u636e\u91cf\u66f4\u5c11\u3002
        • \u7f13\u5b58\u884c\uff1a\u94fe\u8868\u6570\u636e\u5206\u6563\u5728\u5185\u5b58\u5404\u5904\uff0c\u800c\u7f13\u5b58\u662f\u201c\u6309\u884c\u52a0\u8f7d\u201d\u7684\uff0c\u56e0\u6b64\u52a0\u8f7d\u5230\u7684\u65e0\u6548\u6570\u636e\u7684\u6bd4\u4f8b\u66f4\u9ad8\u3002
        • \u9884\u53d6\u673a\u5236\uff1a\u6570\u7ec4\u6bd4\u94fe\u8868\u7684\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u66f4\u5177\u201c\u53ef\u9884\u6d4b\u6027\u201d\uff0c\u5373\u7cfb\u7edf\u66f4\u5bb9\u6613\u731c\u51fa\u5373\u5c06\u88ab\u52a0\u8f7d\u7684\u6570\u636e\u3002
        • \u7a7a\u95f4\u5c40\u90e8\u6027\uff1a\u6570\u7ec4\u88ab\u5b58\u50a8\u5728\u96c6\u4e2d\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u56e0\u6b64\u88ab\u52a0\u8f7d\u6570\u636e\u7684\u9644\u8fd1\u6570\u636e\u66f4\u6709\u53ef\u80fd\u5373\u5c06\u88ab\u8bbf\u95ee\u3002

        \u603b\u4f53\u800c\u8a00\uff0c\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u7f13\u5b58\u547d\u4e2d\u7387\uff0c\u56e0\u6b64\u5b83\u5728\u64cd\u4f5c\u6548\u7387\u4e0a\u901a\u5e38\u4f18\u4e8e\u94fe\u8868\u3002\u8fd9\u4f7f\u5f97\u5728\u89e3\u51b3\u7b97\u6cd5\u95ee\u9898\u65f6\uff0c\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u5f80\u5f80\u66f4\u53d7\u6b22\u8fce\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9ad8\u7f13\u5b58\u6548\u7387\u5e76\u4e0d\u610f\u5473\u7740\u6570\u7ec4\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u4f18\u4e8e\u94fe\u8868\u3002\u5b9e\u9645\u5e94\u7528\u4e2d\u9009\u62e9\u54ea\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u6765\u51b3\u5b9a\u3002\u4f8b\u5982\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u90fd\u53ef\u4ee5\u5b9e\u73b0\u201c\u6808\u201d\u6570\u636e\u7ed3\u6784\uff08\u4e0b\u4e00\u7ae0\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff09\uff0c\u4f46\u5b83\u4eec\u9002\u7528\u4e8e\u4e0d\u540c\u573a\u666f\u3002

        • \u5728\u505a\u7b97\u6cd5\u9898\u65f6\uff0c\u6211\u4eec\u4f1a\u503e\u5411\u4e8e\u9009\u62e9\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u64cd\u4f5c\u6548\u7387\u548c\u968f\u673a\u8bbf\u95ee\u7684\u80fd\u529b\uff0c\u4ee3\u4ef7\u4ec5\u662f\u9700\u8981\u9884\u5148\u4e3a\u6570\u7ec4\u5206\u914d\u4e00\u5b9a\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        • \u5982\u679c\u6570\u636e\u91cf\u975e\u5e38\u5927\u3001\u52a8\u6001\u6027\u5f88\u9ad8\u3001\u6808\u7684\u9884\u671f\u5927\u5c0f\u96be\u4ee5\u4f30\u8ba1\uff0c\u90a3\u4e48\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\u5c31\u66f4\u52a0\u5408\u9002\u3002\u94fe\u8868\u80fd\u591f\u5c06\u5927\u91cf\u6570\u636e\u5206\u6563\u5b58\u50a8\u4e8e\u5185\u5b58\u7684\u4e0d\u540c\u90e8\u5206\uff0c\u5e76\u4e14\u907f\u514d\u4e86\u6570\u7ec4\u6269\u5bb9\u4ea7\u751f\u7684\u989d\u5916\u5f00\u9500\u3002
        "},{"location":"chapter_array_and_linkedlist/summary/","title":"4.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_array_and_linkedlist/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6570\u7ec4\u548c\u94fe\u8868\u662f\u4e24\u79cd\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5206\u522b\u4ee3\u8868\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u4e24\u79cd\u5b58\u50a8\u65b9\u5f0f\uff1a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\u3002\u4e24\u8005\u7684\u7279\u70b9\u5448\u73b0\u51fa\u4e92\u8865\u7684\u7279\u6027\u3002
        • \u6570\u7ec4\u652f\u6301\u968f\u673a\u8bbf\u95ee\u3001\u5360\u7528\u5185\u5b58\u8f83\u5c11\uff1b\u4f46\u63d2\u5165\u548c\u5220\u9664\u5143\u7d20\u6548\u7387\u4f4e\uff0c\u4e14\u521d\u59cb\u5316\u540e\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002
        • \u94fe\u8868\u901a\u8fc7\u66f4\u6539\u5f15\u7528\uff08\u6307\u9488\uff09\u5b9e\u73b0\u9ad8\u6548\u7684\u8282\u70b9\u63d2\u5165\u4e0e\u5220\u9664\uff0c\u4e14\u53ef\u4ee5\u7075\u6d3b\u8c03\u6574\u957f\u5ea6\uff1b\u4f46\u8282\u70b9\u8bbf\u95ee\u6548\u7387\u4f4e\u3001\u5360\u7528\u5185\u5b58\u8f83\u591a\u3002
        • \u5e38\u89c1\u7684\u94fe\u8868\u7c7b\u578b\u5305\u62ec\u5355\u5411\u94fe\u8868\u3001\u73af\u5f62\u94fe\u8868\u3001\u53cc\u5411\u94fe\u8868\uff0c\u5b83\u4eec\u5206\u522b\u5177\u6709\u5404\u81ea\u7684\u5e94\u7528\u573a\u666f\u3002
        • \u5217\u8868\u662f\u4e00\u79cd\u652f\u6301\u589e\u5220\u67e5\u6539\u7684\u5143\u7d20\u6709\u5e8f\u96c6\u5408\uff0c\u901a\u5e38\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\u5b9e\u73b0\uff0c\u5176\u4fdd\u7559\u4e86\u6570\u7ec4\u7684\u4f18\u52bf\uff0c\u540c\u65f6\u53ef\u4ee5\u7075\u6d3b\u8c03\u6574\u957f\u5ea6\u3002
        • \u5217\u8868\u7684\u51fa\u73b0\u5927\u5e45\u5730\u63d0\u9ad8\u4e86\u6570\u7ec4\u7684\u5b9e\u7528\u6027\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u3002
        • \u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u4e3b\u8981\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u6570\u7ec4\u63d0\u4f9b\u66f4\u9ad8\u7684\u5185\u5b58\u7a7a\u95f4\u6548\u7387\uff0c\u800c\u94fe\u8868\u5219\u5728\u5185\u5b58\u4f7f\u7528\u4e0a\u66f4\u52a0\u7075\u6d3b\u3002
        • \u7f13\u5b58\u901a\u8fc7\u7f13\u5b58\u884c\u3001\u9884\u53d6\u673a\u5236\u4ee5\u53ca\u7a7a\u95f4\u548c\u65f6\u95f4\u5c40\u90e8\u6027\u7b49\u6570\u636e\u52a0\u8f7d\u673a\u5236\uff0c\u4e3a CPU \u63d0\u4f9b\u5feb\u901f\u6570\u636e\u8bbf\u95ee\uff0c\u663e\u8457\u63d0\u5347\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\u3002
        • \u7531\u4e8e\u6570\u7ec4\u5177\u6709\u66f4\u9ad8\u7684\u7f13\u5b58\u547d\u4e2d\u7387\uff0c\u56e0\u6b64\u5b83\u901a\u5e38\u6bd4\u94fe\u8868\u66f4\u9ad8\u6548\u3002\u5728\u9009\u62e9\u6570\u636e\u7ed3\u6784\u65f6\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u573a\u666f\u505a\u51fa\u6070\u5f53\u9009\u62e9\u3002
        "},{"location":"chapter_array_and_linkedlist/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6570\u7ec4\u5b58\u50a8\u5728\u6808\u4e0a\u548c\u5b58\u50a8\u5728\u5806\u4e0a\uff0c\u5bf9\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u662f\u5426\u6709\u5f71\u54cd\uff1f

        \u5b58\u50a8\u5728\u6808\u4e0a\u548c\u5806\u4e0a\u7684\u6570\u7ec4\u90fd\u88ab\u5b58\u50a8\u5728\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\u5185\uff0c\u6570\u636e\u64cd\u4f5c\u6548\u7387\u662f\u57fa\u672c\u4e00\u81f4\u7684\u3002\u7136\u800c\uff0c\u6808\u548c\u5806\u5177\u6709\u5404\u81ea\u7684\u7279\u70b9\uff0c\u4ece\u800c\u5bfc\u81f4\u4ee5\u4e0b\u4e0d\u540c\u70b9\u3002

        1. \u5206\u914d\u548c\u91ca\u653e\u6548\u7387\uff1a\u6808\u662f\u4e00\u5757\u8f83\u5c0f\u7684\u5185\u5b58\uff0c\u5206\u914d\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5b8c\u6210\uff1b\u800c\u5806\u5185\u5b58\u76f8\u5bf9\u66f4\u5927\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u52a8\u6001\u5206\u914d\uff0c\u66f4\u5bb9\u6613\u788e\u7247\u5316\u3002\u56e0\u6b64\uff0c\u5806\u4e0a\u7684\u5206\u914d\u548c\u91ca\u653e\u64cd\u4f5c\u901a\u5e38\u6bd4\u6808\u4e0a\u7684\u6162\u3002
        2. \u5927\u5c0f\u9650\u5236\uff1a\u6808\u5185\u5b58\u76f8\u5bf9\u8f83\u5c0f\uff0c\u5806\u7684\u5927\u5c0f\u4e00\u822c\u53d7\u9650\u4e8e\u53ef\u7528\u5185\u5b58\u3002\u56e0\u6b64\u5806\u66f4\u52a0\u9002\u5408\u5b58\u50a8\u5927\u578b\u6570\u7ec4\u3002
        3. \u7075\u6d3b\u6027\uff1a\u6808\u4e0a\u7684\u6570\u7ec4\u7684\u5927\u5c0f\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u786e\u5b9a\uff0c\u800c\u5806\u4e0a\u7684\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u786e\u5b9a\u3002

        \u4e3a\u4ec0\u4e48\u6570\u7ec4\u8981\u6c42\u76f8\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u800c\u5728\u94fe\u8868\u4e2d\u5374\u6ca1\u6709\u5f3a\u8c03\u540c\u7c7b\u578b\u5462\uff1f

        \u94fe\u8868\u7531\u8282\u70b9\u7ec4\u6210\uff0c\u8282\u70b9\u4e4b\u95f4\u901a\u8fc7\u5f15\u7528\uff08\u6307\u9488\uff09\u8fde\u63a5\uff0c\u5404\u4e2a\u8282\u70b9\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u4f8b\u5982 int\u3001double\u3001string\u3001object \u7b49\u3002

        \u76f8\u5bf9\u5730\uff0c\u6570\u7ec4\u5143\u7d20\u5219\u5fc5\u987b\u662f\u76f8\u540c\u7c7b\u578b\u7684\uff0c\u8fd9\u6837\u624d\u80fd\u901a\u8fc7\u8ba1\u7b97\u504f\u79fb\u91cf\u6765\u83b7\u53d6\u5bf9\u5e94\u5143\u7d20\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u6570\u7ec4\u540c\u65f6\u5305\u542b int \u548c long \u4e24\u79cd\u7c7b\u578b\uff0c\u5355\u4e2a\u5143\u7d20\u5206\u522b\u5360\u7528 4 bytes \u548c 8 bytes \uff0c\u6b64\u65f6\u5c31\u4e0d\u80fd\u7528\u4ee5\u4e0b\u516c\u5f0f\u8ba1\u7b97\u504f\u79fb\u91cf\u4e86\uff0c\u56e0\u4e3a\u6570\u7ec4\u4e2d\u5305\u542b\u4e86\u4e24\u79cd\u957f\u5ea6\u7684\u5143\u7d20\u3002

        # \u5143\u7d20\u5185\u5b58\u5730\u5740 = \u6570\u7ec4\u5185\u5b58\u5730\u5740 + \u5143\u7d20\u957f\u5ea6 * \u5143\u7d20\u7d22\u5f15\n

        \u5220\u9664\u8282\u70b9\u540e\uff0c\u662f\u5426\u9700\u8981\u628a P.next \u8bbe\u4e3a \\(\\text{None}\\) \u5462\uff1f

        \u4e0d\u4fee\u6539 P.next \u4e5f\u53ef\u4ee5\u3002\u4ece\u8be5\u94fe\u8868\u7684\u89d2\u5ea6\u770b\uff0c\u4ece\u5934\u8282\u70b9\u904d\u5386\u5230\u5c3e\u8282\u70b9\u5df2\u7ecf\u4e0d\u4f1a\u9047\u5230 P \u4e86\u3002\u8fd9\u610f\u5473\u7740\u8282\u70b9 P \u5df2\u7ecf\u4ece\u94fe\u8868\u4e2d\u5220\u9664\u4e86\uff0c\u6b64\u65f6\u8282\u70b9 P \u6307\u5411\u54ea\u91cc\u90fd\u4e0d\u4f1a\u5bf9\u8be5\u94fe\u8868\u4ea7\u751f\u5f71\u54cd\u3002

        \u4ece\u5783\u573e\u56de\u6536\u7684\u89d2\u5ea6\u770b\uff0c\u5bf9\u4e8e Java\u3001Python\u3001Go \u7b49\u62e5\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\u7684\u8bed\u8a00\u6765\u8bf4\uff0c\u8282\u70b9 P \u662f\u5426\u88ab\u56de\u6536\u53d6\u51b3\u4e8e\u662f\u5426\u4ecd\u5b58\u5728\u6307\u5411\u5b83\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f P.next \u7684\u503c\u3002\u5728 C \u548c C++ \u7b49\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u91ca\u653e\u8282\u70b9\u5185\u5b58\u3002

        \u5728\u94fe\u8868\u4e2d\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002\u4f46\u662f\u589e\u5220\u4e4b\u524d\u90fd\u9700\u8981 \\(O(n)\\) \u7684\u65f6\u95f4\u67e5\u627e\u5143\u7d20\uff0c\u90a3\u4e3a\u4ec0\u4e48\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u662f \\(O(n)\\) \u5462\uff1f

        \u5982\u679c\u662f\u5148\u67e5\u627e\u5143\u7d20\u3001\u518d\u5220\u9664\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u786e\u5b9e\u662f \\(O(n)\\) \u3002\u7136\u800c\uff0c\u94fe\u8868\u7684 \\(O(1)\\) \u589e\u5220\u7684\u4f18\u52bf\u53ef\u4ee5\u5728\u5176\u4ed6\u5e94\u7528\u4e0a\u5f97\u5230\u4f53\u73b0\u3002\u4f8b\u5982\uff0c\u53cc\u5411\u961f\u5217\u9002\u5408\u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\uff0c\u6211\u4eec\u7ef4\u62a4\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\u59cb\u7ec8\u6307\u5411\u5934\u8282\u70b9\u3001\u5c3e\u8282\u70b9\uff0c\u6bcf\u6b21\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u90fd\u662f \\(O(1)\\) \u3002

        \u56fe\u201c\u94fe\u8868\u5b9a\u4e49\u4e0e\u5b58\u50a8\u65b9\u5f0f\u201d\u4e2d\uff0c\u6d45\u84dd\u8272\u7684\u5b58\u50a8\u8282\u70b9\u6307\u9488\u662f\u5360\u7528\u4e00\u5757\u5185\u5b58\u5730\u5740\u5417\uff1f\u8fd8\u662f\u548c\u8282\u70b9\u503c\u5404\u5360\u4e00\u534a\u5462\uff1f

        \u8be5\u793a\u610f\u56fe\u53ea\u662f\u5b9a\u6027\u8868\u793a\uff0c\u5b9a\u91cf\u8868\u793a\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u5206\u6790\u3002

        • \u4e0d\u540c\u7c7b\u578b\u7684\u8282\u70b9\u503c\u5360\u7528\u7684\u7a7a\u95f4\u662f\u4e0d\u540c\u7684\uff0c\u6bd4\u5982 int\u3001long\u3001double \u548c\u5b9e\u4f8b\u5bf9\u8c61\u7b49\u3002
        • \u6307\u9488\u53d8\u91cf\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u5927\u5c0f\u6839\u636e\u6240\u4f7f\u7528\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ca\u7f16\u8bd1\u73af\u5883\u800c\u5b9a\uff0c\u5927\u591a\u4e3a 8 \u5b57\u8282\u6216 4 \u5b57\u8282\u3002

        \u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20\u662f\u5426\u65f6\u65f6\u523b\u523b\u90fd\u4e3a \\(O(1)\\) \uff1f

        \u5982\u679c\u6dfb\u52a0\u5143\u7d20\u65f6\u8d85\u51fa\u5217\u8868\u957f\u5ea6\uff0c\u5219\u9700\u8981\u5148\u6269\u5bb9\u5217\u8868\u518d\u6dfb\u52a0\u3002\u7cfb\u7edf\u4f1a\u7533\u8bf7\u4e00\u5757\u65b0\u7684\u5185\u5b58\uff0c\u5e76\u5c06\u539f\u5217\u8868\u7684\u6240\u6709\u5143\u7d20\u642c\u8fd0\u8fc7\u53bb\uff0c\u8fd9\u65f6\u5019\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u4f1a\u662f \\(O(n)\\) \u3002

        \u201c\u5217\u8868\u7684\u51fa\u73b0\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u6570\u7ec4\u7684\u5b9e\u7528\u6027\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u6d6a\u8d39\u201d\uff0c\u8fd9\u91cc\u7684\u7a7a\u95f4\u6d6a\u8d39\u662f\u6307\u989d\u5916\u589e\u52a0\u7684\u53d8\u91cf\u5982\u5bb9\u91cf\u3001\u957f\u5ea6\u3001\u6269\u5bb9\u500d\u6570\u6240\u5360\u7684\u5185\u5b58\u5417\uff1f

        \u8fd9\u91cc\u7684\u7a7a\u95f4\u6d6a\u8d39\u4e3b\u8981\u6709\u4e24\u65b9\u9762\u542b\u4e49\uff1a\u4e00\u65b9\u9762\uff0c\u5217\u8868\u90fd\u4f1a\u8bbe\u5b9a\u4e00\u4e2a\u521d\u59cb\u957f\u5ea6\uff0c\u6211\u4eec\u4e0d\u4e00\u5b9a\u9700\u8981\u7528\u8fd9\u4e48\u591a\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u4e3a\u4e86\u9632\u6b62\u9891\u7e41\u6269\u5bb9\uff0c\u6269\u5bb9\u4e00\u822c\u4f1a\u4e58\u4ee5\u4e00\u4e2a\u7cfb\u6570\uff0c\u6bd4\u5982 \\(\\times 1.5\\) \u3002\u8fd9\u6837\u4e00\u6765\uff0c\u4e5f\u4f1a\u51fa\u73b0\u5f88\u591a\u7a7a\u4f4d\uff0c\u6211\u4eec\u901a\u5e38\u4e0d\u80fd\u5b8c\u5168\u586b\u6ee1\u5b83\u4eec\u3002

        \u5728 Python \u4e2d\u521d\u59cb\u5316 n = [1, 2, 3] \u540e\uff0c\u8fd9 3 \u4e2a\u5143\u7d20\u7684\u5730\u5740\u662f\u76f8\u8fde\u7684\uff0c\u4f46\u662f\u521d\u59cb\u5316 m = [2, 1, 3] \u4f1a\u53d1\u73b0\u5b83\u4eec\u6bcf\u4e2a\u5143\u7d20\u7684 id \u5e76\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u800c\u662f\u5206\u522b\u8ddf n \u4e2d\u7684\u76f8\u540c\u3002\u8fd9\u4e9b\u5143\u7d20\u7684\u5730\u5740\u4e0d\u8fde\u7eed\uff0c\u90a3\u4e48 m \u8fd8\u662f\u6570\u7ec4\u5417\uff1f

        \u5047\u5982\u628a\u5217\u8868\u5143\u7d20\u6362\u6210\u94fe\u8868\u8282\u70b9 n = [n1, n2, n3, n4, n5] \uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u8fd9 5 \u4e2a\u8282\u70b9\u5bf9\u8c61\u4e5f\u5206\u6563\u5b58\u50a8\u5728\u5185\u5b58\u5404\u5904\u3002\u7136\u800c\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868\u7d22\u5f15\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u83b7\u53d6\u8282\u70b9\u5185\u5b58\u5730\u5740\uff0c\u4ece\u800c\u8bbf\u95ee\u5230\u5bf9\u5e94\u7684\u8282\u70b9\u3002\u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u662f\u8282\u70b9\u7684\u5f15\u7528\uff0c\u800c\u975e\u8282\u70b9\u672c\u8eab\u3002

        \u4e0e\u8bb8\u591a\u8bed\u8a00\u4e0d\u540c\uff0cPython \u4e2d\u7684\u6570\u5b57\u4e5f\u88ab\u5305\u88c5\u4e3a\u5bf9\u8c61\uff0c\u5217\u8868\u4e2d\u5b58\u50a8\u7684\u4e0d\u662f\u6570\u5b57\u672c\u8eab\uff0c\u800c\u662f\u5bf9\u6570\u5b57\u7684\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0\u4e24\u4e2a\u6570\u7ec4\u4e2d\u7684\u76f8\u540c\u6570\u5b57\u62e5\u6709\u540c\u4e00\u4e2a id \uff0c\u5e76\u4e14\u8fd9\u4e9b\u6570\u5b57\u7684\u5185\u5b58\u5730\u5740\u65e0\u987b\u8fde\u7eed\u3002

        C++ STL \u91cc\u9762\u7684 std::list \u5df2\u7ecf\u5b9e\u73b0\u4e86\u53cc\u5411\u94fe\u8868\uff0c\u4f46\u597d\u50cf\u4e00\u4e9b\u7b97\u6cd5\u4e66\u4e0a\u4e0d\u600e\u4e48\u76f4\u63a5\u4f7f\u7528\u5b83\uff0c\u662f\u4e0d\u662f\u56e0\u4e3a\u6709\u4ec0\u4e48\u5c40\u9650\u6027\u5462\uff1f

        \u4e00\u65b9\u9762\uff0c\u6211\u4eec\u5f80\u5f80\u66f4\u9752\u7750\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u7b97\u6cd5\uff0c\u800c\u53ea\u5728\u5fc5\u8981\u65f6\u624d\u4f7f\u7528\u94fe\u8868\uff0c\u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0\u3002

        • \u7a7a\u95f4\u5f00\u9500\uff1a\u7531\u4e8e\u6bcf\u4e2a\u5143\u7d20\u9700\u8981\u4e24\u4e2a\u989d\u5916\u7684\u6307\u9488\uff08\u4e00\u4e2a\u7528\u4e8e\u524d\u4e00\u4e2a\u5143\u7d20\uff0c\u4e00\u4e2a\u7528\u4e8e\u540e\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u6240\u4ee5 std::list \u901a\u5e38\u6bd4 std::vector \u66f4\u5360\u7528\u7a7a\u95f4\u3002
        • \u7f13\u5b58\u4e0d\u53cb\u597d\uff1a\u7531\u4e8e\u6570\u636e\u4e0d\u662f\u8fde\u7eed\u5b58\u653e\u7684\uff0c\u56e0\u6b64 std::list \u5bf9\u7f13\u5b58\u7684\u5229\u7528\u7387\u8f83\u4f4e\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cstd::vector \u7684\u6027\u80fd\u4f1a\u66f4\u597d\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5fc5\u8981\u4f7f\u7528\u94fe\u8868\u7684\u60c5\u51b5\u4e3b\u8981\u662f\u4e8c\u53c9\u6811\u548c\u56fe\u3002\u6808\u548c\u961f\u5217\u5f80\u5f80\u4f1a\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684 stack \u548c queue \uff0c\u800c\u975e\u94fe\u8868\u3002

        \u521d\u59cb\u5316\u5217\u8868 res = [0] * self.size() \u64cd\u4f5c\uff0c\u4f1a\u5bfc\u81f4 res \u7684\u6bcf\u4e2a\u5143\u7d20\u5f15\u7528\u76f8\u540c\u7684\u5730\u5740\u5417\uff1f

        \u4e0d\u4f1a\u3002\u4f46\u4e8c\u7ef4\u6570\u7ec4\u4f1a\u6709\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f8b\u5982\u521d\u59cb\u5316\u4e8c\u7ef4\u5217\u8868 res = [[0] * self.size()] \uff0c\u5219\u591a\u6b21\u5f15\u7528\u4e86\u540c\u4e00\u4e2a\u5217\u8868 [0] \u3002

        \u5728\u5220\u9664\u8282\u70b9\u4e2d\uff0c\u9700\u8981\u65ad\u5f00\u8be5\u8282\u70b9\u4e0e\u5176\u540e\u7ee7\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\u6307\u5411\u5417\uff1f

        \u4ece\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\uff08\u505a\u9898\uff09\u7684\u89d2\u5ea6\u770b\uff0c\u4e0d\u65ad\u5f00\u6ca1\u6709\u5173\u7cfb\uff0c\u53ea\u8981\u4fdd\u8bc1\u7a0b\u5e8f\u7684\u903b\u8f91\u662f\u6b63\u786e\u7684\u5c31\u884c\u3002\u4ece\u6807\u51c6\u5e93\u7684\u89d2\u5ea6\u770b\uff0c\u65ad\u5f00\u66f4\u52a0\u5b89\u5168\u3001\u903b\u8f91\u66f4\u52a0\u6e05\u6670\u3002\u5982\u679c\u4e0d\u65ad\u5f00\uff0c\u5047\u8bbe\u88ab\u5220\u9664\u8282\u70b9\u672a\u88ab\u6b63\u5e38\u56de\u6536\uff0c\u90a3\u4e48\u5b83\u4e5f\u4f1a\u5f71\u54cd\u540e\u7ee7\u8282\u70b9\u7684\u5185\u5b58\u56de\u6536\u3002

        "},{"location":"chapter_backtracking/","title":"\u7b2c 13 \u7ae0 \u00a0 \u56de\u6eaf","text":"

        Abstract

        \u6211\u4eec\u5982\u540c\u8ff7\u5bab\u4e2d\u7684\u63a2\u7d22\u8005\uff0c\u5728\u524d\u8fdb\u7684\u9053\u8def\u4e0a\u53ef\u80fd\u4f1a\u9047\u5230\u56f0\u96be\u3002

        \u56de\u6eaf\u7684\u529b\u91cf\u8ba9\u6211\u4eec\u80fd\u591f\u91cd\u65b0\u5f00\u59cb\uff0c\u4e0d\u65ad\u5c1d\u8bd5\uff0c\u6700\u7ec8\u627e\u5230\u901a\u5f80\u5149\u660e\u7684\u51fa\u53e3\u3002

        "},{"location":"chapter_backtracking/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 13.1 \u00a0 \u56de\u6eaf\u7b97\u6cd5
        • 13.2 \u00a0 \u5168\u6392\u5217\u95ee\u9898
        • 13.3 \u00a0 \u5b50\u96c6\u548c\u95ee\u9898
        • 13.4 \u00a0 N \u7687\u540e\u95ee\u9898
        • 13.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_backtracking/backtracking_algorithm/","title":"13.1 \u00a0 \u56de\u6eaf\u7b97\u6cd5","text":"

        \u300c\u56de\u6eaf\u7b97\u6cd5 backtracking algorithm\u300d\u662f\u4e00\u79cd\u901a\u8fc7\u7a77\u4e3e\u6765\u89e3\u51b3\u95ee\u9898\u7684\u65b9\u6cd5\uff0c\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f\u4ece\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\u51fa\u53d1\uff0c\u66b4\u529b\u641c\u7d22\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5f53\u9047\u5230\u6b63\u786e\u7684\u89e3\u5219\u5c06\u5176\u8bb0\u5f55\uff0c\u76f4\u5230\u627e\u5230\u89e3\u6216\u8005\u5c1d\u8bd5\u4e86\u6240\u6709\u53ef\u80fd\u7684\u9009\u62e9\u90fd\u65e0\u6cd5\u627e\u5230\u89e3\u4e3a\u6b62\u3002

        \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u91c7\u7528\u201c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u6765\u904d\u5386\u89e3\u7a7a\u95f4\u3002\u5728\u201c\u4e8c\u53c9\u6811\u201d\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u63d0\u5230\u524d\u5e8f\u3001\u4e2d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5229\u7528\u524d\u5e8f\u904d\u5386\u6784\u9020\u4e00\u4e2a\u56de\u6eaf\u95ee\u9898\uff0c\u9010\u6b65\u4e86\u89e3\u56de\u6eaf\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u3002

        \u4f8b\u9898\u4e00

        \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\uff0c\u641c\u7d22\u5e76\u8bb0\u5f55\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u8282\u70b9\u5217\u8868\u3002

        \u5bf9\u4e8e\u6b64\u9898\uff0c\u6211\u4eec\u524d\u5e8f\u904d\u5386\u8fd9\u68f5\u6811\uff0c\u5e76\u5224\u65ad\u5f53\u524d\u8282\u70b9\u7684\u503c\u662f\u5426\u4e3a \\(7\\) \uff0c\u82e5\u662f\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u7684\u503c\u52a0\u5165\u7ed3\u679c\u5217\u8868 res \u4e4b\u4e2d\u3002\u76f8\u5173\u8fc7\u7a0b\u5b9e\u73b0\u5982\u56fe 13-1 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_i_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00\"\"\"\nif root is None:\nreturn\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(root)\npre_order(root.left)\npre_order(root.right)\n
        preorder_traversal_i_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr) {\nreturn;\n}\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(root);\n}\npreOrder(root->left);\npreOrder(root->right);\n}\n
        preorder_traversal_i_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode root) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(root);\n}\npreOrder(root.left);\npreOrder(root.right);\n}\n
        preorder_traversal_i_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid PreOrder(TreeNode? root) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(root);\n}\nPreOrder(root.left);\nPreOrder(root.right);\n}\n
        preorder_traversal_i_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrderI(root *TreeNode, res *[]*TreeNode) {\nif root == nil {\nreturn\n}\nif (root.Val).(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, root)\n}\npreOrderI(root.Left, res)\npreOrderI(root.Right, res)\n}\n
        preorder_traversal_i_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(root)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n}\n
        preorder_traversal_i_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root, res) {\nif (root === null) {\nreturn;\n}\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root: TreeNode | null, res: TreeNode[]): void {\nif (root === null) {\nreturn;\n}\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode? root, List<TreeNode> res) {\nif (root == null) {\nreturn;\n}\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(root);\n}\npreOrder(root.left, res);\npreOrder(root.right, res);\n}\n
        preorder_traversal_i_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfn pre_order(res: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\nif root.is_none() {\nreturn;\n}\nif let Some(node) = root {\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(node.clone());\n}\npre_order(res, node.borrow().left.clone());\npre_order(res, node.borrow().right.clone());\n}\n}\n
        preorder_traversal_i_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\nif (root == NULL) {\nreturn;\n}\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres[resSize++] = root;\n}\npreOrder(root->left);\npreOrder(root->right);\n}\n
        preorder_traversal_i_compact.zig
        [class]{}-[func]{preOrder}\n

        \u56fe 13-1 \u00a0 \u5728\u524d\u5e8f\u904d\u5386\u4e2d\u641c\u7d22\u8282\u70b9

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1311","title":"13.1.1 \u00a0 \u5c1d\u8bd5\u4e0e\u56de\u9000","text":"

        \u4e4b\u6240\u4ee5\u79f0\u4e4b\u4e3a\u56de\u6eaf\u7b97\u6cd5\uff0c\u662f\u56e0\u4e3a\u8be5\u7b97\u6cd5\u5728\u641c\u7d22\u89e3\u7a7a\u95f4\u65f6\u4f1a\u91c7\u7528\u201c\u5c1d\u8bd5\u201d\u4e0e\u201c\u56de\u9000\u201d\u7684\u7b56\u7565\u3002\u5f53\u7b97\u6cd5\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u9047\u5230\u67d0\u4e2a\u72b6\u6001\u65e0\u6cd5\u7ee7\u7eed\u524d\u8fdb\u6216\u65e0\u6cd5\u5f97\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u65f6\uff0c\u5b83\u4f1a\u64a4\u9500\u4e0a\u4e00\u6b65\u7684\u9009\u62e9\uff0c\u9000\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5e76\u5c1d\u8bd5\u5176\u4ed6\u53ef\u80fd\u7684\u9009\u62e9\u3002

        \u5bf9\u4e8e\u4f8b\u9898\u4e00\uff0c\u8bbf\u95ee\u6bcf\u4e2a\u8282\u70b9\u90fd\u4ee3\u8868\u4e00\u6b21\u201c\u5c1d\u8bd5\u201d\uff0c\u800c\u8d8a\u8fc7\u53f6\u8282\u70b9\u6216\u8fd4\u56de\u7236\u8282\u70b9\u7684 return \u5219\u8868\u793a\u201c\u56de\u9000\u201d\u3002

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u56de\u9000\u5e76\u4e0d\u4ec5\u4ec5\u5305\u62ec\u51fd\u6570\u8fd4\u56de\u3002\u4e3a\u89e3\u91ca\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u5bf9\u4f8b\u9898\u4e00\u7a0d\u4f5c\u62d3\u5c55\u3002

        \u4f8b\u9898\u4e8c

        \u5728\u4e8c\u53c9\u6811\u4e2d\u641c\u7d22\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u6839\u8282\u70b9\u5230\u8fd9\u4e9b\u8282\u70b9\u7684\u8def\u5f84\u3002

        \u5728\u4f8b\u9898\u4e00\u4ee3\u7801\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u5217\u8868 path \u8bb0\u5f55\u8bbf\u95ee\u8fc7\u7684\u8282\u70b9\u8def\u5f84\u3002\u5f53\u8bbf\u95ee\u5230\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\u65f6\uff0c\u5219\u590d\u5236 path \u5e76\u6dfb\u52a0\u8fdb\u7ed3\u679c\u5217\u8868 res \u3002\u904d\u5386\u5b8c\u6210\u540e\uff0cres \u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u6240\u6709\u7684\u89e3\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_ii_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c\"\"\"\nif root is None:\nreturn\n# \u5c1d\u8bd5\npath.append(root)\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(list(path))\npre_order(root.left)\npre_order(root.right)\n# \u56de\u9000\npath.pop()\n
        preorder_traversal_ii_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push_back(root);\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(path);\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npath.pop_back();\n}\n
        preorder_traversal_ii_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode root) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(new ArrayList<>(path));\n}\npreOrder(root.left);\npreOrder(root.right);\n// \u56de\u9000\npath.remove(path.size() - 1);\n}\n
        preorder_traversal_ii_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid PreOrder(TreeNode? root) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.Add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(new List<TreeNode>(path));\n}\nPreOrder(root.left);\nPreOrder(root.right);\n// \u56de\u9000\npath.RemoveAt(path.Count - 1);\n}\n
        preorder_traversal_ii_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunc preOrderII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {\nif root == nil {\nreturn\n}\n// \u5c1d\u8bd5\n*path = append(*path, root)\nif root.Val.(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, *path)\n}\npreOrderII(root.Left, res, path)\npreOrderII(root.Right, res, path)\n// \u56de\u9000\n*path = (*path)[:len(*path)-1]\n}\n
        preorder_traversal_ii_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u5c1d\u8bd5\npath.append(root)\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(path)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n// \u56de\u9000\npath.removeLast()\n}\n
        preorder_traversal_ii_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(root, path, res) {\nif (root === null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_ii_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(\nroot: TreeNode | null,\npath: TreeNode[],\nres: TreeNode[][]\n): void {\nif (root === null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_ii_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(\nTreeNode? root,\nList<TreeNode> path,\nList<List<TreeNode>> res,\n) {\nif (root == null) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(List.from(path));\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.removeLast();\n}\n
        preorder_traversal_ii_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfn pre_order(res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>, path: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\nif root.is_none() {\nreturn;\n}\nif let Some(node) = root {\n// \u5c1d\u8bd5\npath.push(node.clone());\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(path.clone());\n}\npre_order(res, path, node.borrow().left.clone());\npre_order(res, path, node.borrow().right.clone());\n// \u56de\u9000\npath.remove(path.len() -  1);\n}\n}\n
        preorder_traversal_ii_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\nif (root == NULL) {\nreturn;\n}\n// \u5c1d\u8bd5\npath[pathSize++] = root;\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nfor (int i = 0; i < pathSize; ++i) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npathSize--;\n}\n
        preorder_traversal_ii_compact.zig
        [class]{}-[func]{preOrder}\n

        \u5728\u6bcf\u6b21\u201c\u5c1d\u8bd5\u201d\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u5c06\u5f53\u524d\u8282\u70b9\u6dfb\u52a0\u8fdb path \u6765\u8bb0\u5f55\u8def\u5f84\uff1b\u800c\u5728\u201c\u56de\u9000\u201d\u524d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8be5\u8282\u70b9\u4ece path \u4e2d\u5f39\u51fa\uff0c\u4ee5\u6062\u590d\u672c\u6b21\u5c1d\u8bd5\u4e4b\u524d\u7684\u72b6\u6001\u3002

        \u89c2\u5bdf\u56fe 13-2 \u6240\u793a\u7684\u8fc7\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5c1d\u8bd5\u548c\u56de\u9000\u7406\u89e3\u4e3a\u201c\u524d\u8fdb\u201d\u4e0e\u201c\u64a4\u9500\u201d\uff0c\u4e24\u4e2a\u64cd\u4f5c\u4e92\u4e3a\u9006\u5411\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 13-2 \u00a0 \u5c1d\u8bd5\u4e0e\u56de\u9000

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1312","title":"13.1.2 \u00a0 \u526a\u679d","text":"

        \u590d\u6742\u7684\u56de\u6eaf\u95ee\u9898\u901a\u5e38\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u7ea6\u675f\u6761\u4ef6\uff0c\u7ea6\u675f\u6761\u4ef6\u901a\u5e38\u53ef\u7528\u4e8e\u201c\u526a\u679d\u201d\u3002

        \u4f8b\u9898\u4e09

        \u5728\u4e8c\u53c9\u6811\u4e2d\u641c\u7d22\u6240\u6709\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\uff0c\u8bf7\u8fd4\u56de\u6839\u8282\u70b9\u5230\u8fd9\u4e9b\u8282\u70b9\u7684\u8def\u5f84\uff0c\u5e76\u8981\u6c42\u8def\u5f84\u4e2d\u4e0d\u5305\u542b\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u3002

        \u4e3a\u4e86\u6ee1\u8db3\u4ee5\u4e0a\u7ea6\u675f\u6761\u4ef6\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u526a\u679d\u64cd\u4f5c\uff1a\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u82e5\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\uff0c\u5219\u63d0\u524d\u8fd4\u56de\uff0c\u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_iii_compact.py
        def pre_order(root: TreeNode):\n\"\"\"\u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09\"\"\"\n# \u526a\u679d\nif root is None or root.val == 3:\nreturn\n# \u5c1d\u8bd5\npath.append(root)\nif root.val == 7:\n# \u8bb0\u5f55\u89e3\nres.append(list(path))\npre_order(root.left)\npre_order(root.right)\n# \u56de\u9000\npath.pop()\n
        preorder_traversal_iii_compact.cpp
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n// \u526a\u679d\nif (root == nullptr || root->val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push_back(root);\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nres.push_back(path);\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npath.pop_back();\n}\n
        preorder_traversal_iii_compact.java
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode root) {\n// \u526a\u679d\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(new ArrayList<>(path));\n}\npreOrder(root.left);\npreOrder(root.right);\n// \u56de\u9000\npath.remove(path.size() - 1);\n}\n
        preorder_traversal_iii_compact.cs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid PreOrder(TreeNode? root) {\n// \u526a\u679d\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.Add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.Add(new List<TreeNode>(path));\n}\nPreOrder(root.left);\nPreOrder(root.right);\n// \u56de\u9000\npath.RemoveAt(path.Count - 1);\n}\n
        preorder_traversal_iii_compact.go
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunc preOrderIII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {\n// \u526a\u679d\nif root == nil || root.Val == 3 {\nreturn\n}\n// \u5c1d\u8bd5\n*path = append(*path, root)\nif root.Val.(int) == 7 {\n// \u8bb0\u5f55\u89e3\n*res = append(*res, *path)\n}\npreOrderIII(root.Left, res, path)\npreOrderIII(root.Right, res, path)\n// \u56de\u9000\n*path = (*path)[:len(*path)-1]\n}\n
        preorder_traversal_iii_compact.swift
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunc preOrder(root: TreeNode?) {\n// \u526a\u679d\nguard let root = root, root.val != 3 else {\nreturn\n}\n// \u5c1d\u8bd5\npath.append(root)\nif root.val == 7 {\n// \u8bb0\u5f55\u89e3\nres.append(path)\n}\npreOrder(root: root.left)\npreOrder(root: root.right)\n// \u56de\u9000\npath.removeLast()\n}\n
        preorder_traversal_iii_compact.js
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(root, path, res) {\n// \u526a\u679d\nif (root === null || root.val === 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_iii_compact.ts
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(\nroot: TreeNode | null,\npath: TreeNode[],\nres: TreeNode[][]\n): void {\n// \u526a\u679d\nif (root === null || root.val === 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.push(root);\nif (root.val === 7) {\n// \u8bb0\u5f55\u89e3\nres.push([...path]);\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.pop();\n}\n
        preorder_traversal_iii_compact.dart
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(\nTreeNode? root,\nList<TreeNode> path,\nList<List<TreeNode>> res,\n) {\nif (root == null || root.val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath.add(root);\nif (root.val == 7) {\n// \u8bb0\u5f55\u89e3\nres.add(List.from(path));\n}\npreOrder(root.left, path, res);\npreOrder(root.right, path, res);\n// \u56de\u9000\npath.removeLast();\n}\n
        preorder_traversal_iii_compact.rs
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfn pre_order(res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>, path: &mut Vec<Rc<RefCell<TreeNode>>>, root: Option<Rc<RefCell<TreeNode>>>) {\n// \u526a\u679d\nif root.is_none() || root.as_ref().unwrap().borrow().val == 3 {\nreturn;\n}\nif let Some(node) = root {\n// \u5c1d\u8bd5\npath.push(node.clone());\nif node.borrow().val == 7 {\n// \u8bb0\u5f55\u89e3\nres.push(path.clone());\n}\npre_order(res, path, node.borrow().left.clone());\npre_order(res, path, node.borrow().right.clone());\n// \u56de\u9000\npath.remove(path.len() -  1);\n}\n}\n
        preorder_traversal_iii_compact.c
        /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n// \u526a\u679d\nif (root == NULL || root->val == 3) {\nreturn;\n}\n// \u5c1d\u8bd5\npath[pathSize++] = root;\nif (root->val == 7) {\n// \u8bb0\u5f55\u89e3\nfor (int i = 0; i < pathSize; i++) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\npreOrder(root->left);\npreOrder(root->right);\n// \u56de\u9000\npathSize--;\n}\n
        preorder_traversal_iii_compact.zig
        [class]{}-[func]{preOrder}\n

        \u201c\u526a\u679d\u201d\u662f\u4e00\u4e2a\u975e\u5e38\u5f62\u8c61\u7684\u540d\u8bcd\u3002\u5982\u56fe 13-3 \u6240\u793a\uff0c\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u201c\u526a\u6389\u201d\u4e86\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u641c\u7d22\u5206\u652f\uff0c\u907f\u514d\u8bb8\u591a\u65e0\u610f\u4e49\u7684\u5c1d\u8bd5\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u641c\u7d22\u6548\u7387\u3002

        \u56fe 13-3 \u00a0 \u6839\u636e\u7ea6\u675f\u6761\u4ef6\u526a\u679d

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1313","title":"13.1.3 \u00a0 \u6846\u67b6\u4ee3\u7801","text":"

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c1d\u8bd5\u5c06\u56de\u6eaf\u7684\u201c\u5c1d\u8bd5\u3001\u56de\u9000\u3001\u526a\u679d\u201d\u7684\u4e3b\u4f53\u6846\u67b6\u63d0\u70bc\u51fa\u6765\uff0c\u63d0\u5347\u4ee3\u7801\u7684\u901a\u7528\u6027\u3002

        \u5728\u4ee5\u4e0b\u6846\u67b6\u4ee3\u7801\u4e2d\uff0cstate \u8868\u793a\u95ee\u9898\u7684\u5f53\u524d\u72b6\u6001\uff0cchoices \u8868\u793a\u5f53\u524d\u72b6\u6001\u4e0b\u53ef\u4ee5\u505a\u51fa\u7684\u9009\u62e9\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def backtrack(state: State, choices: list[choice], res: list[state]):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\u6846\u67b6\"\"\"\n# \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif is_solution(state):\n# \u8bb0\u5f55\u89e3\nrecord_solution(state, res)\n# \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice):\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice)\nbacktrack(state, choices, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice)\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State *state, vector<Choice *> &choices, vector<State *> &res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice : choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State state, List<Choice> choices, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice : choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid Backtrack(State state, List<Choice> choices, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (IsSolution(state)) {\n// \u8bb0\u5f55\u89e3\nRecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (Choice choice in choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (IsValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nMakeChoice(state, choice);\nBacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nUndoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunc backtrack(state *State, choices []Choice, res *[]State) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif isSolution(state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res)\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice)\nbacktrack(state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice)\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunc backtrack(state: inout State, choices: [Choice], res: inout [State]) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif isSolution(state: state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state: state, res: &res)\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state: state, choice: choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state: &state, choice: choice)\nbacktrack(state: &state, choices: choices, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state: &state, choice: choice)\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunction backtrack(state, choices, res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let choice of choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfunction backtrack(state: State, choices: Choice[], res: State[]): void {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let choice of choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State state, List<Choice>, List<State> res) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Choice choice in choices) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nfn backtrack(state: &mut State, choices: &Vec<Choice>, res: &mut Vec<State>) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif is_solution(state) {\n// \u8bb0\u5f55\u89e3\nrecord_solution(state, res);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice);\nbacktrack(state, choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice);\n}\n}\n}\n
        /* \u56de\u6eaf\u7b97\u6cd5\u6846\u67b6 */\nvoid backtrack(State *state, Choice *choices, int numChoices, State *res, int numRes) {\n// \u5224\u65ad\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res, numRes);\n// \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < numChoices; i++) {\n// \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, &choices[i])) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, &choices[i]);\nbacktrack(state, choices, numChoices, res, numRes);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, &choices[i]);\n}\n}\n}\n
        \n

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u57fa\u4e8e\u6846\u67b6\u4ee3\u7801\u6765\u89e3\u51b3\u4f8b\u9898\u4e09\u3002\u72b6\u6001 state \u4e3a\u8282\u70b9\u904d\u5386\u8def\u5f84\uff0c\u9009\u62e9 choices \u4e3a\u5f53\u524d\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\uff0c\u7ed3\u679c res \u662f\u8def\u5f84\u5217\u8868\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig preorder_traversal_iii_template.py
        def is_solution(state: list[TreeNode]) -> bool:\n\"\"\"\u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3\"\"\"\nreturn state and state[-1].val == 7\ndef record_solution(state: list[TreeNode], res: list[list[TreeNode]]):\n\"\"\"\u8bb0\u5f55\u89e3\"\"\"\nres.append(list(state))\ndef is_valid(state: list[TreeNode], choice: TreeNode) -> bool:\n\"\"\"\u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5\"\"\"\nreturn choice is not None and choice.val != 3\ndef make_choice(state: list[TreeNode], choice: TreeNode):\n\"\"\"\u66f4\u65b0\u72b6\u6001\"\"\"\nstate.append(choice)\ndef undo_choice(state: list[TreeNode], choice: TreeNode):\n\"\"\"\u6062\u590d\u72b6\u6001\"\"\"\nstate.pop()\ndef backtrack(\nstate: list[TreeNode], choices: list[TreeNode], res: list[list[TreeNode]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09\"\"\"\n# \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif is_solution(state):\n# \u8bb0\u5f55\u89e3\nrecord_solution(state, res)\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice):\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice)\n
        preorder_traversal_iii_template.cpp
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(vector<TreeNode *> &state) {\nreturn !state.empty() && state.back()->val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(vector<TreeNode *> &state, vector<vector<TreeNode *>> &res) {\nres.push_back(state);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(vector<TreeNode *> &state, TreeNode *choice) {\nreturn choice != nullptr && choice->val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(vector<TreeNode *> &state, TreeNode *choice) {\nstate.push_back(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(vector<TreeNode *> &state, TreeNode *choice) {\nstate.pop_back();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode *choice : choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nvector<TreeNode *> nextChoices{choice->left, choice->right};\nbacktrack(state, nextChoices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.java
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nboolean isSolution(List<TreeNode> state) {\nreturn !state.isEmpty() && state.get(state.size() - 1).val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.add(new ArrayList<>(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nboolean isValid(List<TreeNode> state, TreeNode choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode choice) {\nstate.add(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode choice) {\nstate.remove(state.size() - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode choice : choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, Arrays.asList(choice.left, choice.right), res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.cs
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool IsSolution(List<TreeNode> state) {\nreturn state.Count != 0 && state[^1].val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid RecordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.Add(new List<TreeNode>(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool IsValid(List<TreeNode> state, TreeNode choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid MakeChoice(List<TreeNode> state, TreeNode choice) {\nstate.Add(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid UndoChoice(List<TreeNode> state, TreeNode choice) {\nstate.RemoveAt(state.Count - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid Backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (IsSolution(state)) {\n// \u8bb0\u5f55\u89e3\nRecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (TreeNode choice in choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (IsValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nMakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, [choice.left!, choice.right!], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nUndoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.go
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunc isSolution(state *[]*TreeNode) bool {\nreturn len(*state) != 0 && (*state)[len(*state)-1].Val == 7\n}\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state *[]*TreeNode, res *[][]*TreeNode) {\n*res = append(*res, *state)\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunc isValid(state *[]*TreeNode, choice *TreeNode) bool {\nreturn choice != nil && choice.Val != 3\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state *[]*TreeNode, choice *TreeNode) {\n*state = append(*state, choice)\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state *[]*TreeNode, choice *TreeNode) {\n*state = (*state)[:len(*state)-1]\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunc backtrackIII(state *[]*TreeNode, choices *[]*TreeNode, res *[][]*TreeNode) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif isSolution(state) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range *choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state, choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\ntemp := make([]*TreeNode, 0)\ntemp = append(temp, choice.Left, choice.Right)\nbacktrackIII(state, &temp, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice)\n}\n}\n}\n
        preorder_traversal_iii_template.swift
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunc isSolution(state: [TreeNode]) -> Bool {\n!state.isEmpty && state.last!.val == 7\n}\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state: [TreeNode], res: inout [[TreeNode]]) {\nres.append(state)\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunc isValid(state: [TreeNode], choice: TreeNode?) -> Bool {\nchoice != nil && choice!.val != 3\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state: inout [TreeNode], choice: TreeNode) {\nstate.append(choice)\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state: inout [TreeNode], choice: TreeNode) {\nstate.removeLast()\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunc backtrack(state: inout [TreeNode], choices: [TreeNode], res: inout [[TreeNode]]) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif isSolution(state: state) {\nrecordSolution(state: state, res: &res)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif isValid(state: state, choice: choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state: &state, choice: choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: [choice.left, choice.right].compactMap { $0 }, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state: &state, choice: choice)\n}\n}\n}\n
        preorder_traversal_iii_template.js
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunction isSolution(state) {\nreturn state && state[state.length - 1]?.val === 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state, res) {\nres.push([...state]);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state, choice) {\nreturn choice !== null && choice.val !== 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state, choice) {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state) {\nstate.pop();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(state, choices, res) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state);\n}\n}\n}\n
        preorder_traversal_iii_template.ts
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfunction isSolution(state: TreeNode[]): boolean {\nreturn state && state[state.length - 1]?.val === 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state: TreeNode[], res: TreeNode[][]): void {\nres.push([...state]);\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state: TreeNode[], choice: TreeNode): boolean {\nreturn choice !== null && choice.val !== 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state: TreeNode[], choice: TreeNode): void {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state: TreeNode[]): void {\nstate.pop();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(\nstate: TreeNode[],\nchoices: TreeNode[],\nres: TreeNode[][]\n): void {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state);\n}\n}\n}\n
        preorder_traversal_iii_template.dart
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(List<TreeNode> state) {\nreturn state.isNotEmpty && state.last.val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\nres.add(List.from(state));\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(List<TreeNode> state, TreeNode? choice) {\nreturn choice != null && choice.val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode? choice) {\nstate.add(choice!);\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode? choice) {\nstate.removeLast();\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(\nList<TreeNode> state,\nList<TreeNode?> choices,\nList<List<TreeNode>> res,\n) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution(state)) {\n// \u8bb0\u5f55\u89e3\nrecordSolution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (TreeNode? choice in choices) {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(state, choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(state, choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, [choice!.left, choice.right], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice(state, choice);\n}\n}\n}\n
        preorder_traversal_iii_template.rs
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nfn is_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>) -> bool {\nreturn !state.is_empty() && state.get(state.len() - 1).unwrap().borrow().val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nfn record_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\nres.push(state.clone());\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfn is_valid(_: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) -> bool {\nreturn choice.borrow().val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nfn make_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) {\nstate.push(choice);\n}\n/* \u6062\u590d\u72b6\u6001 */\nfn undo_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, _: Rc<RefCell<TreeNode>>) {\nstate.remove(state.len() - 1);\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfn backtrack(state: &mut Vec<Rc<RefCell<TreeNode>>>, choices: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif is_solution(state) {\n// \u8bb0\u5f55\u89e3\nrecord_solution(state, res);\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif is_valid(state, choice.clone()) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmake_choice(state, choice.clone());\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, &mut vec![choice.borrow().left.clone().unwrap(), choice.borrow().right.clone().unwrap()], res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundo_choice(state, choice.clone());\n}\n}\n}\n
        preorder_traversal_iii_template.c
        /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(void) {\nreturn pathSize > 0 && path[pathSize - 1]->val == 7;\n}\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(void) {\nfor (int i = 0; i < pathSize; i++) {\nres[resSize][i] = path[i];\n}\nresSize++;\n}\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(TreeNode *choice) {\nreturn choice != NULL && choice->val != 3;\n}\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(TreeNode *choice) {\npath[pathSize++] = choice;\n}\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(void) {\npathSize--;\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(TreeNode *choices[2]) {\n// \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\nif (isSolution()) {\n// \u8bb0\u5f55\u89e3\nrecordSolution();\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < 2; i++) {\nTreeNode *choice = choices[i];\n// \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\nif (isValid(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nmakeChoice(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nTreeNode *nextChoices[2] = {choice->left, choice->right};\nbacktrack(nextChoices);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nundoChoice();\n}\n}\n}\n
        preorder_traversal_iii_template.zig
        [class]{}-[func]{isSolution}\n[class]{}-[func]{recordSolution}\n[class]{}-[func]{isValid}\n[class]{}-[func]{makeChoice}\n[class]{}-[func]{undoChoice}\n[class]{}-[func]{backtrack}\n

        \u6839\u636e\u9898\u610f\uff0c\u6211\u4eec\u5728\u627e\u5230\u503c\u4e3a \\(7\\) \u7684\u8282\u70b9\u540e\u5e94\u8be5\u7ee7\u7eed\u641c\u7d22\uff0c\u56e0\u6b64\u9700\u8981\u5c06\u8bb0\u5f55\u89e3\u4e4b\u540e\u7684 return \u8bed\u53e5\u5220\u9664\u3002\u56fe 13-4 \u5bf9\u6bd4\u4e86\u4fdd\u7559\u6216\u5220\u9664 return \u8bed\u53e5\u7684\u641c\u7d22\u8fc7\u7a0b\u3002

        \u56fe 13-4 \u00a0 \u4fdd\u7559\u4e0e\u5220\u9664 return \u7684\u641c\u7d22\u8fc7\u7a0b\u5bf9\u6bd4

        \u76f8\u6bd4\u57fa\u4e8e\u524d\u5e8f\u904d\u5386\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u57fa\u4e8e\u56de\u6eaf\u7b97\u6cd5\u6846\u67b6\u7684\u4ee3\u7801\u5b9e\u73b0\u867d\u7136\u663e\u5f97\u5570\u5506\uff0c\u4f46\u901a\u7528\u6027\u66f4\u597d\u3002\u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u56de\u6eaf\u95ee\u9898\u53ef\u4ee5\u5728\u8be5\u6846\u67b6\u4e0b\u89e3\u51b3\u3002\u6211\u4eec\u53ea\u9700\u6839\u636e\u5177\u4f53\u95ee\u9898\u6765\u5b9a\u4e49 state \u548c choices \uff0c\u5e76\u5b9e\u73b0\u6846\u67b6\u4e2d\u7684\u5404\u4e2a\u65b9\u6cd5\u5373\u53ef\u3002

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1314","title":"13.1.4 \u00a0 \u5e38\u7528\u672f\u8bed","text":"

        \u4e3a\u4e86\u66f4\u6e05\u6670\u5730\u5206\u6790\u7b97\u6cd5\u95ee\u9898\uff0c\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\u56de\u6eaf\u7b97\u6cd5\u4e2d\u5e38\u7528\u672f\u8bed\u7684\u542b\u4e49\uff0c\u5e76\u5bf9\u7167\u4f8b\u9898\u4e09\u7ed9\u51fa\u5bf9\u5e94\u793a\u4f8b\uff0c\u5982\u8868 13-1 \u6240\u793a\u3002

        \u8868 13-1 \u00a0 \u5e38\u89c1\u7684\u56de\u6eaf\u7b97\u6cd5\u672f\u8bed

        \u540d\u8bcd \u5b9a\u4e49 \u4f8b\u9898\u4e09 \u89e3\uff08solution\uff09 \u89e3\u662f\u6ee1\u8db3\u95ee\u9898\u7279\u5b9a\u6761\u4ef6\u7684\u7b54\u6848\uff0c\u53ef\u80fd\u6709\u4e00\u4e2a\u6216\u591a\u4e2a \u6839\u8282\u70b9\u5230\u8282\u70b9 \\(7\\) \u7684\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u6240\u6709\u8def\u5f84 \u7ea6\u675f\u6761\u4ef6\uff08constraint\uff09 \u7ea6\u675f\u6761\u4ef6\u662f\u95ee\u9898\u4e2d\u9650\u5236\u89e3\u7684\u53ef\u884c\u6027\u7684\u6761\u4ef6\uff0c\u901a\u5e38\u7528\u4e8e\u526a\u679d \u8def\u5f84\u4e2d\u4e0d\u5305\u542b\u8282\u70b9 \\(3\\) \u72b6\u6001\uff08state\uff09 \u72b6\u6001\u8868\u793a\u95ee\u9898\u5728\u67d0\u4e00\u65f6\u523b\u7684\u60c5\u51b5\uff0c\u5305\u62ec\u5df2\u7ecf\u505a\u51fa\u7684\u9009\u62e9 \u5f53\u524d\u5df2\u8bbf\u95ee\u7684\u8282\u70b9\u8def\u5f84\uff0c\u5373 path \u8282\u70b9\u5217\u8868 \u5c1d\u8bd5\uff08attempt\uff09 \u5c1d\u8bd5\u662f\u6839\u636e\u53ef\u7528\u9009\u62e9\u6765\u63a2\u7d22\u89e3\u7a7a\u95f4\u7684\u8fc7\u7a0b\uff0c\u5305\u62ec\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\uff0c\u68c0\u67e5\u662f\u5426\u4e3a\u89e3 \u9012\u5f52\u8bbf\u95ee\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\uff0c\u5c06\u8282\u70b9\u6dfb\u52a0\u8fdb path \uff0c\u5224\u65ad\u8282\u70b9\u7684\u503c\u662f\u5426\u4e3a \\(7\\) \u56de\u9000\uff08backtracking\uff09 \u56de\u9000\u6307\u9047\u5230\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u72b6\u6001\u65f6\uff0c\u64a4\u9500\u524d\u9762\u505a\u51fa\u7684\u9009\u62e9\uff0c\u56de\u5230\u4e0a\u4e00\u4e2a\u72b6\u6001 \u5f53\u8d8a\u8fc7\u53f6\u8282\u70b9\u3001\u7ed3\u675f\u8282\u70b9\u8bbf\u95ee\u3001\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u65f6\u7ec8\u6b62\u641c\u7d22\uff0c\u51fd\u6570\u8fd4\u56de \u526a\u679d\uff08pruning\uff09 \u526a\u679d\u662f\u6839\u636e\u95ee\u9898\u7279\u6027\u548c\u7ea6\u675f\u6761\u4ef6\u907f\u514d\u65e0\u610f\u4e49\u7684\u641c\u7d22\u8def\u5f84\u7684\u65b9\u6cd5\uff0c\u53ef\u63d0\u9ad8\u641c\u7d22\u6548\u7387 \u5f53\u9047\u5230\u503c\u4e3a \\(3\\) \u7684\u8282\u70b9\u65f6\uff0c\u5219\u4e0d\u518d\u7ee7\u7eed\u641c\u7d22

        Tip

        \u95ee\u9898\u3001\u89e3\u3001\u72b6\u6001\u7b49\u6982\u5ff5\u662f\u901a\u7528\u7684\uff0c\u5728\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u3001\u8d2a\u5fc3\u7b49\u7b97\u6cd5\u4e2d\u90fd\u6709\u6d89\u53ca\u3002

        "},{"location":"chapter_backtracking/backtracking_algorithm/#1315","title":"13.1.5 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u56de\u6eaf\u7b97\u6cd5\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u7b97\u6cd5\uff0c\u5b83\u5c1d\u8bd5\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u76f4\u5230\u627e\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u80fd\u591f\u627e\u5230\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u800c\u4e14\u5728\u5408\u7406\u7684\u526a\u679d\u64cd\u4f5c\u4e0b\uff0c\u5177\u6709\u5f88\u9ad8\u7684\u6548\u7387\u3002

        \u7136\u800c\uff0c\u5728\u5904\u7406\u5927\u89c4\u6a21\u6216\u8005\u590d\u6742\u95ee\u9898\u65f6\uff0c\u56de\u6eaf\u7b97\u6cd5\u7684\u8fd0\u884c\u6548\u7387\u53ef\u80fd\u96be\u4ee5\u63a5\u53d7\u3002

        • \u65f6\u95f4\uff1a\u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u9700\u8981\u904d\u5386\u72b6\u6001\u7a7a\u95f4\u7684\u6240\u6709\u53ef\u80fd\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230\u6307\u6570\u9636\u6216\u9636\u4e58\u9636\u3002
        • \u7a7a\u95f4\uff1a\u5728\u9012\u5f52\u8c03\u7528\u4e2d\u9700\u8981\u4fdd\u5b58\u5f53\u524d\u7684\u72b6\u6001\uff08\u4f8b\u5982\u8def\u5f84\u3001\u7528\u4e8e\u526a\u679d\u7684\u8f85\u52a9\u53d8\u91cf\u7b49\uff09\uff0c\u5f53\u6df1\u5ea6\u5f88\u5927\u65f6\uff0c\u7a7a\u95f4\u9700\u6c42\u53ef\u80fd\u4f1a\u53d8\u5f97\u5f88\u5927\u3002

        \u5373\u4fbf\u5982\u6b64\uff0c\u56de\u6eaf\u7b97\u6cd5\u4ecd\u7136\u662f\u67d0\u4e9b\u641c\u7d22\u95ee\u9898\u548c\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u7684\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u95ee\u9898\uff0c\u7531\u4e8e\u65e0\u6cd5\u9884\u6d4b\u54ea\u4e9b\u9009\u62e9\u53ef\u751f\u6210\u6709\u6548\u7684\u89e3\uff0c\u56e0\u6b64\u6211\u4eec\u5fc5\u987b\u5bf9\u6240\u6709\u53ef\u80fd\u7684\u9009\u62e9\u8fdb\u884c\u904d\u5386\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5173\u952e\u662f\u5982\u4f55\u4f18\u5316\u6548\u7387\uff0c\u5e38\u89c1\u7684\u6548\u7387\u4f18\u5316\u65b9\u6cd5\u6709\u4e24\u79cd\u3002

        • \u526a\u679d\uff1a\u907f\u514d\u641c\u7d22\u90a3\u4e9b\u80af\u5b9a\u4e0d\u4f1a\u4ea7\u751f\u89e3\u7684\u8def\u5f84\uff0c\u4ece\u800c\u8282\u7701\u65f6\u95f4\u548c\u7a7a\u95f4\u3002
        • \u542f\u53d1\u5f0f\u641c\u7d22\uff1a\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u5f15\u5165\u4e00\u4e9b\u7b56\u7565\u6216\u8005\u4f30\u8ba1\u503c\uff0c\u4ece\u800c\u4f18\u5148\u641c\u7d22\u6700\u6709\u53ef\u80fd\u4ea7\u751f\u6709\u6548\u89e3\u7684\u8def\u5f84\u3002
        "},{"location":"chapter_backtracking/backtracking_algorithm/#1316","title":"13.1.6 \u00a0 \u56de\u6eaf\u5178\u578b\u4f8b\u9898","text":"

        \u56de\u6eaf\u7b97\u6cd5\u53ef\u7528\u4e8e\u89e3\u51b3\u8bb8\u591a\u641c\u7d22\u95ee\u9898\u3001\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u548c\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u3002

        \u641c\u7d22\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u5230\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u89e3\u51b3\u65b9\u6848\u3002

        • \u5168\u6392\u5217\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\uff0c\u6c42\u51fa\u5176\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u7ec4\u5408\u3002
        • \u5b50\u96c6\u548c\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\u548c\u4e00\u4e2a\u76ee\u6807\u548c\uff0c\u627e\u5230\u96c6\u5408\u4e2d\u6240\u6709\u548c\u4e3a\u76ee\u6807\u548c\u7684\u5b50\u96c6\u3002
        • \u6c49\u8bfa\u5854\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e09\u6839\u67f1\u5b50\u548c\u4e00\u7cfb\u5217\u5927\u5c0f\u4e0d\u540c\u7684\u5706\u76d8\uff0c\u8981\u6c42\u5c06\u6240\u6709\u5706\u76d8\u4ece\u4e00\u6839\u67f1\u5b50\u79fb\u52a8\u5230\u53e6\u4e00\u6839\u67f1\u5b50\uff0c\u6bcf\u6b21\u53ea\u80fd\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\uff0c\u4e14\u4e0d\u80fd\u5c06\u5927\u5706\u76d8\u653e\u5728\u5c0f\u5706\u76d8\u4e0a\u3002

        \u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u5230\u6ee1\u8db3\u6240\u6709\u7ea6\u675f\u6761\u4ef6\u7684\u89e3\u3002

        • \\(n\\) \u7687\u540e\uff1a\u5728 \\(n \\times n\\) \u7684\u68cb\u76d8\u4e0a\u653e\u7f6e \\(n\\) \u4e2a\u7687\u540e\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e92\u4e0d\u653b\u51fb\u3002
        • \u6570\u72ec\uff1a\u5728 \\(9 \\times 9\\) \u7684\u7f51\u683c\u4e2d\u586b\u5165\u6570\u5b57 \\(1\\) ~ \\(9\\) \uff0c\u4f7f\u5f97\u6bcf\u884c\u3001\u6bcf\u5217\u548c\u6bcf\u4e2a \\(3 \\times 3\\) \u5b50\u7f51\u683c\u4e2d\u7684\u6570\u5b57\u4e0d\u91cd\u590d\u3002
        • \u56fe\u7740\u8272\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u7528\u6700\u5c11\u7684\u989c\u8272\u7ed9\u56fe\u7684\u6bcf\u4e2a\u9876\u70b9\u7740\u8272\uff0c\u4f7f\u5f97\u76f8\u90bb\u9876\u70b9\u989c\u8272\u4e0d\u540c\u3002

        \u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff1a\u8fd9\u7c7b\u95ee\u9898\u7684\u76ee\u6807\u662f\u5728\u4e00\u4e2a\u7ec4\u5408\u7a7a\u95f4\u4e2d\u627e\u5230\u6ee1\u8db3\u67d0\u4e9b\u6761\u4ef6\u7684\u6700\u4f18\u89e3\u3002

        • 0-1 \u80cc\u5305\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u7269\u54c1\u548c\u4e00\u4e2a\u80cc\u5305\uff0c\u6bcf\u4e2a\u7269\u54c1\u6709\u4e00\u5b9a\u7684\u4ef7\u503c\u548c\u91cd\u91cf\uff0c\u8981\u6c42\u5728\u80cc\u5305\u5bb9\u91cf\u9650\u5236\u5185\uff0c\u9009\u62e9\u7269\u54c1\u4f7f\u5f97\u603b\u4ef7\u503c\u6700\u5927\u3002
        • \u65c5\u884c\u5546\u95ee\u9898\uff1a\u5728\u4e00\u4e2a\u56fe\u4e2d\uff0c\u4ece\u4e00\u4e2a\u70b9\u51fa\u53d1\uff0c\u8bbf\u95ee\u6240\u6709\u5176\u4ed6\u70b9\u6070\u597d\u4e00\u6b21\u540e\u8fd4\u56de\u8d77\u70b9\uff0c\u6c42\u6700\u77ed\u8def\u5f84\u3002
        • \u6700\u5927\u56e2\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u65e0\u5411\u56fe\uff0c\u627e\u5230\u6700\u5927\u7684\u5b8c\u5168\u5b50\u56fe\uff0c\u5373\u5b50\u56fe\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u90fd\u6709\u8fb9\u76f8\u8fde\u3002

        \u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e\u8bb8\u591a\u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff0c\u56de\u6eaf\u4e0d\u662f\u6700\u4f18\u89e3\u51b3\u65b9\u6848\u3002

        • 0-1 \u80cc\u5305\u95ee\u9898\u901a\u5e38\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u89e3\u51b3\uff0c\u4ee5\u8fbe\u5230\u66f4\u9ad8\u7684\u65f6\u95f4\u6548\u7387\u3002
        • \u65c5\u884c\u5546\u662f\u4e00\u4e2a\u8457\u540d\u7684 NP-Hard \u95ee\u9898\uff0c\u5e38\u7528\u89e3\u6cd5\u6709\u9057\u4f20\u7b97\u6cd5\u548c\u8681\u7fa4\u7b97\u6cd5\u7b49\u3002
        • \u6700\u5927\u56e2\u95ee\u9898\u662f\u56fe\u8bba\u4e2d\u7684\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\uff0c\u53ef\u7528\u8d2a\u5fc3\u7b97\u6cd5\u7b49\u542f\u53d1\u5f0f\u7b97\u6cd5\u6765\u89e3\u51b3\u3002
        "},{"location":"chapter_backtracking/n_queens_problem/","title":"13.4 \u00a0 N \u7687\u540e\u95ee\u9898","text":"

        Question

        \u6839\u636e\u56fd\u9645\u8c61\u68cb\u7684\u89c4\u5219\uff0c\u7687\u540e\u53ef\u4ee5\u653b\u51fb\u4e0e\u540c\u5904\u4e00\u884c\u3001\u4e00\u5217\u6216\u4e00\u6761\u659c\u7ebf\u4e0a\u7684\u68cb\u5b50\u3002\u7ed9\u5b9a \\(n\\) \u4e2a\u7687\u540e\u548c\u4e00\u4e2a \\(n \\times n\\) \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5bfb\u627e\u4f7f\u5f97\u6240\u6709\u7687\u540e\u4e4b\u95f4\u65e0\u6cd5\u76f8\u4e92\u653b\u51fb\u7684\u6446\u653e\u65b9\u6848\u3002

        \u5982\u56fe 13-15 \u6240\u793a\uff0c\u5f53 \\(n = 4\\) \u65f6\uff0c\u5171\u53ef\u4ee5\u627e\u5230\u4e24\u4e2a\u89e3\u3002\u4ece\u56de\u6eaf\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\\(n \\times n\\) \u5927\u5c0f\u7684\u68cb\u76d8\u5171\u6709 \\(n^2\\) \u4e2a\u683c\u5b50\uff0c\u7ed9\u51fa\u4e86\u6240\u6709\u7684\u9009\u62e9 choices \u3002\u5728\u9010\u4e2a\u653e\u7f6e\u7687\u540e\u7684\u8fc7\u7a0b\u4e2d\uff0c\u68cb\u76d8\u72b6\u6001\u5728\u4e0d\u65ad\u5730\u53d8\u5316\uff0c\u6bcf\u4e2a\u65f6\u523b\u7684\u68cb\u76d8\u5c31\u662f\u72b6\u6001 state \u3002

        \u56fe 13-15 \u00a0 4 \u7687\u540e\u95ee\u9898\u7684\u89e3

        \u56fe 13-16 \u5c55\u793a\u4e86\u672c\u9898\u7684\u4e09\u4e2a\u7ea6\u675f\u6761\u4ef6\uff1a\u591a\u4e2a\u7687\u540e\u4e0d\u80fd\u5728\u540c\u4e00\u884c\u3001\u540c\u4e00\u5217\u3001\u540c\u4e00\u5bf9\u89d2\u7ebf\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u89d2\u7ebf\u5206\u4e3a\u4e3b\u5bf9\u89d2\u7ebf \\ \u548c\u6b21\u5bf9\u89d2\u7ebf / \u4e24\u79cd\u3002

        \u56fe 13-16 \u00a0 n \u7687\u540e\u95ee\u9898\u7684\u7ea6\u675f\u6761\u4ef6

        "},{"location":"chapter_backtracking/n_queens_problem/#1","title":"1. \u00a0 \u9010\u884c\u653e\u7f6e\u7b56\u7565","text":"

        \u7687\u540e\u7684\u6570\u91cf\u548c\u68cb\u76d8\u7684\u884c\u6570\u90fd\u4e3a \\(n\\) \uff0c\u56e0\u6b64\u6211\u4eec\u5bb9\u6613\u5f97\u5230\u4e00\u4e2a\u63a8\u8bba\uff1a\u68cb\u76d8\u6bcf\u884c\u90fd\u5141\u8bb8\u4e14\u53ea\u5141\u8bb8\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u53d6\u9010\u884c\u653e\u7f6e\u7b56\u7565\uff1a\u4ece\u7b2c\u4e00\u884c\u5f00\u59cb\uff0c\u5728\u6bcf\u884c\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\uff0c\u76f4\u81f3\u6700\u540e\u4e00\u884c\u7ed3\u675f\u3002

        \u56fe 13-17 \u6240\u793a\u4e3a \\(4\\) \u7687\u540e\u95ee\u9898\u7684\u9010\u884c\u653e\u7f6e\u8fc7\u7a0b\u3002\u53d7\u753b\u5e45\u9650\u5236\uff0c\u56fe 13-17 \u4ec5\u5c55\u5f00\u4e86\u7b2c\u4e00\u884c\u7684\u5176\u4e2d\u4e00\u4e2a\u641c\u7d22\u5206\u652f\uff0c\u5e76\u4e14\u5c06\u4e0d\u6ee1\u8db3\u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u65b9\u6848\u90fd\u8fdb\u884c\u4e86\u526a\u679d\u3002

        \u56fe 13-17 \u00a0 \u9010\u884c\u653e\u7f6e\u7b56\u7565

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9010\u884c\u653e\u7f6e\u7b56\u7565\u8d77\u5230\u4e86\u526a\u679d\u7684\u4f5c\u7528\uff0c\u5b83\u907f\u514d\u4e86\u540c\u4e00\u884c\u51fa\u73b0\u591a\u4e2a\u7687\u540e\u7684\u6240\u6709\u641c\u7d22\u5206\u652f\u3002

        "},{"location":"chapter_backtracking/n_queens_problem/#2","title":"2. \u00a0 \u5217\u4e0e\u5bf9\u89d2\u7ebf\u526a\u679d","text":"

        \u4e3a\u4e86\u6ee1\u8db3\u5217\u7ea6\u675f\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u5e03\u5c14\u578b\u6570\u7ec4 cols \u8bb0\u5f55\u6bcf\u4e00\u5217\u662f\u5426\u6709\u7687\u540e\u3002\u5728\u6bcf\u6b21\u51b3\u5b9a\u653e\u7f6e\u524d\uff0c\u6211\u4eec\u901a\u8fc7 cols \u5c06\u5df2\u6709\u7687\u540e\u7684\u5217\u8fdb\u884c\u526a\u679d\uff0c\u5e76\u5728\u56de\u6eaf\u4e2d\u52a8\u6001\u66f4\u65b0 cols \u7684\u72b6\u6001\u3002

        \u90a3\u4e48\uff0c\u5982\u4f55\u5904\u7406\u5bf9\u89d2\u7ebf\u7ea6\u675f\u5462\uff1f\u8bbe\u68cb\u76d8\u4e2d\u67d0\u4e2a\u683c\u5b50\u7684\u884c\u5217\u7d22\u5f15\u4e3a \\((row, col)\\) \uff0c\u9009\u5b9a\u77e9\u9635\u4e2d\u7684\u67d0\u6761\u4e3b\u5bf9\u89d2\u7ebf\uff0c\u6211\u4eec\u53d1\u73b0\u8be5\u5bf9\u89d2\u7ebf\u4e0a\u6240\u6709\u683c\u5b50\u7684\u884c\u7d22\u5f15\u51cf\u5217\u7d22\u5f15\u90fd\u76f8\u7b49\uff0c\u5373\u5bf9\u89d2\u7ebf\u4e0a\u6240\u6709\u683c\u5b50\u7684 \\(row - col\\) \u4e3a\u6052\u5b9a\u503c\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u4e24\u4e2a\u683c\u5b50\u6ee1\u8db3 \\(row_1 - col_1 = row_2 - col_2\\) \uff0c\u5219\u5b83\u4eec\u4e00\u5b9a\u5904\u5728\u540c\u4e00\u6761\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u3002\u5229\u7528\u8be5\u89c4\u5f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u56fe 13-18 \u6240\u793a\u7684\u6570\u7ec4 diags1 \u8bb0\u5f55\u6bcf\u6761\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\u3002

        \u540c\u7406\uff0c\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u7684\u6240\u6709\u683c\u5b50\u7684 \\(row + col\\) \u662f\u6052\u5b9a\u503c\u3002\u6211\u4eec\u540c\u6837\u4e5f\u53ef\u4ee5\u501f\u52a9\u6570\u7ec4 diags2 \u6765\u5904\u7406\u6b21\u5bf9\u89d2\u7ebf\u7ea6\u675f\u3002

        \u56fe 13-18 \u00a0 \u5904\u7406\u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f

        "},{"location":"chapter_backtracking/n_queens_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u8bf7\u6ce8\u610f\uff0c\\(n\\) \u7ef4\u65b9\u9635\u4e2d \\(row - col\\) \u7684\u8303\u56f4\u662f \\([-n + 1, n - 1]\\) \uff0c\\(row + col\\) \u7684\u8303\u56f4\u662f \\([0, 2n - 2]\\) \uff0c\u6240\u4ee5\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\u7684\u6570\u91cf\u90fd\u4e3a \\(2n - 1\\) \uff0c\u5373\u6570\u7ec4 diags1 \u548c diags2 \u7684\u957f\u5ea6\u90fd\u4e3a \\(2n - 1\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig n_queens.py
        def backtrack(\nrow: int,\nn: int,\nstate: list[list[str]],\nres: list[list[list[str]]],\ncols: list[bool],\ndiags1: list[bool],\ndiags2: list[bool],\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e\"\"\"\n# \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n:\nres.append([list(row) for row in state])\nreturn\n# \u904d\u5386\u6240\u6709\u5217\nfor col in range(n):\n# \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 = row - col + n - 1\ndiag2 = row + col\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif not cols[col] and not diags1[diag1] and not diags2[diag2]:\n# \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\"\ncols[col] = diags1[diag1] = diags2[diag2] = True\n# \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2)\n# \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\"\ncols[col] = diags1[diag1] = diags2[diag2] = False\ndef n_queens(n: int) -> list[list[list[str]]]:\n\"\"\"\u6c42\u89e3 N \u7687\u540e\"\"\"\n# \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nstate = [[\"#\" for _ in range(n)] for _ in range(n)]\ncols = [False] * n  # \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\ndiags1 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\ndiags2 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nres = []\nbacktrack(0, n, state, res, cols, diags1, diags2)\nreturn res\n
        n_queens.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, vector<vector<string>> &state, vector<vector<vector<string>>> &res, vector<bool> &cols,\nvector<bool> &diags1, vector<bool> &diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nvector<vector<vector<string>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nvector<vector<string>> state(n, vector<string>(n, \"#\"));\nvector<bool> cols(n, false);           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nvector<bool> diags1(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvector<bool> diags2(2 * n - 1, false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvector<vector<vector<string>>> res;\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, List<List<String>> state, List<List<List<String>>> res,\nboolean[] cols, boolean[] diags1, boolean[] diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<String>> copyState = new ArrayList<>();\nfor (List<String> sRow : state) {\ncopyState.add(new ArrayList<>(sRow));\n}\nres.add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate.get(row).set(col, \"Q\");\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate.get(row).set(col, \"#\");\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<String>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<String>> state = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nList<String> row = new ArrayList<>();\nfor (int j = 0; j < n; j++) {\nrow.add(\"#\");\n}\nstate.add(row);\n}\nboolean[] cols = new boolean[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nboolean[] diags1 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nboolean[] diags2 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<String>>> res = new ArrayList<>();\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid Backtrack(int row, int n, List<List<string>> state, List<List<List<string>>> res,\nbool[] cols, bool[] diags1, bool[] diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<string>> copyState = [];\nforeach (List<string> sRow in state) {\ncopyState.Add(new List<string>(sRow));\n}\nres.Add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nBacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<string>>> NQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<string>> state = [];\nfor (int i = 0; i < n; i++) {\nList<string> row = [];\nfor (int j = 0; j < n; j++) {\nrow.Add(\"#\");\n}\nstate.Add(row);\n}\nbool[] cols = new bool[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nbool[] diags1 = new bool[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nbool[] diags2 = new bool[2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<string>>> res = [];\nBacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row, n int, state *[][]string, res *[][][]string, cols, diags1, diags2 *[]bool) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nnewState := make([][]string, len(*state))\nfor i, _ := range newState {\nnewState[i] = make([]string, len((*state)[0]))\ncopy(newState[i], (*state)[i])\n}\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col := 0; col < n; col++ {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 := row - col + n - 1\ndiag2 := row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !(*cols)[col] && !(*diags1)[diag1] && !(*diags2)[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n(*state)[row][col] = \"Q\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = true, true, true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row+1, n, state, res, cols, diags1, diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n(*state)[row][col] = \"#\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = false, false, false\n}\n}\n}\n/* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row, n int, state *[][]string, res *[][][]string, cols, diags1, diags2 *[]bool) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nnewState := make([][]string, len(*state))\nfor i, _ := range newState {\nnewState[i] = make([]string, len((*state)[0]))\ncopy(newState[i], (*state)[i])\n}\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col := 0; col < n; col++ {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\ndiag1 := row - col + n - 1\ndiag2 := row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !(*cols)[col] && !(*diags1)[diag1] && !(*diags2)[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n(*state)[row][col] = \"Q\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = true, true, true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row+1, n, state, res, cols, diags1, diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n(*state)[row][col] = \"#\"\n(*cols)[col], (*diags1)[diag1], (*diags2)[diag2] = false, false, false\n}\n}\n}\nfunc nQueens(n int) [][][]string {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nstate := make([][]string, n)\nfor i := 0; i < n; i++ {\nrow := make([]string, n)\nfor i := 0; i < n; i++ {\nrow[i] = \"#\"\n}\nstate[i] = row\n}\n// \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\ncols := make([]bool, n)\ndiags1 := make([]bool, 2*n-1)\ndiags2 := make([]bool, 2*n-1)\nres := make([][][]string, 0)\nbacktrack(0, n, &state, &res, &cols, &diags1, &diags2)\nreturn res\n}\n
        n_queens.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunc backtrack(row: Int, n: Int, state: inout [[String]], res: inout [[[String]]], cols: inout [Bool], diags1: inout [Bool], diags2: inout [Bool]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col in 0 ..< n {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nlet diag1 = row - col + n - 1\nlet diag2 = row + col\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !cols[col] && !diags1[diag1] && !diags2[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\"\ncols[col] = true\ndiags1[diag1] = true\ndiags2[diag2] = true\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row: row + 1, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\"\ncols[col] = false\ndiags1[diag1] = false\ndiags2[diag2] = false\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunc nQueens(n: Int) -> [[[String]]] {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nvar state = Array(repeating: Array(repeating: \"#\", count: n), count: n)\nvar cols = Array(repeating: false, count: n) // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nvar diags1 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvar diags2 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nvar res: [[[String]]] = []\nbacktrack(row: 0, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\nreturn res\n}\n
        n_queens.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(row, n, state, res, cols, diags1, diags2) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row === n) {\nres.push(state.map((row) => row.slice()));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (let col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nconst diag1 = row - col + n - 1;\nconst diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunction nQueens(n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nconst state = Array.from({ length: n }, () => Array(n).fill('#'));\nconst cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nconst diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst res = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(\nrow: number,\nn: number,\nstate: string[][],\nres: string[][][],\ncols: boolean[],\ndiags1: boolean[],\ndiags2: boolean[]\n): void {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row === n) {\nres.push(state.map((row) => row.slice()));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (let col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nconst diag1 = row - col + n - 1;\nconst diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfunction nQueens(n: number): string[][][] {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nconst state = Array.from({ length: n }, () => Array(n).fill('#'));\nconst cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nconst diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nconst res: string[][][] = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(\nint row,\nint n,\nList<List<String>> state,\nList<List<List<String>>> res,\nList<bool> cols,\nList<bool> diags1,\nList<bool> diags2,\n) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nList<List<String>> copyState = [];\nfor (List<String> sRow in state) {\ncopyState.add(List.from(sRow));\n}\nres.add(copyState);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = \"Q\";\ncols[col] = true;\ndiags1[diag1] = true;\ndiags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = \"#\";\ncols[col] = false;\ndiags1[diag1] = false;\ndiags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nList<List<List<String>>> nQueens(int n) {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nList<List<String>> state = List.generate(n, (index) => List.filled(n, \"#\"));\nList<bool> cols = List.filled(n, false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nList<bool> diags1 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<bool> diags2 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nList<List<List<String>>> res = [];\nbacktrack(0, n, state, res, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfn backtrack(row: usize, n: usize, state: &mut Vec<Vec<String>>, res: &mut Vec<Vec<Vec<String>>>,\ncols: &mut [bool], diags1: &mut [bool], diags2: &mut [bool]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif row == n {\nlet mut copy_state: Vec<Vec<String>> = Vec::new();\nfor s_row in state.clone() {\ncopy_state.push(s_row);\n}\nres.push(copy_state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor col in 0..n {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nlet diag1 = row + n - 1 - col;\nlet diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif !cols[col] && !diags1[diag1] && !diags2[diag2] {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate.get_mut(row).unwrap()[col] = \"Q\".into();\n(cols[col], diags1[diag1], diags2[diag2]) = (true, true, true);\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate.get_mut(row).unwrap()[col] = \"#\".into();\n(cols[col], diags1[diag1], diags2[diag2]) = (false, false, false);\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nfn n_queens(n: usize) -> Vec<Vec<Vec<String>>> {\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nlet mut state: Vec<Vec<String>> = Vec::new();\nfor _ in 0..n {\nlet mut row: Vec<String> = Vec::new();\nfor _ in 0..n {\nrow.push(\"#\".into());\n}\nstate.push(row);\n}\nlet mut cols = vec![false; n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nlet mut diags1 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nlet mut diags2 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nlet mut res: Vec<Vec<Vec<String>>> = Vec::new();\nbacktrack(0, n, &mut state, &mut res, &mut cols, &mut diags1, &mut diags2);\nres\n}\n
        n_queens.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(int row, int n, char state[MAX_SIZE][MAX_SIZE], char ***res, int *resSize, bool cols[MAX_SIZE],\nbool diags1[2 * MAX_SIZE - 1], bool diags2[2 * MAX_SIZE - 1]) {\n// \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (row == n) {\nres[*resSize] = (char **)malloc(sizeof(char *) * n);\nfor (int i = 0; i < n; ++i) {\nres[*resSize][i] = (char *)malloc(sizeof(char) * (n + 1));\nstrcpy(res[*resSize][i], state[i]);\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u5217\nfor (int col = 0; col < n; col++) {\n// \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\nint diag1 = row - col + n - 1;\nint diag2 = row + col;\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\nif (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n// \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\nstate[row][col] = 'Q';\ncols[col] = diags1[diag1] = diags2[diag2] = true;\n// \u653e\u7f6e\u4e0b\u4e00\u884c\nbacktrack(row + 1, n, state, res, resSize, cols, diags1, diags2);\n// \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\nstate[row][col] = '#';\ncols[col] = diags1[diag1] = diags2[diag2] = false;\n}\n}\n}\n/* \u6c42\u89e3 N \u7687\u540e */\nchar ***nQueens(int n, int *returnSize) {\nchar state[MAX_SIZE][MAX_SIZE];\n// \u521d\u59cb\u5316 n*n \u5927\u5c0f\u7684\u68cb\u76d8\uff0c\u5176\u4e2d 'Q' \u4ee3\u8868\u7687\u540e\uff0c'#' \u4ee3\u8868\u7a7a\u4f4d\nfor (int i = 0; i < n; ++i) {\nfor (int j = 0; j < n; ++j) {\nstate[i][j] = '#';\n}\nstate[i][n] = '\\0';\n}\nbool cols[MAX_SIZE] = {false};           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\nbool diags1[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nbool diags2[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\nchar ***res = (char ***)malloc(sizeof(char **) * MAX_SIZE);\n*returnSize = 0;\nbacktrack(0, n, state, res, returnSize, cols, diags1, diags2);\nreturn res;\n}\n
        n_queens.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{nQueens}\n

        \u9010\u884c\u653e\u7f6e \\(n\\) \u6b21\uff0c\u8003\u8651\u5217\u7ea6\u675f\uff0c\u5219\u4ece\u7b2c\u4e00\u884c\u5230\u6700\u540e\u4e00\u884c\u5206\u522b\u6709 \\(n\\)\u3001\\(n-1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u4e2a\u9009\u62e9\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n!)\\) \u3002\u5b9e\u9645\u4e0a\uff0c\u6839\u636e\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u526a\u679d\u4e5f\u80fd\u591f\u5927\u5e45\u7f29\u5c0f\u641c\u7d22\u7a7a\u95f4\uff0c\u56e0\u800c\u641c\u7d22\u6548\u7387\u5f80\u5f80\u4f18\u4e8e\u4ee5\u4e0a\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \u6570\u7ec4 state \u4f7f\u7528 \\(O(n^2)\\) \u7a7a\u95f4\uff0c\u6570\u7ec4 cols\u3001diags1 \u548c diags2 \u7686\u4f7f\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002\u6700\u5927\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/","title":"13.2 \u00a0 \u5168\u6392\u5217\u95ee\u9898","text":"

        \u5168\u6392\u5217\u95ee\u9898\u662f\u56de\u6eaf\u7b97\u6cd5\u7684\u4e00\u4e2a\u5178\u578b\u5e94\u7528\u3002\u5b83\u7684\u5b9a\u4e49\u662f\u5728\u7ed9\u5b9a\u4e00\u4e2a\u96c6\u5408\uff08\u5982\u4e00\u4e2a\u6570\u7ec4\u6216\u5b57\u7b26\u4e32\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u627e\u51fa\u5176\u4e2d\u5143\u7d20\u7684\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002

        \u8868 13-2 \u5217\u4e3e\u4e86\u51e0\u4e2a\u793a\u4f8b\u6570\u636e\uff0c\u5305\u62ec\u8f93\u5165\u6570\u7ec4\u548c\u5bf9\u5e94\u7684\u6240\u6709\u6392\u5217\u3002

        \u8868 13-2 \u00a0 \u5168\u6392\u5217\u793a\u4f8b

        \u8f93\u5165\u6570\u7ec4 \u6240\u6709\u6392\u5217 \\([1]\\) \\([1]\\) \\([1, 2]\\) \\([1, 2], [2, 1]\\) \\([1, 2, 3]\\) \\([1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]\\)"},{"location":"chapter_backtracking/permutations_problem/#1321","title":"13.2.1 \u00a0 \u65e0\u76f8\u7b49\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u5176\u4e2d\u4e0d\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002

        \u4ece\u56de\u6eaf\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u751f\u6210\u6392\u5217\u7684\u8fc7\u7a0b\u60f3\u8c61\u6210\u4e00\u7cfb\u5217\u9009\u62e9\u7684\u7ed3\u679c\u3002\u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u4e3a \\([1, 2, 3]\\) \uff0c\u5982\u679c\u6211\u4eec\u5148\u9009\u62e9 \\(1\\) \uff0c\u518d\u9009\u62e9 \\(3\\) \uff0c\u6700\u540e\u9009\u62e9 \\(2\\) \uff0c\u5219\u83b7\u5f97\u6392\u5217 \\([1, 3, 2]\\) \u3002\u56de\u9000\u8868\u793a\u64a4\u9500\u4e00\u4e2a\u9009\u62e9\uff0c\u4e4b\u540e\u7ee7\u7eed\u5c1d\u8bd5\u5176\u4ed6\u9009\u62e9\u3002

        \u4ece\u56de\u6eaf\u4ee3\u7801\u7684\u89d2\u5ea6\u770b\uff0c\u5019\u9009\u96c6\u5408 choices \u662f\u8f93\u5165\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u72b6\u6001 state \u662f\u76f4\u81f3\u76ee\u524d\u5df2\u88ab\u9009\u62e9\u7684\u5143\u7d20\u3002\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u5141\u8bb8\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u56e0\u6b64 state \u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5e94\u8be5\u662f\u552f\u4e00\u7684\u3002

        \u5982\u56fe 13-5 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u641c\u7d22\u8fc7\u7a0b\u5c55\u5f00\u6210\u4e00\u68f5\u9012\u5f52\u6811\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u5f53\u524d\u72b6\u6001 state \u3002\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u7ecf\u8fc7\u4e09\u8f6e\u9009\u62e9\u540e\u5230\u8fbe\u53f6\u8282\u70b9\uff0c\u6bcf\u4e2a\u53f6\u8282\u70b9\u90fd\u5bf9\u5e94\u4e00\u4e2a\u6392\u5217\u3002

        \u56fe 13-5 \u00a0 \u5168\u6392\u5217\u7684\u9012\u5f52\u6811

        "},{"location":"chapter_backtracking/permutations_problem/#1","title":"1. \u00a0 \u91cd\u590d\u9009\u62e9\u526a\u679d","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u6bcf\u4e2a\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u6211\u4eec\u8003\u8651\u5f15\u5165\u4e00\u4e2a\u5e03\u5c14\u578b\u6570\u7ec4 selected \uff0c\u5176\u4e2d selected[i] \u8868\u793a choices[i] \u662f\u5426\u5df2\u88ab\u9009\u62e9\uff0c\u5e76\u57fa\u4e8e\u5b83\u5b9e\u73b0\u4ee5\u4e0b\u526a\u679d\u64cd\u4f5c\u3002

        • \u5728\u505a\u51fa\u9009\u62e9 choice[i] \u540e\uff0c\u6211\u4eec\u5c31\u5c06 selected[i] \u8d4b\u503c\u4e3a \\(\\text{True}\\) \uff0c\u4ee3\u8868\u5b83\u5df2\u88ab\u9009\u62e9\u3002
        • \u904d\u5386\u9009\u62e9\u5217\u8868 choices \u65f6\uff0c\u8df3\u8fc7\u6240\u6709\u5df2\u88ab\u9009\u62e9\u7684\u8282\u70b9\uff0c\u5373\u526a\u679d\u3002

        \u5982\u56fe 13-6 \u6240\u793a\uff0c\u5047\u8bbe\u6211\u4eec\u7b2c\u4e00\u8f6e\u9009\u62e9 1 \uff0c\u7b2c\u4e8c\u8f6e\u9009\u62e9 3 \uff0c\u7b2c\u4e09\u8f6e\u9009\u62e9 2 \uff0c\u5219\u9700\u8981\u5728\u7b2c\u4e8c\u8f6e\u526a\u6389\u5143\u7d20 1 \u7684\u5206\u652f\uff0c\u5728\u7b2c\u4e09\u8f6e\u526a\u6389\u5143\u7d20 1 \u548c\u5143\u7d20 3 \u7684\u5206\u652f\u3002

        \u56fe 13-6 \u00a0 \u5168\u6392\u5217\u526a\u679d\u793a\u4f8b

        \u89c2\u5bdf\u56fe 13-6 \u53d1\u73b0\uff0c\u8be5\u526a\u679d\u64cd\u4f5c\u5c06\u641c\u7d22\u7a7a\u95f4\u5927\u5c0f\u4ece \\(O(n^n)\\) \u51cf\u5c0f\u81f3 \\(O(n!)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u60f3\u6e05\u695a\u4ee5\u4e0a\u4fe1\u606f\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u6846\u67b6\u4ee3\u7801\u4e2d\u505a\u201c\u5b8c\u5f62\u586b\u7a7a\u201d\u4e86\u3002\u4e3a\u4e86\u7f29\u77ed\u6574\u4f53\u4ee3\u7801\uff0c\u6211\u4eec\u4e0d\u5355\u72ec\u5b9e\u73b0\u6846\u67b6\u4ee3\u7801\u4e2d\u7684\u5404\u4e2a\u51fd\u6570\uff0c\u800c\u662f\u5c06\u5b83\u4eec\u5c55\u5f00\u5728 backtrack() \u51fd\u6570\u4e2d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig permutations_i.py
        def backtrack(\nstate: list[int], choices: list[int], selected: list[bool], res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I\"\"\"\n# \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(state) == len(choices):\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i, choice in enumerate(choices):\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif not selected[i]:\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = True\nstate.append(choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = False\nstate.pop()\ndef permutations_i(nums: list[int]) -> list[list[int]]:\n\"\"\"\u5168\u6392\u5217 I\"\"\"\nres = []\nbacktrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\nreturn res\n
        permutations_i.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.size()) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.size(); i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push_back(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop_back();\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nvector<vector<int>> permutationsI(vector<int> nums) {\nvector<int> state;\nvector<bool> selected(nums.size(), false);\nvector<vector<int>> res;\nbacktrack(state, nums, selected, res);\nreturn res;\n}\n
        permutations_i.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.length) {\nres.add(new ArrayList<Integer>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.size() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<Integer>> permutationsI(int[] nums) {\nList<List<Integer>> res = new ArrayList<List<Integer>>();\nbacktrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\nreturn res;\n}\n
        permutations_i.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid Backtrack(List<int> state, int[] choices, bool[] selected, List<List<int>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.Count == choices.Length) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.Length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.Add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.RemoveAt(state.Count - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<int>> PermutationsI(int[] nums) {\nList<List<int>> res = [];\nBacktrack([], nums, new bool[nums.Length], res);\nreturn res;\n}\n
        permutations_i.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunc backtrackI(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(*state) == len(*choices) {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i := 0; i < len(*choices); i++ {\nchoice := (*choices)[i]\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !(*selected)[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n(*selected)[i] = true\n*state = append(*state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackI(state, choices, selected, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n(*selected)[i] = false\n*state = (*state)[:len(*state)-1]\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums []int) [][]int {\nres := make([][]int, 0)\nstate := make([]int, 0)\nselected := make([]bool, len(nums))\nbacktrackI(&state, &nums, &selected, &res)\nreturn res\n}\n
        permutations_i.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunc backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res: inout [[Int]]) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.count == choices.count {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (i, choice) in choices.enumerated() {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !selected[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true\nstate.append(choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: choices, selected: &selected, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false\nstate.removeLast()\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums: [Int]) -> [[Int]] {\nvar state: [Int] = []\nvar selected = Array(repeating: false, count: nums.count)\nvar res: [[Int]] = []\nbacktrack(state: &state, choices: nums, selected: &selected, res: &res)\nreturn res\n}\n
        permutations_i.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(state, choices, selected, res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums) {\nconst res = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_i.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(\nstate: number[],\nchoices: number[],\nselected: boolean[],\nres: number[][]\n): void {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums: number[]): number[][] {\nconst res: number[][] = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_i.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(\nList<int> state,\nList<int> choices,\nList<bool> selected,\nList<List<int>> res,\n) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length == choices.length) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.removeLast();\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nList<List<int>> permutationsI(List<int> nums) {\nList<List<int>> res = [];\nbacktrack([], nums, List.filled(nums.length, false), res);\nreturn res;\n}\n
        permutations_i.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &mut Vec<Vec<i32>>) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.len() == choices.len() {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in 0..choices.len() {\nlet choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif !selected[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.len() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nfn permutations_i(nums: &mut [i32]) -> Vec<Vec<i32>> {\nlet mut res = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nbacktrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\nres\n}\n
        permutations_i.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(int *state, int stateSize, int *choices, int choicesSize, bool *selected, int **res, int *resSize) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (stateSize == choicesSize) {\nres[*resSize] = (int *)malloc(choicesSize * sizeof(int));\nfor (int i = 0; i < choicesSize; i++) {\nres[*resSize][i] = state[i];\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choicesSize; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\nif (!selected[i]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nselected[i] = true;\nstate[stateSize] = choice;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, stateSize + 1, choices, choicesSize, selected, res, resSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\n}\n}\n}\n/* \u5168\u6392\u5217 I */\nint **permutationsI(int *nums, int numsSize, int *returnSize) {\nint *state = (int *)malloc(numsSize * sizeof(int));\nbool *selected = (bool *)malloc(numsSize * sizeof(bool));\nfor (int i = 0; i < numsSize; i++) {\nselected[i] = false;\n}\nint **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n*returnSize = 0;\nbacktrack(state, 0, nums, numsSize, selected, res, returnSize);\nfree(state);\nfree(selected);\nreturn res;\n}\n
        permutations_i.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{permutationsI}\n
        "},{"location":"chapter_backtracking/permutations_problem/#1322","title":"13.2.2 \u00a0 \u8003\u8651\u76f8\u7b49\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u6570\u7ec4\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd4\u56de\u6240\u6709\u4e0d\u91cd\u590d\u7684\u6392\u5217\u3002

        \u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u4e3a \\([1, 1, 2]\\) \u3002\u4e3a\u4e86\u65b9\u4fbf\u533a\u5206\u4e24\u4e2a\u91cd\u590d\u5143\u7d20 \\(1\\) \uff0c\u6211\u4eec\u5c06\u7b2c\u4e8c\u4e2a \\(1\\) \u8bb0\u4e3a \\(\\hat{1}\\) \u3002

        \u5982\u56fe 13-7 \u6240\u793a\uff0c\u4e0a\u8ff0\u65b9\u6cd5\u751f\u6210\u7684\u6392\u5217\u6709\u4e00\u534a\u662f\u91cd\u590d\u7684\u3002

        \u56fe 13-7 \u00a0 \u91cd\u590d\u6392\u5217

        \u90a3\u4e48\u5982\u4f55\u53bb\u9664\u91cd\u590d\u7684\u6392\u5217\u5462\uff1f\u6700\u76f4\u63a5\u5730\uff0c\u8003\u8651\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\uff0c\u76f4\u63a5\u5bf9\u6392\u5217\u7ed3\u679c\u8fdb\u884c\u53bb\u91cd\u3002\u7136\u800c\u8fd9\u6837\u505a\u4e0d\u591f\u4f18\u96c5\uff0c\u56e0\u4e3a\u751f\u6210\u91cd\u590d\u6392\u5217\u7684\u641c\u7d22\u5206\u652f\u6ca1\u6709\u5fc5\u8981\uff0c\u5e94\u5f53\u63d0\u524d\u8bc6\u522b\u5e76\u526a\u679d\uff0c\u8fd9\u6837\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002

        "},{"location":"chapter_backtracking/permutations_problem/#1_1","title":"1. \u00a0 \u76f8\u7b49\u5143\u7d20\u526a\u679d","text":"

        \u89c2\u5bdf\u56fe 13-8 \uff0c\u5728\u7b2c\u4e00\u8f6e\u4e2d\uff0c\u9009\u62e9 \\(1\\) \u6216\u9009\u62e9 \\(\\hat{1}\\) \u662f\u7b49\u4ef7\u7684\uff0c\u5728\u8fd9\u4e24\u4e2a\u9009\u62e9\u4e4b\u4e0b\u751f\u6210\u7684\u6240\u6709\u6392\u5217\u90fd\u662f\u91cd\u590d\u7684\u3002\u56e0\u6b64\u5e94\u8be5\u628a \\(\\hat{1}\\) \u526a\u679d\u3002

        \u540c\u7406\uff0c\u5728\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(2\\) \u4e4b\u540e\uff0c\u7b2c\u4e8c\u8f6e\u9009\u62e9\u4e2d\u7684 \\(1\\) \u548c \\(\\hat{1}\\) \u4e5f\u4f1a\u4ea7\u751f\u91cd\u590d\u5206\u652f\uff0c\u56e0\u6b64\u4e5f\u5e94\u5c06\u7b2c\u4e8c\u8f6e\u7684 \\(\\hat{1}\\) \u526a\u679d\u3002

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u5728\u67d0\u4e00\u8f6e\u9009\u62e9\u4e2d\uff0c\u4fdd\u8bc1\u591a\u4e2a\u76f8\u7b49\u7684\u5143\u7d20\u4ec5\u88ab\u9009\u62e9\u4e00\u6b21\u3002

        \u56fe 13-8 \u00a0 \u91cd\u590d\u6392\u5217\u526a\u679d

        "},{"location":"chapter_backtracking/permutations_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5728\u4e0a\u4e00\u9898\u7684\u4ee3\u7801\u7684\u57fa\u7840\u4e0a\uff0c\u6211\u4eec\u8003\u8651\u5728\u6bcf\u4e00\u8f6e\u9009\u62e9\u4e2d\u5f00\u542f\u4e00\u4e2a\u54c8\u5e0c\u8868 duplicated \uff0c\u7528\u4e8e\u8bb0\u5f55\u8be5\u8f6e\u4e2d\u5df2\u7ecf\u5c1d\u8bd5\u8fc7\u7684\u5143\u7d20\uff0c\u5e76\u5c06\u91cd\u590d\u5143\u7d20\u526a\u679d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig permutations_ii.py
        def backtrack(\nstate: list[int], choices: list[int], selected: list[bool], res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II\"\"\"\n# \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(state) == len(choices):\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nduplicated = set[int]()\nfor i, choice in enumerate(choices):\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif not selected[i] and choice not in duplicated:\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice)  # \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = True\nstate.append(choice)\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = False\nstate.pop()\ndef permutations_ii(nums: list[int]) -> list[list[int]]:\n\"\"\"\u5168\u6392\u5217 II\"\"\"\nres = []\nbacktrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\nreturn res\n
        permutations_ii.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &selected, vector<vector<int>> &res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.size()) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nunordered_set<int> duplicated;\nfor (int i = 0; i < choices.size(); i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && duplicated.find(choice) == duplicated.end()) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.emplace(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push_back(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop_back();\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nvector<vector<int>> permutationsII(vector<int> nums) {\nvector<int> state;\nvector<bool> selected(nums.size(), false);\nvector<vector<int>> res;\nbacktrack(state, nums, selected, res);\nreturn res;\n}\n
        permutations_ii.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.size() == choices.length) {\nres.add(new ArrayList<Integer>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nSet<Integer> duplicated = new HashSet<Integer>();\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.size() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<Integer>> permutationsII(int[] nums) {\nList<List<Integer>> res = new ArrayList<List<Integer>>();\nbacktrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\nreturn res;\n}\n
        permutations_ii.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid Backtrack(List<int> state, int[] choices, bool[] selected, List<List<int>> res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.Count == choices.Length) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nHashSet<int> duplicated = [];\nfor (int i = 0; i < choices.Length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.Contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.Add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.Add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.RemoveAt(state.Count - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<int>> PermutationsII(int[] nums) {\nList<List<int>> res = [];\nBacktrack([], nums, new bool[nums.Length], res);\nreturn res;\n}\n
        permutations_ii.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunc backtrackII(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif len(*state) == len(*choices) {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nduplicated := make(map[int]struct{}, 0)\nfor i := 0; i < len(*choices); i++ {\nchoice := (*choices)[i]\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif _, ok := duplicated[choice]; !ok && !(*selected)[i] {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n// \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nduplicated[choice] = struct{}{}\n(*selected)[i] = true\n*state = append(*state, choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackI(state, choices, selected, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n(*selected)[i] = false\n*state = (*state)[:len(*state)-1]\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums []int) [][]int {\nres := make([][]int, 0)\nstate := make([]int, 0)\nselected := make([]bool, len(nums))\nbacktrackII(&state, &nums, &selected, &res)\nreturn res\n}\n
        permutations_ii.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunc backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res: inout [[Int]]) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.count == choices.count {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nvar duplicated: Set<Int> = []\nfor (i, choice) in choices.enumerated() {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif !selected[i], !duplicated.contains(choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.insert(choice) // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true\nstate.append(choice)\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, choices: choices, selected: &selected, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false\nstate.removeLast()\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums: [Int]) -> [[Int]] {\nvar state: [Int] = []\nvar selected = Array(repeating: false, count: nums.count)\nvar res: [[Int]] = []\nbacktrack(state: &state, choices: nums, selected: &selected, res: &res)\nreturn res\n}\n
        permutations_ii.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(state, choices, selected, res) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nconst duplicated = new Set();\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.has(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums) {\nconst res = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_ii.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(\nstate: number[],\nchoices: number[],\nselected: boolean[],\nres: number[][]\n): void {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length === choices.length) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nconst duplicated = new Set();\nchoices.forEach((choice, i) => {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.has(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.pop();\n}\n});\n}\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums: number[]): number[][] {\nconst res: number[][] = [];\nbacktrack([], nums, Array(nums.length).fill(false), res);\nreturn res;\n}\n
        permutations_ii.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(\nList<int> state,\nList<int> choices,\nList<bool> selected,\nList<List<int>> res,\n) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (state.length == choices.length) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nSet<int> duplicated = {};\nfor (int i = 0; i < choices.length; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated.contains(choice)) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.add(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.removeLast();\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nList<List<int>> permutationsII(List<int> nums) {\nList<List<int>> res = [];\nbacktrack([], nums, List.filled(nums.length, false), res);\nreturn res;\n}\n
        permutations_ii.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &mut Vec<Vec<i32>>) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif state.len() == choices.len() {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nlet mut duplicated = HashSet::<i32>::new();\nfor i in 0..choices.len() {\nlet choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif !selected[i] && !duplicated.contains(&choice) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated.insert(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate.push(choice);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), choices, selected, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\nstate.remove(state.len() - 1);\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nfn permutations_ii(nums: &mut [i32]) -> Vec<Vec<i32>> {\nlet mut res = Vec::new();\nbacktrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\nres\n}\n
        permutations_ii.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(int *state, int stateSize, int *choices, int choicesSize, bool *selected, int **res, int *resSize) {\n// \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\nif (stateSize == choicesSize) {\nres[*resSize] = (int *)malloc(choicesSize * sizeof(int));\nfor (int i = 0; i < choicesSize; i++) {\nres[*resSize][i] = state[i];\n}\n(*resSize)++;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nbool duplicated[MAX_SIZE] = {false};\nfor (int i = 0; i < choicesSize; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20 \u4e14 \u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u76f8\u7b49\u5143\u7d20\nif (!selected[i] && !duplicated[choice]) {\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nduplicated[choice] = true; // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\nselected[i] = true;\nstate[stateSize] = choice;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, stateSize + 1, choices, choicesSize, selected, res, resSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nselected[i] = false;\n}\n}\n}\n/* \u5168\u6392\u5217 II */\nint **permutationsII(int *nums, int numsSize, int *returnSize) {\nint *state = (int *)malloc(numsSize * sizeof(int));\nbool *selected = (bool *)malloc(numsSize * sizeof(bool));\nfor (int i = 0; i < numsSize; i++) {\nselected[i] = false;\n}\nint **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n*returnSize = 0;\nbacktrack(state, 0, nums, numsSize, selected, res, returnSize);\nfree(state);\nfree(selected);\nreturn res;\n}\n
        permutations_ii.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{permutationsII}\n

        \u5047\u8bbe\u5143\u7d20\u4e24\u4e24\u4e4b\u95f4\u4e92\u4e0d\u76f8\u540c\uff0c\u5219 \\(n\\) \u4e2a\u5143\u7d20\u5171\u6709 \\(n!\\) \u79cd\u6392\u5217\uff08\u9636\u4e58\uff09\uff1b\u5728\u8bb0\u5f55\u7ed3\u679c\u65f6\uff0c\u9700\u8981\u590d\u5236\u957f\u5ea6\u4e3a \\(n\\) \u7684\u5217\u8868\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n!n)\\) \u3002

        \u6700\u5927\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002selected \u4f7f\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002\u540c\u4e00\u65f6\u523b\u6700\u591a\u5171\u6709 \\(n\\) \u4e2a duplicated \uff0c\u4f7f\u7528 \\(O(n^2)\\) \u7a7a\u95f4\u3002\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_backtracking/permutations_problem/#3","title":"3. \u00a0 \u4e24\u79cd\u526a\u679d\u5bf9\u6bd4","text":"

        \u8bf7\u6ce8\u610f\uff0c\u867d\u7136 selected \u548c duplicated \u90fd\u7528\u4e8e\u526a\u679d\uff0c\u4f46\u4e24\u8005\u7684\u76ee\u6807\u4e0d\u540c\u3002

        • \u91cd\u590d\u9009\u62e9\u526a\u679d\uff1a\u6574\u4e2a\u641c\u7d22\u8fc7\u7a0b\u4e2d\u53ea\u6709\u4e00\u4e2a selected \u3002\u5b83\u8bb0\u5f55\u7684\u662f\u5f53\u524d\u72b6\u6001\u4e2d\u5305\u542b\u54ea\u4e9b\u5143\u7d20\uff0c\u5176\u4f5c\u7528\u662f\u9632\u6b62 choices \u4e2d\u7684\u4efb\u4e00\u5143\u7d20\u5728 state \u4e2d\u91cd\u590d\u51fa\u73b0\u3002
        • \u76f8\u7b49\u5143\u7d20\u526a\u679d\uff1a\u6bcf\u8f6e\u9009\u62e9\uff08\u6bcf\u4e2a\u8c03\u7528\u7684 backtrack \u51fd\u6570\uff09\u90fd\u5305\u542b\u4e00\u4e2a duplicated \u3002\u5b83\u8bb0\u5f55\u7684\u662f\u5728\u672c\u8f6e\u904d\u5386\uff08for \u5faa\u73af\uff09\u4e2d\u54ea\u4e9b\u5143\u7d20\u5df2\u88ab\u9009\u62e9\u8fc7\uff0c\u5176\u4f5c\u7528\u662f\u4fdd\u8bc1\u76f8\u7b49\u7684\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\u3002

        \u56fe 13-9 \u5c55\u793a\u4e86\u4e24\u4e2a\u526a\u679d\u6761\u4ef6\u7684\u751f\u6548\u8303\u56f4\u3002\u6ce8\u610f\uff0c\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u9009\u62e9\uff0c\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u7684\u5404\u4e2a\u8282\u70b9\u6784\u6210\u4e00\u4e2a\u6392\u5217\u3002

        \u56fe 13-9 \u00a0 \u4e24\u79cd\u526a\u679d\u6761\u4ef6\u7684\u4f5c\u7528\u8303\u56f4

        "},{"location":"chapter_backtracking/subset_sum_problem/","title":"13.3 \u00a0 \u5b50\u96c6\u548c\u95ee\u9898","text":""},{"location":"chapter_backtracking/subset_sum_problem/#1331","title":"13.3.1 \u00a0 \u65e0\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u6b63\u6574\u6570 target \uff0c\u8bf7\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\uff0c\u4f7f\u5f97\u7ec4\u5408\u4e2d\u7684\u5143\u7d20\u548c\u7b49\u4e8e target \u3002\u7ed9\u5b9a\u6570\u7ec4\u65e0\u91cd\u590d\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u88ab\u9009\u53d6\u591a\u6b21\u3002\u8bf7\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\uff0c\u5217\u8868\u4e2d\u4e0d\u5e94\u5305\u542b\u91cd\u590d\u7ec4\u5408\u3002

        \u4f8b\u5982\uff0c\u8f93\u5165\u96c6\u5408 \\(\\{3, 4, 5\\}\\) \u548c\u76ee\u6807\u6574\u6570 \\(9\\) \uff0c\u89e3\u4e3a \\(\\{3, 3, 3\\}, \\{4, 5\\}\\) \u3002\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e24\u70b9\u3002

        • \u8f93\u5165\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u91cd\u590d\u9009\u53d6\u3002
        • \u5b50\u96c6\u4e0d\u533a\u5206\u5143\u7d20\u987a\u5e8f\uff0c\u6bd4\u5982 \\(\\{4, 5\\}\\) \u548c \\(\\{5, 4\\}\\) \u662f\u540c\u4e00\u4e2a\u5b50\u96c6\u3002
        "},{"location":"chapter_backtracking/subset_sum_problem/#1","title":"1. \u00a0 \u53c2\u8003\u5168\u6392\u5217\u89e3\u6cd5","text":"

        \u7c7b\u4f3c\u4e8e\u5168\u6392\u5217\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b50\u96c6\u7684\u751f\u6210\u8fc7\u7a0b\u60f3\u8c61\u6210\u4e00\u7cfb\u5217\u9009\u62e9\u7684\u7ed3\u679c\uff0c\u5e76\u5728\u9009\u62e9\u8fc7\u7a0b\u4e2d\u5b9e\u65f6\u66f4\u65b0\u201c\u5143\u7d20\u548c\u201d\uff0c\u5f53\u5143\u7d20\u548c\u7b49\u4e8e target \u65f6\uff0c\u5c31\u5c06\u5b50\u96c6\u8bb0\u5f55\u81f3\u7ed3\u679c\u5217\u8868\u3002

        \u800c\u4e0e\u5168\u6392\u5217\u95ee\u9898\u4e0d\u540c\u7684\u662f\uff0c\u672c\u9898\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u88ab\u65e0\u9650\u6b21\u9009\u53d6\uff0c\u56e0\u6b64\u65e0\u987b\u501f\u52a9 selected \u5e03\u5c14\u5217\u8868\u6765\u8bb0\u5f55\u5143\u7d20\u662f\u5426\u5df2\u88ab\u9009\u62e9\u3002\u6211\u4eec\u53ef\u4ee5\u5bf9\u5168\u6392\u5217\u4ee3\u7801\u8fdb\u884c\u5c0f\u5e45\u4fee\u6539\uff0c\u521d\u6b65\u5f97\u5230\u89e3\u9898\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_i_naive.py
        def backtrack(\nstate: list[int],\ntarget: int,\ntotal: int,\nchoices: list[int],\nres: list[list[int]],\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in range(len(choices)):\n# \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_i_naive(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\ntotal = 0  # \u5b50\u96c6\u548c\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res)\nreturn res\n
        subset_sum_i_naive.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(vector<int> &state, int target, int total, vector<int> &choices, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (size_t i = 0; i < choices.size(); i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nvector<vector<int>> subsetSumINaive(vector<int> &nums, int target) {\nvector<int> state;       // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0;           // \u5b50\u96c6\u548c\nvector<vector<int>> res; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(List<Integer> state, int target, int total, int[] choices, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<Integer>> subsetSumINaive(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5b50\u96c6\u548c\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid Backtrack(List<int> state, int target, int total, int[] choices, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.Length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<int>> SubsetSumINaive(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5b50\u96c6\u548c\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrackSubsetSumINaive(total, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == total {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i := 0; i < len(*choices); i++ {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total+(*choices)[i] > target {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumINaive(total+(*choices)[i], target, state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\ntotal := 0              // \u5b50\u96c6\u548c\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumINaive(total, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_i_naive.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrack(state: inout [Int], target: Int, total: Int, choices: [Int], res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in stride(from: 0, to: choices.count, by: 1) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target, total: total + choices[i], choices: choices, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet total = 0 // \u5b50\u96c6\u548c\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, total: total, choices: nums, res: &res)\nreturn res\n}\n
        subset_sum_i_naive.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(state, target, total, choices, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total === target) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nconst total = 0; // \u5b50\u96c6\u548c\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\nstate: number[],\ntarget: number,\ntotal: number,\nchoices: number[],\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total === target) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (let i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nconst total = 0; // \u5b50\u96c6\u548c\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\nList<int> state,\nint target,\nint total,\nList<int> choices,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choices.length; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nList<List<int>> subsetSumINaive(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nint total = 0; // \u5143\u7d20\u548c\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, res);\nreturn res;\n}\n
        subset_sum_i_naive.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfn backtrack(mut state: Vec<i32>, target: i32, total: i32, choices: &[i32], res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif total == target {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor i in 0..choices.len() {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif total + choices[i] > target {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target, total + choices[i], choices, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfn subset_sum_i_naive(nums: &[i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet total = 0; // \u5b50\u96c6\u548c\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, total, nums, &mut res);\nres\n}\n
        subset_sum_i_naive.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(int target, int total, int *choices, int choicesSize) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (total == target) {\nfor (int i = 0; i < stateSize; i++) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < choicesSize; i++) {\n// \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\nif (total + choices[i] > target) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\nstate[stateSize++] = choices[i];\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target, total + choices[i], choices, choicesSize);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nvoid subsetSumINaive(int *nums, int numsSize, int target) {\nresSize = 0; // \u521d\u59cb\u5316\u89e3\u7684\u6570\u91cf\u4e3a0\nbacktrack(target, 0, nums, numsSize);\n}\n
        subset_sum_i_naive.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumINaive}\n

        \u5411\u4ee5\u4e0a\u4ee3\u7801\u8f93\u5165\u6570\u7ec4 \\([3, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a \\([3, 3, 3], [4, 5], [5, 4]\\) \u3002\u867d\u7136\u6210\u529f\u627e\u51fa\u4e86\u6240\u6709\u548c\u4e3a \\(9\\) \u7684\u5b50\u96c6\uff0c\u4f46\u5176\u4e2d\u5b58\u5728\u91cd\u590d\u7684\u5b50\u96c6 \\([4, 5]\\) \u548c \\([5, 4]\\) \u3002

        \u8fd9\u662f\u56e0\u4e3a\u641c\u7d22\u8fc7\u7a0b\u662f\u533a\u5206\u9009\u62e9\u987a\u5e8f\u7684\uff0c\u7136\u800c\u5b50\u96c6\u4e0d\u533a\u5206\u9009\u62e9\u987a\u5e8f\u3002\u5982\u56fe 13-10 \u6240\u793a\uff0c\u5148\u9009 \\(4\\) \u540e\u9009 \\(5\\) \u4e0e\u5148\u9009 \\(5\\) \u540e\u9009 \\(4\\) \u662f\u4e0d\u540c\u7684\u5206\u652f\uff0c\u4f46\u5bf9\u5e94\u540c\u4e00\u4e2a\u5b50\u96c6\u3002

        \u56fe 13-10 \u00a0 \u5b50\u96c6\u641c\u7d22\u4e0e\u8d8a\u754c\u526a\u679d

        \u4e3a\u4e86\u53bb\u9664\u91cd\u590d\u5b50\u96c6\uff0c\u4e00\u79cd\u76f4\u63a5\u7684\u601d\u8def\u662f\u5bf9\u7ed3\u679c\u5217\u8868\u8fdb\u884c\u53bb\u91cd\u3002\u4f46\u8fd9\u4e2a\u65b9\u6cd5\u6548\u7387\u5f88\u4f4e\uff0c\u6709\u4e24\u65b9\u9762\u539f\u56e0\u3002

        • \u5f53\u6570\u7ec4\u5143\u7d20\u8f83\u591a\uff0c\u5c24\u5176\u662f\u5f53 target \u8f83\u5927\u65f6\uff0c\u641c\u7d22\u8fc7\u7a0b\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u91cd\u590d\u5b50\u96c6\u3002
        • \u6bd4\u8f83\u5b50\u96c6\uff08\u6570\u7ec4\uff09\u7684\u5f02\u540c\u975e\u5e38\u8017\u65f6\uff0c\u9700\u8981\u5148\u6392\u5e8f\u6570\u7ec4\uff0c\u518d\u6bd4\u8f83\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5f02\u540c\u3002
        "},{"location":"chapter_backtracking/subset_sum_problem/#2","title":"2. \u00a0 \u91cd\u590d\u5b50\u96c6\u526a\u679d","text":"

        \u6211\u4eec\u8003\u8651\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u901a\u8fc7\u526a\u679d\u8fdb\u884c\u53bb\u91cd\u3002\u89c2\u5bdf\u56fe 13-11 \uff0c\u91cd\u590d\u5b50\u96c6\u662f\u5728\u4ee5\u4e0d\u540c\u987a\u5e8f\u9009\u62e9\u6570\u7ec4\u5143\u7d20\u65f6\u4ea7\u751f\u7684\uff0c\u4f8b\u5982\u4ee5\u4e0b\u60c5\u51b5\u3002

        1. \u5f53\u7b2c\u4e00\u8f6e\u548c\u7b2c\u4e8c\u8f6e\u5206\u522b\u9009\u62e9 \\(3\\) \u548c \\(4\\) \u65f6\uff0c\u4f1a\u751f\u6210\u5305\u542b\u8fd9\u4e24\u4e2a\u5143\u7d20\u7684\u6240\u6709\u5b50\u96c6\uff0c\u8bb0\u4e3a \\([3, 4, \\dots]\\) \u3002
        2. \u4e4b\u540e\uff0c\u5f53\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(4\\) \u65f6\uff0c\u5219\u7b2c\u4e8c\u8f6e\u5e94\u8be5\u8df3\u8fc7 \\(3\\) \uff0c\u56e0\u4e3a\u8be5\u9009\u62e9\u4ea7\u751f\u7684\u5b50\u96c6 \\([4, 3, \\dots]\\) \u548c\u7b2c 1. \u6b65\u4e2d\u751f\u6210\u7684\u5b50\u96c6\u5b8c\u5168\u91cd\u590d\u3002

        \u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e00\u5c42\u7684\u9009\u62e9\u90fd\u662f\u4ece\u5de6\u5230\u53f3\u88ab\u9010\u4e2a\u5c1d\u8bd5\u7684\uff0c\u56e0\u6b64\u8d8a\u9760\u53f3\u7684\u5206\u652f\u88ab\u526a\u6389\u7684\u8d8a\u591a\u3002

        1. \u524d\u4e24\u8f6e\u9009\u62e9 \\(3\\) \u548c \\(5\\) \uff0c\u751f\u6210\u5b50\u96c6 \\([3, 5, \\dots]\\) \u3002
        2. \u524d\u4e24\u8f6e\u9009\u62e9 \\(4\\) \u548c \\(5\\) \uff0c\u751f\u6210\u5b50\u96c6 \\([4, 5, \\dots]\\) \u3002
        3. \u82e5\u7b2c\u4e00\u8f6e\u9009\u62e9 \\(5\\) \uff0c\u5219\u7b2c\u4e8c\u8f6e\u5e94\u8be5\u8df3\u8fc7 \\(3\\) \u548c \\(4\\) \uff0c\u56e0\u4e3a\u5b50\u96c6 \\([5, 3, \\dots]\\) \u548c \\([5, 4, \\dots]\\) \u4e0e\u7b2c 1. \u6b65\u548c\u7b2c 2. \u6b65\u4e2d\u63cf\u8ff0\u7684\u5b50\u96c6\u5b8c\u5168\u91cd\u590d\u3002

        \u56fe 13-11 \u00a0 \u4e0d\u540c\u9009\u62e9\u987a\u5e8f\u5bfc\u81f4\u7684\u91cd\u590d\u5b50\u96c6

        \u603b\u7ed3\u6765\u770b\uff0c\u7ed9\u5b9a\u8f93\u5165\u6570\u7ec4 \\([x_1, x_2, \\dots, x_n]\\) \uff0c\u8bbe\u641c\u7d22\u8fc7\u7a0b\u4e2d\u7684\u9009\u62e9\u5e8f\u5217\u4e3a \\([x_{i_1}, x_{i_2}, \\dots, x_{i_m}]\\) \uff0c\u5219\u8be5\u9009\u62e9\u5e8f\u5217\u9700\u8981\u6ee1\u8db3 \\(i_1 \\leq i_2 \\leq \\dots \\leq i_m\\) \uff0c\u4e0d\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u9009\u62e9\u5e8f\u5217\u90fd\u4f1a\u9020\u6210\u91cd\u590d\uff0c\u5e94\u5f53\u526a\u679d\u3002

        "},{"location":"chapter_backtracking/subset_sum_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4e3a\u5b9e\u73b0\u8be5\u526a\u679d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u53d8\u91cf start \uff0c\u7528\u4e8e\u6307\u793a\u904d\u5386\u8d77\u59cb\u70b9\u3002\u5f53\u505a\u51fa\u9009\u62e9 \\(x_{i}\\) \u540e\uff0c\u8bbe\u5b9a\u4e0b\u4e00\u8f6e\u4ece\u7d22\u5f15 \\(i\\) \u5f00\u59cb\u904d\u5386\u3002\u8fd9\u6837\u505a\u5c31\u53ef\u4ee5\u8ba9\u9009\u62e9\u5e8f\u5217\u6ee1\u8db3 \\(i_1 \\leq i_2 \\leq \\dots \\leq i_m\\) \uff0c\u4ece\u800c\u4fdd\u8bc1\u5b50\u96c6\u552f\u4e00\u3002

        \u9664\u6b64\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u5bf9\u4ee3\u7801\u8fdb\u884c\u4e86\u4ee5\u4e0b\u4e24\u9879\u4f18\u5316\u3002

        • \u5728\u5f00\u542f\u641c\u7d22\u524d\uff0c\u5148\u5c06\u6570\u7ec4 nums \u6392\u5e8f\u3002\u5728\u904d\u5386\u6240\u6709\u9009\u62e9\u65f6\uff0c\u5f53\u5b50\u96c6\u548c\u8d85\u8fc7 target \u65f6\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\uff0c\u56e0\u4e3a\u540e\u8fb9\u7684\u5143\u7d20\u66f4\u5927\uff0c\u5176\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target \u3002
        • \u7701\u53bb\u5143\u7d20\u548c\u53d8\u91cf total \uff0c\u901a\u8fc7\u5728 target \u4e0a\u6267\u884c\u51cf\u6cd5\u6765\u7edf\u8ba1\u5143\u7d20\u548c\uff0c\u5f53 target \u7b49\u4e8e \\(0\\) \u65f6\u8bb0\u5f55\u89e3\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_i.py
        def backtrack(\nstate: list[int], target: int, choices: list[int], start: int, res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\n# \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in range(start, len(choices)):\n# \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n# \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0:\nbreak\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_i(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart = 0  # \u904d\u5386\u8d77\u59cb\u70b9\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res)\nreturn res\n
        subset_sum_i.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(vector<int> &state, int target, vector<int> &choices, int start, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.size(); i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvector<vector<int>> subsetSumI(vector<int> &nums, int target) {\nvector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\nvector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<Integer>> subsetSumI(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid Backtrack(List<int> state, int target, int[] choices, int start, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.Length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> SubsetSumI(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArray.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrackSubsetSumI(start, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i := start; i < len(*choices); i++ {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target-(*choices)[i] < 0 {\nbreak\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumI(i, target-(*choices)[i], state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart := 0              // \u904d\u5386\u8d77\u59cb\u70b9\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumI(start, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_i.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunc backtrack(state: inout [Int], target: Int, choices: [Int], start: Int, res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in stride(from: start, to: choices.count, by: 1) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target - choices[i], choices: choices, start: i, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, choices: nums, start: start, res: &res)\nreturn res\n}\n
        subset_sum_i.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(state, target, choices, start, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\nstate: number[],\ntarget: number,\nchoices: number[],\nstart: number,\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\nList<int> state,\nint target,\nList<int> choices,\nint start,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> subsetSumI(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_i.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfn backtrack(mut state: Vec<i32>, target: i32, choices: &[i32], start: usize, res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor i in start..choices.len() {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfn subset_sum_i(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, &mut res);\nres\n}\n
        subset_sum_i.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(int target, int *choices, int choicesSize, int start) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nfor (int i = 0; i < stateSize; ++i) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\nfor (int i = start; i < choicesSize; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate[stateSize] = choices[i];\nstateSize++;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target - choices[i], choices, choicesSize, i);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvoid subsetSumI(int *nums, int numsSize, int target) {\nqsort(nums, numsSize, sizeof(int), cmp); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                           // \u904d\u5386\u8d77\u59cb\u70b9\nbacktrack(target, nums, numsSize, start);\n}\n
        subset_sum_i.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumI}\n

        \u56fe 13-12 \u6240\u793a\u4e3a\u5c06\u6570\u7ec4 \\([3, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \u8f93\u5165\u4ee5\u4e0a\u4ee3\u7801\u540e\u7684\u6574\u4f53\u56de\u6eaf\u8fc7\u7a0b\u3002

        \u56fe 13-12 \u00a0 \u5b50\u96c6\u548c I \u56de\u6eaf\u8fc7\u7a0b

        "},{"location":"chapter_backtracking/subset_sum_problem/#1332","title":"13.3.2 \u00a0 \u8003\u8651\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u6b63\u6574\u6570 target \uff0c\u8bf7\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\uff0c\u4f7f\u5f97\u7ec4\u5408\u4e2d\u7684\u5143\u7d20\u548c\u7b49\u4e8e target \u3002\u7ed9\u5b9a\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ea\u53ef\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u8bf7\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u8fd9\u4e9b\u7ec4\u5408\uff0c\u5217\u8868\u4e2d\u4e0d\u5e94\u5305\u542b\u91cd\u590d\u7ec4\u5408\u3002

        \u76f8\u6bd4\u4e8e\u4e0a\u9898\uff0c\u672c\u9898\u7684\u8f93\u5165\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u8fd9\u5f15\u5165\u4e86\u65b0\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u7ed9\u5b9a\u6570\u7ec4 \\([4, \\hat{4}, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \uff0c\u5219\u73b0\u6709\u4ee3\u7801\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a \\([4, 5], [\\hat{4}, 5]\\) \uff0c\u51fa\u73b0\u4e86\u91cd\u590d\u5b50\u96c6\u3002

        \u9020\u6210\u8fd9\u79cd\u91cd\u590d\u7684\u539f\u56e0\u662f\u76f8\u7b49\u5143\u7d20\u5728\u67d0\u8f6e\u4e2d\u88ab\u591a\u6b21\u9009\u62e9\u3002\u5728\u56fe 13-13 \u4e2d\uff0c\u7b2c\u4e00\u8f6e\u5171\u6709\u4e09\u4e2a\u9009\u62e9\uff0c\u5176\u4e2d\u4e24\u4e2a\u90fd\u4e3a \\(4\\) \uff0c\u4f1a\u4ea7\u751f\u4e24\u4e2a\u91cd\u590d\u7684\u641c\u7d22\u5206\u652f\uff0c\u4ece\u800c\u8f93\u51fa\u91cd\u590d\u5b50\u96c6\uff1b\u540c\u7406\uff0c\u7b2c\u4e8c\u8f6e\u7684\u4e24\u4e2a \\(4\\) \u4e5f\u4f1a\u4ea7\u751f\u91cd\u590d\u5b50\u96c6\u3002

        \u56fe 13-13 \u00a0 \u76f8\u7b49\u5143\u7d20\u5bfc\u81f4\u7684\u91cd\u590d\u5b50\u96c6

        "},{"location":"chapter_backtracking/subset_sum_problem/#1_1","title":"1. \u00a0 \u76f8\u7b49\u5143\u7d20\u526a\u679d","text":"

        \u4e3a\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u9650\u5236\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u4e00\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u5b9e\u73b0\u65b9\u5f0f\u6bd4\u8f83\u5de7\u5999\uff1a\u7531\u4e8e\u6570\u7ec4\u662f\u5df2\u6392\u5e8f\u7684\uff0c\u56e0\u6b64\u76f8\u7b49\u5143\u7d20\u90fd\u662f\u76f8\u90bb\u7684\u3002\u8fd9\u610f\u5473\u7740\u5728\u67d0\u8f6e\u9009\u62e9\u4e2d\uff0c\u82e5\u5f53\u524d\u5143\u7d20\u4e0e\u5176\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u8bf4\u660e\u5b83\u5df2\u7ecf\u88ab\u9009\u62e9\u8fc7\uff0c\u56e0\u6b64\u76f4\u63a5\u8df3\u8fc7\u5f53\u524d\u5143\u7d20\u3002

        \u4e0e\u6b64\u540c\u65f6\uff0c\u672c\u9898\u89c4\u5b9a\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5229\u7528\u53d8\u91cf start \u6765\u6ee1\u8db3\u8be5\u7ea6\u675f\uff1a\u5f53\u505a\u51fa\u9009\u62e9 \\(x_{i}\\) \u540e\uff0c\u8bbe\u5b9a\u4e0b\u4e00\u8f6e\u4ece\u7d22\u5f15 \\(i + 1\\) \u5f00\u59cb\u5411\u540e\u904d\u5386\u3002\u8fd9\u6837\u65e2\u80fd\u53bb\u9664\u91cd\u590d\u5b50\u96c6\uff0c\u4e5f\u80fd\u907f\u514d\u91cd\u590d\u9009\u62e9\u5143\u7d20\u3002

        "},{"location":"chapter_backtracking/subset_sum_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig subset_sum_ii.py
        def backtrack(\nstate: list[int], target: int, choices: list[int], start: int, res: list[list[int]]\n):\n\"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II\"\"\"\n# \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0:\nres.append(list(state))\nreturn\n# \u904d\u5386\u6240\u6709\u9009\u62e9\n# \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n# \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in range(start, len(choices)):\n# \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n# \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0:\nbreak\n# \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start and choices[i] == choices[i - 1]:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n# \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res)\n# \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop()\ndef subset_sum_ii(nums: list[int], target: int) -> list[list[int]]:\n\"\"\"\u6c42\u89e3\u5b50\u96c6\u548c II\"\"\"\nstate = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart = 0  # \u904d\u5386\u8d77\u59cb\u70b9\nres = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res)\nreturn res\n
        subset_sum_ii.cpp
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(vector<int> &state, int target, vector<int> &choices, int start, vector<vector<int>> &res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.push_back(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.size(); i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push_back(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop_back();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvector<vector<int>> subsetSumII(vector<int> &nums, int target) {\nvector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\nvector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.java
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(new ArrayList<>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.remove(state.size() - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<Integer>> subsetSumII(int[] nums, int target) {\nList<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.cs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid Backtrack(List<int> state, int target, int[] choices, int start, List<List<int>> res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.Add(new List<int>(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.Length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.Add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nBacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.RemoveAt(state.Count - 1);\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> SubsetSumII(int[] nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nArray.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nBacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.go
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunc backtrackSubsetSumII(start, target int, state, choices *[]int, res *[][]int) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nnewState := append([]int{}, *state...)\n*res = append(*res, newState)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i := start; i < len(*choices); i++ {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target-(*choices)[i] < 0 {\nbreak\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start && (*choices)[i] == (*choices)[i-1] {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n*state = append(*state, (*choices)[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrackSubsetSumII(i+1, target-(*choices)[i], state, choices, res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n*state = (*state)[:len(*state)-1]\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums []int, target int) [][]int {\nstate := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nsort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nstart := 0              // \u904d\u5386\u8d77\u59cb\u70b9\nres := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrackSubsetSumII(start, target, &state, &nums, &res)\nreturn res\n}\n
        subset_sum_ii.swift
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunc backtrack(state: inout [Int], target: Int, choices: [Int], start: Int, res: inout [[Int]]) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.append(state)\nreturn\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in stride(from: start, to: choices.count, by: 1) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start, choices[i] == choices[i - 1] {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.append(choices[i])\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state: &state, target: target - choices[i], choices: choices, start: i + 1, res: &res)\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast()\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums: [Int], target: Int) -> [[Int]] {\nvar state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nlet nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\nvar res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state: &state, target: target, choices: nums, start: start, res: &res)\nreturn res\n}\n
        subset_sum_ii.js
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(state, target, choices, start, res) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] === choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums, target) {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.ts
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(\nstate: number[],\ntarget: number,\nchoices: number[],\nstart: number,\nres: number[][]\n): void {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target === 0) {\nres.push([...state]);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (let i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] === choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums: number[], target: number): number[][] {\nconst state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nconst start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nconst res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.dart
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(\nList<int> state,\nint target,\nList<int> choices,\nint start,\nList<List<int>> res,\n) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nres.add(List.from(state));\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choices.length; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif (target - choices[i] < 0) {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.add(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state, target - choices[i], choices, i + 1, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.removeLast();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> subsetSumII(List<int> nums, int target) {\nList<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nint start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nList<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, res);\nreturn res;\n}\n
        subset_sum_ii.rs
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfn backtrack(mut state: Vec<i32>, target: i32, choices: &[i32], start: usize, res: &mut Vec<Vec<i32>>) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif target == 0 {\nres.push(state);\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor i in start..choices.len() {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u7ed3\u675f\u5faa\u73af\n// \u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u5df2\u6392\u5e8f\uff0c\u540e\u8fb9\u5143\u7d20\u66f4\u5927\uff0c\u5b50\u96c6\u548c\u4e00\u5b9a\u8d85\u8fc7 target\nif target - choices[i] < 0 {\nbreak;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif i > start && choices[i] == choices[i - 1] {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate.push(choices[i]);\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(state.clone(), target - choices[i], choices, i, res);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstate.pop();\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfn subset_sum_ii(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\nlet state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\nnums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nlet start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\nlet mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\nbacktrack(state, target, nums, start, &mut res);\nres\n}\n
        subset_sum_ii.c
        /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(int target, int *choices, int choicesSize, int start) {\n// \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\nif (target == 0) {\nfor (int i = 0; i < stateSize; i++) {\nres[resSize][i] = state[i];\n}\nresColSizes[resSize++] = stateSize;\nreturn;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\n// \u526a\u679d\u4e8c\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u751f\u6210\u91cd\u590d\u5b50\u96c6\n// \u526a\u679d\u4e09\uff1a\u4ece start \u5f00\u59cb\u904d\u5386\uff0c\u907f\u514d\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\nfor (int i = start; i < choicesSize; i++) {\n// \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\nif (target - choices[i] < 0) {\ncontinue;\n}\n// \u526a\u679d\u56db\uff1a\u5982\u679c\u8be5\u5143\u7d20\u4e0e\u5de6\u8fb9\u5143\u7d20\u76f8\u7b49\uff0c\u8bf4\u660e\u8be5\u641c\u7d22\u5206\u652f\u91cd\u590d\uff0c\u76f4\u63a5\u8df3\u8fc7\nif (i > start && choices[i] == choices[i - 1]) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\nstate[stateSize] = choices[i];\nstateSize++;\n// \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\nbacktrack(target - choices[i], choices, choicesSize, i + 1);\n// \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\nstateSize--;\n}\n}\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvoid subsetSumII(int *nums, int numsSize, int target) {\n// \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\nqsort(nums, numsSize, sizeof(int), cmp);\n// \u5f00\u59cb\u56de\u6eaf\nbacktrack(target, nums, numsSize, 0);\n}\n
        subset_sum_ii.zig
        [class]{}-[func]{backtrack}\n[class]{}-[func]{subsetSumII}\n

        \u56fe 13-14 \u5c55\u793a\u4e86\u6570\u7ec4 \\([4, 4, 5]\\) \u548c\u76ee\u6807\u5143\u7d20 \\(9\\) \u7684\u56de\u6eaf\u8fc7\u7a0b\uff0c\u5171\u5305\u542b\u56db\u79cd\u526a\u679d\u64cd\u4f5c\u3002\u8bf7\u4f60\u5c06\u56fe\u793a\u4e0e\u4ee3\u7801\u6ce8\u91ca\u76f8\u7ed3\u5408\uff0c\u7406\u89e3\u6574\u4e2a\u641c\u7d22\u8fc7\u7a0b\uff0c\u4ee5\u53ca\u6bcf\u79cd\u526a\u679d\u64cd\u4f5c\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002

        \u56fe 13-14 \u00a0 \u5b50\u96c6\u548c II \u56de\u6eaf\u8fc7\u7a0b

        "},{"location":"chapter_backtracking/summary/","title":"13.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_backtracking/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u56de\u6eaf\u7b97\u6cd5\u672c\u8d28\u662f\u7a77\u4e3e\u6cd5\uff0c\u901a\u8fc7\u5bf9\u89e3\u7a7a\u95f4\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u6765\u5bfb\u627e\u7b26\u5408\u6761\u4ef6\u7684\u89e3\u3002\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\uff0c\u9047\u5230\u6ee1\u8db3\u6761\u4ef6\u7684\u89e3\u5219\u8bb0\u5f55\uff0c\u76f4\u81f3\u627e\u5230\u6240\u6709\u89e3\u6216\u904d\u5386\u5b8c\u6210\u540e\u7ed3\u675f\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u7684\u641c\u7d22\u8fc7\u7a0b\u5305\u62ec\u5c1d\u8bd5\u4e0e\u56de\u9000\u4e24\u4e2a\u90e8\u5206\u3002\u5b83\u901a\u8fc7\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u6765\u5c1d\u8bd5\u5404\u79cd\u9009\u62e9\uff0c\u5f53\u9047\u5230\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\u7684\u60c5\u51b5\u65f6\uff0c\u5219\u64a4\u9500\u4e0a\u4e00\u6b65\u7684\u9009\u62e9\uff0c\u9000\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5e76\u7ee7\u7eed\u5c1d\u8bd5\u5176\u4ed6\u9009\u62e9\u3002\u5c1d\u8bd5\u4e0e\u56de\u9000\u662f\u4e24\u4e2a\u65b9\u5411\u76f8\u53cd\u7684\u64cd\u4f5c\u3002
        • \u56de\u6eaf\u95ee\u9898\u901a\u5e38\u5305\u542b\u591a\u4e2a\u7ea6\u675f\u6761\u4ef6\uff0c\u5b83\u4eec\u53ef\u7528\u4e8e\u5b9e\u73b0\u526a\u679d\u64cd\u4f5c\u3002\u526a\u679d\u53ef\u4ee5\u63d0\u524d\u7ed3\u675f\u4e0d\u5fc5\u8981\u7684\u641c\u7d22\u5206\u652f\uff0c\u5927\u5e45\u63d0\u5347\u641c\u7d22\u6548\u7387\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u4e3b\u8981\u53ef\u7528\u4e8e\u89e3\u51b3\u641c\u7d22\u95ee\u9898\u548c\u7ea6\u675f\u6ee1\u8db3\u95ee\u9898\u3002\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u867d\u7136\u53ef\u4ee5\u7528\u56de\u6eaf\u7b97\u6cd5\u89e3\u51b3\uff0c\u4f46\u5f80\u5f80\u5b58\u5728\u6548\u7387\u66f4\u9ad8\u6216\u6548\u679c\u66f4\u597d\u7684\u89e3\u6cd5\u3002
        • \u5168\u6392\u5217\u95ee\u9898\u65e8\u5728\u641c\u7d22\u7ed9\u5b9a\u96c6\u5408\u5143\u7d20\u7684\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u3002\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u6570\u7ec4\u6765\u8bb0\u5f55\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u88ab\u9009\u62e9\uff0c\u526a\u6389\u91cd\u590d\u9009\u62e9\u540c\u4e00\u5143\u7d20\u7684\u641c\u7d22\u5206\u652f\uff0c\u786e\u4fdd\u6bcf\u4e2a\u5143\u7d20\u53ea\u88ab\u9009\u62e9\u4e00\u6b21\u3002
        • \u5728\u5168\u6392\u5217\u95ee\u9898\u4e2d\uff0c\u5982\u679c\u96c6\u5408\u4e2d\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff0c\u5219\u6700\u7ec8\u7ed3\u679c\u4f1a\u51fa\u73b0\u91cd\u590d\u6392\u5217\u3002\u6211\u4eec\u9700\u8981\u7ea6\u675f\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u62e9\u4e00\u6b21\uff0c\u8fd9\u901a\u5e38\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\u6765\u5b9e\u73b0\u3002
        • \u5b50\u96c6\u548c\u95ee\u9898\u7684\u76ee\u6807\u662f\u5728\u7ed9\u5b9a\u96c6\u5408\u4e2d\u627e\u5230\u548c\u4e3a\u76ee\u6807\u503c\u7684\u6240\u6709\u5b50\u96c6\u3002\u96c6\u5408\u4e0d\u533a\u5206\u5143\u7d20\u987a\u5e8f\uff0c\u800c\u641c\u7d22\u8fc7\u7a0b\u4f1a\u8f93\u51fa\u6240\u6709\u987a\u5e8f\u7684\u7ed3\u679c\uff0c\u4ea7\u751f\u91cd\u590d\u5b50\u96c6\u3002\u6211\u4eec\u5728\u56de\u6eaf\u524d\u5c06\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e2a\u53d8\u91cf\u6765\u6307\u793a\u6bcf\u4e00\u8f6e\u7684\u904d\u5386\u8d77\u59cb\u70b9\uff0c\u4ece\u800c\u5c06\u751f\u6210\u91cd\u590d\u5b50\u96c6\u7684\u641c\u7d22\u5206\u652f\u8fdb\u884c\u526a\u679d\u3002
        • \u5bf9\u4e8e\u5b50\u96c6\u548c\u95ee\u9898\uff0c\u6570\u7ec4\u4e2d\u7684\u76f8\u7b49\u5143\u7d20\u4f1a\u4ea7\u751f\u91cd\u590d\u96c6\u5408\u3002\u6211\u4eec\u5229\u7528\u6570\u7ec4\u5df2\u6392\u5e8f\u7684\u524d\u7f6e\u6761\u4ef6\uff0c\u901a\u8fc7\u5224\u65ad\u76f8\u90bb\u5143\u7d20\u662f\u5426\u76f8\u7b49\u5b9e\u73b0\u526a\u679d\uff0c\u4ece\u800c\u786e\u4fdd\u76f8\u7b49\u5143\u7d20\u5728\u6bcf\u8f6e\u4e2d\u53ea\u80fd\u88ab\u9009\u4e2d\u4e00\u6b21\u3002
        • \\(n\\) \u7687\u540e\u95ee\u9898\u65e8\u5728\u5bfb\u627e\u5c06 \\(n\\) \u4e2a\u7687\u540e\u653e\u7f6e\u5230 \\(n \\times n\\) \u5c3a\u5bf8\u68cb\u76d8\u4e0a\u7684\u65b9\u6848\uff0c\u8981\u6c42\u6240\u6709\u7687\u540e\u4e24\u4e24\u4e4b\u95f4\u65e0\u6cd5\u653b\u51fb\u5bf9\u65b9\u3002\u8be5\u95ee\u9898\u7684\u7ea6\u675f\u6761\u4ef6\u6709\u884c\u7ea6\u675f\u3001\u5217\u7ea6\u675f\u3001\u4e3b\u5bf9\u89d2\u7ebf\u548c\u526f\u5bf9\u89d2\u7ebf\u7ea6\u675f\u3002\u4e3a\u6ee1\u8db3\u884c\u7ea6\u675f\uff0c\u6211\u4eec\u91c7\u7528\u6309\u884c\u653e\u7f6e\u7684\u7b56\u7565\uff0c\u4fdd\u8bc1\u6bcf\u4e00\u884c\u653e\u7f6e\u4e00\u4e2a\u7687\u540e\u3002
        • \u5217\u7ea6\u675f\u548c\u5bf9\u89d2\u7ebf\u7ea6\u675f\u7684\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\u3002\u5bf9\u4e8e\u5217\u7ea6\u675f\uff0c\u6211\u4eec\u5229\u7528\u4e00\u4e2a\u6570\u7ec4\u6765\u8bb0\u5f55\u6bcf\u4e00\u5217\u662f\u5426\u6709\u7687\u540e\uff0c\u4ece\u800c\u6307\u793a\u9009\u4e2d\u7684\u683c\u5b50\u662f\u5426\u5408\u6cd5\u3002\u5bf9\u4e8e\u5bf9\u89d2\u7ebf\u7ea6\u675f\uff0c\u6211\u4eec\u501f\u52a9\u4e24\u4e2a\u6570\u7ec4\u6765\u5206\u522b\u8bb0\u5f55\u8be5\u4e3b\u3001\u526f\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u5b58\u5728\u7687\u540e\uff1b\u96be\u70b9\u5728\u4e8e\u627e\u5904\u5728\u5230\u540c\u4e00\u4e3b\uff08\u526f\uff09\u5bf9\u89d2\u7ebf\u4e0a\u683c\u5b50\u6ee1\u8db3\u7684\u884c\u5217\u7d22\u5f15\u89c4\u5f8b\u3002
        "},{"location":"chapter_backtracking/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u600e\u4e48\u7406\u89e3\u56de\u6eaf\u548c\u9012\u5f52\u7684\u5173\u7cfb\uff1f

        \u603b\u7684\u6765\u770b\uff0c\u56de\u6eaf\u662f\u4e00\u79cd\u201c\u7b97\u6cd5\u7b56\u7565\u201d\uff0c\u800c\u9012\u5f52\u66f4\u50cf\u662f\u4e00\u4e2a\u201c\u5de5\u5177\u201d\u3002

        • \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\u3002\u7136\u800c\uff0c\u56de\u6eaf\u662f\u9012\u5f52\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\uff0c\u662f\u9012\u5f52\u5728\u641c\u7d22\u95ee\u9898\u4e2d\u7684\u5e94\u7528\u3002
        • \u9012\u5f52\u7684\u7ed3\u6784\u4f53\u73b0\u4e86\u201c\u5b50\u95ee\u9898\u5206\u89e3\u201d\u7684\u89e3\u9898\u8303\u5f0f\uff0c\u5e38\u7528\u4e8e\u89e3\u51b3\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\uff08\u8bb0\u5fc6\u5316\u9012\u5f52\uff09\u7b49\u95ee\u9898\u3002
        "},{"location":"chapter_computational_complexity/","title":"\u7b2c 2 \u7ae0 \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        Abstract

        \u590d\u6742\u5ea6\u5206\u6790\u72b9\u5982\u6d69\u701a\u7684\u7b97\u6cd5\u5b87\u5b99\u4e2d\u7684\u65f6\u7a7a\u5411\u5bfc\u3002

        \u5b83\u5e26\u9886\u6211\u4eec\u5728\u65f6\u95f4\u4e0e\u7a7a\u95f4\u8fd9\u4e24\u4e2a\u7ef4\u5ea6\u4e0a\u6df1\u5165\u63a2\u7d22\uff0c\u5bfb\u627e\u66f4\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\u3002

        "},{"location":"chapter_computational_complexity/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 2.1 \u00a0 \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30
        • 2.2 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52
        • 2.3 \u00a0 \u65f6\u95f4\u590d\u6742\u5ea6
        • 2.4 \u00a0 \u7a7a\u95f4\u590d\u6742\u5ea6
        • 2.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/","title":"2.2 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52","text":"

        \u5728\u7b97\u6cd5\u4e2d\uff0c\u91cd\u590d\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u662f\u5f88\u5e38\u89c1\u7684\uff0c\u5176\u4e0e\u590d\u6742\u5ea6\u5206\u6790\u606f\u606f\u76f8\u5173\u3002\u56e0\u6b64\uff0c\u5728\u5c55\u5f00\u4ecb\u7ecd\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u4e86\u89e3\u5982\u4f55\u5728\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u91cd\u590d\u6267\u884c\u4efb\u52a1\uff0c\u5373\u4e24\u79cd\u57fa\u672c\u7684\u7a0b\u5e8f\u63a7\u5236\u7ed3\u6784\uff1a\u8fed\u4ee3\u3001\u9012\u5f52\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#221","title":"2.2.1 \u00a0 \u8fed\u4ee3","text":"

        \u300c\u8fed\u4ee3 iteration\u300d\u662f\u4e00\u79cd\u91cd\u590d\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u7684\u63a7\u5236\u7ed3\u6784\u3002\u5728\u8fed\u4ee3\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u5728\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\u4e0b\u91cd\u590d\u6267\u884c\u67d0\u6bb5\u4ee3\u7801\uff0c\u76f4\u5230\u8fd9\u4e2a\u6761\u4ef6\u4e0d\u518d\u6ee1\u8db3\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#1-for","title":"1. \u00a0 for \u5faa\u73af","text":"

        for \u5faa\u73af\u662f\u6700\u5e38\u89c1\u7684\u8fed\u4ee3\u5f62\u5f0f\u4e4b\u4e00\uff0c\u9002\u5408\u5728\u9884\u5148\u77e5\u9053\u8fed\u4ee3\u6b21\u6570\u65f6\u4f7f\u7528\u3002

        \u4ee5\u4e0b\u51fd\u6570\u57fa\u4e8e for \u5faa\u73af\u5b9e\u73b0\u4e86\u6c42\u548c \\(1 + 2 + \\dots + n\\) \uff0c\u6c42\u548c\u7ed3\u679c\u4f7f\u7528\u53d8\u91cf res \u8bb0\u5f55\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPython \u4e2d range(a, b) \u5bf9\u5e94\u7684\u533a\u95f4\u662f\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u7684\uff0c\u5bf9\u5e94\u7684\u904d\u5386\u8303\u56f4\u4e3a \\(a, a + 1, \\dots, b-1\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def for_loop(n: int) -> int:\n\"\"\"for \u5faa\u73af\"\"\"\nres = 0\n# \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in range(1, n + 1):\nres += i\nreturn res\n
        iteration.cpp
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; ++i) {\nres += i;\n}\nreturn res;\n}\n
        iteration.java
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.cs
        /* for \u5faa\u73af */\nint ForLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.go
        /* for \u5faa\u73af */\nfunc forLoop(n int) int {\nres := 0\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i := 1; i <= n; i++ {\nres += i\n}\nreturn res\n}\n
        iteration.swift
        /* for \u5faa\u73af */\nfunc forLoop(n: Int) -> Int {\nvar res = 0\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in 1 ... n {\nres += i\n}\nreturn res\n}\n
        iteration.js
        /* for \u5faa\u73af */\nfunction forLoop(n) {\nlet res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.ts
        /* for \u5faa\u73af */\nfunction forLoop(n: number): number {\nlet res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.dart
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.rs
        /* for \u5faa\u73af */\nfn for_loop(n: i32) -> i32 {\nlet mut res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i in 1..=n {\nres += i;\n}\nres\n} 
        iteration.c
        /* for \u5faa\u73af */\nint forLoop(int n) {\nint res = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\nres += i;\n}\nreturn res;\n}\n
        iteration.zig
        // for \u5faa\u73af\nfn forLoop(n: usize) i32 {\nvar res: i32 = 0;\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor (1..n+1) |i| {\nres = res + @as(i32, @intCast(i));\n}\nreturn res;\n} 

        \u56fe 2-1 \u662f\u8be5\u6c42\u548c\u51fd\u6570\u7684\u6d41\u7a0b\u6846\u56fe\u3002

        \u56fe 2-1 \u00a0 \u6c42\u548c\u51fd\u6570\u7684\u6d41\u7a0b\u6846\u56fe

        \u6b64\u6c42\u548c\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u6210\u6b63\u6bd4\uff0c\u6216\u8005\u8bf4\u6210\u201c\u7ebf\u6027\u5173\u7cfb\u201d\u3002\u5b9e\u9645\u4e0a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u63cf\u8ff0\u7684\u5c31\u662f\u8fd9\u4e2a\u201c\u7ebf\u6027\u5173\u7cfb\u201d\u3002\u76f8\u5173\u5185\u5bb9\u5c06\u4f1a\u5728\u4e0b\u4e00\u8282\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#2-while","title":"2. \u00a0 while \u5faa\u73af","text":"

        \u4e0e for \u5faa\u73af\u7c7b\u4f3c\uff0cwhile \u5faa\u73af\u4e5f\u662f\u4e00\u79cd\u5b9e\u73b0\u8fed\u4ee3\u7684\u65b9\u6cd5\u3002\u5728 while \u5faa\u73af\u4e2d\uff0c\u7a0b\u5e8f\u6bcf\u8f6e\u90fd\u4f1a\u5148\u68c0\u67e5\u6761\u4ef6\uff0c\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u7ee7\u7eed\u6267\u884c\uff0c\u5426\u5219\u5c31\u7ed3\u675f\u5faa\u73af\u3002

        \u4e0b\u9762\u6211\u4eec\u7528 while \u5faa\u73af\u6765\u5b9e\u73b0\u6c42\u548c \\(1 + 2 + \\dots + n\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def while_loop(n: int) -> int:\n\"\"\"while \u5faa\u73af\"\"\"\nres = 0\ni = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n# \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n:\nres += i\ni += 1  # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\nreturn res\n
        iteration.cpp
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.java
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.cs
        /* while \u5faa\u73af */\nint WhileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.go
        /* while \u5faa\u73af */\nfunc whileLoop(n int) int {\nres := 0\n// \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\ni := 1\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nfor i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++\n}\nreturn res\n}\n
        iteration.swift
        /* while \u5faa\u73af */\nfunc whileLoop(n: Int) -> Int {\nvar res = 0\nvar i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n {\nres += i\ni += 1 // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res\n}\n
        iteration.js
        /* while \u5faa\u73af */\nfunction whileLoop(n) {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.ts
        /* while \u5faa\u73af */\nfunction whileLoop(n: number): number {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.dart
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.rs
        /* while \u5faa\u73af */\nfn while_loop(n: i32) -> i32 {\nlet mut res = 0;\nlet mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile i <= n {\nres += i;\ni += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nres\n}\n
        iteration.c
        /* while \u5faa\u73af */\nint whileLoop(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += i;\ni++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n}\nreturn res;\n}\n
        iteration.zig
        // while \u5faa\u73af\nfn whileLoop(n: i32) i32 {\nvar res: i32 = 0;\nvar i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\nwhile (i <= n) {\nres += @intCast(i);\ni += 1;\n}\nreturn res;\n}\n

        while \u5faa\u73af\u6bd4 for \u5faa\u73af\u7684\u81ea\u7531\u5ea6\u66f4\u9ad8\u3002\u5728 while \u5faa\u73af\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u7531\u5730\u8bbe\u8ba1\u6761\u4ef6\u53d8\u91cf\u7684\u521d\u59cb\u5316\u548c\u66f4\u65b0\u6b65\u9aa4\u3002

        \u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u6761\u4ef6\u53d8\u91cf \\(i\\) \u6bcf\u8f6e\u8fdb\u884c\u4e24\u6b21\u66f4\u65b0\uff0c\u8fd9\u79cd\u60c5\u51b5\u5c31\u4e0d\u592a\u65b9\u4fbf\u7528 for \u5faa\u73af\u5b9e\u73b0\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def while_loop_ii(n: int) -> int:\n\"\"\"while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\"\"\"\nres = 0\ni = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n# \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n:\nres += i\n# \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1\ni *= 2\nreturn res\n
        iteration.cpp
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.java
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.cs
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint WhileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 2, 4, 5...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1; i *= 2;\n}\nreturn res;\n}\n
        iteration.go
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n int) int {\nres := 0\n// \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\ni := 1\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nfor i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++\ni *= 2\n}\nreturn res\n}\n
        iteration.swift
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n: Int) -> Int {\nvar res = 0\nvar i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n {\nres += i\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1\ni *= 2\n}\nreturn res\n}\n
        iteration.js
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n) {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.ts
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n: number): number {\nlet res = 0;\nlet i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.dart
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.rs
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfn while_loop_ii(n: i32) -> i32 {\nlet mut res = 0;\nlet mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile i <= n {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1;\ni *= 2;\n}\nres\n}\n
        iteration.c
        /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\nint res = 0;\nint i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += i;\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni++;\ni *= 2;\n}\nreturn res;\n}\n
        iteration.zig
        //  while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\nfn whileLoopII(n: i32) i32 {\nvar res: i32 = 0;\nvar i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n// \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\nwhile (i <= n) {\nres += @intCast(i);\n// \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\ni += 1;\ni *= 2;\n}\nreturn res;\n}\n

        \u603b\u7684\u6765\u8bf4\uff0cfor \u5faa\u73af\u7684\u4ee3\u7801\u66f4\u52a0\u7d27\u51d1\uff0cwhile \u5faa\u73af\u66f4\u52a0\u7075\u6d3b\uff0c\u4e24\u8005\u90fd\u53ef\u4ee5\u5b9e\u73b0\u8fed\u4ee3\u7ed3\u6784\u3002\u9009\u62e9\u4f7f\u7528\u54ea\u4e00\u4e2a\u5e94\u8be5\u6839\u636e\u7279\u5b9a\u95ee\u9898\u7684\u9700\u6c42\u6765\u51b3\u5b9a\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#3","title":"3. \u00a0 \u5d4c\u5957\u5faa\u73af","text":"

        \u6211\u4eec\u53ef\u4ee5\u5728\u4e00\u4e2a\u5faa\u73af\u7ed3\u6784\u5185\u5d4c\u5957\u53e6\u4e00\u4e2a\u5faa\u73af\u7ed3\u6784\uff0c\u4e0b\u9762\u4ee5 for \u5faa\u73af\u4e3a\u4f8b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig iteration.py
        def nested_for_loop(n: int) -> str:\n\"\"\"\u53cc\u5c42 for \u5faa\u73af\"\"\"\nres = \"\"\n# \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in range(1, n + 1):\n# \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in range(1, n + 1):\nres += f\"({i}, {j}), \"\nreturn res\n
        iteration.cpp
        /* \u53cc\u5c42 for \u5faa\u73af */\nstring nestedForLoop(int n) {\nostringstream res;\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; ++i) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; ++j) {\nres << \"(\" << i << \", \" << j << \"), \";\n}\n}\nreturn res.str();\n}\n
        iteration.java
        /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\nStringBuilder res = new StringBuilder();\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres.append(\"(\" + i + \", \" + j + \"), \");\n}\n}\nreturn res.toString();\n}\n
        iteration.cs
        /* \u53cc\u5c42 for \u5faa\u73af */\nstring NestedForLoop(int n) {\nStringBuilder res = new();\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres.Append($\"({i}, {j}), \");\n}\n}\nreturn res.ToString();\n}\n
        iteration.go
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n int) string {\nres := \"\"\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i := 1; i <= n; i++ {\nfor j := 1; j <= n; j++ {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nres += fmt.Sprintf(\"(%d, %d), \", i, j)\n}\n}\nreturn res\n}\n
        iteration.swift
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n: Int) -> String {\nvar res = \"\"\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in 1 ... n {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in 1 ... n {\nres.append(\"(\\(i), \\(j)), \")\n}\n}\nreturn res\n}\n
        iteration.js
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n) {\nlet res = '';\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (let j = 1; j <= n; j++) {\nres += `(${i}, ${j}), `;\n}\n}\nreturn res;\n}\n
        iteration.ts
        /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n: number): string {\nlet res = '';\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (let i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (let j = 1; j <= n; j++) {\nres += `(${i}, ${j}), `;\n}\n}\nreturn res;\n}\n
        iteration.dart
        /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\nString res = \"\";\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nres += \"($i, $j), \";\n}\n}\nreturn res;\n}\n
        iteration.rs
        /* \u53cc\u5c42 for \u5faa\u73af */\nfn nested_for_loop(n: i32) -> String {\nlet mut res = vec![];\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor i in 1..=n {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor j in 1..=n {\nres.push(format!(\"({}, {}), \", i, j));\n}\n}\nres.join(\"\")\n}\n
        iteration.c
        /* \u53cc\u5c42 for \u5faa\u73af */\nchar *nestedForLoop(int n) {\n// n * n \u4e3a\u5bf9\u5e94\u70b9\u6570\u91cf\uff0c\"(i, j), \" \u5bf9\u5e94\u5b57\u7b26\u4e32\u957f\u6700\u5927\u4e3a 6+10*2\uff0c\u52a0\u4e0a\u6700\u540e\u4e00\u4e2a\u7a7a\u5b57\u7b26 \\0 \u7684\u989d\u5916\u7a7a\u95f4\nint size = n * n * 26 + 1;\nchar *res = malloc(size * sizeof(char));\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (int i = 1; i <= n; i++) {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (int j = 1; j <= n; j++) {\nchar tmp[26];\nsnprintf(tmp, sizeof(tmp), \"(%d, %d), \", i, j);\nstrncat(res, tmp, size - strlen(res) - 1);\n}\n}\nreturn res;\n}\n
        iteration.zig
        // \u53cc\u5c42 for \u5faa\u73af\nfn nestedForLoop(allocator: Allocator, n: usize) ![]const u8 {\nvar res = std.ArrayList(u8).init(allocator);\ndefer res.deinit();\nvar buffer: [20]u8 = undefined;\n// \u5faa\u73af i = 1, 2, ..., n-1, n\nfor (1..n+1) |i| {\n// \u5faa\u73af j = 1, 2, ..., n-1, n\nfor (1..n+1) |j| {\nvar _str = try std.fmt.bufPrint(&buffer, \"({d}, {d}), \", .{i, j});\ntry res.appendSlice(_str);\n}\n}\nreturn res.toOwnedSlice();\n}\n

        \u56fe 2-2 \u662f\u8be5\u5d4c\u5957\u5faa\u73af\u7684\u6d41\u7a0b\u6846\u56fe\u3002

        \u56fe 2-2 \u00a0 \u5d4c\u5957\u5faa\u73af\u7684\u6d41\u7a0b\u6846\u56fe

        \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e \\(n^2\\) \u6210\u6b63\u6bd4\uff0c\u6216\u8005\u8bf4\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u548c\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u6210\u201c\u5e73\u65b9\u5173\u7cfb\u201d\u3002

        \u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u6dfb\u52a0\u5d4c\u5957\u5faa\u73af\uff0c\u6bcf\u4e00\u6b21\u5d4c\u5957\u90fd\u662f\u4e00\u6b21\u201c\u5347\u7ef4\u201d\uff0c\u5c06\u4f1a\u4f7f\u65f6\u95f4\u590d\u6742\u5ea6\u63d0\u9ad8\u81f3\u201c\u7acb\u65b9\u5173\u7cfb\u201d\u201c\u56db\u6b21\u65b9\u5173\u7cfb\u201d\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#222","title":"2.2.2 \u00a0 \u9012\u5f52","text":"

        \u300c\u9012\u5f52 recursion\u300d\u662f\u4e00\u79cd\u7b97\u6cd5\u7b56\u7565\uff0c\u901a\u8fc7\u51fd\u6570\u8c03\u7528\u81ea\u8eab\u6765\u89e3\u51b3\u95ee\u9898\u3002\u5b83\u4e3b\u8981\u5305\u542b\u4e24\u4e2a\u9636\u6bb5\u3002

        1. \u9012\uff1a\u7a0b\u5e8f\u4e0d\u65ad\u6df1\u5165\u5730\u8c03\u7528\u81ea\u8eab\uff0c\u901a\u5e38\u4f20\u5165\u66f4\u5c0f\u6216\u66f4\u7b80\u5316\u7684\u53c2\u6570\uff0c\u76f4\u5230\u8fbe\u5230\u201c\u7ec8\u6b62\u6761\u4ef6\u201d\u3002
        2. \u5f52\uff1a\u89e6\u53d1\u201c\u7ec8\u6b62\u6761\u4ef6\u201d\u540e\uff0c\u7a0b\u5e8f\u4ece\u6700\u6df1\u5c42\u7684\u9012\u5f52\u51fd\u6570\u5f00\u59cb\u9010\u5c42\u8fd4\u56de\uff0c\u6c47\u805a\u6bcf\u4e00\u5c42\u7684\u7ed3\u679c\u3002

        \u800c\u4ece\u5b9e\u73b0\u7684\u89d2\u5ea6\u770b\uff0c\u9012\u5f52\u4ee3\u7801\u4e3b\u8981\u5305\u542b\u4e09\u4e2a\u8981\u7d20\u3002

        1. \u7ec8\u6b62\u6761\u4ef6\uff1a\u7528\u4e8e\u51b3\u5b9a\u4ec0\u4e48\u65f6\u5019\u7531\u201c\u9012\u201d\u8f6c\u201c\u5f52\u201d\u3002
        2. \u9012\u5f52\u8c03\u7528\uff1a\u5bf9\u5e94\u201c\u9012\u201d\uff0c\u51fd\u6570\u8c03\u7528\u81ea\u8eab\uff0c\u901a\u5e38\u8f93\u5165\u66f4\u5c0f\u6216\u66f4\u7b80\u5316\u7684\u53c2\u6570\u3002
        3. \u8fd4\u56de\u7ed3\u679c\uff1a\u5bf9\u5e94\u201c\u5f52\u201d\uff0c\u5c06\u5f53\u524d\u9012\u5f52\u5c42\u7ea7\u7684\u7ed3\u679c\u8fd4\u56de\u81f3\u4e0a\u4e00\u5c42\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6211\u4eec\u53ea\u9700\u8c03\u7528\u51fd\u6570 recur(n) \uff0c\u5c31\u53ef\u4ee5\u5b8c\u6210 \\(1 + 2 + \\dots + n\\) \u7684\u8ba1\u7b97\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def recur(n: int) -> int:\n\"\"\"\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif n == 1:\nreturn 1\n# \u9012\uff1a\u9012\u5f52\u8c03\u7528\nres = recur(n - 1)\n# \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n
        recursion.cpp
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.java
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.cs
        /* \u9012\u5f52 */\nint Recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = Recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.go
        /* \u9012\u5f52 */\nfunc recur(n int) int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nres := recur(n - 1)\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n}\n
        recursion.swift
        /* \u9012\u5f52 */\nfunc recur(n: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nlet res = recur(n: n - 1)\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res\n}\n
        recursion.js
        /* \u9012\u5f52 */\nfunction recur(n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nconst res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.ts
        /* \u9012\u5f52 */\nfunction recur(n: number): number {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nconst res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.dart
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1) return 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.rs
        /* \u9012\u5f52 */\nfn recur(n: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 1 {\nreturn 1;\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nlet res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nn + res\n}\n
        recursion.c
        /* \u9012\u5f52 */\nint recur(int n) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1)\nreturn 1;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nint res = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n
        recursion.zig
        // \u9012\u5f52\u51fd\u6570\nfn recur(n: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 1) {\nreturn 1;\n}\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nvar res: i32 = recur(n - 1);\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nreturn n + res;\n}\n

        \u56fe 2-3 \u5c55\u793a\u4e86\u8be5\u51fd\u6570\u7684\u9012\u5f52\u8fc7\u7a0b\u3002

        \u56fe 2-3 \u00a0 \u6c42\u548c\u51fd\u6570\u7684\u9012\u5f52\u8fc7\u7a0b

        \u867d\u7136\u4ece\u8ba1\u7b97\u89d2\u5ea6\u770b\uff0c\u8fed\u4ee3\u4e0e\u9012\u5f52\u53ef\u4ee5\u5f97\u5230\u76f8\u540c\u7684\u7ed3\u679c\uff0c\u4f46\u5b83\u4eec\u4ee3\u8868\u4e86\u4e24\u79cd\u5b8c\u5168\u4e0d\u540c\u7684\u601d\u8003\u548c\u89e3\u51b3\u95ee\u9898\u7684\u8303\u5f0f\u3002

        • \u8fed\u4ee3\uff1a\u201c\u81ea\u4e0b\u800c\u4e0a\u201d\u5730\u89e3\u51b3\u95ee\u9898\u3002\u4ece\u6700\u57fa\u7840\u7684\u6b65\u9aa4\u5f00\u59cb\uff0c\u7136\u540e\u4e0d\u65ad\u91cd\u590d\u6216\u7d2f\u52a0\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u76f4\u5230\u4efb\u52a1\u5b8c\u6210\u3002
        • \u9012\u5f52\uff1a\u201c\u81ea\u4e0a\u800c\u4e0b\u201d\u5730\u89e3\u51b3\u95ee\u9898\u3002\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u8fd9\u4e9b\u5b50\u95ee\u9898\u548c\u539f\u95ee\u9898\u5177\u6709\u76f8\u540c\u7684\u5f62\u5f0f\u3002\u63a5\u4e0b\u6765\u5c06\u5b50\u95ee\u9898\u7ee7\u7eed\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u5230\u57fa\u672c\u60c5\u51b5\u65f6\u505c\u6b62\uff08\u57fa\u672c\u60c5\u51b5\u7684\u89e3\u662f\u5df2\u77e5\u7684\uff09\u3002

        \u4ee5\u4e0a\u8ff0\u6c42\u548c\u51fd\u6570\u4e3a\u4f8b\uff0c\u8bbe\u95ee\u9898 \\(f(n) = 1 + 2 + \\dots + n\\) \u3002

        • \u8fed\u4ee3\uff1a\u5728\u5faa\u73af\u4e2d\u6a21\u62df\u6c42\u548c\u8fc7\u7a0b\uff0c\u4ece \\(1\\) \u904d\u5386\u5230 \\(n\\) \uff0c\u6bcf\u8f6e\u6267\u884c\u6c42\u548c\u64cd\u4f5c\uff0c\u5373\u53ef\u6c42\u5f97 \\(f(n)\\) \u3002
        • \u9012\u5f52\uff1a\u5c06\u95ee\u9898\u5206\u89e3\u4e3a\u5b50\u95ee\u9898 \\(f(n) = n + f(n-1)\\) \uff0c\u4e0d\u65ad\uff08\u9012\u5f52\u5730\uff09\u5206\u89e3\u4e0b\u53bb\uff0c\u76f4\u81f3\u57fa\u672c\u60c5\u51b5 \\(f(1) = 1\\) \u65f6\u7ec8\u6b62\u3002
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#1","title":"1. \u00a0 \u8c03\u7528\u6808","text":"

        \u9012\u5f52\u51fd\u6570\u6bcf\u6b21\u8c03\u7528\u81ea\u8eab\u65f6\uff0c\u7cfb\u7edf\u90fd\u4f1a\u4e3a\u65b0\u5f00\u542f\u7684\u51fd\u6570\u5206\u914d\u5185\u5b58\uff0c\u4ee5\u5b58\u50a8\u5c40\u90e8\u53d8\u91cf\u3001\u8c03\u7528\u5730\u5740\u548c\u5176\u4ed6\u4fe1\u606f\u7b49\u3002\u8fd9\u5c06\u5bfc\u81f4\u4e24\u65b9\u9762\u7684\u7ed3\u679c\u3002

        • \u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u6570\u636e\u90fd\u5b58\u50a8\u5728\u79f0\u4e3a\u201c\u6808\u5e27\u7a7a\u95f4\u201d\u7684\u5185\u5b58\u533a\u57df\u4e2d\uff0c\u76f4\u81f3\u51fd\u6570\u8fd4\u56de\u540e\u624d\u4f1a\u88ab\u91ca\u653e\u3002\u56e0\u6b64\uff0c\u9012\u5f52\u901a\u5e38\u6bd4\u8fed\u4ee3\u66f4\u52a0\u8017\u8d39\u5185\u5b58\u7a7a\u95f4\u3002
        • \u9012\u5f52\u8c03\u7528\u51fd\u6570\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u5f00\u9500\u3002\u56e0\u6b64\u9012\u5f52\u901a\u5e38\u6bd4\u5faa\u73af\u7684\u65f6\u95f4\u6548\u7387\u66f4\u4f4e\u3002

        \u5982\u56fe 2-4 \u6240\u793a\uff0c\u5728\u89e6\u53d1\u7ec8\u6b62\u6761\u4ef6\u524d\uff0c\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684\u9012\u5f52\u51fd\u6570\uff0c\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \u3002

        \u56fe 2-4 \u00a0 \u9012\u5f52\u8c03\u7528\u6df1\u5ea6

        \u5728\u5b9e\u9645\u4e2d\uff0c\u7f16\u7a0b\u8bed\u8a00\u5141\u8bb8\u7684\u9012\u5f52\u6df1\u5ea6\u901a\u5e38\u662f\u6709\u9650\u7684\uff0c\u8fc7\u6df1\u7684\u9012\u5f52\u53ef\u80fd\u5bfc\u81f4\u6808\u6ea2\u51fa\u9519\u8bef\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#2","title":"2. \u00a0 \u5c3e\u9012\u5f52","text":"

        \u6709\u8da3\u7684\u662f\uff0c\u5982\u679c\u51fd\u6570\u5728\u8fd4\u56de\u524d\u7684\u6700\u540e\u4e00\u6b65\u624d\u8fdb\u884c\u9012\u5f52\u8c03\u7528\uff0c\u5219\u8be5\u51fd\u6570\u53ef\u4ee5\u88ab\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u4f18\u5316\uff0c\u4f7f\u5176\u5728\u7a7a\u95f4\u6548\u7387\u4e0a\u4e0e\u8fed\u4ee3\u76f8\u5f53\u3002\u8fd9\u79cd\u60c5\u51b5\u88ab\u79f0\u4e3a\u300c\u5c3e\u9012\u5f52 tail recursion\u300d\u3002

        • \u666e\u901a\u9012\u5f52\uff1a\u5f53\u51fd\u6570\u8fd4\u56de\u5230\u4e0a\u4e00\u5c42\u7ea7\u7684\u51fd\u6570\u540e\uff0c\u9700\u8981\u7ee7\u7eed\u6267\u884c\u4ee3\u7801\uff0c\u56e0\u6b64\u7cfb\u7edf\u9700\u8981\u4fdd\u5b58\u4e0a\u4e00\u5c42\u8c03\u7528\u7684\u4e0a\u4e0b\u6587\u3002
        • \u5c3e\u9012\u5f52\uff1a\u9012\u5f52\u8c03\u7528\u662f\u51fd\u6570\u8fd4\u56de\u524d\u7684\u6700\u540e\u4e00\u4e2a\u64cd\u4f5c\uff0c\u8fd9\u610f\u5473\u7740\u51fd\u6570\u8fd4\u56de\u5230\u4e0a\u4e00\u5c42\u7ea7\u540e\uff0c\u65e0\u987b\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u56e0\u6b64\u7cfb\u7edf\u65e0\u987b\u4fdd\u5b58\u4e0a\u4e00\u5c42\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u3002

        \u4ee5\u8ba1\u7b97 \\(1 + 2 + \\dots + n\\) \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u7ed3\u679c\u53d8\u91cf res \u8bbe\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u4ece\u800c\u5b9e\u73b0\u5c3e\u9012\u5f52\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def tail_recur(n, res):\n\"\"\"\u5c3e\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif n == 0:\nreturn res\n# \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tail_recur(n - 1, res + n)\n
        recursion.cpp
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.java
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.cs
        /* \u5c3e\u9012\u5f52 */\nint TailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn TailRecur(n - 1, res + n);\n}\n
        recursion.go
        /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n int, res int) int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n-1, res+n)\n}\n
        recursion.swift
        /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n: Int, res: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n: n - 1, res: res + n)\n}\n
        recursion.js
        /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n, res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.ts
        /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n: number, res: number): number {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n === 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.dart
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0) return res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.rs
        /* \u5c3e\u9012\u5f52 */\nfn tail_recur(n: i32, res: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif n == 0 {\nreturn res;\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\ntail_recur(n - 1, res + n)\n}\n
        recursion.c
        /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0)\nreturn res;\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n
        recursion.zig
        // \u5c3e\u9012\u5f52\u51fd\u6570\nfn tailRecur(n: i32, res: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6\nif (n == 0) {\nreturn res;\n}\n// \u5c3e\u9012\u5f52\u8c03\u7528\nreturn tailRecur(n - 1, res + n);\n}\n

        \u5c3e\u9012\u5f52\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u56fe 2-5 \u6240\u793a\u3002\u5bf9\u6bd4\u666e\u901a\u9012\u5f52\u548c\u5c3e\u9012\u5f52\uff0c\u4e24\u8005\u7684\u6c42\u548c\u64cd\u4f5c\u7684\u6267\u884c\u70b9\u662f\u4e0d\u540c\u7684\u3002

        • \u666e\u901a\u9012\u5f52\uff1a\u6c42\u548c\u64cd\u4f5c\u662f\u5728\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u4e2d\u6267\u884c\u7684\uff0c\u6bcf\u5c42\u8fd4\u56de\u540e\u90fd\u8981\u518d\u6267\u884c\u4e00\u6b21\u6c42\u548c\u64cd\u4f5c\u3002
        • \u5c3e\u9012\u5f52\uff1a\u6c42\u548c\u64cd\u4f5c\u662f\u5728\u201c\u9012\u201d\u7684\u8fc7\u7a0b\u4e2d\u6267\u884c\u7684\uff0c\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u53ea\u9700\u5c42\u5c42\u8fd4\u56de\u3002

        \u56fe 2-5 \u00a0 \u5c3e\u9012\u5f52\u8fc7\u7a0b

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u8bb8\u591a\u7f16\u8bd1\u5668\u6216\u89e3\u91ca\u5668\u5e76\u4e0d\u652f\u6301\u5c3e\u9012\u5f52\u4f18\u5316\u3002\u4f8b\u5982\uff0cPython \u9ed8\u8ba4\u4e0d\u652f\u6301\u5c3e\u9012\u5f52\u4f18\u5316\uff0c\u56e0\u6b64\u5373\u4f7f\u51fd\u6570\u662f\u5c3e\u9012\u5f52\u5f62\u5f0f\uff0c\u4ecd\u7136\u53ef\u80fd\u4f1a\u9047\u5230\u6808\u6ea2\u51fa\u95ee\u9898\u3002

        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#3_1","title":"3. \u00a0 \u9012\u5f52\u6811","text":"

        \u5f53\u5904\u7406\u4e0e\u201c\u5206\u6cbb\u201d\u76f8\u5173\u7684\u7b97\u6cd5\u95ee\u9898\u65f6\uff0c\u9012\u5f52\u5f80\u5f80\u6bd4\u8fed\u4ee3\u7684\u601d\u8def\u66f4\u52a0\u76f4\u89c2\u3001\u4ee3\u7801\u66f4\u52a0\u6613\u8bfb\u3002\u4ee5\u201c\u6590\u6ce2\u90a3\u5951\u6570\u5217\u201d\u4e3a\u4f8b\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6590\u6ce2\u90a3\u5951\u6570\u5217 \\(0, 1, 1, 2, 3, 5, 8, 13, \\dots\\) \uff0c\u6c42\u8be5\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\u3002

        \u8bbe\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\u4e3a \\(f(n)\\) \uff0c\u6613\u5f97\u4e24\u4e2a\u7ed3\u8bba\u3002

        • \u6570\u5217\u7684\u524d\u4e24\u4e2a\u6570\u5b57\u4e3a \\(f(1) = 0\\) \u548c \\(f(2) = 1\\) \u3002
        • \u6570\u5217\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u662f\u524d\u4e24\u4e2a\u6570\u5b57\u7684\u548c\uff0c\u5373 \\(f(n) = f(n - 1) + f(n - 2)\\) \u3002

        \u6309\u7167\u9012\u63a8\u5173\u7cfb\u8fdb\u884c\u9012\u5f52\u8c03\u7528\uff0c\u5c06\u524d\u4e24\u4e2a\u6570\u5b57\u4f5c\u4e3a\u7ec8\u6b62\u6761\u4ef6\uff0c\u4fbf\u53ef\u5199\u51fa\u9012\u5f52\u4ee3\u7801\u3002\u8c03\u7528 fib(n) \u5373\u53ef\u5f97\u5230\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u7b2c \\(n\\) \u4e2a\u6570\u5b57\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def fib(n: int) -> int:\n\"\"\"\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 or n == 2:\nreturn n - 1\n# \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nres = fib(n - 1) + fib(n - 2)\n# \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n
        recursion.cpp
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.java
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.cs
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint Fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = Fib(n - 1) + Fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.go
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunc fib(n int) int {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nres := fib(n-1) + fib(n-2)\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n}\n
        recursion.swift
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunc fib(n: Int) -> Int {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nlet res = fib(n: n - 1) + fib(n: n - 2)\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res\n}\n
        recursion.js
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunction fib(n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n === 1 || n === 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nconst res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.ts
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfunction fib(n: number): number {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n === 1 || n === 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nconst res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.dart
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2) return n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.rs
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nfn fib(n: i32) -> i32 {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif n == 1 || n == 2 {\nreturn n - 1;\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nlet res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c\nres\n}\n
        recursion.c
        /* \u6590\u6ce2\u90a3\u5951\u6570\u5217\uff1a\u9012\u5f52 */\nint fib(int n) {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 || n == 2)\nreturn n - 1;\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nint res = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n
        recursion.zig
        // \u6590\u6ce2\u90a3\u5951\u6570\u5217\nfn fib(n: i32) i32 {\n// \u7ec8\u6b62\u6761\u4ef6 f(1) = 0, f(2) = 1\nif (n == 1 or n == 2) {\nreturn n - 1;\n}\n// \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\nvar res: i32 = fib(n - 1) + fib(n - 2);\n// \u8fd4\u56de\u7ed3\u679c f(n)\nreturn res;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u6211\u4eec\u5728\u51fd\u6570\u5185\u9012\u5f52\u8c03\u7528\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u4ece\u4e00\u4e2a\u8c03\u7528\u4ea7\u751f\u4e86\u4e24\u4e2a\u8c03\u7528\u5206\u652f\u3002\u5982\u56fe 2-6 \u6240\u793a\uff0c\u8fd9\u6837\u4e0d\u65ad\u9012\u5f52\u8c03\u7528\u4e0b\u53bb\uff0c\u6700\u7ec8\u5c06\u4ea7\u751f\u4e00\u68f5\u5c42\u6570\u4e3a \\(n\\) \u7684\u300c\u9012\u5f52\u6811 recursion tree\u300d\u3002

        \u56fe 2-6 \u00a0 \u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u9012\u5f52\u6811

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9012\u5f52\u4f53\u73b0\u4e86\u201c\u5c06\u95ee\u9898\u5206\u89e3\u4e3a\u66f4\u5c0f\u5b50\u95ee\u9898\u201d\u7684\u601d\u7ef4\u8303\u5f0f\uff0c\u8fd9\u79cd\u5206\u6cbb\u7b56\u7565\u81f3\u5173\u91cd\u8981\u3002

        • \u4ece\u7b97\u6cd5\u89d2\u5ea6\u770b\uff0c\u641c\u7d22\u3001\u6392\u5e8f\u3001\u56de\u6eaf\u3001\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u7b49\u8bb8\u591a\u91cd\u8981\u7b97\u6cd5\u7b56\u7565\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u5e94\u7528\u4e86\u8fd9\u79cd\u601d\u7ef4\u65b9\u5f0f\u3002
        • \u4ece\u6570\u636e\u7ed3\u6784\u89d2\u5ea6\u770b\uff0c\u9012\u5f52\u5929\u7136\u9002\u5408\u5904\u7406\u94fe\u8868\u3001\u6811\u548c\u56fe\u7684\u76f8\u5173\u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u4eec\u975e\u5e38\u9002\u5408\u7528\u5206\u6cbb\u601d\u60f3\u8fdb\u884c\u5206\u6790\u3002
        "},{"location":"chapter_computational_complexity/iteration_and_recursion/#223","title":"2.2.3 \u00a0 \u4e24\u8005\u5bf9\u6bd4","text":"

        \u603b\u7ed3\u4ee5\u4e0a\u5185\u5bb9\uff0c\u5982\u8868 2-1 \u6240\u793a\uff0c\u8fed\u4ee3\u548c\u9012\u5f52\u5728\u5b9e\u73b0\u3001\u6027\u80fd\u548c\u9002\u7528\u6027\u4e0a\u6709\u6240\u4e0d\u540c\u3002

        \u8868 2-1 \u00a0 \u8fed\u4ee3\u4e0e\u9012\u5f52\u7279\u70b9\u5bf9\u6bd4

        \u8fed\u4ee3 \u9012\u5f52 \u5b9e\u73b0\u65b9\u5f0f \u5faa\u73af\u7ed3\u6784 \u51fd\u6570\u8c03\u7528\u81ea\u8eab \u65f6\u95f4\u6548\u7387 \u6548\u7387\u901a\u5e38\u8f83\u9ad8\uff0c\u65e0\u51fd\u6570\u8c03\u7528\u5f00\u9500 \u6bcf\u6b21\u51fd\u6570\u8c03\u7528\u90fd\u4f1a\u4ea7\u751f\u5f00\u9500 \u5185\u5b58\u4f7f\u7528 \u901a\u5e38\u4f7f\u7528\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4 \u7d2f\u79ef\u51fd\u6570\u8c03\u7528\u53ef\u80fd\u4f7f\u7528\u5927\u91cf\u7684\u6808\u5e27\u7a7a\u95f4 \u9002\u7528\u95ee\u9898 \u9002\u7528\u4e8e\u7b80\u5355\u5faa\u73af\u4efb\u52a1\uff0c\u4ee3\u7801\u76f4\u89c2\u3001\u53ef\u8bfb\u6027\u597d \u9002\u7528\u4e8e\u5b50\u95ee\u9898\u5206\u89e3\uff0c\u5982\u6811\u3001\u56fe\u3001\u5206\u6cbb\u3001\u56de\u6eaf\u7b49\uff0c\u4ee3\u7801\u7ed3\u6784\u7b80\u6d01\u3001\u6e05\u6670

        Tip

        \u5982\u679c\u611f\u89c9\u4ee5\u4e0b\u5185\u5bb9\u7406\u89e3\u56f0\u96be\uff0c\u53ef\u4ee5\u5728\u8bfb\u5b8c\u201c\u6808\u201d\u7ae0\u8282\u540e\u518d\u6765\u590d\u4e60\u3002

        \u90a3\u4e48\uff0c\u8fed\u4ee3\u548c\u9012\u5f52\u5177\u6709\u4ec0\u4e48\u5185\u5728\u8054\u7cfb\u5462\uff1f\u4ee5\u4e0a\u8ff0\u7684\u9012\u5f52\u51fd\u6570\u4e3a\u4f8b\uff0c\u6c42\u548c\u64cd\u4f5c\u5728\u9012\u5f52\u7684\u201c\u5f52\u201d\u9636\u6bb5\u8fdb\u884c\u3002\u8fd9\u610f\u5473\u7740\u6700\u521d\u88ab\u8c03\u7528\u7684\u51fd\u6570\u5b9e\u9645\u4e0a\u662f\u6700\u540e\u5b8c\u6210\u5176\u6c42\u548c\u64cd\u4f5c\u7684\uff0c\u8fd9\u79cd\u5de5\u4f5c\u673a\u5236\u4e0e\u6808\u7684\u201c\u5148\u5165\u540e\u51fa\u201d\u539f\u5219\u662f\u5f02\u66f2\u540c\u5de5\u7684\u3002

        \u4e8b\u5b9e\u4e0a\uff0c\u201c\u8c03\u7528\u6808\u201d\u548c\u201c\u6808\u5e27\u7a7a\u95f4\u201d\u8fd9\u7c7b\u9012\u5f52\u672f\u8bed\u5df2\u7ecf\u6697\u793a\u4e86\u9012\u5f52\u4e0e\u6808\u4e4b\u95f4\u7684\u5bc6\u5207\u5173\u7cfb\u3002

        1. \u9012\uff1a\u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5728\u201c\u8c03\u7528\u6808\u201d\u4e0a\u4e3a\u8be5\u51fd\u6570\u5206\u914d\u65b0\u7684\u6808\u5e27\uff0c\u7528\u4e8e\u5b58\u50a8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3001\u53c2\u6570\u3001\u8fd4\u56de\u5730\u5740\u7b49\u6570\u636e\u3002
        2. \u5f52\uff1a\u5f53\u51fd\u6570\u5b8c\u6210\u6267\u884c\u5e76\u8fd4\u56de\u65f6\uff0c\u5bf9\u5e94\u7684\u6808\u5e27\u4f1a\u4ece\u201c\u8c03\u7528\u6808\u201d\u4e0a\u88ab\u79fb\u9664\uff0c\u6062\u590d\u4e4b\u524d\u51fd\u6570\u7684\u6267\u884c\u73af\u5883\u3002

        \u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u8c03\u7528\u6808\u7684\u884c\u4e3a\uff0c\u4ece\u800c\u5c06\u9012\u5f52\u8f6c\u5316\u4e3a\u8fed\u4ee3\u5f62\u5f0f\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig recursion.py
        def for_loop_recur(n: int) -> int:\n\"\"\"\u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52\"\"\"\n# \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack = []\nres = 0\n# \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in range(n, 0, -1):\n# \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.append(i)\n# \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile stack:\n# \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop()\n# res = 1+2+3+...+n\nreturn res\n
        recursion.cpp
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack<int> stack;\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.empty()) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.top();\nstack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.java
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nStack<Integer> stack = new Stack<>();\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.isEmpty()) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.cs
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint ForLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nStack<int> stack = new();\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.Push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.Count > 0) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.Pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.go
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunc forLoopRecur(n int) int {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nstack := list.New()\nres := 0\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i := n; i > 0; i-- {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.PushBack(i)\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nfor stack.Len() != 0 {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.Back().Value.(int)\nstack.Remove(stack.Back())\n}\n// res = 1+2+3+...+n\nreturn res\n}\n
        recursion.swift
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunc forLoopRecur(n: Int) -> Int {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nvar stack: [Int] = []\nvar res = 0\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in stride(from: n, to: 0, by: -1) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.append(i)\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile !stack.isEmpty {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.removeLast()\n}\n// res = 1+2+3+...+n\nreturn res\n}\n
        recursion.js
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunction forLoopRecur(n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nconst stack = [];\nlet res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (let i = 1; i <= n; i++) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.length) { // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.ts
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfunction forLoopRecur(n: number): number {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808 \nconst stack: number[] = [];\nlet res: number = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (let i = 1; i <= n; i++) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (stack.length) { // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.dart
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nList<int> stack = [];\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.add(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (!stack.isEmpty) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.removeLast();\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.rs
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nfn for_loop_recur(n: i32) -> i32 {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nlet mut stack = Vec::new();\nlet mut res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor i in (1..=n).rev() {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack.push(i);\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile !stack.is_empty() {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack.pop().unwrap();\n}\n// res = 1+2+3+...+n\nres\n}\n
        recursion.c
        /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\nint stack[1000]; // \u501f\u52a9\u4e00\u4e2a\u5927\u6570\u7ec4\u6765\u6a21\u62df\u6808\nint top = -1;    // \u6808\u9876\u7d22\u5f15\nint res = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nfor (int i = n; i > 0; i--) {\n// \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\nstack[1 + top++] = i;\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nwhile (top >= 0) {\n// \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\nres += stack[top--];\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n
        recursion.zig
        // \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52\nfn forLoopRecur(comptime n: i32) i32 {\n// \u4f7f\u7528\u4e00\u4e2a\u663e\u5f0f\u7684\u6808\u6765\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\nvar stack: [n]i32 = undefined;\nvar res: i32 = 0;\n// \u9012\uff1a\u9012\u5f52\u8c03\u7528\nvar i: usize = n;\nwhile (i > 0) {\nstack[i - 1] = @intCast(i);\ni -= 1;\n}\n// \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\nvar index: usize = n;\nwhile (index > 0) {\nindex -= 1;\nres += stack[index];\n}\n// res = 1+2+3+...+n\nreturn res;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u5f53\u9012\u5f52\u88ab\u8f6c\u6362\u4e3a\u8fed\u4ee3\u540e\uff0c\u4ee3\u7801\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u4e86\u3002\u5c3d\u7ba1\u8fed\u4ee3\u548c\u9012\u5f52\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362\uff0c\u4f46\u4e5f\u4e0d\u4e00\u5b9a\u503c\u5f97\u8fd9\u6837\u505a\uff0c\u6709\u4ee5\u4e0b\u4e24\u70b9\u539f\u56e0\u3002

        • \u8f6c\u5316\u540e\u7684\u4ee3\u7801\u53ef\u80fd\u66f4\u52a0\u96be\u4ee5\u7406\u89e3\uff0c\u53ef\u8bfb\u6027\u66f4\u5dee\u3002
        • \u5bf9\u4e8e\u67d0\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u6a21\u62df\u7cfb\u7edf\u8c03\u7528\u6808\u7684\u884c\u4e3a\u53ef\u80fd\u975e\u5e38\u56f0\u96be\u3002

        \u603b\u4e4b\uff0c\u9009\u62e9\u8fed\u4ee3\u8fd8\u662f\u9012\u5f52\u53d6\u51b3\u4e8e\u7279\u5b9a\u95ee\u9898\u7684\u6027\u8d28\u3002\u5728\u7f16\u7a0b\u5b9e\u8df5\u4e2d\uff0c\u6743\u8861\u4e24\u8005\u7684\u4f18\u52a3\u5e76\u6839\u636e\u60c5\u5883\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/","title":"2.1 \u00a0 \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30","text":"

        \u5728\u7b97\u6cd5\u8bbe\u8ba1\u4e2d\uff0c\u6211\u4eec\u5148\u540e\u8ffd\u6c42\u4ee5\u4e0b\u4e24\u4e2a\u5c42\u9762\u7684\u76ee\u6807\u3002

        1. \u627e\u5230\u95ee\u9898\u89e3\u6cd5\uff1a\u7b97\u6cd5\u9700\u8981\u5728\u89c4\u5b9a\u7684\u8f93\u5165\u8303\u56f4\u5185\u53ef\u9760\u5730\u6c42\u5f97\u95ee\u9898\u7684\u6b63\u786e\u89e3\u3002
        2. \u5bfb\u6c42\u6700\u4f18\u89e3\u6cd5\uff1a\u540c\u4e00\u4e2a\u95ee\u9898\u53ef\u80fd\u5b58\u5728\u591a\u79cd\u89e3\u6cd5\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u5230\u5c3d\u53ef\u80fd\u9ad8\u6548\u7684\u7b97\u6cd5\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u80fd\u591f\u89e3\u51b3\u95ee\u9898\u7684\u524d\u63d0\u4e0b\uff0c\u7b97\u6cd5\u6548\u7387\u5df2\u6210\u4e3a\u8861\u91cf\u7b97\u6cd5\u4f18\u52a3\u7684\u4e3b\u8981\u8bc4\u4ef7\u6307\u6807\uff0c\u5b83\u5305\u62ec\u4ee5\u4e0b\u4e24\u4e2a\u7ef4\u5ea6\u3002

        • \u65f6\u95f4\u6548\u7387\uff1a\u7b97\u6cd5\u8fd0\u884c\u901f\u5ea6\u7684\u5feb\u6162\u3002
        • \u7a7a\u95f4\u6548\u7387\uff1a\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u7684\u5927\u5c0f\u3002

        \u7b80\u800c\u8a00\u4e4b\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u8bbe\u8ba1\u201c\u65e2\u5feb\u53c8\u7701\u201d\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u3002\u800c\u6709\u6548\u5730\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u53ea\u6709\u8fd9\u6837\u6211\u4eec\u624d\u80fd\u5c06\u5404\u79cd\u7b97\u6cd5\u8fdb\u884c\u5bf9\u6bd4\uff0c\u8fdb\u800c\u6307\u5bfc\u7b97\u6cd5\u8bbe\u8ba1\u4e0e\u4f18\u5316\u8fc7\u7a0b\u3002

        \u6548\u7387\u8bc4\u4f30\u65b9\u6cd5\u4e3b\u8981\u5206\u4e3a\u4e24\u79cd\uff1a\u5b9e\u9645\u6d4b\u8bd5\u3001\u7406\u8bba\u4f30\u7b97\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/#211","title":"2.1.1 \u00a0 \u5b9e\u9645\u6d4b\u8bd5","text":"

        \u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u7b97\u6cd5 A \u548c\u7b97\u6cd5 B \uff0c\u5b83\u4eec\u90fd\u80fd\u89e3\u51b3\u540c\u4e00\u95ee\u9898\uff0c\u73b0\u5728\u9700\u8981\u5bf9\u6bd4\u8fd9\u4e24\u4e2a\u7b97\u6cd5\u7684\u6548\u7387\u3002\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u627e\u4e00\u53f0\u8ba1\u7b97\u673a\uff0c\u8fd0\u884c\u8fd9\u4e24\u4e2a\u7b97\u6cd5\uff0c\u5e76\u76d1\u63a7\u8bb0\u5f55\u5b83\u4eec\u7684\u8fd0\u884c\u65f6\u95f4\u548c\u5185\u5b58\u5360\u7528\u60c5\u51b5\u3002\u8fd9\u79cd\u8bc4\u4f30\u65b9\u5f0f\u80fd\u591f\u53cd\u6620\u771f\u5b9e\u60c5\u51b5\uff0c\u4f46\u4e5f\u5b58\u5728\u8f83\u5927\u7684\u5c40\u9650\u6027\u3002

        \u4e00\u65b9\u9762\uff0c\u96be\u4ee5\u6392\u9664\u6d4b\u8bd5\u73af\u5883\u7684\u5e72\u6270\u56e0\u7d20\u3002\u786c\u4ef6\u914d\u7f6e\u4f1a\u5f71\u54cd\u7b97\u6cd5\u7684\u6027\u80fd\u3002\u6bd4\u5982\u5728\u67d0\u53f0\u8ba1\u7b97\u673a\u4e2d\uff0c\u7b97\u6cd5 A \u7684\u8fd0\u884c\u65f6\u95f4\u6bd4\u7b97\u6cd5 B \u77ed\uff1b\u4f46\u5728\u53e6\u4e00\u53f0\u914d\u7f6e\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u4e2d\uff0c\u53ef\u80fd\u5f97\u5230\u76f8\u53cd\u7684\u6d4b\u8bd5\u7ed3\u679c\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u9700\u8981\u5728\u5404\u79cd\u673a\u5668\u4e0a\u8fdb\u884c\u6d4b\u8bd5\uff0c\u7edf\u8ba1\u5e73\u5747\u6548\u7387\uff0c\u800c\u8fd9\u662f\u4e0d\u73b0\u5b9e\u7684\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5c55\u5f00\u5b8c\u6574\u6d4b\u8bd5\u975e\u5e38\u8017\u8d39\u8d44\u6e90\u3002\u968f\u7740\u8f93\u5165\u6570\u636e\u91cf\u7684\u53d8\u5316\uff0c\u7b97\u6cd5\u4f1a\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u6548\u7387\u3002\u4f8b\u5982\uff0c\u5728\u8f93\u5165\u6570\u636e\u91cf\u8f83\u5c0f\u65f6\uff0c\u7b97\u6cd5 A \u7684\u8fd0\u884c\u65f6\u95f4\u6bd4\u7b97\u6cd5 B \u77ed\uff1b\u800c\u5728\u8f93\u5165\u6570\u636e\u91cf\u8f83\u5927\u65f6\uff0c\u6d4b\u8bd5\u7ed3\u679c\u53ef\u80fd\u6070\u6070\u76f8\u53cd\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5f97\u5230\u6709\u8bf4\u670d\u529b\u7684\u7ed3\u8bba\uff0c\u6211\u4eec\u9700\u8981\u6d4b\u8bd5\u5404\u79cd\u89c4\u6a21\u7684\u8f93\u5165\u6570\u636e\uff0c\u800c\u8fd9\u9700\u8981\u8017\u8d39\u5927\u91cf\u7684\u8ba1\u7b97\u8d44\u6e90\u3002

        "},{"location":"chapter_computational_complexity/performance_evaluation/#212","title":"2.1.2 \u00a0 \u7406\u8bba\u4f30\u7b97","text":"

        \u7531\u4e8e\u5b9e\u9645\u6d4b\u8bd5\u5177\u6709\u8f83\u5927\u7684\u5c40\u9650\u6027\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u4ec5\u901a\u8fc7\u4e00\u4e9b\u8ba1\u7b97\u6765\u8bc4\u4f30\u7b97\u6cd5\u7684\u6548\u7387\u3002\u8fd9\u79cd\u4f30\u7b97\u65b9\u6cd5\u88ab\u79f0\u4e3a\u300c\u6e10\u8fd1\u590d\u6742\u5ea6\u5206\u6790 asymptotic complexity analysis\u300d\uff0c\u7b80\u79f0\u300c\u590d\u6742\u5ea6\u5206\u6790\u300d\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u80fd\u591f\u4f53\u73b0\u7b97\u6cd5\u8fd0\u884c\u6240\u9700\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b83\u63cf\u8ff0\u4e86\u968f\u7740\u8f93\u5165\u6570\u636e\u5927\u5c0f\u7684\u589e\u52a0\uff0c\u7b97\u6cd5\u6267\u884c\u6240\u9700\u65f6\u95f4\u548c\u7a7a\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u3002\u8fd9\u4e2a\u5b9a\u4e49\u6709\u4e9b\u62d7\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5206\u4e3a\u4e09\u4e2a\u91cd\u70b9\u6765\u7406\u89e3\u3002

        • \u201c\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\u201d\u5206\u522b\u5bf9\u5e94\u300c\u65f6\u95f4\u590d\u6742\u5ea6 time complexity\u300d\u548c\u300c\u7a7a\u95f4\u590d\u6742\u5ea6 space complexity\u300d\u3002
        • \u201c\u968f\u7740\u8f93\u5165\u6570\u636e\u5927\u5c0f\u7684\u589e\u52a0\u201d\u610f\u5473\u7740\u590d\u6742\u5ea6\u53cd\u6620\u4e86\u7b97\u6cd5\u8fd0\u884c\u6548\u7387\u4e0e\u8f93\u5165\u6570\u636e\u4f53\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002
        • \u201c\u65f6\u95f4\u548c\u7a7a\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u201d\u8868\u793a\u590d\u6742\u5ea6\u5206\u6790\u5173\u6ce8\u7684\u4e0d\u662f\u8fd0\u884c\u65f6\u95f4\u6216\u5360\u7528\u7a7a\u95f4\u7684\u5177\u4f53\u503c\uff0c\u800c\u662f\u65f6\u95f4\u6216\u7a7a\u95f4\u589e\u957f\u7684\u201c\u5feb\u6162\u201d\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u514b\u670d\u4e86\u5b9e\u9645\u6d4b\u8bd5\u65b9\u6cd5\u7684\u5f0a\u7aef\uff0c\u4f53\u73b0\u5728\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u9762\u3002

        • \u5b83\u72ec\u7acb\u4e8e\u6d4b\u8bd5\u73af\u5883\uff0c\u5206\u6790\u7ed3\u679c\u9002\u7528\u4e8e\u6240\u6709\u8fd0\u884c\u5e73\u53f0\u3002
        • \u5b83\u53ef\u4ee5\u4f53\u73b0\u4e0d\u540c\u6570\u636e\u91cf\u4e0b\u7684\u7b97\u6cd5\u6548\u7387\uff0c\u5c24\u5176\u662f\u5728\u5927\u6570\u636e\u91cf\u4e0b\u7684\u7b97\u6cd5\u6027\u80fd\u3002

        Tip

        \u5982\u679c\u4f60\u4ecd\u5bf9\u590d\u6742\u5ea6\u7684\u6982\u5ff5\u611f\u5230\u56f0\u60d1\uff0c\u65e0\u987b\u62c5\u5fc3\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u7eed\u7ae0\u8282\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002

        \u590d\u6742\u5ea6\u5206\u6790\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u628a\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u7684\u201c\u6807\u5c3a\u201d\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u8861\u91cf\u6267\u884c\u67d0\u4e2a\u7b97\u6cd5\u6240\u9700\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u8d44\u6e90\uff0c\u5bf9\u6bd4\u4e0d\u540c\u7b97\u6cd5\u4e4b\u95f4\u7684\u6548\u7387\u3002

        \u590d\u6742\u5ea6\u662f\u4e2a\u6570\u5b66\u6982\u5ff5\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u53ef\u80fd\u6bd4\u8f83\u62bd\u8c61\uff0c\u5b66\u4e60\u96be\u5ea6\u76f8\u5bf9\u8f83\u9ad8\u3002\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u770b\uff0c\u590d\u6742\u5ea6\u5206\u6790\u53ef\u80fd\u4e0d\u592a\u9002\u5408\u4f5c\u4e3a\u6700\u5148\u4ecb\u7ecd\u7684\u5185\u5bb9\u3002\u7136\u800c\uff0c\u5f53\u6211\u4eec\u8ba8\u8bba\u67d0\u4e2a\u6570\u636e\u7ed3\u6784\u6216\u7b97\u6cd5\u7684\u7279\u70b9\u65f6\uff0c\u96be\u4ee5\u907f\u514d\u8981\u5206\u6790\u5176\u8fd0\u884c\u901f\u5ea6\u548c\u7a7a\u95f4\u4f7f\u7528\u60c5\u51b5\u3002

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u5efa\u8bae\u4f60\u5728\u6df1\u5165\u5b66\u4e60\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u4e4b\u524d\uff0c\u5148\u5bf9\u590d\u6742\u5ea6\u5206\u6790\u5efa\u7acb\u521d\u6b65\u7684\u4e86\u89e3\uff0c\u4ee5\u4fbf\u80fd\u591f\u5b8c\u6210\u7b80\u5355\u7b97\u6cd5\u7684\u590d\u6742\u5ea6\u5206\u6790\u3002

        "},{"location":"chapter_computational_complexity/space_complexity/","title":"2.4 \u00a0 \u7a7a\u95f4\u590d\u6742\u5ea6","text":"

        \u300c\u7a7a\u95f4\u590d\u6742\u5ea6 space complexity\u300d\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u968f\u7740\u6570\u636e\u91cf\u53d8\u5927\u65f6\u7684\u589e\u957f\u8d8b\u52bf\u3002\u8fd9\u4e2a\u6982\u5ff5\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u975e\u5e38\u7c7b\u4f3c\uff0c\u53ea\u9700\u5c06\u201c\u8fd0\u884c\u65f6\u95f4\u201d\u66ff\u6362\u4e3a\u201c\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u201d\u3002

        "},{"location":"chapter_computational_complexity/space_complexity/#241","title":"2.4.1 \u00a0 \u7b97\u6cd5\u76f8\u5173\u7a7a\u95f4","text":"

        \u7b97\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002

        • \u8f93\u5165\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u7684\u8f93\u5165\u6570\u636e\u3002
        • \u6682\u5b58\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u53d8\u91cf\u3001\u5bf9\u8c61\u3001\u51fd\u6570\u4e0a\u4e0b\u6587\u7b49\u6570\u636e\u3002
        • \u8f93\u51fa\u7a7a\u95f4\uff1a\u7528\u4e8e\u5b58\u50a8\u7b97\u6cd5\u7684\u8f93\u51fa\u6570\u636e\u3002

        \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u7edf\u8ba1\u8303\u56f4\u662f\u201c\u6682\u5b58\u7a7a\u95f4\u201d\u52a0\u4e0a\u201c\u8f93\u51fa\u7a7a\u95f4\u201d\u3002

        \u6682\u5b58\u7a7a\u95f4\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\u3002

        • \u6682\u5b58\u6570\u636e\uff1a\u7528\u4e8e\u4fdd\u5b58\u7b97\u6cd5\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u5404\u79cd\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u7b49\u3002
        • \u6808\u5e27\u7a7a\u95f4\uff1a\u7528\u4e8e\u4fdd\u5b58\u8c03\u7528\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u6570\u636e\u3002\u7cfb\u7edf\u5728\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u4f1a\u5728\u6808\u9876\u90e8\u521b\u5efa\u4e00\u4e2a\u6808\u5e27\uff0c\u51fd\u6570\u8fd4\u56de\u540e\uff0c\u6808\u5e27\u7a7a\u95f4\u4f1a\u88ab\u91ca\u653e\u3002
        • \u6307\u4ee4\u7a7a\u95f4\uff1a\u7528\u4e8e\u4fdd\u5b58\u7f16\u8bd1\u540e\u7684\u7a0b\u5e8f\u6307\u4ee4\uff0c\u5728\u5b9e\u9645\u7edf\u8ba1\u4e2d\u901a\u5e38\u5ffd\u7565\u4e0d\u8ba1\u3002

        \u5728\u5206\u6790\u4e00\u6bb5\u7a0b\u5e8f\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u7edf\u8ba1\u6682\u5b58\u6570\u636e\u3001\u6808\u5e27\u7a7a\u95f4\u548c\u8f93\u51fa\u6570\u636e\u4e09\u90e8\u5206\uff0c\u5982\u56fe 2-15 \u6240\u793a\u3002

        \u56fe 2-15 \u00a0 \u7b97\u6cd5\u4f7f\u7528\u7684\u76f8\u5173\u7a7a\u95f4

        \u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class Node:\n\"\"\"\u7c7b\"\"\"\ndef __init__(self, x: int):\nself.val: int = x              # \u8282\u70b9\u503c\nself.next: Node | None = None  # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\ndef function() -> int:\n\"\"\"\u51fd\u6570\"\"\"\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\ndef algorithm(n) -> int:  # \u8f93\u5165\u6570\u636e\nA = 0                 # \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff0c\u4e00\u822c\u7528\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff09\nb = 0                 # \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nnode = Node(0)        # \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nc = function()        # \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn A + b + c      # \u8f93\u51fa\u6570\u636e\n
        /* \u7ed3\u6784\u4f53 */\nstruct Node {\nint val;\nNode *next;\nNode(int x) : val(x), next(nullptr) {}\n};\n/* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nconst int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode* node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = func();           // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nint val;\nNode next;\nNode(int x) { val = x; }\n}\n/* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nfinal int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = new Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node(int x) {\nint val = x;\nNode next;\n}\n/* \u51fd\u6570 */\nint Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint Algorithm(int n) {        // \u8f93\u5165\u6570\u636e\nconst int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = new(0);       // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = Function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7ed3\u6784\u4f53 */\ntype node struct {\nval  int\nnext *node\n}\n/* \u521b\u5efa node \u7ed3\u6784\u4f53  */\nfunc newNode(val int) *node {\nreturn &node{val: val}\n}\n/* \u51fd\u6570 */\nfunc function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\nfunc algorithm(n int) int { // \u8f93\u5165\u6570\u636e\nconst a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nb := 0                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nnewNode(0)              // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nc := function()         // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c        // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nvar val: Int\nvar next: Node?\ninit(x: Int) {\nval = x\n}\n}\n/* \u51fd\u6570 */\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\nfunc algorithm(n: Int) -> Int { // \u8f93\u5165\u6570\u636e\nlet a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nvar b = 0             // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nlet node = Node(x: 0) // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nlet c = function()    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c      // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nval;\nnext;\nconstructor(val) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n/* \u51fd\u6570 */\nfunction constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\nfunction algorithm(n) {       // \u8f93\u5165\u6570\u636e\nconst a = 0;              // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nconst node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nconst c = constFunc();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nval: number;\nnext: Node | null;\nconstructor(val?: number) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n}\n/* \u51fd\u6570 */\nfunction constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\nfunction algorithm(n: number): number { // \u8f93\u5165\u6570\u636e\nconst a = 0;                        // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet b = 0;                          // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nconst node = new Node(0);           // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nconst c = constFunc();              // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;                   // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u7c7b */\nclass Node {\nint val;\nNode next;\nNode(this.val, [this.next]);\n}\n/* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) {  // \u8f93\u5165\u6570\u636e\nconst int a = 0;      // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;            // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nNode node = Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nint c = function();   // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;     // \u8f93\u51fa\u6570\u636e\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u7ed3\u6784\u4f53 */\nstruct Node {\nval: i32,\nnext: Option<Rc<RefCell<Node>>>,\n}\n/* \u521b\u5efa Node \u7ed3\u6784\u4f53 */\nimpl Node {\nfn new(val: i32) -> Self {\nSelf { val: val, next: None }\n}\n}\n/* \u51fd\u6570 */\nfn function() -> i32 {      // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nfn algorithm(n: i32) -> i32 {       // \u8f93\u5165\u6570\u636e\nconst a: i32 = 0;               // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nlet mut b = 0;                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nlet node = Node::new(0);        // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\nlet c = function();             // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;               // \u8f93\u51fa\u6570\u636e\n}\n
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0;\n}\nint algorithm(int n) { // \u8f93\u5165\u6570\u636e\nconst int a = 0;   // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\nint b = 0;         // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\nint c = func();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\nreturn a + b + c;  // \u8f93\u51fa\u6570\u636e\n}\n
        \n
        "},{"location":"chapter_computational_complexity/space_complexity/#242","title":"2.4.2 \u00a0 \u63a8\u7b97\u65b9\u6cd5","text":"

        \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u5927\u81f4\u76f8\u540c\uff0c\u53ea\u9700\u5c06\u7edf\u8ba1\u5bf9\u8c61\u4ece\u201c\u64cd\u4f5c\u6570\u91cf\u201d\u8f6c\u4e3a\u201c\u4f7f\u7528\u7a7a\u95f4\u5927\u5c0f\u201d\u3002

        \u800c\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u540c\u7684\u662f\uff0c\u6211\u4eec\u901a\u5e38\u53ea\u5173\u6ce8\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u3002\u8fd9\u662f\u56e0\u4e3a\u5185\u5b58\u7a7a\u95f4\u662f\u4e00\u9879\u786c\u6027\u8981\u6c42\uff0c\u6211\u4eec\u5fc5\u987b\u786e\u4fdd\u5728\u6240\u6709\u8f93\u5165\u6570\u636e\u4e0b\u90fd\u6709\u8db3\u591f\u7684\u5185\u5b58\u7a7a\u95f4\u9884\u7559\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e2d\u7684\u201c\u6700\u5dee\u201d\u6709\u4e24\u5c42\u542b\u4e49\u3002

        1. \u4ee5\u6700\u5dee\u8f93\u5165\u6570\u636e\u4e3a\u51c6\uff1a\u5f53 \\(n < 10\\) \u65f6\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff1b\u4f46\u5f53 \\(n > 10\\) \u65f6\uff0c\u521d\u59cb\u5316\u7684\u6570\u7ec4 nums \u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\uff0c\u56e0\u6b64\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        2. \u4ee5\u7b97\u6cd5\u8fd0\u884c\u4e2d\u7684\u5cf0\u503c\u5185\u5b58\u4e3a\u51c6\uff1a\u4f8b\u5982\uff0c\u7a0b\u5e8f\u5728\u6267\u884c\u6700\u540e\u4e00\u884c\u4e4b\u524d\uff0c\u5360\u7528 \\(O(1)\\) \u7a7a\u95f4\uff1b\u5f53\u521d\u59cb\u5316\u6570\u7ec4 nums \u65f6\uff0c\u7a0b\u5e8f\u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\uff0c\u56e0\u6b64\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 0               # O(1)\nb = [0] * 10000     # O(1)\nif n > 10:\nnums = [0] * n  # O(n)\n
        void algorithm(int n) {\nint a = 0;               // O(1)\nvector<int> b(10000);    // O(1)\nif (n > 10)\nvector<int> nums(n); // O(n)\n}\n
        void algorithm(int n) {\nint a = 0;                   // O(1)\nint[] b = new int[10000];    // O(1)\nif (n > 10)\nint[] nums = new int[n]; // O(n)\n}\n
        void Algorithm(int n) {\nint a = 0;                   // O(1)\nint[] b = new int[10000];    // O(1)\nif (n > 10) {\nint[] nums = new int[n]; // O(n)\n}\n}\n
        func algorithm(n int) {\na := 0                      // O(1)\nb := make([]int, 10000)     // O(1)\nvar nums []int\nif n > 10 {\nnums := make([]int, n)  // O(n)\n}\nfmt.Println(a, b, nums)\n}\n
        func algorithm(n: Int) {\nlet a = 0 // O(1)\nlet b = Array(repeating: 0, count: 10000) // O(1)\nif n > 10 {\nlet nums = Array(repeating: 0, count: n) // O(n)\n}\n}\n
        function algorithm(n) {\nconst a = 0;                   // O(1)\nconst b = new Array(10000);    // O(1)\nif (n > 10) {\nconst nums = new Array(n); // O(n)\n}\n}\n
        function algorithm(n: number): void {\nconst a = 0;                   // O(1)\nconst b = new Array(10000);    // O(1)\nif (n > 10) {\nconst nums = new Array(n); // O(n)\n}\n}\n
        void algorithm(int n) {\nint a = 0;                            // O(1)\nList<int> b = List.filled(10000, 0);  // O(1)\nif (n > 10) {\nList<int> nums = List.filled(n, 0); // O(n)\n}\n}\n
        fn algorithm(n: i32) {\nlet a = 0;                              // O(1)\nlet b = [0; 10000];                     // O(1)\nif n > 10 {\nlet nums = vec![0; n as usize];     // O(n)\n}\n}\n
        void algorithm(int n) {\nint a = 0;               // O(1)\nint b[10000];            // O(1)\nif (n > 10)\nint nums[n] = {0};   // O(n)\n}\n
        \n

        \u5728\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u7edf\u8ba1\u6808\u5e27\u7a7a\u95f4\u3002\u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def function() -> int:\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\ndef loop(n: int):\n\"\"\"\u5faa\u73af O(1)\"\"\"\nfor _ in range(n):\nfunction()\ndef recur(n: int) -> int:\n\"\"\"\u9012\u5f52 O(n)\"\"\"\nif n == 1: return\nreturn recur(n - 1)\n
        int func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        int function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        int Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid Loop(int n) {\nfor (int i = 0; i < n; i++) {\nFunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nint Recur(int n) {\nif (n == 1) return 1;\nreturn Recur(n - 1);\n}\n
        func function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5faa\u73af O(1) */\nfunc loop(n int) {\nfor i := 0; i < n; i++ {\nfunction()\n}\n}\n/* \u9012\u5f52 O(n) */\nfunc recur(n int) {\nif n == 1 {\nreturn\n}\nrecur(n - 1)\n}\n
        @discardableResult\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5faa\u73af O(1) */\nfunc loop(n: Int) {\nfor _ in 0 ..< n {\nfunction()\n}\n}\n/* \u9012\u5f52 O(n) */\nfunc recur(n: Int) {\nif n == 1 {\nreturn\n}\nrecur(n: n - 1)\n}\n
        function constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n) {\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n) {\nif (n === 1) return;\nreturn recur(n - 1);\n}\n
        function constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n: number): void {\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n: number): void {\nif (n === 1) return;\nreturn recur(n - 1);\n}\n
        int function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        fn function() -> i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nfn loop(n: i32) {\nfor i in 0..n {\nfunction();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(n: i32) {\nif n == 1 {\nreturn;\n}\nrecur(n - 1);\n}\n
        int func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\nif (n == 1) return;\nreturn recur(n - 1);\n}\n
        \n

        \u51fd\u6570 loop() \u548c recur() \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n)\\) \uff0c\u4f46\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0d\u540c\u3002

        • \u51fd\u6570 loop() \u5728\u5faa\u73af\u4e2d\u8c03\u7528\u4e86 \\(n\\) \u6b21 function() \uff0c\u6bcf\u8f6e\u4e2d\u7684 function() \u90fd\u8fd4\u56de\u5e76\u91ca\u653e\u4e86\u6808\u5e27\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \u3002
        • \u9012\u5f52\u51fd\u6570 recur() \u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f1a\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684 recur() \uff0c\u4ece\u800c\u5360\u7528 \\(O(n)\\) \u7684\u6808\u5e27\u7a7a\u95f4\u3002
        "},{"location":"chapter_computational_complexity/space_complexity/#243","title":"2.4.3 \u00a0 \u5e38\u89c1\u7c7b\u578b","text":"

        \u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u56fe 2-16 \u5c55\u793a\u4e86\u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\uff08\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\uff09\u3002

        \\[ \\begin{aligned} O(1) < O(\\log n) < O(n) < O(n^2) < O(2^n) \\newline \\text{\u5e38\u6570\u9636} < \\text{\u5bf9\u6570\u9636} < \\text{\u7ebf\u6027\u9636} < \\text{\u5e73\u65b9\u9636} < \\text{\u6307\u6570\u9636} \\end{aligned} \\]

        \u56fe 2-16 \u00a0 \u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b

        "},{"location":"chapter_computational_complexity/space_complexity/#1-o1","title":"1. \u00a0 \u5e38\u6570\u9636 \\(O(1)\\)","text":"

        \u5e38\u6570\u9636\u5e38\u89c1\u4e8e\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u5faa\u73af\u4e2d\u521d\u59cb\u5316\u53d8\u91cf\u6216\u8c03\u7528\u51fd\u6570\u800c\u5360\u7528\u7684\u5185\u5b58\uff0c\u5728\u8fdb\u5165\u4e0b\u4e00\u5faa\u73af\u540e\u5c31\u4f1a\u88ab\u91ca\u653e\uff0c\u56e0\u6b64\u4e0d\u4f1a\u7d2f\u79ef\u5360\u7528\u7a7a\u95f4\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def function() -> int:\n\"\"\"\u51fd\u6570\"\"\"\n# \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\ndef constant(n: int):\n\"\"\"\u5e38\u6570\u9636\"\"\"\n# \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\na = 0\nnums = [0] * 10000\nnode = ListNode(0)\n# \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in range(n):\nc = 0\n# \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in range(n):\nfunction()\n
        space_complexity.cpp
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst int a = 0;\nint b = 0;\nvector<int> nums(10000);\nListNode node(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n
        space_complexity.java
        /* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nfinal int a = 0;\nint b = 0;\nint[] nums = new int[10000];\nListNode node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunction();\n}\n}\n
        space_complexity.cs
        /* \u51fd\u6570 */\nint Function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid Constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nint a = 0;\nint b = 0;\nint[] nums = new int[10000];\nListNode node = new(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nFunction();\n}\n}\n
        space_complexity.go
        /* \u51fd\u6570 */\nfunc function() int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\nreturn 0\n}\n/* \u5e38\u6570\u9636 */\nfunc spaceConstant(n int) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0\nb := 0\nnums := make([]int, 10000)\nListNode := newNode(0)\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nvar c int\nfor i := 0; i < n; i++ {\nc = 0\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor i := 0; i < n; i++ {\nfunction()\n}\nfmt.Println(a, b, nums, c, ListNode)\n}\n
        space_complexity.swift
        /* \u51fd\u6570 */\n@discardableResult\nfunc function() -> Int {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0\n}\n/* \u5e38\u6570\u9636 */\nfunc constant(n: Int) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nlet a = 0\nvar b = 0\nlet nums = Array(repeating: 0, count: 10000)\nlet node = ListNode(x: 0)\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in 0 ..< n {\nlet c = 0\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor _ in 0 ..< n {\nfunction()\n}\n}\n
        space_complexity.js
        /* \u51fd\u6570 */\nfunction constFunc() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nfunction constant(n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0;\nconst b = 0;\nconst nums = new Array(10000);\nconst node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconst c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n
        space_complexity.ts
        /* \u51fd\u6570 */\nfunction constFunc(): number {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nfunction constant(n: number): void {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a = 0;\nconst b = 0;\nconst nums = new Array(10000);\nconst node = new ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconst c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (let i = 0; i < n; i++) {\nconstFunc();\n}\n}\n
        space_complexity.dart
        /* \u51fd\u6570 */\nint function() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nfinal int a = 0;\nint b = 0;\nList<int> nums = List.filled(10000, 0);\nListNode node = ListNode(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (var i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (var i = 0; i < n; i++) {\nfunction();\n}\n}\n
        space_complexity.rs
        /* \u51fd\u6570 */\nfn function() ->i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\n#[allow(unused)]\nfn constant(n: i32) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst A: i32 = 0;\nlet b = 0;\nlet nums = vec![0; 10000];\nlet node = ListNode::new(0);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor i in 0..n {\nlet c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor i in 0..n {\nfunction();\n}\n}\n
        space_complexity.c
        /* \u51fd\u6570 */\nint func() {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst int a = 0;\nint b = 0;\nint nums[1000];\nListNode *node = newListNode(0);\nfree(node);\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nint c = 0;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\nfor (int i = 0; i < n; i++) {\nfunc();\n}\n}\n
        space_complexity.zig
        // \u51fd\u6570\nfn function() i32 {\n// \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\nreturn 0;\n}\n// \u5e38\u6570\u9636\nfn constant(n: i32) void {\n// \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\nconst a: i32 = 0;\nvar b: i32 = 0;\nvar nums = [_]i32{0}**10000;\nvar node = inc.ListNode(i32){.val = 0};\nvar i: i32 = 0;\n// \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\nwhile (i < n) : (i += 1) {\nvar c: i32 = 0;\n_ = c;\n}\n// \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\ni = 0;\nwhile (i < n) : (i += 1) {\n_ = function();\n}\n_ = a;\n_ = b;\n_ = nums;\n_ = node;\n}\n
        "},{"location":"chapter_computational_complexity/space_complexity/#2-on","title":"2. \u00a0 \u7ebf\u6027\u9636 \\(O(n)\\)","text":"

        \u7ebf\u6027\u9636\u5e38\u89c1\u4e8e\u5143\u7d20\u6570\u91cf\u4e0e \\(n\\) \u6210\u6b63\u6bd4\u7684\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u7b49\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def linear(n: int):\n\"\"\"\u7ebf\u6027\u9636\"\"\"\n# \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nnums = [0] * n\n# \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nhmap = dict[int, str]()\nfor i in range(n):\nhmap[i] = str(i)\n
        space_complexity.cpp
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nvector<int> nums(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvector<ListNode> nodes;\nfor (int i = 0; i < n; i++) {\nnodes.push_back(ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nunordered_map<int, string> map;\nfor (int i = 0; i < n; i++) {\nmap[i] = to_string(i);\n}\n}\n
        space_complexity.java
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint[] nums = new int[n];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nnodes.add(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nMap<Integer, String> map = new HashMap<>();\nfor (int i = 0; i < n; i++) {\nmap.put(i, String.valueOf(i));\n}\n}\n
        space_complexity.cs
        /* \u7ebf\u6027\u9636 */\nvoid Linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint[] nums = new int[n];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = [];\nfor (int i = 0; i < n; i++) {\nnodes.Add(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nDictionary<int, string> map = [];\nfor (int i = 0; i < n; i++) {\nmap.Add(i, i.ToString());\n}\n}\n
        space_complexity.go
        /* \u7ebf\u6027\u9636 */\nfunc spaceLinear(n int) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\n_ = make([]int, n)\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar nodes []*node\nfor i := 0; i < n; i++ {\nnodes = append(nodes, newNode(i))\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nm := make(map[int]string, n)\nfor i := 0; i < n; i++ {\nm[i] = strconv.Itoa(i)\n}\n}\n
        space_complexity.swift
        /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nlet nums = Array(repeating: 0, count: n)\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet nodes = (0 ..< n).map { ListNode(x: $0) }\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet map = Dictionary(uniqueKeysWithValues: (0 ..< n).map { ($0, \"\\($0)\") })\n}\n
        space_complexity.js
        /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nconst nums = new Array(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst nodes = [];\nfor (let i = 0; i < n; i++) {\nnodes.push(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst map = new Map();\nfor (let i = 0; i < n; i++) {\nmap.set(i, i.toString());\n}\n}\n
        space_complexity.ts
        /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): void {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nconst nums = new Array(n);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst nodes: ListNode[] = [];\nfor (let i = 0; i < n; i++) {\nnodes.push(new ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nconst map = new Map();\nfor (let i = 0; i < n; i++) {\nmap.set(i, i.toString());\n}\n}\n
        space_complexity.dart
        /* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nList<int> nums = List.filled(n, 0);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nList<ListNode> nodes = [];\nfor (var i = 0; i < n; i++) {\nnodes.add(ListNode(i));\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nMap<int, String> map = HashMap();\nfor (var i = 0; i < n; i++) {\nmap.putIfAbsent(i, () => i.toString());\n}\n}\n
        space_complexity.rs
        /* \u7ebf\u6027\u9636 */\n#[allow(unused)]\nfn linear(n: i32) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut nums = vec![0; n as usize];\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut nodes = Vec::new();\nfor i in 0..n {\nnodes.push(ListNode::new(i))\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nlet mut map = HashMap::new();\nfor i in 0..n {\nmap.insert(i, i.to_string());\n}\n}\n
        space_complexity.c
        /* \u54c8\u5e0c\u8868 */\ntypedef struct {\nint key;\nint val;\nUT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n/* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nint *nums = malloc(sizeof(int) * n);\nfree(nums);\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nListNode **nodes = malloc(sizeof(ListNode *) * n);\nfor (int i = 0; i < n; i++) {\nnodes[i] = newListNode(i);\n}\n// \u5185\u5b58\u91ca\u653e\nfor (int i = 0; i < n; i++) {\nfree(nodes[i]);\n}\nfree(nodes);\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nHashTable *h = NULL;\nfor (int i = 0; i < n; i++) {\nHashTable *tmp = malloc(sizeof(HashTable));\ntmp->key = i;\ntmp->val = i;\nHASH_ADD_INT(h, key, tmp);\n}\n// \u5185\u5b58\u91ca\u653e\nHashTable *curr, *tmp;\nHASH_ITER(hh, h, curr, tmp) {\nHASH_DEL(h, curr);\nfree(curr);\n}\n}\n
        space_complexity.zig
        // \u7ebf\u6027\u9636\nfn linear(comptime n: i32) !void {\n// \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\nvar nums = [_]i32{0}**n;\n// \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar nodes = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer nodes.deinit();\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\ntry nodes.append(i);\n}\n// \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\nvar map = std.AutoArrayHashMap(i32, []const u8).init(std.heap.page_allocator);\ndefer map.deinit();\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\nconst string = try std.fmt.allocPrint(std.heap.page_allocator, \"{d}\", .{j});\ndefer std.heap.page_allocator.free(string);\ntry map.put(i, string);\n}\n_ = nums;\n}\n

        \u5982\u56fe 2-17 \u6240\u793a\uff0c\u6b64\u51fd\u6570\u7684\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u5373\u540c\u65f6\u5b58\u5728 \\(n\\) \u4e2a\u672a\u8fd4\u56de\u7684 linear_recur() \u51fd\u6570\uff0c\u4f7f\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def linear_recur(n: int):\n\"\"\"\u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nprint(\"\u9012\u5f52 n =\", n)\nif n == 1:\nreturn\nlinear_recur(n - 1)\n
        space_complexity.cpp
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\ncout << \"\u9012\u5f52 n = \" << n << endl;\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.java
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nSystem.out.println(\"\u9012\u5f52 n = \" + n);\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.cs
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid LinearRecur(int n) {\nConsole.WriteLine(\"\u9012\u5f52 n = \" + n);\nif (n == 1) return;\nLinearRecur(n - 1);\n}\n
        space_complexity.go
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceLinearRecur(n int) {\nfmt.Println(\"\u9012\u5f52 n =\", n)\nif n == 1 {\nreturn\n}\nspaceLinearRecur(n - 1)\n}\n
        space_complexity.swift
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc linearRecur(n: Int) {\nprint(\"\u9012\u5f52 n = \\(n)\")\nif n == 1 {\nreturn\n}\nlinearRecur(n: n - 1)\n}\n
        space_complexity.js
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n) {\nconsole.log(`\u9012\u5f52 n = ${n}`);\nif (n === 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.ts
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n: number): void {\nconsole.log(`\u9012\u5f52 n = ${n}`);\nif (n === 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.dart
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nprint('\u9012\u5f52 n = $n');\nif (n == 1) return;\nlinearRecur(n - 1);\n}\n
        space_complexity.rs
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn linear_recur(n: i32) {\nprintln!(\"\u9012\u5f52 n = {}\", n);\nif n == 1 {return};\nlinear_recur(n - 1);\n}\n
        space_complexity.c
        /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\nprintf(\"\u9012\u5f52 n = %d\\r\\n\", n);\nif (n == 1)\nreturn;\nlinearRecur(n - 1);\n}\n
        space_complexity.zig
        // \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn linearRecur(comptime n: i32) void {\nstd.debug.print(\"\u9012\u5f52 n = {}\\n\", .{n});\nif (n == 1) return;\nlinearRecur(n - 1);\n}\n

        \u56fe 2-17 \u00a0 \u9012\u5f52\u51fd\u6570\u4ea7\u751f\u7684\u7ebf\u6027\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#3-on2","title":"3. \u00a0 \u5e73\u65b9\u9636 \\(O(n^2)\\)","text":"

        \u5e73\u65b9\u9636\u5e38\u89c1\u4e8e\u77e9\u9635\u548c\u56fe\uff0c\u5143\u7d20\u6570\u91cf\u4e0e \\(n\\) \u6210\u5e73\u65b9\u5173\u7cfb\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def quadratic(n: int):\n\"\"\"\u5e73\u65b9\u9636\"\"\"\n# \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nnum_matrix = [[0] * n for _ in range(n)]\n
        space_complexity.cpp
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nvector<vector<int>> numMatrix;\nfor (int i = 0; i < n; i++) {\nvector<int> tmp;\nfor (int j = 0; j < n; j++) {\ntmp.push_back(0);\n}\nnumMatrix.push_back(tmp);\n}\n}\n
        space_complexity.java
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nint[][] numMatrix = new int[n][n];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<Integer>> numList = new ArrayList<>();\nfor (int i = 0; i < n; i++) {\nList<Integer> tmp = new ArrayList<>();\nfor (int j = 0; j < n; j++) {\ntmp.add(0);\n}\nnumList.add(tmp);\n}\n}\n
        space_complexity.cs
        /* \u5e73\u65b9\u9636 */\nvoid Quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nint[,] numMatrix = new int[n, n];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numList = [];\nfor (int i = 0; i < n; i++) {\nList<int> tmp = [];\nfor (int j = 0; j < n; j++) {\ntmp.Add(0);\n}\nnumList.Add(tmp);\n}\n}\n
        space_complexity.go
        /* \u5e73\u65b9\u9636 */\nfunc spaceQuadratic(n int) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nnumMatrix := make([][]int, n)\nfor i := 0; i < n; i++ {\nnumMatrix[i] = make([]int, n)\n}\n}\n
        space_complexity.swift
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet numList = Array(repeating: Array(repeating: 0, count: n), count: n)\n}\n
        space_complexity.js
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numMatrix = Array(n)\n.fill(null)\n.map(() => Array(n).fill(null));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numList = [];\nfor (let i = 0; i < n; i++) {\nconst tmp = [];\nfor (let j = 0; j < n; j++) {\ntmp.push(0);\n}\nnumList.push(tmp);\n}\n}\n
        space_complexity.ts
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): void {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numMatrix = Array(n)\n.fill(null)\n.map(() => Array(n).fill(null));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nconst numList = [];\nfor (let i = 0; i < n; i++) {\nconst tmp = [];\nfor (let j = 0; j < n; j++) {\ntmp.push(0);\n}\nnumList.push(tmp);\n}\n}\n
        space_complexity.dart
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numMatrix = List.generate(n, (_) => List.filled(n, 0));\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nList<List<int>> numList = [];\nfor (var i = 0; i < n; i++) {\nList<int> tmp = [];\nfor (int j = 0; j < n; j++) {\ntmp.add(0);\n}\nnumList.add(tmp);\n}\n}\n
        space_complexity.rs
        /* \u5e73\u65b9\u9636 */\n#[allow(unused)]\nfn quadratic(n: i32) {\n// \u77e9\u9635\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet num_matrix = vec![vec![0; n as usize]; n as usize];\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nlet mut num_list = Vec::new();\nfor i in 0..n {\nlet mut tmp = Vec::new();\nfor j in 0..n {\ntmp.push(0);\n}\nnum_list.push(tmp);\n}\n}\n
        space_complexity.c
        /* \u5e73\u65b9\u9636 */\nvoid quadratic(int n) {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nint **numMatrix = malloc(sizeof(int *) * n);\nfor (int i = 0; i < n; i++) {\nint *tmp = malloc(sizeof(int) * n);\nfor (int j = 0; j < n; j++) {\ntmp[j] = 0;\n}\nnumMatrix[i] = tmp;\n}\n// \u5185\u5b58\u91ca\u653e\nfor (int i = 0; i < n; i++) {\nfree(numMatrix[i]);\n}\nfree(numMatrix);\n}\n
        space_complexity.zig
        // \u5e73\u65b9\u9636\nfn quadratic(n: i32) !void {\n// \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\nvar nodes = std.ArrayList(std.ArrayList(i32)).init(std.heap.page_allocator);\ndefer nodes.deinit();\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\nvar tmp = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer tmp.deinit();\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\ntry tmp.append(0);\n}\ntry nodes.append(tmp);\n}\n}\n

        \u5982\u56fe 2-18 \u6240\u793a\uff0c\u8be5\u51fd\u6570\u7684\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u5728\u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u4e2d\u90fd\u521d\u59cb\u5316\u4e86\u4e00\u4e2a\u6570\u7ec4\uff0c\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\)\u3001\\(n-1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u5e73\u5747\u957f\u5ea6\u4e3a \\(n / 2\\) \uff0c\u56e0\u6b64\u603b\u4f53\u5360\u7528 \\(O(n^2)\\) \u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def quadratic_recur(n: int) -> int:\n\"\"\"\u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n <= 0:\nreturn 0\n# \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nnums = [0] * n\nreturn quadratic_recur(n - 1)\n
        space_complexity.cpp
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\nvector<int> nums(n);\ncout << \"\u9012\u5f52 n = \" << n << \" \u4e2d\u7684 nums \u957f\u5ea6 = \" << nums.size() << endl;\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.java
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nint[] nums = new int[n];\nSystem.out.println(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.length);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.cs
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint QuadraticRecur(int n) {\nif (n <= 0) return 0;\nint[] nums = new int[n];\nConsole.WriteLine(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.Length);\nreturn QuadraticRecur(n - 1);\n}\n
        space_complexity.go
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceQuadraticRecur(n int) int {\nif n <= 0 {\nreturn 0\n}\nnums := make([]int, n)\nfmt.Printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d \\n\", n, len(nums))\nreturn spaceQuadraticRecur(n - 1)\n}\n
        space_complexity.swift
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\n@discardableResult\nfunc quadraticRecur(n: Int) -> Int {\nif n <= 0 {\nreturn 0\n}\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nlet nums = Array(repeating: 0, count: n)\nprint(\"\u9012\u5f52 n = \\(n) \u4e2d\u7684 nums \u957f\u5ea6 = \\(nums.count)\")\nreturn quadraticRecur(n: n - 1)\n}\n
        space_complexity.js
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n) {\nif (n <= 0) return 0;\nconst nums = new Array(n);\nconsole.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.ts
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n: number): number {\nif (n <= 0) return 0;\nconst nums = new Array(n);\nconsole.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.dart
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0) return 0;\nList<int> nums = List.filled(n, 0);\nprint('\u9012\u5f52 n = $n \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}');\nreturn quadraticRecur(n - 1);\n}\n
        space_complexity.rs
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn quadratic_recur(n: i32) -> i32 {\nif n <= 0 {return 0};\n// \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\nlet nums = vec![0; n as usize];\nprintln!(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\", n, nums.len());\nreturn quadratic_recur(n - 1);\n}\n
        space_complexity.c
        /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\nif (n <= 0)\nreturn 0;\nint *nums = malloc(sizeof(int) * n);\nprintf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d\\r\\n\", n, n);\nint res = quadraticRecur(n - 1);\nfree(nums);\nreturn res;\n}\n
        space_complexity.zig
        // \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn quadraticRecur(comptime n: i32) i32 {\nif (n <= 0) return 0;\nvar nums = [_]i32{0}**n;\nstd.debug.print(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\\n\", .{n, nums.len});\nreturn quadraticRecur(n - 1);\n}\n

        \u56fe 2-18 \u00a0 \u9012\u5f52\u51fd\u6570\u4ea7\u751f\u7684\u5e73\u65b9\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#4-o2n","title":"4. \u00a0 \u6307\u6570\u9636 \\(O(2^n)\\)","text":"

        \u6307\u6570\u9636\u5e38\u89c1\u4e8e\u4e8c\u53c9\u6811\u3002\u89c2\u5bdf\u56fe 2-19 \uff0c\u9ad8\u5ea6\u4e3a \\(n\\) \u7684\u201c\u6ee1\u4e8c\u53c9\u6811\u201d\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(2^n - 1\\) \uff0c\u5360\u7528 \\(O(2^n)\\) \u7a7a\u95f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig space_complexity.py
        def build_tree(n: int) -> TreeNode | None:\n\"\"\"\u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09\"\"\"\nif n == 0:\nreturn None\nroot = TreeNode(0)\nroot.left = build_tree(n - 1)\nroot.right = build_tree(n - 1)\nreturn root\n
        space_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\nif (n == 0)\nreturn nullptr;\nTreeNode *root = new TreeNode(0);\nroot->left = buildTree(n - 1);\nroot->right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.java
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode buildTree(int n) {\nif (n == 0)\nreturn null;\nTreeNode root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.cs
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? BuildTree(int n) {\nif (n == 0) return null;\nTreeNode root = new(0) {\nleft = BuildTree(n - 1),\nright = BuildTree(n - 1)\n};\nreturn root;\n}\n
        space_complexity.go
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n int) *treeNode {\nif n == 0 {\nreturn nil\n}\nroot := newTreeNode(0)\nroot.left = buildTree(n - 1)\nroot.right = buildTree(n - 1)\nreturn root\n}\n
        space_complexity.swift
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n: Int) -> TreeNode? {\nif n == 0 {\nreturn nil\n}\nlet root = TreeNode(x: 0)\nroot.left = buildTree(n: n - 1)\nroot.right = buildTree(n: n - 1)\nreturn root\n}\n
        space_complexity.js
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n) {\nif (n === 0) return null;\nconst root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.ts
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n: number): TreeNode | null {\nif (n === 0) return null;\nconst root = new TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.dart
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? buildTree(int n) {\nif (n == 0) return null;\nTreeNode root = TreeNode(0);\nroot.left = buildTree(n - 1);\nroot.right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.rs
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfn build_tree(n: i32) -> Option<Rc<RefCell<TreeNode>>> {\nif n == 0 {return None};\nlet root = TreeNode::new(0);\nroot.borrow_mut().left = build_tree(n - 1);\nroot.borrow_mut().right = build_tree(n - 1);\nreturn Some(root);\n}\n
        space_complexity.c
        /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\nif (n == 0)\nreturn NULL;\nTreeNode *root = newTreeNode(0);\nroot->left = buildTree(n - 1);\nroot->right = buildTree(n - 1);\nreturn root;\n}\n
        space_complexity.zig
        // \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09\nfn buildTree(mem_allocator: std.mem.Allocator, n: i32) !?*inc.TreeNode(i32) {\nif (n == 0) return null;\nconst root = try mem_allocator.create(inc.TreeNode(i32));\nroot.init(0);\nroot.left = try buildTree(mem_allocator, n - 1);\nroot.right = try buildTree(mem_allocator, n - 1);\nreturn root;\n}\n

        \u56fe 2-19 \u00a0 \u6ee1\u4e8c\u53c9\u6811\u4ea7\u751f\u7684\u6307\u6570\u9636\u7a7a\u95f4\u590d\u6742\u5ea6

        "},{"location":"chapter_computational_complexity/space_complexity/#5-olog-n","title":"5. \u00a0 \u5bf9\u6570\u9636 \\(O(\\log n)\\)","text":"

        \u5bf9\u6570\u9636\u5e38\u89c1\u4e8e\u5206\u6cbb\u7b97\u6cd5\u3002\u4f8b\u5982\u5f52\u5e76\u6392\u5e8f\uff0c\u8f93\u5165\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\uff0c\u6bcf\u8f6e\u9012\u5f52\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5212\u5206\u4e3a\u4e24\u534a\uff0c\u5f62\u6210\u9ad8\u5ea6\u4e3a \\(\\log n\\) \u7684\u9012\u5f52\u6811\uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u6808\u5e27\u7a7a\u95f4\u3002

        \u518d\u4f8b\u5982\u5c06\u6570\u5b57\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u8f93\u5165\u4e00\u4e2a\u6b63\u6574\u6570 \\(n\\) \uff0c\u5b83\u7684\u4f4d\u6570\u4e3a \\(\\log_{10} n + 1\\) \uff0c\u5373\u5bf9\u5e94\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a \\(\\log_{10} n + 1\\) \uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log_{10} n + 1) = O(\\log n)\\) \u3002

        "},{"location":"chapter_computational_complexity/space_complexity/#244","title":"2.4.4 \u00a0 \u6743\u8861\u65f6\u95f4\u4e0e\u7a7a\u95f4","text":"

        \u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u90fd\u80fd\u8fbe\u5230\u6700\u4f18\u3002\u7136\u800c\u5728\u5b9e\u9645\u60c5\u51b5\u4e2d\uff0c\u540c\u65f6\u4f18\u5316\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u975e\u5e38\u56f0\u96be\u3002

        \u964d\u4f4e\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u9700\u8981\u4ee5\u63d0\u5347\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a\u4ee3\u4ef7\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u6211\u4eec\u5c06\u727a\u7272\u5185\u5b58\u7a7a\u95f4\u6765\u63d0\u5347\u7b97\u6cd5\u8fd0\u884c\u901f\u5ea6\u7684\u601d\u8def\u79f0\u4e3a\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\uff1b\u53cd\u4e4b\uff0c\u5219\u79f0\u4e3a\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u3002

        \u9009\u62e9\u54ea\u79cd\u601d\u8def\u53d6\u51b3\u4e8e\u6211\u4eec\u66f4\u770b\u91cd\u54ea\u4e2a\u65b9\u9762\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u65f6\u95f4\u6bd4\u7a7a\u95f4\u66f4\u5b9d\u8d35\uff0c\u56e0\u6b64\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u901a\u5e38\u662f\u66f4\u5e38\u7528\u7684\u7b56\u7565\u3002\u5f53\u7136\uff0c\u5728\u6570\u636e\u91cf\u5f88\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u63a7\u5236\u7a7a\u95f4\u590d\u6742\u5ea6\u4e5f\u975e\u5e38\u91cd\u8981\u3002

        "},{"location":"chapter_computational_complexity/summary/","title":"2.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_computational_complexity/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"

        \u7b97\u6cd5\u6548\u7387\u8bc4\u4f30

        • \u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u662f\u8861\u91cf\u7b97\u6cd5\u4f18\u52a3\u7684\u4e24\u4e2a\u4e3b\u8981\u8bc4\u4ef7\u6307\u6807\u3002
        • \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5b9e\u9645\u6d4b\u8bd5\u6765\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\uff0c\u4f46\u96be\u4ee5\u6d88\u9664\u6d4b\u8bd5\u73af\u5883\u7684\u5f71\u54cd\uff0c\u4e14\u4f1a\u8017\u8d39\u5927\u91cf\u8ba1\u7b97\u8d44\u6e90\u3002
        • \u590d\u6742\u5ea6\u5206\u6790\u53ef\u4ee5\u6d88\u9664\u5b9e\u9645\u6d4b\u8bd5\u7684\u5f0a\u7aef\uff0c\u5206\u6790\u7ed3\u679c\u9002\u7528\u4e8e\u6240\u6709\u8fd0\u884c\u5e73\u53f0\uff0c\u5e76\u4e14\u80fd\u591f\u63ed\u793a\u7b97\u6cd5\u5728\u4e0d\u540c\u6570\u636e\u89c4\u6a21\u4e0b\u7684\u6548\u7387\u3002

        \u65f6\u95f4\u590d\u6742\u5ea6

        • \u65f6\u95f4\u590d\u6742\u5ea6\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u6570\u636e\u91cf\u589e\u957f\u7684\u8d8b\u52bf\uff0c\u53ef\u4ee5\u6709\u6548\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u5931\u6548\uff0c\u5982\u5728\u8f93\u5165\u7684\u6570\u636e\u91cf\u8f83\u5c0f\u6216\u65f6\u95f4\u590d\u6742\u5ea6\u76f8\u540c\u65f6\uff0c\u65e0\u6cd5\u7cbe\u786e\u5bf9\u6bd4\u7b97\u6cd5\u6548\u7387\u7684\u4f18\u52a3\u3002
        • \u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4f7f\u7528\u5927 \\(O\\) \u7b26\u53f7\u8868\u793a\uff0c\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0a\u754c\uff0c\u53cd\u6620\u5f53 \\(n\\) \u8d8b\u5411\u6b63\u65e0\u7a77\u65f6\uff0c\u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u7684\u589e\u957f\u7ea7\u522b\u3002
        • \u63a8\u7b97\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u4e3a\u4e24\u6b65\uff0c\u9996\u5148\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff0c\u7136\u540e\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c\u3002
        • \u5e38\u89c1\u65f6\u95f4\u590d\u6742\u5ea6\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\u6709 \\(O(1)\\)\u3001\\(O(\\log n)\\)\u3001\\(O(n)\\)\u3001\\(O(n \\log n)\\)\u3001\\(O(n^2)\\)\u3001\\(O(2^n)\\) \u548c \\(O(n!)\\) \u7b49\u3002
        • \u67d0\u4e9b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u975e\u56fa\u5b9a\uff0c\u800c\u662f\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u6709\u5173\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u4e3a\u6700\u5dee\u3001\u6700\u4f73\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u51e0\u4e4e\u4e0d\u7528\uff0c\u56e0\u4e3a\u8f93\u5165\u6570\u636e\u4e00\u822c\u9700\u8981\u6ee1\u8db3\u4e25\u683c\u6761\u4ef6\u624d\u80fd\u8fbe\u5230\u6700\u4f73\u60c5\u51b5\u3002
        • \u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u53cd\u6620\u7b97\u6cd5\u5728\u968f\u673a\u6570\u636e\u8f93\u5165\u4e0b\u7684\u8fd0\u884c\u6548\u7387\uff0c\u6700\u63a5\u8fd1\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u7b97\u6cd5\u6027\u80fd\u3002\u8ba1\u7b97\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u9700\u8981\u7edf\u8ba1\u8f93\u5165\u6570\u636e\u5206\u5e03\u4ee5\u53ca\u7efc\u5408\u540e\u7684\u6570\u5b66\u671f\u671b\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6

        • \u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u7528\u4e8e\u8861\u91cf\u7b97\u6cd5\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u968f\u6570\u636e\u91cf\u589e\u957f\u7684\u8d8b\u52bf\u3002
        • \u7b97\u6cd5\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u76f8\u5173\u5185\u5b58\u7a7a\u95f4\u53ef\u5206\u4e3a\u8f93\u5165\u7a7a\u95f4\u3001\u6682\u5b58\u7a7a\u95f4\u3001\u8f93\u51fa\u7a7a\u95f4\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8f93\u5165\u7a7a\u95f4\u4e0d\u7eb3\u5165\u7a7a\u95f4\u590d\u6742\u5ea6\u8ba1\u7b97\u3002\u6682\u5b58\u7a7a\u95f4\u53ef\u5206\u4e3a\u6682\u5b58\u6570\u636e\u3001\u6808\u5e27\u7a7a\u95f4\u548c\u6307\u4ee4\u7a7a\u95f4\uff0c\u5176\u4e2d\u6808\u5e27\u7a7a\u95f4\u901a\u5e38\u4ec5\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u5f71\u54cd\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u6211\u4eec\u901a\u5e38\u53ea\u5173\u6ce8\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\uff0c\u5373\u7edf\u8ba1\u7b97\u6cd5\u5728\u6700\u5dee\u8f93\u5165\u6570\u636e\u548c\u6700\u5dee\u8fd0\u884c\u65f6\u523b\u4e0b\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u5e38\u89c1\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece\u4f4e\u5230\u9ad8\u6392\u5217\u6709 \\(O(1)\\)\u3001\\(O(\\log n)\\)\u3001\\(O(n)\\)\u3001\\(O(n^2)\\) \u548c \\(O(2^n)\\) \u7b49\u3002
        "},{"location":"chapter_computational_complexity/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u5c3e\u9012\u5f52\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u5417\uff1f

        \u7406\u8bba\u4e0a\uff0c\u5c3e\u9012\u5f52\u51fd\u6570\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(1)\\) \u3002\u4e0d\u8fc7\u7edd\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\uff08\u4f8b\u5982 Java\u3001Python\u3001C++\u3001Go\u3001C# \u7b49\uff09\u4e0d\u652f\u6301\u81ea\u52a8\u4f18\u5316\u5c3e\u9012\u5f52\uff0c\u56e0\u6b64\u901a\u5e38\u8ba4\u4e3a\u7a7a\u95f4\u590d\u6742\u5ea6\u662f \\(O(n)\\) \u3002

        \u51fd\u6570\u548c\u65b9\u6cd5\u8fd9\u4e24\u4e2a\u672f\u8bed\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f

        \u300c\u51fd\u6570 function\u300d\u53ef\u4ee5\u88ab\u72ec\u7acb\u6267\u884c\uff0c\u6240\u6709\u53c2\u6570\u90fd\u4ee5\u663e\u5f0f\u4f20\u9012\u3002\u300c\u65b9\u6cd5 method\u300d\u4e0e\u4e00\u4e2a\u5bf9\u8c61\u5173\u8054\uff0c\u88ab\u9690\u5f0f\u4f20\u9012\u7ed9\u8c03\u7528\u5b83\u7684\u5bf9\u8c61\uff0c\u80fd\u591f\u5bf9\u7c7b\u7684\u5b9e\u4f8b\u4e2d\u5305\u542b\u7684\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u3002

        \u4e0b\u9762\u4ee5\u51e0\u79cd\u5e38\u89c1\u7684\u7f16\u7a0b\u8bed\u8a00\u4e3a\u4f8b\u6765\u8bf4\u660e\u3002

        • C \u8bed\u8a00\u662f\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\u8bed\u8a00\uff0c\u6ca1\u6709\u9762\u5411\u5bf9\u8c61\u7684\u6982\u5ff5\uff0c\u6240\u4ee5\u53ea\u6709\u51fd\u6570\u3002\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u7ed3\u6784\u4f53\uff08struct\uff09\u6765\u6a21\u62df\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u4e0e\u7ed3\u6784\u4f53\u76f8\u5173\u8054\u7684\u51fd\u6570\u5c31\u76f8\u5f53\u4e8e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u65b9\u6cd5\u3002
        • Java \u548c C# \u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4ee3\u7801\u5757\uff08\u65b9\u6cd5\uff09\u901a\u5e38\u4f5c\u4e3a\u67d0\u4e2a\u7c7b\u7684\u4e00\u90e8\u5206\u3002\u9759\u6001\u65b9\u6cd5\u7684\u884c\u4e3a\u7c7b\u4f3c\u4e8e\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u88ab\u7ed1\u5b9a\u5728\u7c7b\u4e0a\uff0c\u4e0d\u80fd\u8bbf\u95ee\u7279\u5b9a\u7684\u5b9e\u4f8b\u53d8\u91cf\u3002
        • C++ \u548c Python \u65e2\u652f\u6301\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\uff08\u51fd\u6570\uff09\uff0c\u4e5f\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08\u65b9\u6cd5\uff09\u3002

        \u56fe\u89e3\u201c\u5e38\u89c1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\u201d\u53cd\u6620\u7684\u662f\u5426\u662f\u5360\u7528\u7a7a\u95f4\u7684\u7edd\u5bf9\u5927\u5c0f\uff1f

        \u4e0d\u662f\uff0c\u8be5\u56fe\u5c55\u793a\u7684\u662f\u7a7a\u95f4\u590d\u6742\u5ea6\uff0c\u5176\u53cd\u6620\u7684\u662f\u589e\u957f\u8d8b\u52bf\uff0c\u800c\u4e0d\u662f\u5360\u7528\u7a7a\u95f4\u7684\u7edd\u5bf9\u5927\u5c0f\u3002

        \u5047\u8bbe\u53d6 \\(n = 8\\) \uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u6bcf\u6761\u66f2\u7ebf\u7684\u503c\u4e0e\u51fd\u6570\u5bf9\u5e94\u4e0d\u4e0a\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u6761\u66f2\u7ebf\u90fd\u5305\u542b\u4e00\u4e2a\u5e38\u6570\u9879\uff0c\u7528\u4e8e\u5c06\u53d6\u503c\u8303\u56f4\u538b\u7f29\u5230\u4e00\u4e2a\u89c6\u89c9\u8212\u9002\u7684\u8303\u56f4\u5185\u3002

        \u5728\u5b9e\u9645\u4e2d\uff0c\u56e0\u4e3a\u6211\u4eec\u901a\u5e38\u4e0d\u77e5\u9053\u6bcf\u4e2a\u65b9\u6cd5\u7684\u201c\u5e38\u6570\u9879\u201d\u590d\u6742\u5ea6\u662f\u591a\u5c11\uff0c\u6240\u4ee5\u4e00\u822c\u65e0\u6cd5\u4ec5\u51ed\u590d\u6742\u5ea6\u6765\u9009\u62e9 \\(n = 8\\) \u4e4b\u4e0b\u7684\u6700\u4f18\u89e3\u6cd5\u3002\u4f46\u5bf9\u4e8e \\(n = 8^5\\) \u5c31\u5f88\u597d\u9009\u4e86\uff0c\u8fd9\u65f6\u589e\u957f\u8d8b\u52bf\u5df2\u7ecf\u5360\u4e3b\u5bfc\u4e86\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/","title":"2.3 \u00a0 \u65f6\u95f4\u590d\u6742\u5ea6","text":"

        \u8fd0\u884c\u65f6\u95f4\u53ef\u4ee5\u76f4\u89c2\u4e14\u51c6\u786e\u5730\u53cd\u6620\u7b97\u6cd5\u7684\u6548\u7387\u3002\u5982\u679c\u6211\u4eec\u60f3\u51c6\u786e\u9884\u4f30\u4e00\u6bb5\u4ee3\u7801\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u5e94\u8be5\u5982\u4f55\u64cd\u4f5c\u5462\uff1f

        1. \u786e\u5b9a\u8fd0\u884c\u5e73\u53f0\uff0c\u5305\u62ec\u786c\u4ef6\u914d\u7f6e\u3001\u7f16\u7a0b\u8bed\u8a00\u3001\u7cfb\u7edf\u73af\u5883\u7b49\uff0c\u8fd9\u4e9b\u56e0\u7d20\u90fd\u4f1a\u5f71\u54cd\u4ee3\u7801\u7684\u8fd0\u884c\u6548\u7387\u3002
        2. \u8bc4\u4f30\u5404\u79cd\u8ba1\u7b97\u64cd\u4f5c\u6240\u9700\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u4f8b\u5982\u52a0\u6cd5\u64cd\u4f5c + \u9700\u8981 1 ns \uff0c\u4e58\u6cd5\u64cd\u4f5c * \u9700\u8981 10 ns \uff0c\u6253\u5370\u64cd\u4f5c print() \u9700\u8981 5 ns \u7b49\u3002
        3. \u7edf\u8ba1\u4ee3\u7801\u4e2d\u6240\u6709\u7684\u8ba1\u7b97\u64cd\u4f5c\uff0c\u5e76\u5c06\u6240\u6709\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u95f4\u6c42\u548c\uff0c\u4ece\u800c\u5f97\u5230\u8fd0\u884c\u65f6\u95f4\u3002

        \u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\ndef algorithm(n: int):\na = 2      # 1 ns\na = a + 1  # 1 ns\na = a * 2  # 10 ns\n# \u5faa\u73af n \u6b21\nfor _ in range(n):  # 1 ns\nprint(0)        # 5 ns\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\ncout << 0 << endl;         // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nSystem.out.println(0);     // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid Algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nConsole.WriteLine(0);      // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n int) {\na := 2     // 1 ns\na = a + 1  // 1 ns\na = a * 2  // 10 ns\n// \u5faa\u73af n \u6b21\nfor i := 0; i < n; i++ {  // 1 ns\nfmt.Println(a)        // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n: Int) {\nvar a = 2 // 1 ns\na = a + 1 // 1 ns\na = a * 2 // 10 ns\n// \u5faa\u73af n \u6b21\nfor _ in 0 ..< n { // 1 ns\nprint(0) // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n) {\nvar a = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nconsole.log(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n: number): void {\nvar a: number = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nconsole.log(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2; // 1 ns\na = a + 1; // 1 ns\na = a * 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprint(0); // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: i32) {\nlet mut a = 2;      // 1 ns\na = a + 1;          // 1 ns\na = a * 2;          // 10 ns\n// \u5faa\u73af n \u6b21\nfor _ in 0..n {     // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprintln!(\"{}\", 0);  // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\nint a = 2;  // 1 ns\na = a + 1;  // 1 ns\na = a * 2;  // 10 ns\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\nprintf(\"%d\", 0);            // 5 ns\n}\n}\n
        // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: usize) void {\nvar a: i32 = 2; // 1 ns\na += 1; // 1 ns\na *= 2; // 10 ns\n// \u5faa\u73af n \u6b21\nfor (0..n) |_| { // 1 ns\nstd.debug.print(\"{}\\n\", .{0}); // 5 ns\n}\n}\n

        \u6839\u636e\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5f97\u5230\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u4e3a \\((6n + 12)\\) ns \uff1a

        \\[ 1 + 1 + 10 + (1 + 5) \\times n = 6n + 12 \\]

        \u4f46\u5b9e\u9645\u4e0a\uff0c\u7edf\u8ba1\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u65e2\u4e0d\u5408\u7406\u4e5f\u4e0d\u73b0\u5b9e\u3002\u9996\u5148\uff0c\u6211\u4eec\u4e0d\u5e0c\u671b\u5c06\u9884\u4f30\u65f6\u95f4\u548c\u8fd0\u884c\u5e73\u53f0\u7ed1\u5b9a\uff0c\u56e0\u4e3a\u7b97\u6cd5\u9700\u8981\u5728\u5404\u79cd\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002\u5176\u6b21\uff0c\u6211\u4eec\u5f88\u96be\u83b7\u77e5\u6bcf\u79cd\u64cd\u4f5c\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u8fd9\u7ed9\u9884\u4f30\u8fc7\u7a0b\u5e26\u6765\u4e86\u6781\u5927\u7684\u96be\u5ea6\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#231","title":"2.3.1 \u00a0 \u7edf\u8ba1\u65f6\u95f4\u589e\u957f\u8d8b\u52bf","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u7edf\u8ba1\u7684\u4e0d\u662f\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\uff0c\u800c\u662f\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u7740\u6570\u636e\u91cf\u53d8\u5927\u65f6\u7684\u589e\u957f\u8d8b\u52bf\u3002

        \u201c\u65f6\u95f4\u589e\u957f\u8d8b\u52bf\u201d\u8fd9\u4e2a\u6982\u5ff5\u6bd4\u8f83\u62bd\u8c61\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u52a0\u4ee5\u7406\u89e3\u3002\u5047\u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u7ed9\u5b9a\u4e09\u4e2a\u7b97\u6cd5 A\u3001B \u548c C \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_A(n: int):\nprint(0)\n# \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\ndef algorithm_B(n: int):\nfor _ in range(n):\nprint(0)\n# \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_C(n: int):\nfor _ in range(1000000):\nprint(0)\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\ncout << 0 << endl;\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\ncout << 0 << endl;\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\ncout << 0 << endl;\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\nSystem.out.println(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\nSystem.out.println(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\nSystem.out.println(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmA(int n) {\nConsole.WriteLine(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid AlgorithmB(int n) {\nfor (int i = 0; i < n; i++) {\nConsole.WriteLine(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmC(int n) {\nfor (int i = 0; i < 1000000; i++) {\nConsole.WriteLine(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_A(n int) {\nfmt.Println(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithm_B(n int) {\nfor i := 0; i < n; i++ {\nfmt.Println(0)\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_C(n int) {\nfor i := 0; i < 1000000; i++ {\nfmt.Println(0)\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmA(n: Int) {\nprint(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithmB(n: Int) {\nfor _ in 0 ..< n {\nprint(0)\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmC(n: Int) {\nfor _ in 0 ..< 1000000 {\nprint(0)\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n) {\nconsole.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n) {\nfor (let i = 0; i < n; i++) {\nconsole.log(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n) {\nfor (let i = 0; i < 1000000; i++) {\nconsole.log(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n: number): void {\nconsole.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n: number): void {\nfor (let i = 0; i < n; i++) {\nconsole.log(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n: number): void {\nfor (let i = 0; i < 1000000; i++) {\nconsole.log(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmA(int n) {\nprint(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithmB(int n) {\nfor (int i = 0; i < n; i++) {\nprint(0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmC(int n) {\nfor (int i = 0; i < 1000000; i++) {\nprint(0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: i32) {\nprintln!(\"{}\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) {\nfor _ in 0..n {\nprintln!(\"{}\", 0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) {\nfor _ in 0..1000000 {\nprintln!(\"{}\", 0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\nprintf(\"%d\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\nfor (int i = 0; i < n; i++) {\nprintf(\"%d\", 0);\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\nfor (int i = 0; i < 1000000; i++) {\nprintf(\"%d\", 0);\n}\n}\n
        // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: usize) void {\n_ = n;\nstd.debug.print(\"{}\\n\", .{0});\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) void {\nfor (0..n) |_| {\nstd.debug.print(\"{}\\n\", .{0});\n}\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) void {\n_ = n;\nfor (0..1000000) |_| { std.debug.print(\"{}\\n\", .{0});\n}\n}\n

        \u56fe 2-7 \u5c55\u793a\u4e86\u4ee5\u4e0a\u4e09\u4e2a\u7b97\u6cd5\u51fd\u6570\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        • \u7b97\u6cd5 A \u53ea\u6709 \\(1\\) \u4e2a\u6253\u5370\u64cd\u4f5c\uff0c\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u4e0d\u968f\u7740 \\(n\\) \u589e\u5927\u800c\u589e\u957f\u3002\u6211\u4eec\u79f0\u6b64\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u201c\u5e38\u6570\u9636\u201d\u3002
        • \u7b97\u6cd5 B \u4e2d\u7684\u6253\u5370\u64cd\u4f5c\u9700\u8981\u5faa\u73af \\(n\\) \u6b21\uff0c\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u968f\u7740 \\(n\\) \u589e\u5927\u5448\u7ebf\u6027\u589e\u957f\u3002\u6b64\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u88ab\u79f0\u4e3a\u201c\u7ebf\u6027\u9636\u201d\u3002
        • \u7b97\u6cd5 C \u4e2d\u7684\u6253\u5370\u64cd\u4f5c\u9700\u8981\u5faa\u73af \\(1000000\\) \u6b21\uff0c\u867d\u7136\u8fd0\u884c\u65f6\u95f4\u5f88\u957f\uff0c\u4f46\u5b83\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\u3002\u56e0\u6b64 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c A \u76f8\u540c\uff0c\u4ecd\u4e3a\u201c\u5e38\u6570\u9636\u201d\u3002

        \u56fe 2-7 \u00a0 \u7b97\u6cd5 A\u3001B \u548c C \u7684\u65f6\u95f4\u589e\u957f\u8d8b\u52bf

        \u76f8\u8f83\u4e8e\u76f4\u63a5\u7edf\u8ba1\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u6709\u54ea\u4e9b\u7279\u70b9\u5462\uff1f

        • \u65f6\u95f4\u590d\u6742\u5ea6\u80fd\u591f\u6709\u6548\u8bc4\u4f30\u7b97\u6cd5\u6548\u7387\u3002\u4f8b\u5982\uff0c\u7b97\u6cd5 B \u7684\u8fd0\u884c\u65f6\u95f4\u5448\u7ebf\u6027\u589e\u957f\uff0c\u5728 \\(n > 1\\) \u65f6\u6bd4\u7b97\u6cd5 A \u66f4\u6162\uff0c\u5728 \\(n > 1000000\\) \u65f6\u6bd4\u7b97\u6cd5 C \u66f4\u6162\u3002\u4e8b\u5b9e\u4e0a\uff0c\u53ea\u8981\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u8db3\u591f\u5927\uff0c\u590d\u6742\u5ea6\u4e3a\u201c\u5e38\u6570\u9636\u201d\u7684\u7b97\u6cd5\u4e00\u5b9a\u4f18\u4e8e\u201c\u7ebf\u6027\u9636\u201d\u7684\u7b97\u6cd5\uff0c\u8fd9\u6b63\u662f\u65f6\u95f4\u589e\u957f\u8d8b\u52bf\u7684\u542b\u4e49\u3002
        • \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u66f4\u7b80\u4fbf\u3002\u663e\u7136\uff0c\u8fd0\u884c\u5e73\u53f0\u548c\u8ba1\u7b97\u64cd\u4f5c\u7c7b\u578b\u90fd\u4e0e\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u65e0\u5173\u3002\u56e0\u6b64\u5728\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u5c06\u6240\u6709\u8ba1\u7b97\u64cd\u4f5c\u7684\u6267\u884c\u65f6\u95f4\u89c6\u4e3a\u76f8\u540c\u7684\u201c\u5355\u4f4d\u65f6\u95f4\u201d\uff0c\u4ece\u800c\u5c06\u201c\u8ba1\u7b97\u64cd\u4f5c\u8fd0\u884c\u65f6\u95f4\u7edf\u8ba1\u201d\u7b80\u5316\u4e3a\u201c\u8ba1\u7b97\u64cd\u4f5c\u6570\u91cf\u7edf\u8ba1\u201d\uff0c\u8fd9\u6837\u4e00\u6765\u4f30\u7b97\u96be\u5ea6\u5c31\u5927\u5927\u964d\u4f4e\u4e86\u3002
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u5b58\u5728\u4e00\u5b9a\u7684\u5c40\u9650\u6027\u3002\u4f8b\u5982\uff0c\u5c3d\u7ba1\u7b97\u6cd5 A \u548c C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u76f8\u540c\uff0c\u4f46\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u5dee\u522b\u5f88\u5927\u3002\u540c\u6837\uff0c\u5c3d\u7ba1\u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6bd4 C \u9ad8\uff0c\u4f46\u5728\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u8f83\u5c0f\u65f6\uff0c\u7b97\u6cd5 B \u660e\u663e\u4f18\u4e8e\u7b97\u6cd5 C \u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5f88\u96be\u4ec5\u51ed\u65f6\u95f4\u590d\u6742\u5ea6\u5224\u65ad\u7b97\u6cd5\u6548\u7387\u7684\u9ad8\u4f4e\u3002\u5f53\u7136\uff0c\u5c3d\u7ba1\u5b58\u5728\u4e0a\u8ff0\u95ee\u9898\uff0c\u590d\u6742\u5ea6\u5206\u6790\u4ecd\u7136\u662f\u8bc4\u5224\u7b97\u6cd5\u6548\u7387\u6700\u6709\u6548\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\u3002
        "},{"location":"chapter_computational_complexity/time_complexity/#232","title":"2.3.2 \u00a0 \u51fd\u6570\u6e10\u8fd1\u4e0a\u754c","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u8f93\u5165\u5927\u5c0f\u4e3a \\(n\\) \u7684\u51fd\u6570\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 1      # +1\na = a + 1  # +1\na = a * 2  # +1\n# \u5faa\u73af n \u6b21\nfor i in range(n):  # +1\nprint(0)        # +1\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\ncout << 0 << endl;    // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nSystem.out.println(0);    // +1\n}\n}\n
        void Algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nConsole.WriteLine(0);   // +1\n}\n}\n
        func algorithm(n int) {\na := 1      // +1\na = a + 1   // +1\na = a * 2   // +1\n// \u5faa\u73af n \u6b21\nfor i := 0; i < n; i++ {   // +1\nfmt.Println(a)         // +1\n}\n}\n
        func algorithm(n: Int) {\nvar a = 1 // +1\na = a + 1 // +1\na = a * 2 // +1\n// \u5faa\u73af n \u6b21\nfor _ in 0 ..< n { // +1\nprint(0) // +1\n}\n}\n
        function algorithm(n) {\nvar a = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nconsole.log(0); // +1\n}\n}\n
        function algorithm(n: number): void{\nvar a: number = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nconsole.log(0); // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1; // +1\na = a + 1; // +1\na = a * 2; // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprint(0); // +1\n}\n}\n
        fn algorithm(n: i32) {\nlet mut a = 1;   // +1\na = a + 1;      // +1\na = a * 2;      // +1\n// \u5faa\u73af n \u6b21\nfor _ in 0..n { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprintln!(\"{}\", 0); // +1\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +1\na = a + 1;  // +1\na = a * 2;  // +1\n// \u5faa\u73af n \u6b21\nfor (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nprintf(\"%d\", 0);            // +1\n}\n}  
        fn algorithm(n: usize) void {\nvar a: i32 = 1; // +1\na += 1; // +1\na *= 2; // +1\n// \u5faa\u73af n \u6b21\nfor (0..n) |_| { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\nstd.debug.print(\"{}\\n\", .{0}); // +1\n}\n}\n

        \u8bbe\u7b97\u6cd5\u7684\u64cd\u4f5c\u6570\u91cf\u662f\u4e00\u4e2a\u5173\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u7684\u51fd\u6570\uff0c\u8bb0\u4e3a \\(T(n)\\) \uff0c\u5219\u4ee5\u4e0a\u51fd\u6570\u7684\u64cd\u4f5c\u6570\u91cf\u4e3a\uff1a

        \\[ T(n) = 3 + 2n \\]

        \\(T(n)\\) \u662f\u4e00\u6b21\u51fd\u6570\uff0c\u8bf4\u660e\u5176\u8fd0\u884c\u65f6\u95f4\u7684\u589e\u957f\u8d8b\u52bf\u662f\u7ebf\u6027\u7684\uff0c\u56e0\u6b64\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u7ebf\u6027\u9636\u3002

        \u6211\u4eec\u5c06\u7ebf\u6027\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u8bb0\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4e2a\u6570\u5b66\u7b26\u53f7\u79f0\u4e3a\u300c\u5927 \\(O\\) \u8bb0\u53f7 big-\\(O\\) notation\u300d\uff0c\u8868\u793a\u51fd\u6570 \\(T(n)\\) \u7684\u300c\u6e10\u8fd1\u4e0a\u754c asymptotic upper bound\u300d\u3002

        \u65f6\u95f4\u590d\u6742\u5ea6\u5206\u6790\u672c\u8d28\u4e0a\u662f\u8ba1\u7b97\u201c\u64cd\u4f5c\u6570\u91cf \\(T(n)\\)\u201d\u7684\u6e10\u8fd1\u4e0a\u754c\uff0c\u5b83\u5177\u6709\u660e\u786e\u7684\u6570\u5b66\u5b9a\u4e49\u3002

        \u51fd\u6570\u6e10\u8fd1\u4e0a\u754c

        \u82e5\u5b58\u5728\u6b63\u5b9e\u6570 \\(c\\) \u548c\u5b9e\u6570 \\(n_0\\) \uff0c\u4f7f\u5f97\u5bf9\u4e8e\u6240\u6709\u7684 \\(n > n_0\\) \uff0c\u5747\u6709 \\(T(n) \\leq c \\cdot f(n)\\) \uff0c\u5219\u53ef\u8ba4\u4e3a \\(f(n)\\) \u7ed9\u51fa\u4e86 \\(T(n)\\) \u7684\u4e00\u4e2a\u6e10\u8fd1\u4e0a\u754c\uff0c\u8bb0\u4e3a \\(T(n) = O(f(n))\\) \u3002

        \u5982\u56fe 2-8 \u6240\u793a\uff0c\u8ba1\u7b97\u6e10\u8fd1\u4e0a\u754c\u5c31\u662f\u5bfb\u627e\u4e00\u4e2a\u51fd\u6570 \\(f(n)\\) \uff0c\u4f7f\u5f97\u5f53 \\(n\\) \u8d8b\u5411\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\\(T(n)\\) \u548c \\(f(n)\\) \u5904\u4e8e\u76f8\u540c\u7684\u589e\u957f\u7ea7\u522b\uff0c\u4ec5\u76f8\u5dee\u4e00\u4e2a\u5e38\u6570\u9879 \\(c\\) \u7684\u500d\u6570\u3002

        \u56fe 2-8 \u00a0 \u51fd\u6570\u7684\u6e10\u8fd1\u4e0a\u754c

        "},{"location":"chapter_computational_complexity/time_complexity/#233","title":"2.3.3 \u00a0 \u63a8\u7b97\u65b9\u6cd5","text":"

        \u6e10\u8fd1\u4e0a\u754c\u7684\u6570\u5b66\u5473\u513f\u6709\u70b9\u91cd\uff0c\u5982\u679c\u4f60\u611f\u89c9\u6ca1\u6709\u5b8c\u5168\u7406\u89e3\uff0c\u4e5f\u65e0\u987b\u62c5\u5fc3\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u638c\u63e1\u63a8\u7b97\u65b9\u6cd5\uff0c\u5728\u4e0d\u65ad\u7684\u5b9e\u8df5\u4e2d\uff0c\u5c31\u53ef\u4ee5\u9010\u6e10\u9886\u609f\u5176\u6570\u5b66\u610f\u4e49\u3002

        \u6839\u636e\u5b9a\u4e49\uff0c\u786e\u5b9a \\(f(n)\\) \u4e4b\u540e\uff0c\u6211\u4eec\u4fbf\u53ef\u5f97\u5230\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(f(n))\\) \u3002\u90a3\u4e48\u5982\u4f55\u786e\u5b9a\u6e10\u8fd1\u4e0a\u754c \\(f(n)\\) \u5462\uff1f\u603b\u4f53\u5206\u4e3a\u4e24\u6b65\uff1a\u9996\u5148\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff0c\u7136\u540e\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#1","title":"1. \u00a0 \u7b2c\u4e00\u6b65\uff1a\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf","text":"

        \u9488\u5bf9\u4ee3\u7801\uff0c\u9010\u884c\u4ece\u4e0a\u5230\u4e0b\u8ba1\u7b97\u5373\u53ef\u3002\u7136\u800c\uff0c\u7531\u4e8e\u4e0a\u8ff0 \\(c \\cdot f(n)\\) \u4e2d\u7684\u5e38\u6570\u9879 \\(c\\) \u53ef\u4ee5\u53d6\u4efb\u610f\u5927\u5c0f\uff0c\u56e0\u6b64\u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u4e2d\u7684\u5404\u79cd\u7cfb\u6570\u3001\u5e38\u6570\u9879\u90fd\u53ef\u4ee5\u5ffd\u7565\u3002\u6839\u636e\u6b64\u539f\u5219\uff0c\u53ef\u4ee5\u603b\u7ed3\u51fa\u4ee5\u4e0b\u8ba1\u6570\u7b80\u5316\u6280\u5de7\u3002

        1. \u5ffd\u7565 \\(T(n)\\) \u4e2d\u7684\u5e38\u6570\u9879\u3002\u56e0\u4e3a\u5b83\u4eec\u90fd\u4e0e \\(n\\) \u65e0\u5173\uff0c\u6240\u4ee5\u5bf9\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u4ea7\u751f\u5f71\u54cd\u3002
        2. \u7701\u7565\u6240\u6709\u7cfb\u6570\u3002\u4f8b\u5982\uff0c\u5faa\u73af \\(2n\\) \u6b21\u3001\\(5n + 1\\) \u6b21\u7b49\uff0c\u90fd\u53ef\u4ee5\u7b80\u5316\u8bb0\u4e3a \\(n\\) \u6b21\uff0c\u56e0\u4e3a \\(n\\) \u524d\u9762\u7684\u7cfb\u6570\u5bf9\u65f6\u95f4\u590d\u6742\u5ea6\u6ca1\u6709\u5f71\u54cd\u3002
        3. \u5faa\u73af\u5d4c\u5957\u65f6\u4f7f\u7528\u4e58\u6cd5\u3002\u603b\u64cd\u4f5c\u6570\u91cf\u7b49\u4e8e\u5916\u5c42\u5faa\u73af\u548c\u5185\u5c42\u5faa\u73af\u64cd\u4f5c\u6570\u91cf\u4e4b\u79ef\uff0c\u6bcf\u4e00\u5c42\u5faa\u73af\u4f9d\u7136\u53ef\u4ee5\u5206\u522b\u5957\u7528\u7b2c 1. \u70b9\u548c\u7b2c 2. \u70b9\u7684\u6280\u5de7\u3002

        \u7ed9\u5b9a\u4e00\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u4e0a\u8ff0\u6280\u5de7\u6765\u7edf\u8ba1\u64cd\u4f5c\u6570\u91cf\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        def algorithm(n: int):\na = 1      # +0\uff08\u6280\u5de7 1\uff09\na = a + n  # +0\uff08\u6280\u5de7 1\uff09\n# +n\uff08\u6280\u5de7 2\uff09\nfor i in range(5 * n + 1):\nprint(0)\n# +n*n\uff08\u6280\u5de7 3\uff09\nfor i in range(2 * n):\nfor j in range(n + 1):\nprint(0)\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\ncout << 0 << endl;\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\ncout << 0 << endl;\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nSystem.out.println(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nSystem.out.println(0);\n}\n}\n}\n
        void Algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nConsole.WriteLine(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nConsole.WriteLine(0);\n}\n}\n}\n
        func algorithm(n int) {\na := 1     // +0\uff08\u6280\u5de7 1\uff09\na = a + n  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor i := 0; i < 5 * n + 1; i++ {\nfmt.Println(0)\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor i := 0; i < 2 * n; i++ {\nfor j := 0; j < n + 1; j++ {\nfmt.Println(0)\n}\n}\n}\n
        func algorithm(n: Int) {\nvar a = 1 // +0\uff08\u6280\u5de7 1\uff09\na = a + n // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor _ in 0 ..< (5 * n + 1) {\nprint(0)\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor _ in 0 ..< (2 * n) {\nfor _ in 0 ..< (n + 1) {\nprint(0)\n}\n}\n}\n
        function algorithm(n) {\nlet a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (let i = 0; i < 5 * n + 1; i++) {\nconsole.log(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (let i = 0; i < 2 * n; i++) {\nfor (let j = 0; j < n + 1; j++) {\nconsole.log(0);\n}\n}\n}\n
        function algorithm(n: number): void {\nlet a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (let i = 0; i < 5 * n + 1; i++) {\nconsole.log(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (let i = 0; i < 2 * n; i++) {\nfor (let j = 0; j < n + 1; j++) {\nconsole.log(0);\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1; // +0\uff08\u6280\u5de7 1\uff09\na = a + n; // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nprint(0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nprint(0);\n}\n}\n}\n
        fn algorithm(n: i32) {\nlet mut a = 1;     // +0\uff08\u6280\u5de7 1\uff09\na = a + n;        // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor i in 0..(5 * n + 1) {\nprintln!(\"{}\", 0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor i in 0..(2 * n) {\nfor j in 0..(n + 1) {\nprintln!(\"{}\", 0);\n}\n}\n}\n
        void algorithm(int n) {\nint a = 1;  // +0\uff08\u6280\u5de7 1\uff09\na = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor (int i = 0; i < 5 * n + 1; i++) {\nprintf(\"%d\", 0);\n}\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor (int i = 0; i < 2 * n; i++) {\nfor (int j = 0; j < n + 1; j++) {\nprintf(\"%d\", 0);\n}\n}\n}\n
        fn algorithm(n: usize) void {\nvar a: i32 = 1;     // +0\uff08\u6280\u5de7 1\uff09\na = a + @as(i32, @intCast(n));        // +0\uff08\u6280\u5de7 1\uff09\n// +n\uff08\u6280\u5de7 2\uff09\nfor(0..(5 * n + 1)) |_| {\nstd.debug.print(\"{}\\n\", .{0}); }\n// +n*n\uff08\u6280\u5de7 3\uff09\nfor(0..(2 * n)) |_| {\nfor(0..(n + 1)) |_| {\nstd.debug.print(\"{}\\n\", .{0}); }\n}\n}\n

        \u4ee5\u4e0b\u516c\u5f0f\u5c55\u793a\u4e86\u4f7f\u7528\u4e0a\u8ff0\u6280\u5de7\u524d\u540e\u7684\u7edf\u8ba1\u7ed3\u679c\uff0c\u4e24\u8005\u63a8\u7b97\u51fa\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \u3002

        \\[ \\begin{aligned} T(n) & = 2n(n + 1) + (5n + 1) + 2 & \\text{\u5b8c\u6574\u7edf\u8ba1 (-.-|||)} \\newline & = 2n^2 + 7n + 3 \\newline T(n) & = n^2 + n & \\text{\u5077\u61d2\u7edf\u8ba1 (o.O)} \\end{aligned} \\]"},{"location":"chapter_computational_complexity/time_complexity/#2","title":"2. \u00a0 \u7b2c\u4e8c\u6b65\uff1a\u5224\u65ad\u6e10\u8fd1\u4e0a\u754c","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\u7531 \\(T(n)\\) \u4e2d\u6700\u9ad8\u9636\u7684\u9879\u6765\u51b3\u5b9a\u3002\u8fd9\u662f\u56e0\u4e3a\u5728 \\(n\\) \u8d8b\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\u6700\u9ad8\u9636\u7684\u9879\u5c06\u53d1\u6325\u4e3b\u5bfc\u4f5c\u7528\uff0c\u5176\u4ed6\u9879\u7684\u5f71\u54cd\u90fd\u53ef\u4ee5\u5ffd\u7565\u3002

        \u8868 2-2 \u5c55\u793a\u4e86\u4e00\u4e9b\u4f8b\u5b50\uff0c\u5176\u4e2d\u4e00\u4e9b\u5938\u5f20\u7684\u503c\u662f\u4e3a\u4e86\u5f3a\u8c03\u201c\u7cfb\u6570\u65e0\u6cd5\u64bc\u52a8\u9636\u6570\u201d\u8fd9\u4e00\u7ed3\u8bba\u3002\u5f53 \\(n\\) \u8d8b\u4e8e\u65e0\u7a77\u5927\u65f6\uff0c\u8fd9\u4e9b\u5e38\u6570\u53d8\u5f97\u65e0\u8db3\u8f7b\u91cd\u3002

        \u8868 2-2 \u00a0 \u4e0d\u540c\u64cd\u4f5c\u6570\u91cf\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u64cd\u4f5c\u6570\u91cf \\(T(n)\\) \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(f(n))\\) \\(100000\\) \\(O(1)\\) \\(3n + 2\\) \\(O(n)\\) \\(2n^2 + 3n + 2\\) \\(O(n^2)\\) \\(n^3 + 10000n^2\\) \\(O(n^3)\\) \\(2^n + 10000n^{10000}\\) \\(O(2^n)\\)"},{"location":"chapter_computational_complexity/time_complexity/#234","title":"2.3.4 \u00a0 \u5e38\u89c1\u7c7b\u578b","text":"

        \u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u5e38\u89c1\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7c7b\u578b\u5982\u56fe 2-9 \u6240\u793a\uff08\u6309\u7167\u4ece\u4f4e\u5230\u9ad8\u7684\u987a\u5e8f\u6392\u5217\uff09\u3002

        \\[ \\begin{aligned} O(1) < O(\\log n) < O(n) < O(n \\log n) < O(n^2) < O(2^n) < O(n!) \\newline \\text{\u5e38\u6570\u9636} < \\text{\u5bf9\u6570\u9636} < \\text{\u7ebf\u6027\u9636} < \\text{\u7ebf\u6027\u5bf9\u6570\u9636} < \\text{\u5e73\u65b9\u9636} < \\text{\u6307\u6570\u9636} < \\text{\u9636\u4e58\u9636} \\end{aligned} \\]

        \u56fe 2-9 \u00a0 \u5e38\u89c1\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7c7b\u578b

        "},{"location":"chapter_computational_complexity/time_complexity/#1-o1","title":"1. \u00a0 \u5e38\u6570\u9636 \\(O(1)\\)","text":"

        \u5e38\u6570\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\uff0c\u5373\u4e0d\u968f\u7740 \\(n\\) \u7684\u53d8\u5316\u800c\u53d8\u5316\u3002

        \u5728\u4ee5\u4e0b\u51fd\u6570\u4e2d\uff0c\u5c3d\u7ba1\u64cd\u4f5c\u6570\u91cf size \u53ef\u80fd\u5f88\u5927\uff0c\u4f46\u7531\u4e8e\u5176\u4e0e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u65e0\u5173\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def constant(n: int) -> int:\n\"\"\"\u5e38\u6570\u9636\"\"\"\ncount = 0\nsize = 100000\nfor _ in range(size):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.java
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e38\u6570\u9636 */\nint Constant(int n) {\nint count = 0;\nint size = 100000;\nfor (int i = 0; i < size; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.go
        /* \u5e38\u6570\u9636 */\nfunc constant(n int) int {\ncount := 0\nsize := 100000\nfor i := 0; i < size; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e38\u6570\u9636 */\nfunc constant(n: Int) -> Int {\nvar count = 0\nlet size = 100_000\nfor _ in 0 ..< size {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e38\u6570\u9636 */\nfunction constant(n) {\nlet count = 0;\nconst size = 100000;\nfor (let i = 0; i < size; i++) count++;\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e38\u6570\u9636 */\nfunction constant(n: number): number {\nlet count = 0;\nconst size = 100000;\nfor (let i = 0; i < size; i++) count++;\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nfor (var i = 0; i < size; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e38\u6570\u9636 */\nfn constant(n: i32) -> i32 {\n_ = n;\nlet mut count = 0;\nlet size = 100_000;\nfor _ in 0..size {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u5e38\u6570\u9636 */\nint constant(int n) {\nint count = 0;\nint size = 100000;\nint i = 0;\nfor (int i = 0; i < size; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e38\u6570\u9636\nfn constant(n: i32) i32 {\n_ = n;\nvar count: i32 = 0;\nconst size: i32 = 100_000;\nvar i: i32 = 0;\nwhile(i<size) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n
        "},{"location":"chapter_computational_complexity/time_complexity/#2-on","title":"2. \u00a0 \u7ebf\u6027\u9636 \\(O(n)\\)","text":"

        \u7ebf\u6027\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u76f8\u5bf9\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u4ee5\u7ebf\u6027\u7ea7\u522b\u589e\u957f\u3002\u7ebf\u6027\u9636\u901a\u5e38\u51fa\u73b0\u5728\u5355\u5c42\u5faa\u73af\u4e2d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def linear(n: int) -> int:\n\"\"\"\u7ebf\u6027\u9636\"\"\"\ncount = 0\nfor _ in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u9636 */\nint Linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++)\ncount++;\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u9636 */\nfunc linear(n int) int {\ncount := 0\nfor i := 0; i < n; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) -> Int {\nvar count = 0\nfor _ in 0 ..< n {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\nlet count = 0;\nfor (let i = 0; i < n; i++) count++;\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): number {\nlet count = 0;\nfor (let i = 0; i < n; i++) count++;\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (var i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u9636 */\nfn linear(n: i32) -> i32 {\nlet mut count = 0;\nfor _ in 0..n {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u9636 */\nint linear(int n) {\nint count = 0;\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u9636\nfn linear(n: i32) i32 {\nvar count: i32 = 0;\nvar i: i32 = 0;\nwhile (i < n) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n

        \u904d\u5386\u6570\u7ec4\u548c\u904d\u5386\u94fe\u8868\u7b49\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u6570\u7ec4\u6216\u94fe\u8868\u7684\u957f\u5ea6\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def array_traversal(nums: list[int]) -> int:\n\"\"\"\u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\"\"\"\ncount = 0\n# \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor num in nums:\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(vector<int> &nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int num : nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int[] nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int num : nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint ArrayTraversal(int[] nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nforeach (int num in nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums []int) int {\ncount := 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor range nums {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums: [Int]) -> Int {\nvar count = 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor _ in nums {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums) {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (let i = 0; i < nums.length; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums: number[]): number {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (let i = 0; i < nums.length; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(List<int> nums) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (var _num in nums) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfn array_traversal(nums: &[i32]) -> i32 {\nlet mut count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor _ in nums {\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int *nums, int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\nfn arrayTraversal(nums: []i32) i32 {\nvar count: i32 = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\nfor (nums) |_| {\ncount += 1;\n}\nreturn count;\n}\n

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u9700\u6839\u636e\u8f93\u5165\u6570\u636e\u7684\u7c7b\u578b\u6765\u5177\u4f53\u786e\u5b9a\u3002\u6bd4\u5982\u5728\u7b2c\u4e00\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53d8\u91cf \\(n\\) \u4e3a\u8f93\u5165\u6570\u636e\u5927\u5c0f\uff1b\u5728\u7b2c\u4e8c\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u4e3a\u6570\u636e\u5927\u5c0f\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#3-on2","title":"3. \u00a0 \u5e73\u65b9\u9636 \\(O(n^2)\\)","text":"

        \u5e73\u65b9\u9636\u7684\u64cd\u4f5c\u6570\u91cf\u76f8\u5bf9\u4e8e\u8f93\u5165\u6570\u636e\u5927\u5c0f \\(n\\) \u4ee5\u5e73\u65b9\u7ea7\u522b\u589e\u957f\u3002\u5e73\u65b9\u9636\u901a\u5e38\u51fa\u73b0\u5728\u5d4c\u5957\u5faa\u73af\u4e2d\uff0c\u5916\u5c42\u5faa\u73af\u548c\u5185\u5c42\u5faa\u73af\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n)\\) \uff0c\u56e0\u6b64\u603b\u4f53\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def quadratic(n: int) -> int:\n\"\"\"\u5e73\u65b9\u9636\"\"\"\ncount = 0\n# \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor i in range(n):\nfor j in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e73\u65b9\u9636 */\nint Quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n int) int {\ncount := 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor i := 0; i < n; i++ {\nfor j := 0; j < n; j++ {\ncount++\n}\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) -> Int {\nvar count = 0\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor _ in 0 ..< n {\nfor _ in 0 ..< n {\ncount += 1\n}\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): number {\nlet count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e73\u65b9\u9636 */\nfn quadratic(n: i32) -> i32 {\nlet mut count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor _ in 0..n {\nfor _ in 0..n {\ncount += 1;\n}\n}\ncount\n}\n
        time_complexity.c
        /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\nint count = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < n; j++) {\ncount++;\n}\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e73\u65b9\u9636\nfn quadratic(n: i32) i32 {\nvar count: i32 = 0;\nvar i: i32 = 0;\n// \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\nwhile (i < n) : (i += 1) {\nvar j: i32 = 0;\nwhile (j < n) : (j += 1) {\ncount += 1;\n}\n}\nreturn count;\n}\n

        \u56fe 2-10 \u5bf9\u6bd4\u4e86\u5e38\u6570\u9636\u3001\u7ebf\u6027\u9636\u548c\u5e73\u65b9\u9636\u4e09\u79cd\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \u56fe 2-10 \u00a0 \u5e38\u6570\u9636\u3001\u7ebf\u6027\u9636\u548c\u5e73\u65b9\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4ee5\u5192\u6ce1\u6392\u5e8f\u4e3a\u4f8b\uff0c\u5916\u5c42\u5faa\u73af\u6267\u884c \\(n - 1\\) \u6b21\uff0c\u5185\u5c42\u5faa\u73af\u6267\u884c \\(n-1\\)\u3001\\(n-2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u6b21\uff0c\u5e73\u5747\u4e3a \\(n / 2\\) \u6b21\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O((n - 1) n / 2) = O(n^2)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def bubble_sort(nums: list[int]) -> int:\n\"\"\"\u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\"\"\"\ncount = 0  # \u8ba1\u6570\u5668\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(len(nums) - 1, 0, -1):\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\ntmp: int = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\ncount += 3  # \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\nreturn count\n
        time_complexity.cpp
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(vector<int> &nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int[] nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint BubbleSort(int[] nums) {\nint count = 0;  // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\ncount += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums []int) int {\ncount := 0 // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\ntmp := nums[j]\nnums[j] = nums[j+1]\nnums[j+1] = tmp\ncount += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums: inout [Int]) -> Int {\nvar count = 0 // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0 ..< i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\ncount += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums) {\nlet count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums: number[]): number {\nlet count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(List<int> nums) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (var i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (var j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfn bubble_sort(nums: &mut [i32]) -> i32 {\nlet mut count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\ncount\n}\n
        time_complexity.c
        /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int *nums, int n) {\nint count = 0; // \u8ba1\u6570\u5668\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = n - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\nfn bubbleSort(nums: []i32) i32 {\nvar count: i32 = 0;  // \u8ba1\u6570\u5668 \n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: i32 = @as(i32, @intCast(nums.len)) - 1;\nwhile (i > 0) : (i -= 1) {\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\ncount += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n}\n}\n}\nreturn count;\n}\n
        "},{"location":"chapter_computational_complexity/time_complexity/#4-o2n","title":"4. \u00a0 \u6307\u6570\u9636 \\(O(2^n)\\)","text":"

        \u751f\u7269\u5b66\u7684\u201c\u7ec6\u80de\u5206\u88c2\u201d\u662f\u6307\u6570\u9636\u589e\u957f\u7684\u5178\u578b\u4f8b\u5b50\uff1a\u521d\u59cb\u72b6\u6001\u4e3a \\(1\\) \u4e2a\u7ec6\u80de\uff0c\u5206\u88c2\u4e00\u8f6e\u540e\u53d8\u4e3a \\(2\\) \u4e2a\uff0c\u5206\u88c2\u4e24\u8f6e\u540e\u53d8\u4e3a \\(4\\) \u4e2a\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u5206\u88c2 \\(n\\) \u8f6e\u540e\u6709 \\(2^n\\) \u4e2a\u7ec6\u80de\u3002

        \u56fe 2-11 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6a21\u62df\u4e86\u7ec6\u80de\u5206\u88c2\u7684\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def exponential(n: int) -> int:\n\"\"\"\u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\ncount = 0\nbase = 1\n# \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in range(n):\nfor _ in range(base):\ncount += 1\nbase *= 2\n# count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n
        time_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.java
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.cs
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Exponential(int n) {\nint count = 0, bas = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < bas; j++) {\ncount++;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.go
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc exponential(n int) int {\ncount, base := 0, 1\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor i := 0; i < n; i++ {\nfor j := 0; j < base; j++ {\ncount++\n}\nbase *= 2\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n}\n
        time_complexity.swift
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc exponential(n: Int) -> Int {\nvar count = 0\nvar base = 1\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in 0 ..< n {\nfor _ in 0 ..< base {\ncount += 1\n}\nbase *= 2\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count\n}\n
        time_complexity.js
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n) {\nlet count = 0,\nbase = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.ts
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n: number): number {\nlet count = 0,\nbase = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (let i = 0; i < n; i++) {\nfor (let j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.dart
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0, base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (var i = 0; i < n; i++) {\nfor (var j = 0; j < base; j++) {\ncount++;\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.rs
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn exponential(n: i32) -> i32 {\nlet mut count = 0;\nlet mut base = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor _ in 0..n {\nfor _ in 0..base {\ncount += 1\n}\nbase *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\ncount\n}\n
        time_complexity.c
        /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\nint count = 0;\nint bas = 1;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nfor (int i = 0; i < n; i++) {\nfor (int j = 0; j < bas; j++) {\ncount++;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n
        time_complexity.zig
        // \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn exponential(n: i32) i32 {\nvar count: i32 = 0;\nvar bas: i32 = 1;\nvar i: i32 = 0;\n// \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\nwhile (i < n) : (i += 1) {\nvar j: i32 = 0;\nwhile (j < bas) : (j += 1) {\ncount += 1;\n}\nbas *= 2;\n}\n// count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\nreturn count;\n}\n

        \u56fe 2-11 \u00a0 \u6307\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u5728\u5b9e\u9645\u7b97\u6cd5\u4e2d\uff0c\u6307\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u9012\u5f52\u51fd\u6570\u4e2d\u3002\u4f8b\u5982\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u5176\u9012\u5f52\u5730\u4e00\u5206\u4e3a\u4e8c\uff0c\u7ecf\u8fc7 \\(n\\) \u6b21\u5206\u88c2\u540e\u505c\u6b62\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def exp_recur(n: int) -> int:\n\"\"\"\u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n == 1:\nreturn 1\nreturn exp_recur(n - 1) + exp_recur(n - 1) + 1\n
        time_complexity.cpp
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.java
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.cs
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint ExpRecur(int n) {\nif (n == 1) return 1;\nreturn ExpRecur(n - 1) + ExpRecur(n - 1) + 1;\n}\n
        time_complexity.go
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc expRecur(n int) int {\nif n == 1 {\nreturn 1\n}\nreturn expRecur(n-1) + expRecur(n-1) + 1\n}\n
        time_complexity.swift
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc expRecur(n: Int) -> Int {\nif n == 1 {\nreturn 1\n}\nreturn expRecur(n: n - 1) + expRecur(n: n - 1) + 1\n}\n
        time_complexity.js
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction expRecur(n) {\nif (n === 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.ts
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction expRecur(n: number): number {\nif (n === 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.dart
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.rs
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn exp_recur(n: i32) -> i32 {\nif n == 1 {\nreturn 1;\n}\nexp_recur(n - 1) + exp_recur(n - 1) + 1\n}\n
        time_complexity.c
        /* \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint expRecur(int n) {\nif (n == 1)\nreturn 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n
        time_complexity.zig
        // \u6307\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn expRecur(n: i32) i32 {\nif (n == 1) return 1;\nreturn expRecur(n - 1) + expRecur(n - 1) + 1;\n}\n

        \u6307\u6570\u9636\u589e\u957f\u975e\u5e38\u8fc5\u901f\uff0c\u5728\u7a77\u4e3e\u6cd5\uff08\u66b4\u529b\u641c\u7d22\u3001\u56de\u6eaf\u7b49\uff09\u4e2d\u6bd4\u8f83\u5e38\u89c1\u3002\u5bf9\u4e8e\u6570\u636e\u89c4\u6a21\u8f83\u5927\u7684\u95ee\u9898\uff0c\u6307\u6570\u9636\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u6216\u8d2a\u5fc3\u7b97\u6cd5\u7b49\u6765\u89e3\u51b3\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#5-olog-n","title":"5. \u00a0 \u5bf9\u6570\u9636 \\(O(\\log n)\\)","text":"

        \u4e0e\u6307\u6570\u9636\u76f8\u53cd\uff0c\u5bf9\u6570\u9636\u53cd\u6620\u4e86\u201c\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\u201d\u7684\u60c5\u51b5\u3002\u8bbe\u8f93\u5165\u6570\u636e\u5927\u5c0f\u4e3a \\(n\\) \uff0c\u7531\u4e8e\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\uff0c\u56e0\u6b64\u5faa\u73af\u6b21\u6570\u662f \\(\\log_2 n\\) \uff0c\u5373 \\(2^n\\) \u7684\u53cd\u51fd\u6570\u3002

        \u56fe 2-12 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6a21\u62df\u4e86\u201c\u6bcf\u8f6e\u7f29\u51cf\u5230\u4e00\u534a\u201d\u7684\u8fc7\u7a0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log_2 n)\\) \uff0c\u7b80\u8bb0\u4e3a \\(O(\\log n)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def logarithmic(n: float) -> int:\n\"\"\"\u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\ncount = 0\nwhile n > 1:\nn = n / 2\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn /= 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc logarithmic(n float64) int {\ncount := 0\nfor n > 1 {\nn = n / 2\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc logarithmic(n: Double) -> Int {\nvar count = 0\nvar n = n\nwhile n > 1 {\nn = n / 2\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n) {\nlet count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n: number): number {\nlet count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(num n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn logarithmic(mut n: f32) -> i32 {\nlet mut count = 0;\nwhile n > 1.0 {\nn = n / 2.0;\ncount += 1;\n}\ncount\n}\n
        time_complexity.c
        /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\nint count = 0;\nwhile (n > 1) {\nn = n / 2;\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn logarithmic(n: f32) i32 {\nvar count: i32 = 0;\nvar n_var = n;\nwhile (n_var > 1)\n{\nn_var = n_var / 2;\ncount +=1;\n}\nreturn count;\n}\n

        \u56fe 2-12 \u00a0 \u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4e0e\u6307\u6570\u9636\u7c7b\u4f3c\uff0c\u5bf9\u6570\u9636\u4e5f\u5e38\u51fa\u73b0\u4e8e\u9012\u5f52\u51fd\u6570\u4e2d\u3002\u4ee5\u4e0b\u4ee3\u7801\u5f62\u6210\u4e86\u4e00\u68f5\u9ad8\u5ea6\u4e3a \\(\\log_2 n\\) \u7684\u9012\u5f52\u6811\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def log_recur(n: float) -> int:\n\"\"\"\u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n <= 1:\nreturn 0\nreturn log_recur(n / 2) + 1\n
        time_complexity.cpp
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.java
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.cs
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint LogRecur(float n) {\nif (n <= 1) return 0;\nreturn LogRecur(n / 2) + 1;\n}\n
        time_complexity.go
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc logRecur(n float64) int {\nif n <= 1 {\nreturn 0\n}\nreturn logRecur(n/2) + 1\n}\n
        time_complexity.swift
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc logRecur(n: Double) -> Int {\nif n <= 1 {\nreturn 0\n}\nreturn logRecur(n: n / 2) + 1\n}\n
        time_complexity.js
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n) {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.ts
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n: number): number {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.dart
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(num n) {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.rs
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn log_recur(n: f32) -> i32 {\nif n <= 1.0 {\nreturn 0;\n}\nlog_recur(n / 2.0) + 1\n}\n
        time_complexity.c
        /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\nif (n <= 1)\nreturn 0;\nreturn logRecur(n / 2) + 1;\n}\n
        time_complexity.zig
        // \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn logRecur(n: f32) i32 {\nif (n <= 1) return 0;\nreturn logRecur(n / 2) + 1;\n}\n

        \u5bf9\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u7b97\u6cd5\u4e2d\uff0c\u4f53\u73b0\u4e86\u201c\u4e00\u5206\u4e3a\u591a\u201d\u548c\u201c\u5316\u7e41\u4e3a\u7b80\u201d\u7684\u7b97\u6cd5\u601d\u60f3\u3002\u5b83\u589e\u957f\u7f13\u6162\uff0c\u662f\u4ec5\u6b21\u4e8e\u5e38\u6570\u9636\u7684\u7406\u60f3\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        \\(O(\\log n)\\) \u7684\u5e95\u6570\u662f\u591a\u5c11\uff1f

        \u51c6\u786e\u6765\u8bf4\uff0c\u201c\u4e00\u5206\u4e3a \\(m\\)\u201d\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(\\log_m n)\\) \u3002\u800c\u901a\u8fc7\u5bf9\u6570\u6362\u5e95\u516c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5177\u6709\u4e0d\u540c\u5e95\u6570\u3001\u76f8\u7b49\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a

        \\[ O(\\log_m n) = O(\\log_k n / \\log_k m) = O(\\log_k n) \\]

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5e95\u6570 \\(m\\) \u53ef\u4ee5\u5728\u4e0d\u5f71\u54cd\u590d\u6742\u5ea6\u7684\u524d\u63d0\u4e0b\u8f6c\u6362\u3002\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f1a\u7701\u7565\u5e95\u6570 \\(m\\) \uff0c\u5c06\u5bf9\u6570\u9636\u76f4\u63a5\u8bb0\u4e3a \\(O(\\log n)\\) \u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#6-on-log-n","title":"6. \u00a0 \u7ebf\u6027\u5bf9\u6570\u9636 \\(O(n \\log n)\\)","text":"

        \u7ebf\u6027\u5bf9\u6570\u9636\u5e38\u51fa\u73b0\u4e8e\u5d4c\u5957\u5faa\u73af\u4e2d\uff0c\u4e24\u5c42\u5faa\u73af\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u522b\u4e3a \\(O(\\log n)\\) \u548c \\(O(n)\\) \u3002\u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def linear_log_recur(n: float) -> int:\n\"\"\"\u7ebf\u6027\u5bf9\u6570\u9636\"\"\"\nif n <= 1:\nreturn 1\ncount: int = linear_log_recur(n // 2) + linear_log_recur(n // 2)\nfor _ in range(n):\ncount += 1\nreturn count\n
        time_complexity.cpp
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint LinearLogRecur(float n) {\nif (n <= 1) return 1;\nint count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n float64) int {\nif n <= 1 {\nreturn 1\n}\ncount := linearLogRecur(n/2) + linearLogRecur(n/2)\nfor i := 0.0; i < n; i++ {\ncount++\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n: Double) -> Int {\nif n <= 1 {\nreturn 1\n}\nvar count = linearLogRecur(n: n / 2) + linearLogRecur(n: n / 2)\nfor _ in stride(from: 0, to: n, by: 1) {\ncount += 1\n}\nreturn count\n}\n
        time_complexity.js
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n) {\nif (n <= 1) return 1;\nlet count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (let i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n: number): number {\nif (n <= 1) return 1;\nlet count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (let i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(num n) {\nif (n <= 1) return 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (var i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfn linear_log_recur(n: f32) -> i32 {\nif n <= 1.0 {\nreturn 1;\n}\nlet mut count = linear_log_recur(n / 2.0) + linear_log_recur(n / 2.0);\nfor _ in 0 ..n as i32 {\ncount += 1;\n}\nreturn count\n}\n
        time_complexity.c
        /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\nif (n <= 1)\nreturn 1;\nint count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nfor (int i = 0; i < n; i++) {\ncount++;\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u7ebf\u6027\u5bf9\u6570\u9636\nfn linearLogRecur(n: f32) i32 {\nif (n <= 1) return 1;\nvar count: i32 = linearLogRecur(n / 2) + linearLogRecur(n / 2);\nvar i: f32 = 0;\nwhile (i < n) : (i += 1) {\ncount += 1;\n}\nreturn count;\n}\n

        \u56fe 2-13 \u5c55\u793a\u4e86\u7ebf\u6027\u5bf9\u6570\u9636\u7684\u751f\u6210\u65b9\u5f0f\u3002\u4e8c\u53c9\u6811\u7684\u6bcf\u4e00\u5c42\u7684\u64cd\u4f5c\u603b\u6570\u90fd\u4e3a \\(n\\) \uff0c\u6811\u5171\u6709 \\(\\log_2 n + 1\\) \u5c42\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u56fe 2-13 \u00a0 \u7ebf\u6027\u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u4e3b\u6d41\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u4e3a \\(O(n \\log n)\\) \uff0c\u4f8b\u5982\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u7b49\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#7-on","title":"7. \u00a0 \u9636\u4e58\u9636 \\(O(n!)\\)","text":"

        \u9636\u4e58\u9636\u5bf9\u5e94\u6570\u5b66\u4e0a\u7684\u201c\u5168\u6392\u5217\u201d\u95ee\u9898\u3002\u7ed9\u5b9a \\(n\\) \u4e2a\u4e92\u4e0d\u91cd\u590d\u7684\u5143\u7d20\uff0c\u6c42\u5176\u6240\u6709\u53ef\u80fd\u7684\u6392\u5217\u65b9\u6848\uff0c\u65b9\u6848\u6570\u91cf\u4e3a\uff1a

        \\[ n! = n \\times (n - 1) \\times (n - 2) \\times \\dots \\times 2 \\times 1 \\]

        \u9636\u4e58\u901a\u5e38\u4f7f\u7528\u9012\u5f52\u5b9e\u73b0\u3002\u5982\u56fe 2-14 \u548c\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u7b2c\u4e00\u5c42\u5206\u88c2\u51fa \\(n\\) \u4e2a\uff0c\u7b2c\u4e8c\u5c42\u5206\u88c2\u51fa \\(n - 1\\) \u4e2a\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u7b2c \\(n\\) \u5c42\u65f6\u505c\u6b62\u5206\u88c2\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
        def factorial_recur(n: int) -> int:\n\"\"\"\u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\"\"\"\nif n == 0:\nreturn 1\ncount = 0\n# \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in range(n):\ncount += factorial_recur(n - 1)\nreturn count\n
        time_complexity.cpp
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.java
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.cs
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint FactorialRecur(int n) {\nif (n == 0) return 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (int i = 0; i < n; i++) {\ncount += FactorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.go
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n int) int {\nif n == 0 {\nreturn 1\n}\ncount := 0\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor i := 0; i < n; i++ {\ncount += factorialRecur(n - 1)\n}\nreturn count\n}\n
        time_complexity.swift
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n: Int) -> Int {\nif n == 0 {\nreturn 1\n}\nvar count = 0\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in 0 ..< n {\ncount += factorialRecur(n: n - 1)\n}\nreturn count\n}\n
        time_complexity.js
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n) {\nif (n === 0) return 1;\nlet count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (let i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.ts
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n: number): number {\nif (n === 0) return 1;\nlet count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (let i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.dart
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0) return 1;\nint count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor (var i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.rs
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn factorial_recur(n: i32) -> i32 {\nif n == 0 {\nreturn 1;\n}\nlet mut count = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nfor _ in 0..n {\ncount += factorial_recur(n - 1);\n}\ncount\n}\n
        time_complexity.c
        /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\nif (n == 0)\nreturn 1;\nint count = 0;\nfor (int i = 0; i < n; i++) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n
        time_complexity.zig
        // \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn factorialRecur(n: i32) i32 {\nif (n == 0) return 1;\nvar count: i32 = 0;\nvar i: i32 = 0;\n// \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\nwhile (i < n) : (i += 1) {\ncount += factorialRecur(n - 1);\n}\nreturn count;\n}\n

        \u56fe 2-14 \u00a0 \u9636\u4e58\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6

        \u8bf7\u6ce8\u610f\uff0c\u56e0\u4e3a\u5f53 \\(n \\geq 4\\) \u65f6\u6052\u6709 \\(n! > 2^n\\) \uff0c\u6240\u4ee5\u9636\u4e58\u9636\u6bd4\u6307\u6570\u9636\u589e\u957f\u5f97\u66f4\u5feb\uff0c\u5728 \\(n\\) \u8f83\u5927\u65f6\u4e5f\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\u3002

        "},{"location":"chapter_computational_complexity/time_complexity/#235","title":"2.3.5 \u00a0 \u6700\u5dee\u3001\u6700\u4f73\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6","text":"

        \u7b97\u6cd5\u7684\u65f6\u95f4\u6548\u7387\u5f80\u5f80\u4e0d\u662f\u56fa\u5b9a\u7684\uff0c\u800c\u662f\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5206\u5e03\u6709\u5173\u3002\u5047\u8bbe\u8f93\u5165\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d nums \u7531\u4ece \\(1\\) \u81f3 \\(n\\) \u7684\u6570\u5b57\u7ec4\u6210\uff0c\u6bcf\u4e2a\u6570\u5b57\u53ea\u51fa\u73b0\u4e00\u6b21\uff1b\u4f46\u5143\u7d20\u987a\u5e8f\u662f\u968f\u673a\u6253\u4e71\u7684\uff0c\u4efb\u52a1\u76ee\u6807\u662f\u8fd4\u56de\u5143\u7d20 \\(1\\) \u7684\u7d22\u5f15\u3002\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4ee5\u4e0b\u7ed3\u8bba\u3002

        • \u5f53 nums = [?, ?, ..., 1] \uff0c\u5373\u5f53\u672b\u5c3e\u5143\u7d20\u662f \\(1\\) \u65f6\uff0c\u9700\u8981\u5b8c\u6574\u904d\u5386\u6570\u7ec4\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002
        • \u5f53 nums = [1, ?, ?, ...] \uff0c\u5373\u5f53\u9996\u4e2a\u5143\u7d20\u4e3a \\(1\\) \u65f6\uff0c\u65e0\u8bba\u6570\u7ec4\u591a\u957f\u90fd\u4e0d\u9700\u8981\u7ee7\u7eed\u904d\u5386\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(\\Omega(1)\\) \u3002

        \u201c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u201d\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0a\u754c\uff0c\u4f7f\u7528\u5927 \\(O\\) \u8bb0\u53f7\u8868\u793a\u3002\u76f8\u5e94\u5730\uff0c\u201c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u201d\u5bf9\u5e94\u51fd\u6570\u6e10\u8fd1\u4e0b\u754c\uff0c\u7528 \\(\\Omega\\) \u8bb0\u53f7\u8868\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig worst_best_time_complexity.py
        def random_numbers(n: int) -> list[int]:\n\"\"\"\u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a: 1, 2, ..., n \uff0c\u987a\u5e8f\u88ab\u6253\u4e71\"\"\"\n# \u751f\u6210\u6570\u7ec4 nums =: 1, 2, 3, ..., n\nnums = [i for i in range(1, n + 1)]\n# \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nrandom.shuffle(nums)\nreturn nums\ndef find_one(nums: list[int]) -> int:\n\"\"\"\u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\"\"\"\nfor i in range(len(nums)):\n# \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n# \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1:\nreturn i\nreturn -1\n
        worst_best_time_complexity.cpp
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nvector<int> randomNumbers(int n) {\nvector<int> nums(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u4f7f\u7528\u7cfb\u7edf\u65f6\u95f4\u751f\u6210\u968f\u673a\u79cd\u5b50\nunsigned seed = chrono::system_clock::now().time_since_epoch().count();\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nshuffle(nums.begin(), nums.end(), default_random_engine(seed));\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(vector<int> &nums) {\nfor (int i = 0; i < nums.size(); i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.java
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint[] randomNumbers(int n) {\nInteger[] nums = new Integer[n];\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nCollections.shuffle(Arrays.asList(nums));\n// Integer[] -> int[]\nint[] res = new int[n];\nfor (int i = 0; i < n; i++) {\nres[i] = nums[i];\n}\nreturn res;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int[] nums) {\nfor (int i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.cs
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint[] RandomNumbers(int n) {\nint[] nums = new int[n];\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (int i = 0; i < nums.Length; i++) {\nint index = new Random().Next(i, nums.Length);\n(nums[i], nums[index]) = (nums[index], nums[i]);\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint FindOne(int[] nums) {\nfor (int i = 0; i < nums.Length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.go
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunc randomNumbers(n int) []int {\nnums := make([]int, n)\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor i := 0; i < n; i++ {\nnums[i] = i + 1\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nrand.Shuffle(len(nums), func(i, j int) {\nnums[i], nums[j] = nums[j], nums[i]\n})\nreturn nums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums []int) int {\nfor i := 0; i < len(nums); i++ {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn i\n}\n}\nreturn -1\n}\n
        worst_best_time_complexity.swift
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunc randomNumbers(n: Int) -> [Int] {\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nvar nums = Array(1 ... n)\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle()\nreturn nums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums: [Int]) -> Int {\nfor i in nums.indices {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn i\n}\n}\nreturn -1\n}\n
        worst_best_time_complexity.js
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunction randomNumbers(n) {\nconst nums = Array(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (let i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (let i = 0; i < n; i++) {\nconst r = Math.floor(Math.random() * (i + 1));\nconst temp = nums[i];\nnums[i] = nums[r];\nnums[r] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums) {\nfor (let i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] === 1) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        worst_best_time_complexity.ts
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfunction randomNumbers(n: number): number[] {\nconst nums = Array(n);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (let i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (let i = 0; i < n; i++) {\nconst r = Math.floor(Math.random() * (i + 1));\nconst temp = nums[i];\nnums[i] = nums[r];\nnums[r] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums: number[]): number {\nfor (let i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] === 1) {\nreturn i;\n}\n}\nreturn -1;\n}\n
        worst_best_time_complexity.dart
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nList<int> randomNumbers(int n) {\nfinal nums = List.filled(n, 0);\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (var i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle();\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(List<int> nums) {\nfor (var i = 0; i < nums.length; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1) return i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.rs
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nfn random_numbers(n: i32) -> Vec<i32> {\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nlet mut nums = (1..=n).collect::<Vec<i32>>();\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nnums.shuffle(&mut thread_rng());\nnums\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfn find_one(nums: &[i32]) -> Option<usize> {\nfor i in 0..nums.len() {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif nums[i] == 1 {\nreturn Some(i);\n}\n}\nNone\n}\n
        worst_best_time_complexity.c
        /* \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71 */\nint *randomNumbers(int n) {\n// \u5206\u914d\u5806\u533a\u5185\u5b58\uff08\u521b\u5efa\u4e00\u7ef4\u53ef\u53d8\u957f\u6570\u7ec4\uff1a\u6570\u7ec4\u4e2d\u5143\u7d20\u6570\u91cf\u4e3a n \uff0c\u5143\u7d20\u7c7b\u578b\u4e3a int \uff09\nint *nums = (int *)malloc(n * sizeof(int));\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (int i = 0; i < n; i++) {\nnums[i] = i + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nfor (int i = n - 1; i > 0; i--) {\nint j = rand() % (i + 1);\nint temp = nums[i];\nnums[i] = nums[j];\nnums[j] = temp;\n}\nreturn nums;\n}\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int *nums, int n) {\nfor (int i = 0; i < n; i++) {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (nums[i] == 1)\nreturn i;\n}\nreturn -1;\n}\n
        worst_best_time_complexity.zig
        // \u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5143\u7d20\u4e3a { 1, 2, ..., n }\uff0c\u987a\u5e8f\u88ab\u6253\u4e71\nfn randomNumbers(comptime n: usize) [n]i32 {\nvar nums: [n]i32 = undefined;\n// \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\nfor (&nums, 0..) |*num, i| {\nnum.* = @as(i32, @intCast(i)) + 1;\n}\n// \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\nconst rand = std.crypto.random;\nrand.shuffle(i32, &nums);\nreturn nums;\n}\n// \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\nfn findOne(nums: []i32) i32 {\nfor (nums, 0..) |num, i| {\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5934\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\n// \u5f53\u5143\u7d20 1 \u5728\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u8fbe\u5230\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\nif (num == 1) return @intCast(i);\n}\nreturn -1;\n}\n

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6211\u4eec\u5728\u5b9e\u9645\u4e2d\u5f88\u5c11\u4f7f\u7528\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u56e0\u4e3a\u901a\u5e38\u53ea\u6709\u5728\u5f88\u5c0f\u6982\u7387\u4e0b\u624d\u80fd\u8fbe\u5230\uff0c\u53ef\u80fd\u4f1a\u5e26\u6765\u4e00\u5b9a\u7684\u8bef\u5bfc\u6027\u3002\u800c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u66f4\u4e3a\u5b9e\u7528\uff0c\u56e0\u4e3a\u5b83\u7ed9\u51fa\u4e86\u4e00\u4e2a\u6548\u7387\u5b89\u5168\u503c\uff0c\u8ba9\u6211\u4eec\u53ef\u4ee5\u653e\u5fc3\u5730\u4f7f\u7528\u7b97\u6cd5\u3002

        \u4ece\u4e0a\u8ff0\u793a\u4f8b\u53ef\u4ee5\u770b\u51fa\uff0c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u53ea\u51fa\u73b0\u4e8e\u201c\u7279\u6b8a\u7684\u6570\u636e\u5206\u5e03\u201d\uff0c\u8fd9\u4e9b\u60c5\u51b5\u7684\u51fa\u73b0\u6982\u7387\u53ef\u80fd\u5f88\u5c0f\uff0c\u5e76\u4e0d\u80fd\u771f\u5b9e\u5730\u53cd\u6620\u7b97\u6cd5\u8fd0\u884c\u6548\u7387\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f53\u73b0\u7b97\u6cd5\u5728\u968f\u673a\u8f93\u5165\u6570\u636e\u4e0b\u7684\u8fd0\u884c\u6548\u7387\uff0c\u7528 \\(\\Theta\\) \u8bb0\u53f7\u6765\u8868\u793a\u3002

        \u5bf9\u4e8e\u90e8\u5206\u7b97\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u63a8\u7b97\u51fa\u968f\u673a\u6570\u636e\u5206\u5e03\u4e0b\u7684\u5e73\u5747\u60c5\u51b5\u3002\u6bd4\u5982\u4e0a\u8ff0\u793a\u4f8b\uff0c\u7531\u4e8e\u8f93\u5165\u6570\u7ec4\u662f\u88ab\u6253\u4e71\u7684\uff0c\u56e0\u6b64\u5143\u7d20 \\(1\\) \u51fa\u73b0\u5728\u4efb\u610f\u7d22\u5f15\u7684\u6982\u7387\u90fd\u662f\u76f8\u7b49\u7684\uff0c\u90a3\u4e48\u7b97\u6cd5\u7684\u5e73\u5747\u5faa\u73af\u6b21\u6570\u5c31\u662f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a \\(n / 2\\) \uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(\\Theta(n / 2) = \\Theta(n)\\) \u3002

        \u4f46\u5bf9\u4e8e\u8f83\u4e3a\u590d\u6742\u7684\u7b97\u6cd5\uff0c\u8ba1\u7b97\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5f80\u5f80\u6bd4\u8f83\u56f0\u96be\uff0c\u56e0\u4e3a\u5f88\u96be\u5206\u6790\u51fa\u5728\u6570\u636e\u5206\u5e03\u4e0b\u7684\u6574\u4f53\u6570\u5b66\u671f\u671b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4f5c\u4e3a\u7b97\u6cd5\u6548\u7387\u7684\u8bc4\u5224\u6807\u51c6\u3002

        \u4e3a\u4ec0\u4e48\u5f88\u5c11\u770b\u5230 \\(\\Theta\\) \u7b26\u53f7\uff1f

        \u53ef\u80fd\u7531\u4e8e \\(O\\) \u7b26\u53f7\u8fc7\u4e8e\u6717\u6717\u4e0a\u53e3\uff0c\u56e0\u6b64\u6211\u4eec\u5e38\u5e38\u4f7f\u7528\u5b83\u6765\u8868\u793a\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u4f46\u4ece\u4e25\u683c\u610f\u4e49\u4e0a\u8bb2\uff0c\u8fd9\u79cd\u505a\u6cd5\u5e76\u4e0d\u89c4\u8303\u3002\u5728\u672c\u4e66\u548c\u5176\u4ed6\u8d44\u6599\u4e2d\uff0c\u82e5\u9047\u5230\u7c7b\u4f3c\u201c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u201d\u7684\u8868\u8ff0\uff0c\u8bf7\u5c06\u5176\u76f4\u63a5\u7406\u89e3\u4e3a \\(\\Theta(n)\\) \u3002

        "},{"location":"chapter_data_structure/","title":"\u7b2c 3 \u7ae0 \u00a0 \u6570\u636e\u7ed3\u6784","text":"

        Abstract

        \u6570\u636e\u7ed3\u6784\u5982\u540c\u4e00\u526f\u7a33\u56fa\u800c\u591a\u6837\u7684\u6846\u67b6\u3002

        \u5b83\u4e3a\u6570\u636e\u7684\u6709\u5e8f\u7ec4\u7ec7\u63d0\u4f9b\u4e86\u84dd\u56fe\uff0c\u7b97\u6cd5\u5f97\u4ee5\u5728\u6b64\u57fa\u7840\u4e0a\u751f\u52a8\u8d77\u6765\u3002

        "},{"location":"chapter_data_structure/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 3.1 \u00a0 \u6570\u636e\u7ed3\u6784\u5206\u7c7b
        • 3.2 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b
        • 3.3 \u00a0 \u6570\u5b57\u7f16\u7801 *
        • 3.4 \u00a0 \u5b57\u7b26\u7f16\u7801 *
        • 3.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_data_structure/basic_data_types/","title":"3.2 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b","text":"

        \u5f53\u8c08\u53ca\u8ba1\u7b97\u673a\u4e2d\u7684\u6570\u636e\u65f6\uff0c\u6211\u4eec\u4f1a\u60f3\u5230\u6587\u672c\u3001\u56fe\u7247\u3001\u89c6\u9891\u3001\u8bed\u97f3\u30013D \u6a21\u578b\u7b49\u5404\u79cd\u5f62\u5f0f\u3002\u5c3d\u7ba1\u8fd9\u4e9b\u6570\u636e\u7684\u7ec4\u7ec7\u5f62\u5f0f\u5404\u5f02\uff0c\u4f46\u5b83\u4eec\u90fd\u7531\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6784\u6210\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u662f CPU \u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u8fd0\u7b97\u7684\u7c7b\u578b\uff0c\u5728\u7b97\u6cd5\u4e2d\u76f4\u63a5\u88ab\u4f7f\u7528\uff0c\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002

        • \u6574\u6570\u7c7b\u578b byte\u3001short\u3001int\u3001long \u3002
        • \u6d6e\u70b9\u6570\u7c7b\u578b float\u3001double \uff0c\u7528\u4e8e\u8868\u793a\u5c0f\u6570\u3002
        • \u5b57\u7b26\u7c7b\u578b char \uff0c\u7528\u4e8e\u8868\u793a\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u6bcd\u3001\u6807\u70b9\u7b26\u53f7\u751a\u81f3\u8868\u60c5\u7b26\u53f7\u7b49\u3002
        • \u5e03\u5c14\u7c7b\u578b bool \uff0c\u7528\u4e8e\u8868\u793a\u201c\u662f\u201d\u4e0e\u201c\u5426\u201d\u5224\u65ad\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4ee5\u4e8c\u8fdb\u5236\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u3002\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5373\u4e3a \\(1\\) \u6bd4\u7279\u3002\u5728\u7edd\u5927\u591a\u6570\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\\(1\\) \u5b57\u8282\uff08byte\uff09\u7531 \\(8\\) \u6bd4\u7279\uff08bit\uff09\u7ec4\u6210\u3002

        \u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u53d6\u51b3\u4e8e\u5176\u5360\u7528\u7684\u7a7a\u95f4\u5927\u5c0f\u3002\u4e0b\u9762\u4ee5 Java \u4e3a\u4f8b\u3002

        • \u6574\u6570\u7c7b\u578b byte \u5360\u7528 \\(1\\) byte = \\(8\\) bits \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{8}\\) \u4e2a\u6570\u5b57\u3002
        • \u6574\u6570\u7c7b\u578b int \u5360\u7528 \\(4\\) bytes = \\(32\\) bits \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{32}\\) \u4e2a\u6570\u5b57\u3002

        \u8868 3-1 \u5217\u4e3e\u4e86 Java \u4e2d\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5360\u7528\u7a7a\u95f4\u3001\u53d6\u503c\u8303\u56f4\u548c\u9ed8\u8ba4\u503c\u3002\u6b64\u8868\u683c\u65e0\u987b\u6b7b\u8bb0\u786c\u80cc\uff0c\u5927\u81f4\u7406\u89e3\u5373\u53ef\uff0c\u9700\u8981\u65f6\u53ef\u4ee5\u901a\u8fc7\u67e5\u8868\u6765\u56de\u5fc6\u3002

        \u8868 3-1 \u00a0 \u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5360\u7528\u7a7a\u95f4\u548c\u53d6\u503c\u8303\u56f4

        \u7c7b\u578b \u7b26\u53f7 \u5360\u7528\u7a7a\u95f4 \u6700\u5c0f\u503c \u6700\u5927\u503c \u9ed8\u8ba4\u503c \u6574\u6570 byte 1 byte \\(-2^7\\) (\\(-128\\)) \\(2^7 - 1\\) (\\(127\\)) \\(0\\) short 2 bytes \\(-2^{15}\\) \\(2^{15} - 1\\) \\(0\\) int 4 bytes \\(-2^{31}\\) \\(2^{31} - 1\\) \\(0\\) long 8 bytes \\(-2^{63}\\) \\(2^{63} - 1\\) \\(0\\) \u6d6e\u70b9\u6570 float 4 bytes \\(1.175 \\times 10^{-38}\\) \\(3.403 \\times 10^{38}\\) \\(0.0\\text{f}\\) double 8 bytes \\(2.225 \\times 10^{-308}\\) \\(1.798 \\times 10^{308}\\) \\(0.0\\) \u5b57\u7b26 char 2 bytes \\(0\\) \\(2^{16} - 1\\) \\(0\\) \u5e03\u5c14 bool 1 byte \\(\\text{false}\\) \\(\\text{true}\\) \\(\\text{false}\\)

        \u8bf7\u6ce8\u610f\uff0c\u8868 3-1 \u9488\u5bf9\u7684\u662f Java \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u60c5\u51b5\u3002\u6bcf\u79cd\u7f16\u7a0b\u8bed\u8a00\u6709\u5404\u81ea\u7684\u6570\u636e\u7c7b\u578b\u5b9a\u4e49\uff0c\u5b83\u4eec\u7684\u5360\u7528\u7a7a\u95f4\u3001\u53d6\u503c\u8303\u56f4\u548c\u9ed8\u8ba4\u503c\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002

        • \u5728 Python \u4e2d\uff0c\u6574\u6570\u7c7b\u578b int \u53ef\u4ee5\u662f\u4efb\u610f\u5927\u5c0f\uff0c\u53ea\u53d7\u9650\u4e8e\u53ef\u7528\u5185\u5b58\uff1b\u6d6e\u70b9\u6570 float \u662f\u53cc\u7cbe\u5ea6 64 \u4f4d\uff1b\u6ca1\u6709 char \u7c7b\u578b\uff0c\u5355\u4e2a\u5b57\u7b26\u5b9e\u9645\u4e0a\u662f\u957f\u5ea6\u4e3a 1 \u7684\u5b57\u7b26\u4e32 str \u3002
        • C \u548c C++ \u672a\u660e\u786e\u89c4\u5b9a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5927\u5c0f\uff0c\u800c\u56e0\u5b9e\u73b0\u548c\u5e73\u53f0\u5404\u5f02\u3002\u8868 3-1 \u9075\u5faa LP64 \u6570\u636e\u6a21\u578b\uff0c\u5176\u7528\u4e8e\u5305\u62ec Linux \u548c macOS \u5728\u5185\u7684 Unix 64 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\u3002
        • \u5b57\u7b26 char \u7684\u5927\u5c0f\u5728 C \u548c C++ \u4e2d\u4e3a 1 \u5b57\u8282\uff0c\u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\u53d6\u51b3\u4e8e\u7279\u5b9a\u7684\u5b57\u7b26\u7f16\u7801\u65b9\u6cd5\uff0c\u8be6\u89c1\u201c\u5b57\u7b26\u7f16\u7801\u201d\u7ae0\u8282\u3002
        • \u5373\u4f7f\u8868\u793a\u5e03\u5c14\u91cf\u4ec5\u9700 1 \u4f4d\uff08\\(0\\) \u6216 \\(1\\)\uff09\uff0c\u5b83\u5728\u5185\u5b58\u4e2d\u901a\u5e38\u5b58\u50a8\u4e3a 1 \u5b57\u8282\u3002\u8fd9\u662f\u56e0\u4e3a\u73b0\u4ee3\u8ba1\u7b97\u673a CPU \u901a\u5e38\u5c06 1 \u5b57\u8282\u4f5c\u4e3a\u6700\u5c0f\u5bfb\u5740\u5185\u5b58\u5355\u5143\u3002

        \u90a3\u4e48\uff0c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e0e\u6570\u636e\u7ed3\u6784\u4e4b\u95f4\u6709\u4ec0\u4e48\u8054\u7cfb\u5462\uff1f\u6211\u4eec\u77e5\u9053\uff0c\u6570\u636e\u7ed3\u6784\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u4e0e\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\u3002\u8fd9\u53e5\u8bdd\u7684\u4e3b\u8bed\u662f\u201c\u7ed3\u6784\u201d\u800c\u975e\u201c\u6570\u636e\u201d\u3002

        \u5982\u679c\u60f3\u8868\u793a\u201c\u4e00\u6392\u6570\u5b57\u201d\uff0c\u6211\u4eec\u81ea\u7136\u4f1a\u60f3\u5230\u4f7f\u7528\u6570\u7ec4\u3002\u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u7684\u7ebf\u6027\u7ed3\u6784\u53ef\u4ee5\u8868\u793a\u6570\u5b57\u7684\u76f8\u90bb\u5173\u7cfb\u548c\u987a\u5e8f\u5173\u7cfb\uff0c\u4f46\u81f3\u4e8e\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u6574\u6570 int\u3001\u5c0f\u6570 float \u6216\u662f\u5b57\u7b26 char \uff0c\u5219\u4e0e\u201c\u6570\u636e\u7ed3\u6784\u201d\u65e0\u5173\u3002

        \u6362\u53e5\u8bdd\u8bf4\uff0c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u201c\u5185\u5bb9\u7c7b\u578b\u201d\uff0c\u800c\u6570\u636e\u7ed3\u6784\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u201c\u7ec4\u7ec7\u65b9\u5f0f\u201d\u3002\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6211\u4eec\u7528\u76f8\u540c\u7684\u6570\u636e\u7ed3\u6784\uff08\u6570\u7ec4\uff09\u6765\u5b58\u50a8\u4e0e\u8868\u793a\u4e0d\u540c\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec int\u3001float\u3001char\u3001bool \u7b49\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nnumbers: list[int] = [0] * 5\ndecimals: list[float] = [0.0] * 5\n# Python \u7684\u5b57\u7b26\u5b9e\u9645\u4e0a\u662f\u957f\u5ea6\u4e3a 1 \u7684\u5b57\u7b26\u4e32\ncharacters: list[str] = ['0'] * 5\nbools: list[bool] = [False] * 5\n# Python \u7684\u5217\u8868\u53ef\u4ee5\u81ea\u7531\u5b58\u50a8\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5bf9\u8c61\u5f15\u7528\ndata = [0, 0.0, 'a', False, ListNode(0)]\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint numbers[5];\nfloat decimals[5];\nchar characters[5];\nbool bools[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint[] numbers = new int[5];\nfloat[] decimals = new float[5];\nchar[] characters = new char[5];\nboolean[] bools = new boolean[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint[] numbers = new int[5];\nfloat[] decimals = new float[5];\nchar[] characters = new char[5];\nbool[] bools = new bool[5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nvar numbers = [5]int{}\nvar decimals = [5]float64{}\nvar characters = [5]byte{}\nvar bools = [5]bool{}\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nlet numbers = Array(repeating: Int(), count: 5)\nlet decimals = Array(repeating: Double(), count: 5)\nlet characters = Array(repeating: Character(\"a\"), count: 5)\nlet bools = Array(repeating: Bool(), count: 5)\n
        // JavaScript \u7684\u6570\u7ec4\u53ef\u4ee5\u81ea\u7531\u5b58\u50a8\u5404\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5bf9\u8c61\nconst array = [0, 0.0, 'a', false];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nconst numbers: number[] = [];\nconst characters: string[] = [];\nconst bools: boolean[] = [];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nList<int> numbers = List.filled(5, 0);\nList<double> decimals = List.filled(5, 0.0);\nList<String> characters = List.filled(5, 'a');\nList<bool> bools = List.filled(5, false);\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nlet numbers: Vec<i32> = vec![0; 5];\nlet decimals: Vec<f32> = vec![0.0, 5];\nlet characters: Vec<char> = vec!['0'; 5];\nlet bools: Vec<bool> = vec![false; 5];\n
        // \u4f7f\u7528\u591a\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u521d\u59cb\u5316\u6570\u7ec4\nint numbers[10];\nfloat decimals[10];\nchar characters[10];\nbool bools[10];\n
        \n
        "},{"location":"chapter_data_structure/character_encoding/","title":"3.4 \u00a0 \u5b57\u7b26\u7f16\u7801 *","text":"

        \u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u662f\u4ee5\u4e8c\u8fdb\u5236\u6570\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\uff0c\u5b57\u7b26 char \u4e5f\u4e0d\u4f8b\u5916\u3002\u4e3a\u4e86\u8868\u793a\u5b57\u7b26\uff0c\u6211\u4eec\u9700\u8981\u5efa\u7acb\u4e00\u5957\u201c\u5b57\u7b26\u96c6\u201d\uff0c\u89c4\u5b9a\u6bcf\u4e2a\u5b57\u7b26\u548c\u4e8c\u8fdb\u5236\u6570\u4e4b\u95f4\u7684\u4e00\u4e00\u5bf9\u5e94\u5173\u7cfb\u3002\u6709\u4e86\u5b57\u7b26\u96c6\u4e4b\u540e\uff0c\u8ba1\u7b97\u673a\u5c31\u53ef\u4ee5\u901a\u8fc7\u67e5\u8868\u5b8c\u6210\u4e8c\u8fdb\u5236\u6570\u5230\u5b57\u7b26\u7684\u8f6c\u6362\u3002

        "},{"location":"chapter_data_structure/character_encoding/#341-ascii","title":"3.4.1 \u00a0 ASCII \u5b57\u7b26\u96c6","text":"

        \u300cASCII \u7801\u300d\u662f\u6700\u65e9\u51fa\u73b0\u7684\u5b57\u7b26\u96c6\uff0c\u5176\u5168\u79f0\u4e3a American Standard Code for Information Interchange\uff08\u7f8e\u56fd\u6807\u51c6\u4fe1\u606f\u4ea4\u6362\u4ee3\u7801\uff09\u3002\u5b83\u4f7f\u7528 7 \u4f4d\u4e8c\u8fdb\u5236\u6570\uff08\u4e00\u4e2a\u5b57\u8282\u7684\u4f4e 7 \u4f4d\uff09\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6700\u591a\u80fd\u591f\u8868\u793a 128 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002\u5982\u56fe 3-6 \u6240\u793a\uff0cASCII \u7801\u5305\u62ec\u82f1\u6587\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u3001\u6570\u5b57 0 ~ 9\u3001\u4e00\u4e9b\u6807\u70b9\u7b26\u53f7\uff0c\u4ee5\u53ca\u4e00\u4e9b\u63a7\u5236\u5b57\u7b26\uff08\u5982\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\uff09\u3002

        \u56fe 3-6 \u00a0 ASCII \u7801

        \u7136\u800c\uff0cASCII \u7801\u4ec5\u80fd\u591f\u8868\u793a\u82f1\u6587\u3002\u968f\u7740\u8ba1\u7b97\u673a\u7684\u5168\u7403\u5316\uff0c\u8bde\u751f\u4e86\u4e00\u79cd\u80fd\u591f\u8868\u793a\u66f4\u591a\u8bed\u8a00\u7684\u5b57\u7b26\u96c6\u300cEASCII\u300d\u3002\u5b83\u5728 ASCII \u7684 7 \u4f4d\u57fa\u7840\u4e0a\u6269\u5c55\u5230 8 \u4f4d\uff0c\u80fd\u591f\u8868\u793a 256 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002

        \u5728\u4e16\u754c\u8303\u56f4\u5185\uff0c\u9646\u7eed\u51fa\u73b0\u4e86\u4e00\u6279\u9002\u7528\u4e8e\u4e0d\u540c\u5730\u533a\u7684 EASCII \u5b57\u7b26\u96c6\u3002\u8fd9\u4e9b\u5b57\u7b26\u96c6\u7684\u524d 128 \u4e2a\u5b57\u7b26\u7edf\u4e00\u4e3a ASCII \u7801\uff0c\u540e 128 \u4e2a\u5b57\u7b26\u5b9a\u4e49\u4e0d\u540c\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u8bed\u8a00\u7684\u9700\u6c42\u3002

        "},{"location":"chapter_data_structure/character_encoding/#342-gbk","title":"3.4.2 \u00a0 GBK \u5b57\u7b26\u96c6","text":"

        \u540e\u6765\u4eba\u4eec\u53d1\u73b0\uff0cEASCII \u7801\u4ecd\u7136\u65e0\u6cd5\u6ee1\u8db3\u8bb8\u591a\u8bed\u8a00\u7684\u5b57\u7b26\u6570\u91cf\u8981\u6c42\u3002\u6bd4\u5982\u6c49\u5b57\u6709\u8fd1\u5341\u4e07\u4e2a\uff0c\u5149\u65e5\u5e38\u4f7f\u7528\u7684\u5c31\u6709\u51e0\u5343\u4e2a\u3002\u4e2d\u56fd\u56fd\u5bb6\u6807\u51c6\u603b\u5c40\u4e8e 1980 \u5e74\u53d1\u5e03\u4e86\u300cGB2312\u300d\u5b57\u7b26\u96c6\uff0c\u5176\u6536\u5f55\u4e86 6763 \u4e2a\u6c49\u5b57\uff0c\u57fa\u672c\u6ee1\u8db3\u4e86\u6c49\u5b57\u7684\u8ba1\u7b97\u673a\u5904\u7406\u9700\u8981\u3002

        \u7136\u800c\uff0cGB2312 \u65e0\u6cd5\u5904\u7406\u90e8\u5206\u7f55\u89c1\u5b57\u548c\u7e41\u4f53\u5b57\u3002\u300cGBK\u300d\u5b57\u7b26\u96c6\u662f\u5728 GB2312 \u7684\u57fa\u7840\u4e0a\u6269\u5c55\u5f97\u5230\u7684\uff0c\u5b83\u5171\u6536\u5f55\u4e86 21886 \u4e2a\u6c49\u5b57\u3002\u5728 GBK \u7684\u7f16\u7801\u65b9\u6848\u4e2d\uff0cASCII \u5b57\u7b26\u4f7f\u7528\u4e00\u4e2a\u5b57\u8282\u8868\u793a\uff0c\u6c49\u5b57\u4f7f\u7528\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u3002

        "},{"location":"chapter_data_structure/character_encoding/#343-unicode","title":"3.4.3 \u00a0 Unicode \u5b57\u7b26\u96c6","text":"

        \u968f\u7740\u8ba1\u7b97\u673a\u6280\u672f\u7684\u84ec\u52c3\u53d1\u5c55\uff0c\u5b57\u7b26\u96c6\u4e0e\u7f16\u7801\u6807\u51c6\u767e\u82b1\u9f50\u653e\uff0c\u800c\u8fd9\u5e26\u6765\u4e86\u8bb8\u591a\u95ee\u9898\u3002\u4e00\u65b9\u9762\uff0c\u8fd9\u4e9b\u5b57\u7b26\u96c6\u4e00\u822c\u53ea\u5b9a\u4e49\u4e86\u7279\u5b9a\u8bed\u8a00\u7684\u5b57\u7b26\uff0c\u65e0\u6cd5\u5728\u591a\u8bed\u8a00\u73af\u5883\u4e0b\u6b63\u5e38\u5de5\u4f5c\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u540c\u4e00\u79cd\u8bed\u8a00\u5b58\u5728\u591a\u79cd\u5b57\u7b26\u96c6\u6807\u51c6\uff0c\u5982\u679c\u4e24\u53f0\u8ba1\u7b97\u673a\u4f7f\u7528\u7684\u662f\u4e0d\u540c\u7684\u7f16\u7801\u6807\u51c6\uff0c\u5219\u5728\u4fe1\u606f\u4f20\u9012\u65f6\u5c31\u4f1a\u51fa\u73b0\u4e71\u7801\u3002

        \u90a3\u4e2a\u65f6\u4ee3\u7684\u7814\u7a76\u4eba\u5458\u5c31\u5728\u60f3\uff1a\u5982\u679c\u63a8\u51fa\u4e00\u4e2a\u8db3\u591f\u5b8c\u6574\u7684\u5b57\u7b26\u96c6\uff0c\u5c06\u4e16\u754c\u8303\u56f4\u5185\u7684\u6240\u6709\u8bed\u8a00\u548c\u7b26\u53f7\u90fd\u6536\u5f55\u5176\u4e2d\uff0c\u4e0d\u5c31\u53ef\u4ee5\u89e3\u51b3\u8de8\u8bed\u8a00\u73af\u5883\u548c\u4e71\u7801\u95ee\u9898\u4e86\u5417\uff1f\u5728\u8fd9\u79cd\u60f3\u6cd5\u7684\u9a71\u52a8\u4e0b\uff0c\u4e00\u4e2a\u5927\u800c\u5168\u7684\u5b57\u7b26\u96c6 Unicode \u5e94\u8fd0\u800c\u751f\u3002

        \u300cUnicode\u300d\u7684\u4e2d\u6587\u540d\u79f0\u4e3a\u201c\u7edf\u4e00\u7801\u201d\uff0c\u7406\u8bba\u4e0a\u80fd\u5bb9\u7eb3 100 \u591a\u4e07\u4e2a\u5b57\u7b26\u3002\u5b83\u81f4\u529b\u4e8e\u5c06\u5168\u7403\u8303\u56f4\u5185\u7684\u5b57\u7b26\u7eb3\u5165\u7edf\u4e00\u7684\u5b57\u7b26\u96c6\u4e4b\u4e2d\uff0c\u63d0\u4f9b\u4e00\u79cd\u901a\u7528\u7684\u5b57\u7b26\u96c6\u6765\u5904\u7406\u548c\u663e\u793a\u5404\u79cd\u8bed\u8a00\u6587\u5b57\uff0c\u51cf\u5c11\u56e0\u4e3a\u7f16\u7801\u6807\u51c6\u4e0d\u540c\u800c\u4ea7\u751f\u7684\u4e71\u7801\u95ee\u9898\u3002

        \u81ea 1991 \u5e74\u53d1\u5e03\u4ee5\u6765\uff0cUnicode \u4e0d\u65ad\u6269\u5145\u65b0\u7684\u8bed\u8a00\u4e0e\u5b57\u7b26\u3002\u622a\u81f3 2022 \u5e74 9 \u6708\uff0cUnicode \u5df2\u7ecf\u5305\u542b 149186 \u4e2a\u5b57\u7b26\uff0c\u5305\u62ec\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u7b26\u3001\u7b26\u53f7\u751a\u81f3\u8868\u60c5\u7b26\u53f7\u7b49\u3002\u5728\u5e9e\u5927\u7684 Unicode \u5b57\u7b26\u96c6\u4e2d\uff0c\u5e38\u7528\u7684\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\uff0c\u6709\u4e9b\u751f\u50fb\u7684\u5b57\u7b26\u5360\u7528 3 \u5b57\u8282\u751a\u81f3 4 \u5b57\u8282\u3002

        Unicode \u662f\u4e00\u79cd\u901a\u7528\u5b57\u7b26\u96c6\uff0c\u672c\u8d28\u4e0a\u662f\u7ed9\u6bcf\u4e2a\u5b57\u7b26\u5206\u914d\u4e00\u4e2a\u7f16\u53f7\uff08\u79f0\u4e3a\u201c\u7801\u70b9\u201d\uff09\uff0c\u4f46\u5b83\u5e76\u6ca1\u6709\u89c4\u5b9a\u5728\u8ba1\u7b97\u673a\u4e2d\u5982\u4f55\u5b58\u50a8\u8fd9\u4e9b\u5b57\u7b26\u7801\u70b9\u3002\u6211\u4eec\u4e0d\u7981\u4f1a\u95ee\uff1a\u5f53\u591a\u79cd\u957f\u5ea6\u7684 Unicode \u7801\u70b9\u540c\u65f6\u51fa\u73b0\u5728\u4e00\u4e2a\u6587\u672c\u4e2d\u65f6\uff0c\u7cfb\u7edf\u5982\u4f55\u89e3\u6790\u5b57\u7b26\uff1f\u4f8b\u5982\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a 2 \u5b57\u8282\u7684\u7f16\u7801\uff0c\u7cfb\u7edf\u5982\u4f55\u786e\u8ba4\u5b83\u662f\u4e00\u4e2a 2 \u5b57\u8282\u7684\u5b57\u7b26\u8fd8\u662f\u4e24\u4e2a 1 \u5b57\u8282\u7684\u5b57\u7b26\uff1f

        \u5bf9\u4e8e\u4ee5\u4e0a\u95ee\u9898\uff0c\u4e00\u79cd\u76f4\u63a5\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u6240\u6709\u5b57\u7b26\u5b58\u50a8\u4e3a\u7b49\u957f\u7684\u7f16\u7801\u3002\u5982\u56fe 3-7 \u6240\u793a\uff0c\u201cHello\u201d\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 1 \u5b57\u8282\uff0c\u201c\u7b97\u6cd5\u201d\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9ad8\u4f4d\u586b 0 \u5c06\u201cHello \u7b97\u6cd5\u201d\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u7f16\u7801\u4e3a 2 \u5b57\u8282\u957f\u5ea6\u3002\u8fd9\u6837\u7cfb\u7edf\u5c31\u53ef\u4ee5\u6bcf\u9694 2 \u5b57\u8282\u89e3\u6790\u4e00\u4e2a\u5b57\u7b26\uff0c\u6062\u590d\u8fd9\u4e2a\u77ed\u8bed\u7684\u5185\u5bb9\u4e86\u3002

        \u56fe 3-7 \u00a0 Unicode \u7f16\u7801\u793a\u4f8b

        \u7136\u800c ASCII \u7801\u5df2\u7ecf\u5411\u6211\u4eec\u8bc1\u660e\uff0c\u7f16\u7801\u82f1\u6587\u53ea\u9700 1 \u5b57\u8282\u3002\u82e5\u91c7\u7528\u4e0a\u8ff0\u65b9\u6848\uff0c\u82f1\u6587\u6587\u672c\u5360\u7528\u7a7a\u95f4\u7684\u5927\u5c0f\u5c06\u4f1a\u662f ASCII \u7f16\u7801\u4e0b\u7684\u4e24\u500d\uff0c\u975e\u5e38\u6d6a\u8d39\u5185\u5b58\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u66f4\u52a0\u9ad8\u6548\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\u3002

        "},{"location":"chapter_data_structure/character_encoding/#344-utf-8","title":"3.4.4 \u00a0 UTF-8 \u7f16\u7801","text":"

        \u76ee\u524d\uff0cUTF-8 \u5df2\u6210\u4e3a\u56fd\u9645\u4e0a\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\u3002\u5b83\u662f\u4e00\u79cd\u53ef\u53d8\u957f\u5ea6\u7684\u7f16\u7801\uff0c\u4f7f\u7528 1 \u5230 4 \u5b57\u8282\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\uff0c\u6839\u636e\u5b57\u7b26\u7684\u590d\u6742\u6027\u800c\u53d8\u3002ASCII \u5b57\u7b26\u53ea\u9700 1 \u5b57\u8282\uff0c\u62c9\u4e01\u5b57\u6bcd\u548c\u5e0c\u814a\u5b57\u6bcd\u9700\u8981 2 \u5b57\u8282\uff0c\u5e38\u7528\u7684\u4e2d\u6587\u5b57\u7b26\u9700\u8981 3 \u5b57\u8282\uff0c\u5176\u4ed6\u7684\u4e00\u4e9b\u751f\u50fb\u5b57\u7b26\u9700\u8981 4 \u5b57\u8282\u3002

        UTF-8 \u7684\u7f16\u7801\u89c4\u5219\u5e76\u4e0d\u590d\u6742\uff0c\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\u3002

        • \u5bf9\u4e8e\u957f\u5ea6\u4e3a 1 \u5b57\u8282\u7684\u5b57\u7b26\uff0c\u5c06\u6700\u9ad8\u4f4d\u8bbe\u7f6e\u4e3a \\(0\\) \uff0c\u5176\u4f59 7 \u4f4d\u8bbe\u7f6e\u4e3a Unicode \u7801\u70b9\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cASCII \u5b57\u7b26\u5728 Unicode \u5b57\u7b26\u96c6\u4e2d\u5360\u636e\u4e86\u524d 128 \u4e2a\u7801\u70b9\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cUTF-8 \u7f16\u7801\u53ef\u4ee5\u5411\u4e0b\u517c\u5bb9 ASCII \u7801\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 UTF-8 \u6765\u89e3\u6790\u5e74\u4ee3\u4e45\u8fdc\u7684 ASCII \u7801\u6587\u672c\u3002
        • \u5bf9\u4e8e\u957f\u5ea6\u4e3a \\(n\\) \u5b57\u8282\u7684\u5b57\u7b26\uff08\u5176\u4e2d \\(n > 1\\)\uff09\uff0c\u5c06\u9996\u4e2a\u5b57\u8282\u7684\u9ad8 \\(n\\) \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(1\\) \uff0c\u7b2c \\(n + 1\\) \u4f4d\u8bbe\u7f6e\u4e3a \\(0\\) \uff1b\u4ece\u7b2c\u4e8c\u4e2a\u5b57\u8282\u5f00\u59cb\uff0c\u5c06\u6bcf\u4e2a\u5b57\u8282\u7684\u9ad8 2 \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(10\\) \uff1b\u5176\u4f59\u6240\u6709\u4f4d\u7528\u4e8e\u586b\u5145\u5b57\u7b26\u7684 Unicode \u7801\u70b9\u3002

        \u56fe 3-8 \u5c55\u793a\u4e86\u201cHello\u7b97\u6cd5\u201d\u5bf9\u5e94\u7684 UTF-8 \u7f16\u7801\u3002\u89c2\u5bdf\u53d1\u73b0\uff0c\u7531\u4e8e\u6700\u9ad8 \\(n\\) \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(1\\) \uff0c\u56e0\u6b64\u7cfb\u7edf\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6\u6700\u9ad8\u4f4d \\(1\\) \u7684\u4e2a\u6570\u6765\u89e3\u6790\u51fa\u5b57\u7b26\u7684\u957f\u5ea6\u4e3a \\(n\\) \u3002

        \u4f46\u4e3a\u4ec0\u4e48\u8981\u5c06\u5176\u4f59\u6240\u6709\u5b57\u8282\u7684\u9ad8 2 \u4f4d\u90fd\u8bbe\u7f6e\u4e3a \\(10\\) \u5462\uff1f\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e2a \\(10\\) \u80fd\u591f\u8d77\u5230\u6821\u9a8c\u7b26\u7684\u4f5c\u7528\u3002\u5047\u8bbe\u7cfb\u7edf\u4ece\u4e00\u4e2a\u9519\u8bef\u7684\u5b57\u8282\u5f00\u59cb\u89e3\u6790\u6587\u672c\uff0c\u5b57\u8282\u5934\u90e8\u7684 \\(10\\) \u80fd\u591f\u5e2e\u52a9\u7cfb\u7edf\u5feb\u901f\u5224\u65ad\u51fa\u5f02\u5e38\u3002

        \u4e4b\u6240\u4ee5\u5c06 \\(10\\) \u5f53\u4f5c\u6821\u9a8c\u7b26\uff0c\u662f\u56e0\u4e3a\u5728 UTF-8 \u7f16\u7801\u89c4\u5219\u4e0b\uff0c\u4e0d\u53ef\u80fd\u6709\u5b57\u7b26\u7684\u6700\u9ad8\u4e24\u4f4d\u662f \\(10\\) \u3002\u8fd9\u4e2a\u7ed3\u8bba\u53ef\u4ee5\u7528\u53cd\u8bc1\u6cd5\u6765\u8bc1\u660e\uff1a\u5047\u8bbe\u4e00\u4e2a\u5b57\u7b26\u7684\u6700\u9ad8\u4e24\u4f4d\u662f \\(10\\) \uff0c\u8bf4\u660e\u8be5\u5b57\u7b26\u7684\u957f\u5ea6\u4e3a \\(1\\) \uff0c\u5bf9\u5e94 ASCII \u7801\u3002\u800c ASCII \u7801\u7684\u6700\u9ad8\u4f4d\u5e94\u8be5\u662f \\(0\\) \uff0c\u4e0e\u5047\u8bbe\u77db\u76fe\u3002

        \u56fe 3-8 \u00a0 UTF-8 \u7f16\u7801\u793a\u4f8b

        \u9664\u4e86 UTF-8 \u4e4b\u5916\uff0c\u5e38\u89c1\u7684\u7f16\u7801\u65b9\u5f0f\u8fd8\u5305\u62ec\u4ee5\u4e0b\u4e24\u79cd\u3002

        • UTF-16 \u7f16\u7801\uff1a\u4f7f\u7528 2 \u6216 4 \u5b57\u8282\u6765\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002\u6240\u6709\u7684 ASCII \u5b57\u7b26\u548c\u5e38\u7528\u7684\u975e\u82f1\u6587\u5b57\u7b26\uff0c\u90fd\u7528 2 \u5b57\u8282\u8868\u793a\uff1b\u5c11\u6570\u5b57\u7b26\u9700\u8981\u7528\u5230 4 \u5b57\u8282\u8868\u793a\u3002\u5bf9\u4e8e 2 \u5b57\u8282\u7684\u5b57\u7b26\uff0cUTF-16 \u7f16\u7801\u4e0e Unicode \u7801\u70b9\u76f8\u7b49\u3002
        • UTF-32 \u7f16\u7801\uff1a\u6bcf\u4e2a\u5b57\u7b26\u90fd\u4f7f\u7528 4 \u5b57\u8282\u3002\u8fd9\u610f\u5473\u7740 UTF-32 \u6bd4 UTF-8 \u548c UTF-16 \u66f4\u5360\u7528\u7a7a\u95f4\uff0c\u7279\u522b\u662f\u5bf9\u4e8e ASCII \u5b57\u7b26\u5360\u6bd4\u8f83\u9ad8\u7684\u6587\u672c\u3002

        \u4ece\u5b58\u50a8\u7a7a\u95f4\u5360\u7528\u7684\u89d2\u5ea6\u770b\uff0c\u4f7f\u7528 UTF-8 \u8868\u793a\u82f1\u6587\u5b57\u7b26\u975e\u5e38\u9ad8\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9700 1 \u5b57\u8282\uff1b\u4f7f\u7528 UTF-16 \u7f16\u7801\u67d0\u4e9b\u975e\u82f1\u6587\u5b57\u7b26\uff08\u4f8b\u5982\u4e2d\u6587\uff09\u4f1a\u66f4\u52a0\u9ad8\u6548\uff0c\u56e0\u4e3a\u5b83\u4ec5\u9700 2 \u5b57\u8282\uff0c\u800c UTF-8 \u53ef\u80fd\u9700\u8981 3 \u5b57\u8282\u3002

        \u4ece\u517c\u5bb9\u6027\u7684\u89d2\u5ea6\u770b\uff0cUTF-8 \u7684\u901a\u7528\u6027\u6700\u4f73\uff0c\u8bb8\u591a\u5de5\u5177\u548c\u5e93\u4f18\u5148\u652f\u6301 UTF-8 \u3002

        "},{"location":"chapter_data_structure/character_encoding/#345","title":"3.4.5 \u00a0 \u7f16\u7a0b\u8bed\u8a00\u7684\u5b57\u7b26\u7f16\u7801","text":"

        \u5bf9\u4e8e\u4ee5\u5f80\u7684\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\uff0c\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u7684\u5b57\u7b26\u4e32\u90fd\u91c7\u7528 UTF-16 \u6216 UTF-32 \u8fd9\u7c7b\u7b49\u957f\u7684\u7f16\u7801\u3002\u5728\u7b49\u957f\u7f16\u7801\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u770b\u4f5c\u6570\u7ec4\u6765\u5904\u7406\uff0c\u8fd9\u79cd\u505a\u6cd5\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\u3002

        • \u968f\u673a\u8bbf\u95ee\uff1aUTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u8fdb\u884c\u968f\u673a\u8bbf\u95ee\u3002UTF-8 \u662f\u4e00\u79cd\u53d8\u957f\u7f16\u7801\uff0c\u8981\u60f3\u627e\u5230\u7b2c \\(i\\) \u4e2a\u5b57\u7b26\uff0c\u6211\u4eec\u9700\u8981\u4ece\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u5904\u904d\u5386\u5230\u7b2c \\(i\\) \u4e2a\u5b57\u7b26\uff0c\u8fd9\u9700\u8981 \\(O(n)\\) \u7684\u65f6\u95f4\u3002
        • \u5b57\u7b26\u8ba1\u6570\uff1a\u4e0e\u968f\u673a\u8bbf\u95ee\u7c7b\u4f3c\uff0c\u8ba1\u7b97 UTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e5f\u662f \\(O(1)\\) \u7684\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u8ba1\u7b97 UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u9700\u8981\u904d\u5386\u6574\u4e2a\u5b57\u7b26\u4e32\u3002
        • \u5b57\u7b26\u4e32\u64cd\u4f5c\uff1a\u5728 UTF-16 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4e0a\uff0c\u5f88\u591a\u5b57\u7b26\u4e32\u64cd\u4f5c\uff08\u5982\u5206\u5272\u3001\u8fde\u63a5\u3001\u63d2\u5165\u3001\u5220\u9664\u7b49\uff09\u66f4\u5bb9\u6613\u8fdb\u884c\u3002\u5728 UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u4e0a\uff0c\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u901a\u5e38\u9700\u8981\u989d\u5916\u7684\u8ba1\u7b97\uff0c\u4ee5\u786e\u4fdd\u4e0d\u4f1a\u4ea7\u751f\u65e0\u6548\u7684 UTF-8 \u7f16\u7801\u3002

        \u5b9e\u9645\u4e0a\uff0c\u7f16\u7a0b\u8bed\u8a00\u7684\u5b57\u7b26\u7f16\u7801\u65b9\u6848\u8bbe\u8ba1\u662f\u4e00\u4e2a\u5f88\u6709\u8da3\u7684\u8bdd\u9898\uff0c\u6d89\u53ca\u8bb8\u591a\u56e0\u7d20\u3002

        • Java \u7684 String \u7c7b\u578b\u4f7f\u7528 UTF-16 \u7f16\u7801\uff0c\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u5b57\u8282\u3002\u8fd9\u662f\u56e0\u4e3a Java \u8bed\u8a00\u8bbe\u8ba1\u4e4b\u521d\uff0c\u4eba\u4eec\u8ba4\u4e3a 16 \u4f4d\u8db3\u4ee5\u8868\u793a\u6240\u6709\u53ef\u80fd\u7684\u5b57\u7b26\u3002\u7136\u800c\uff0c\u8fd9\u662f\u4e00\u4e2a\u4e0d\u6b63\u786e\u7684\u5224\u65ad\u3002\u540e\u6765 Unicode \u89c4\u8303\u6269\u5c55\u5230\u4e86\u8d85\u8fc7 16 \u4f4d\uff0c\u6240\u4ee5 Java \u4e2d\u7684\u5b57\u7b26\u73b0\u5728\u53ef\u80fd\u7531\u4e00\u5bf9 16 \u4f4d\u7684\u503c\uff08\u79f0\u4e3a\u201c\u4ee3\u7406\u5bf9\u201d\uff09\u8868\u793a\u3002
        • JavaScript \u548c TypeScript \u7684\u5b57\u7b26\u4e32\u4f7f\u7528 UTF-16 \u7f16\u7801\u7684\u539f\u56e0\u4e0e Java \u7c7b\u4f3c\u3002\u5f53 1995 \u5e74 Netscape \u516c\u53f8\u9996\u6b21\u63a8\u51fa JavaScript \u8bed\u8a00\u65f6\uff0cUnicode \u8fd8\u5904\u4e8e\u53d1\u5c55\u65e9\u671f\uff0c\u90a3\u65f6\u5019\u4f7f\u7528 16 \u4f4d\u7684\u7f16\u7801\u5c31\u8db3\u4ee5\u8868\u793a\u6240\u6709\u7684 Unicode \u5b57\u7b26\u4e86\u3002
        • C# \u4f7f\u7528 UTF-16 \u7f16\u7801\uff0c\u4e3b\u8981\u662f\u56e0\u4e3a .NET \u5e73\u53f0\u662f\u7531 Microsoft \u8bbe\u8ba1\u7684\uff0c\u800c Microsoft \u7684\u5f88\u591a\u6280\u672f\uff08\u5305\u62ec Windows \u64cd\u4f5c\u7cfb\u7edf\uff09\u90fd\u5e7f\u6cdb\u4f7f\u7528 UTF-16 \u7f16\u7801\u3002

        \u7531\u4e8e\u4ee5\u4e0a\u7f16\u7a0b\u8bed\u8a00\u5bf9\u5b57\u7b26\u6570\u91cf\u7684\u4f4e\u4f30\uff0c\u5b83\u4eec\u4e0d\u5f97\u4e0d\u91c7\u53d6\u201c\u4ee3\u7406\u5bf9\u201d\u7684\u65b9\u5f0f\u6765\u8868\u793a\u8d85\u8fc7 16 \u4f4d\u957f\u5ea6\u7684 Unicode \u5b57\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u4e0d\u5f97\u5df2\u4e3a\u4e4b\u7684\u65e0\u5948\u4e4b\u4e3e\u3002\u4e00\u65b9\u9762\uff0c\u5305\u542b\u4ee3\u7406\u5bf9\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u4e00\u4e2a\u5b57\u7b26\u53ef\u80fd\u5360\u7528 2 \u5b57\u8282\u6216 4 \u5b57\u8282\uff0c\u4ece\u800c\u4e27\u5931\u4e86\u7b49\u957f\u7f16\u7801\u7684\u4f18\u52bf\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u5904\u7406\u4ee3\u7406\u5bf9\u9700\u8981\u589e\u52a0\u989d\u5916\u4ee3\u7801\uff0c\u8fd9\u63d0\u9ad8\u4e86\u7f16\u7a0b\u7684\u590d\u6742\u6027\u548c\u8c03\u8bd5\u96be\u5ea6\u3002

        \u51fa\u4e8e\u4ee5\u4e0a\u539f\u56e0\uff0c\u90e8\u5206\u7f16\u7a0b\u8bed\u8a00\u63d0\u51fa\u4e86\u4e00\u4e9b\u4e0d\u540c\u7684\u7f16\u7801\u65b9\u6848\u3002

        • Python \u4e2d\u7684 str \u4f7f\u7528 Unicode \u7f16\u7801\uff0c\u5e76\u91c7\u7528\u4e00\u79cd\u7075\u6d3b\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5b58\u50a8\u7684\u5b57\u7b26\u957f\u5ea6\u53d6\u51b3\u4e8e\u5b57\u7b26\u4e32\u4e2d\u6700\u5927\u7684 Unicode \u7801\u70b9\u3002\u82e5\u5b57\u7b26\u4e32\u4e2d\u5168\u90e8\u662f ASCII \u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 1 \u4e2a\u5b57\u8282\uff1b\u5982\u679c\u6709\u5b57\u7b26\u8d85\u51fa\u4e86 ASCII \u8303\u56f4\uff0c\u4f46\u5168\u90e8\u5728\u57fa\u672c\u591a\u8bed\u8a00\u5e73\u9762\uff08BMP\uff09\u5185\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 2 \u4e2a\u5b57\u8282\uff1b\u5982\u679c\u6709\u8d85\u51fa BMP \u7684\u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 4 \u4e2a\u5b57\u8282\u3002
        • Go \u8bed\u8a00\u7684 string \u7c7b\u578b\u5728\u5185\u90e8\u4f7f\u7528 UTF-8 \u7f16\u7801\u3002Go \u8bed\u8a00\u8fd8\u63d0\u4f9b\u4e86 rune \u7c7b\u578b\uff0c\u5b83\u7528\u4e8e\u8868\u793a\u5355\u4e2a Unicode \u7801\u70b9\u3002
        • Rust \u8bed\u8a00\u7684 str \u548c String \u7c7b\u578b\u5728\u5185\u90e8\u4f7f\u7528 UTF-8 \u7f16\u7801\u3002Rust \u4e5f\u63d0\u4f9b\u4e86 char \u7c7b\u578b\uff0c\u7528\u4e8e\u8868\u793a\u5355\u4e2a Unicode \u7801\u70b9\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ee5\u4e0a\u8ba8\u8bba\u7684\u90fd\u662f\u5b57\u7b26\u4e32\u5728\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u8fd9\u548c\u5b57\u7b26\u4e32\u5982\u4f55\u5728\u6587\u4ef6\u4e2d\u5b58\u50a8\u6216\u5728\u7f51\u7edc\u4e2d\u4f20\u8f93\u662f\u4e0d\u540c\u7684\u95ee\u9898\u3002\u5728\u6587\u4ef6\u5b58\u50a8\u6216\u7f51\u7edc\u4f20\u8f93\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u5b57\u7b26\u4e32\u7f16\u7801\u4e3a UTF-8 \u683c\u5f0f\uff0c\u4ee5\u8fbe\u5230\u6700\u4f18\u7684\u517c\u5bb9\u6027\u548c\u7a7a\u95f4\u6548\u7387\u3002

        "},{"location":"chapter_data_structure/classification_of_data_structure/","title":"3.1 \u00a0 \u6570\u636e\u7ed3\u6784\u5206\u7c7b","text":"

        \u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u5305\u62ec\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\uff0c\u5b83\u4eec\u53ef\u4ee5\u4ece\u201c\u903b\u8f91\u7ed3\u6784\u201d\u548c\u201c\u7269\u7406\u7ed3\u6784\u201d\u4e24\u4e2a\u7ef4\u5ea6\u8fdb\u884c\u5206\u7c7b\u3002

        "},{"location":"chapter_data_structure/classification_of_data_structure/#311","title":"3.1.1 \u00a0 \u903b\u8f91\u7ed3\u6784\uff1a\u7ebf\u6027\u4e0e\u975e\u7ebf\u6027","text":"

        \u903b\u8f91\u7ed3\u6784\u63ed\u793a\u4e86\u6570\u636e\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\u3002\u5728\u6570\u7ec4\u548c\u94fe\u8868\u4e2d\uff0c\u6570\u636e\u6309\u7167\u4e00\u5b9a\u987a\u5e8f\u6392\u5217\uff0c\u4f53\u73b0\u4e86\u6570\u636e\u4e4b\u95f4\u7684\u7ebf\u6027\u5173\u7cfb\uff1b\u800c\u5728\u6811\u4e2d\uff0c\u6570\u636e\u4ece\u9876\u90e8\u5411\u4e0b\u6309\u5c42\u6b21\u6392\u5217\uff0c\u8868\u73b0\u51fa\u201c\u7956\u5148\u201d\u4e0e\u201c\u540e\u4ee3\u201d\u4e4b\u95f4\u7684\u6d3e\u751f\u5173\u7cfb\uff1b\u56fe\u5219\u7531\u8282\u70b9\u548c\u8fb9\u6784\u6210\uff0c\u53cd\u6620\u4e86\u590d\u6742\u7684\u7f51\u7edc\u5173\u7cfb\u3002

        \u5982\u56fe 3-1 \u6240\u793a\uff0c\u903b\u8f91\u7ed3\u6784\u53ef\u5206\u4e3a\u201c\u7ebf\u6027\u201d\u548c\u201c\u975e\u7ebf\u6027\u201d\u4e24\u5927\u7c7b\u3002\u7ebf\u6027\u7ed3\u6784\u6bd4\u8f83\u76f4\u89c2\uff0c\u6307\u6570\u636e\u5728\u903b\u8f91\u5173\u7cfb\u4e0a\u5448\u7ebf\u6027\u6392\u5217\uff1b\u975e\u7ebf\u6027\u7ed3\u6784\u5219\u76f8\u53cd\uff0c\u5448\u975e\u7ebf\u6027\u6392\u5217\u3002

        • \u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3002
        • \u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1a\u6811\u3001\u5806\u3001\u56fe\u3001\u54c8\u5e0c\u8868\u3002

        \u56fe 3-1 \u00a0 \u7ebf\u6027\u6570\u636e\u7ed3\u6784\u4e0e\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784

        \u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5212\u5206\u4e3a\u6811\u5f62\u7ed3\u6784\u548c\u7f51\u72b6\u7ed3\u6784\u3002

        • \u7ebf\u6027\u7ed3\u6784\uff1a\u6570\u7ec4\u3001\u94fe\u8868\u3001\u961f\u5217\u3001\u6808\u3001\u54c8\u5e0c\u8868\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u4e00\u5bf9\u4e00\u7684\u987a\u5e8f\u5173\u7cfb\u3002
        • \u6811\u5f62\u7ed3\u6784\uff1a\u6811\u3001\u5806\u3001\u54c8\u5e0c\u8868\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u4e00\u5bf9\u591a\u7684\u5173\u7cfb\u3002
        • \u7f51\u72b6\u7ed3\u6784\uff1a\u56fe\uff0c\u5143\u7d20\u4e4b\u95f4\u662f\u591a\u5bf9\u591a\u7684\u5173\u7cfb\u3002
        "},{"location":"chapter_data_structure/classification_of_data_structure/#312","title":"3.1.2 \u00a0 \u7269\u7406\u7ed3\u6784\uff1a\u8fde\u7eed\u4e0e\u5206\u6563","text":"

        \u5f53\u7b97\u6cd5\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6b63\u5728\u5904\u7406\u7684\u6570\u636e\u4e3b\u8981\u88ab\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u3002\u56fe 3-2 \u5c55\u793a\u4e86\u4e00\u4e2a\u8ba1\u7b97\u673a\u5185\u5b58\u6761\uff0c\u5176\u4e2d\u6bcf\u4e2a\u9ed1\u8272\u65b9\u5757\u90fd\u5305\u542b\u4e00\u5757\u5185\u5b58\u7a7a\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5185\u5b58\u60f3\u8c61\u6210\u4e00\u4e2a\u5de8\u5927\u7684 Excel \u8868\u683c\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u53ef\u4ee5\u5b58\u50a8\u4e00\u5b9a\u5927\u5c0f\u7684\u6570\u636e\u3002

        \u7cfb\u7edf\u901a\u8fc7\u5185\u5b58\u5730\u5740\u6765\u8bbf\u95ee\u76ee\u6807\u4f4d\u7f6e\u7684\u6570\u636e\u3002\u5982\u56fe 3-2 \u6240\u793a\uff0c\u8ba1\u7b97\u673a\u6839\u636e\u7279\u5b9a\u89c4\u5219\u4e3a\u8868\u683c\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u5206\u914d\u7f16\u53f7\uff0c\u786e\u4fdd\u6bcf\u4e2a\u5185\u5b58\u7a7a\u95f4\u90fd\u6709\u552f\u4e00\u7684\u5185\u5b58\u5730\u5740\u3002\u6709\u4e86\u8fd9\u4e9b\u5730\u5740\uff0c\u7a0b\u5e8f\u4fbf\u53ef\u4ee5\u8bbf\u95ee\u5185\u5b58\u4e2d\u7684\u6570\u636e\u3002

        \u56fe 3-2 \u00a0 \u5185\u5b58\u6761\u3001\u5185\u5b58\u7a7a\u95f4\u3001\u5185\u5b58\u5730\u5740

        Tip

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5c06\u5185\u5b58\u6bd4\u4f5c Excel \u8868\u683c\u662f\u4e00\u4e2a\u7b80\u5316\u7684\u7c7b\u6bd4\uff0c\u5b9e\u9645\u5185\u5b58\u7684\u5de5\u4f5c\u673a\u5236\u6bd4\u8f83\u590d\u6742\uff0c\u6d89\u53ca\u5230\u5730\u5740\u7a7a\u95f4\u3001\u5185\u5b58\u7ba1\u7406\u3001\u7f13\u5b58\u673a\u5236\u3001\u865a\u62df\u548c\u7269\u7406\u5185\u5b58\u7b49\u6982\u5ff5\u3002

        \u5185\u5b58\u662f\u6240\u6709\u7a0b\u5e8f\u7684\u5171\u4eab\u8d44\u6e90\uff0c\u5f53\u67d0\u5757\u5185\u5b58\u88ab\u67d0\u4e2a\u7a0b\u5e8f\u5360\u7528\u65f6\uff0c\u5219\u65e0\u6cd5\u88ab\u5176\u4ed6\u7a0b\u5e8f\u540c\u65f6\u4f7f\u7528\u4e86\u3002\u56e0\u6b64\u5728\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u8bbe\u8ba1\u4e2d\uff0c\u5185\u5b58\u8d44\u6e90\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u6bd4\u5982\uff0c\u7b97\u6cd5\u6240\u5360\u7528\u7684\u5185\u5b58\u5cf0\u503c\u4e0d\u5e94\u8d85\u8fc7\u7cfb\u7edf\u5269\u4f59\u7a7a\u95f2\u5185\u5b58\uff1b\u5982\u679c\u7f3a\u5c11\u8fde\u7eed\u5927\u5757\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u90a3\u4e48\u6240\u9009\u7528\u7684\u6570\u636e\u7ed3\u6784\u5fc5\u987b\u80fd\u591f\u5b58\u50a8\u5728\u5206\u6563\u7684\u5185\u5b58\u7a7a\u95f4\u5185\u3002

        \u5982\u56fe 3-3 \u6240\u793a\uff0c\u7269\u7406\u7ed3\u6784\u53cd\u6620\u4e86\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u53ef\u5206\u4e3a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\uff08\u6570\u7ec4\uff09\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\uff08\u94fe\u8868\uff09\u3002\u7269\u7406\u7ed3\u6784\u4ece\u5e95\u5c42\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u8bbf\u95ee\u3001\u66f4\u65b0\u3001\u589e\u5220\u7b49\u64cd\u4f5c\u65b9\u6cd5\uff0c\u4e24\u79cd\u7269\u7406\u7ed3\u6784\u5728\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u65b9\u9762\u5448\u73b0\u51fa\u4e92\u8865\u7684\u7279\u70b9\u3002

        \u56fe 3-3 \u00a0 \u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\u4e0e\u5206\u6563\u7a7a\u95f4\u5b58\u50a8

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6240\u6709\u6570\u636e\u7ed3\u6784\u90fd\u662f\u57fa\u4e8e\u6570\u7ec4\u3001\u94fe\u8868\u6216\u4e8c\u8005\u7684\u7ec4\u5408\u5b9e\u73b0\u7684\u3002\u4f8b\u5982\uff0c\u6808\u548c\u961f\u5217\u65e2\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\uff1b\u800c\u54c8\u5e0c\u8868\u7684\u5b9e\u73b0\u53ef\u80fd\u540c\u65f6\u5305\u542b\u6570\u7ec4\u548c\u94fe\u8868\u3002

        • \u57fa\u4e8e\u6570\u7ec4\u53ef\u5b9e\u73b0\uff1a\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u3001\u77e9\u9635\u3001\u5f20\u91cf\uff08\u7ef4\u5ea6 \\(\\geq 3\\) \u7684\u6570\u7ec4\uff09\u7b49\u3002
        • \u57fa\u4e8e\u94fe\u8868\u53ef\u5b9e\u73b0\uff1a\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u7b49\u3002

        \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u79f0\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d\uff0c\u8fd9\u610f\u5473\u7740\u6b64\u7c7b\u6570\u636e\u7ed3\u6784\u5728\u521d\u59cb\u5316\u540e\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002\u76f8\u5bf9\u5e94\u5730\uff0c\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u79f0\u201c\u52a8\u6001\u6570\u636e\u7ed3\u6784\u201d\uff0c\u8fd9\u7c7b\u6570\u636e\u7ed3\u6784\u5728\u521d\u59cb\u5316\u540e\uff0c\u4ecd\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u5bf9\u5176\u957f\u5ea6\u8fdb\u884c\u8c03\u6574\u3002

        Tip

        \u5982\u679c\u4f60\u611f\u89c9\u7269\u7406\u7ed3\u6784\u7406\u89e3\u8d77\u6765\u6709\u56f0\u96be\uff0c\u5efa\u8bae\u5148\u9605\u8bfb\u4e0b\u4e00\u7ae0\uff0c\u7136\u540e\u518d\u56de\u987e\u672c\u8282\u5185\u5bb9\u3002

        "},{"location":"chapter_data_structure/number_encoding/","title":"3.3 \u00a0 \u6570\u5b57\u7f16\u7801 *","text":"

        Note

        \u5728\u672c\u4e66\u4e2d\uff0c\u6807\u9898\u5e26\u6709 * \u7b26\u53f7\u7684\u662f\u9009\u8bfb\u7ae0\u8282\u3002\u5982\u679c\u4f60\u65f6\u95f4\u6709\u9650\u6216\u611f\u5230\u7406\u89e3\u56f0\u96be\uff0c\u53ef\u4ee5\u5148\u8df3\u8fc7\uff0c\u7b49\u5b66\u5b8c\u5fc5\u8bfb\u7ae0\u8282\u540e\u518d\u5355\u72ec\u653b\u514b\u3002

        "},{"location":"chapter_data_structure/number_encoding/#331","title":"3.3.1 \u00a0 \u6574\u6570\u7f16\u7801","text":"

        \u5728\u4e0a\u4e00\u8282\u7684\u8868\u683c\u4e2d\u6211\u4eec\u53d1\u73b0\uff0c\u6240\u6709\u6574\u6570\u7c7b\u578b\u80fd\u591f\u8868\u793a\u7684\u8d1f\u6570\u90fd\u6bd4\u6b63\u6570\u591a\u4e00\u4e2a\uff0c\u4f8b\u5982 byte \u7684\u53d6\u503c\u8303\u56f4\u662f \\([-128, 127]\\) \u3002\u8fd9\u4e2a\u73b0\u8c61\u6bd4\u8f83\u53cd\u76f4\u89c9\uff0c\u5b83\u7684\u5185\u5728\u539f\u56e0\u6d89\u53ca\u539f\u7801\u3001\u53cd\u7801\u3001\u8865\u7801\u7684\u76f8\u5173\u77e5\u8bc6\u3002

        \u9996\u5148\u9700\u8981\u6307\u51fa\uff0c\u6570\u5b57\u662f\u4ee5\u201c\u8865\u7801\u201d\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u4e2d\u7684\u3002\u5728\u5206\u6790\u8fd9\u6837\u505a\u7684\u539f\u56e0\u4e4b\u524d\uff0c\u9996\u5148\u7ed9\u51fa\u4e09\u8005\u7684\u5b9a\u4e49\u3002

        • \u539f\u7801\uff1a\u6211\u4eec\u5c06\u6570\u5b57\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u7684\u6700\u9ad8\u4f4d\u89c6\u4e3a\u7b26\u53f7\u4f4d\uff0c\u5176\u4e2d \\(0\\) \u8868\u793a\u6b63\u6570\uff0c\\(1\\) \u8868\u793a\u8d1f\u6570\uff0c\u5176\u4f59\u4f4d\u8868\u793a\u6570\u5b57\u7684\u503c\u3002
        • \u53cd\u7801\uff1a\u6b63\u6570\u7684\u53cd\u7801\u4e0e\u5176\u539f\u7801\u76f8\u540c\uff0c\u8d1f\u6570\u7684\u53cd\u7801\u662f\u5bf9\u5176\u539f\u7801\u9664\u7b26\u53f7\u4f4d\u5916\u7684\u6240\u6709\u4f4d\u53d6\u53cd\u3002
        • \u8865\u7801\uff1a\u6b63\u6570\u7684\u8865\u7801\u4e0e\u5176\u539f\u7801\u76f8\u540c\uff0c\u8d1f\u6570\u7684\u8865\u7801\u662f\u5728\u5176\u53cd\u7801\u7684\u57fa\u7840\u4e0a\u52a0 \\(1\\) \u3002

        \u56fe 3-4 \u5c55\u793a\u4e86\u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\u4e4b\u95f4\u7684\u8f6c\u6362\u65b9\u6cd5\u3002

        \u56fe 3-4 \u00a0 \u539f\u7801\u3001\u53cd\u7801\u4e0e\u8865\u7801\u4e4b\u95f4\u7684\u76f8\u4e92\u8f6c\u6362

        \u300c\u539f\u7801 sign\u2013magnitude\u300d\u867d\u7136\u6700\u76f4\u89c2\uff0c\u4f46\u5b58\u5728\u4e00\u4e9b\u5c40\u9650\u6027\u3002\u4e00\u65b9\u9762\uff0c\u8d1f\u6570\u7684\u539f\u7801\u4e0d\u80fd\u76f4\u63a5\u7528\u4e8e\u8fd0\u7b97\u3002\u4f8b\u5982\u5728\u539f\u7801\u4e0b\u8ba1\u7b97 \\(1 + (-2)\\) \uff0c\u5f97\u5230\u7684\u7ed3\u679c\u662f \\(-3\\) \uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u5bf9\u7684\u3002

        \\[ \\begin{aligned} & 1 + (-2) \\newline & \\rightarrow 0000 \\; 0001 + 1000 \\; 0010 \\newline & = 1000 \\; 0011 \\newline & \\rightarrow -3 \\end{aligned} \\]

        \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8ba1\u7b97\u673a\u5f15\u5165\u4e86\u300c\u53cd\u7801 1's complement\u300d\u3002\u5982\u679c\u6211\u4eec\u5148\u5c06\u539f\u7801\u8f6c\u6362\u4e3a\u53cd\u7801\uff0c\u5e76\u5728\u53cd\u7801\u4e0b\u8ba1\u7b97 \\(1 + (-2)\\) \uff0c\u6700\u540e\u5c06\u7ed3\u679c\u4ece\u53cd\u7801\u8f6c\u6362\u56de\u539f\u7801\uff0c\u5219\u53ef\u5f97\u5230\u6b63\u786e\u7ed3\u679c \\(-1\\) \u3002

        \\[ \\begin{aligned} & 1 + (-2) \\newline & \\rightarrow 0000 \\; 0001 \\; \\text{(\u539f\u7801)} + 1000 \\; 0010 \\; \\text{(\u539f\u7801)} \\newline & = 0000 \\; 0001 \\; \\text{(\u53cd\u7801)} + 1111 \\; 1101 \\; \\text{(\u53cd\u7801)} \\newline & = 1111 \\; 1110 \\; \\text{(\u53cd\u7801)} \\newline & = 1000 \\; 0001 \\; \\text{(\u539f\u7801)} \\newline & \\rightarrow -1 \\end{aligned} \\]

        \u53e6\u4e00\u65b9\u9762\uff0c\u6570\u5b57\u96f6\u7684\u539f\u7801\u6709 \\(+0\\) \u548c \\(-0\\) \u4e24\u79cd\u8868\u793a\u65b9\u5f0f\u3002\u8fd9\u610f\u5473\u7740\u6570\u5b57\u96f6\u5bf9\u5e94\u4e24\u4e2a\u4e0d\u540c\u7684\u4e8c\u8fdb\u5236\u7f16\u7801\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5e26\u6765\u6b67\u4e49\u3002\u6bd4\u5982\u5728\u6761\u4ef6\u5224\u65ad\u4e2d\uff0c\u5982\u679c\u6ca1\u6709\u533a\u5206\u6b63\u96f6\u548c\u8d1f\u96f6\uff0c\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5224\u65ad\u7ed3\u679c\u51fa\u9519\u3002\u800c\u5982\u679c\u6211\u4eec\u60f3\u5904\u7406\u6b63\u96f6\u548c\u8d1f\u96f6\u6b67\u4e49\uff0c\u5219\u9700\u8981\u5f15\u5165\u989d\u5916\u7684\u5224\u65ad\u64cd\u4f5c\uff0c\u8fd9\u53ef\u80fd\u4f1a\u964d\u4f4e\u8ba1\u7b97\u673a\u7684\u8fd0\u7b97\u6548\u7387\u3002

        \\[ \\begin{aligned} +0 & \\rightarrow 0000 \\; 0000 \\newline -0 & \\rightarrow 1000 \\; 0000 \\end{aligned} \\]

        \u4e0e\u539f\u7801\u4e00\u6837\uff0c\u53cd\u7801\u4e5f\u5b58\u5728\u6b63\u8d1f\u96f6\u6b67\u4e49\u95ee\u9898\uff0c\u56e0\u6b64\u8ba1\u7b97\u673a\u8fdb\u4e00\u6b65\u5f15\u5165\u4e86\u300c\u8865\u7801 2's complement\u300d\u3002\u6211\u4eec\u5148\u6765\u89c2\u5bdf\u4e00\u4e0b\u8d1f\u96f6\u7684\u539f\u7801\u3001\u53cd\u7801\u3001\u8865\u7801\u7684\u8f6c\u6362\u8fc7\u7a0b\uff1a

        \\[ \\begin{aligned} -0 \\rightarrow \\; & 1000 \\; 0000 \\; \\text{(\u539f\u7801)} \\newline = \\; & 1111 \\; 1111 \\; \\text{(\u53cd\u7801)} \\newline = 1 \\; & 0000 \\; 0000 \\; \\text{(\u8865\u7801)} \\newline \\end{aligned} \\]

        \u5728\u8d1f\u96f6\u7684\u53cd\u7801\u57fa\u7840\u4e0a\u52a0 \\(1\\) \u4f1a\u4ea7\u751f\u8fdb\u4f4d\uff0c\u4f46 byte \u7c7b\u578b\u7684\u957f\u5ea6\u53ea\u6709 8 \u4f4d\uff0c\u56e0\u6b64\u6ea2\u51fa\u5230\u7b2c 9 \u4f4d\u7684 \\(1\\) \u4f1a\u88ab\u820d\u5f03\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8d1f\u96f6\u7684\u8865\u7801\u4e3a \\(0000 \\; 0000\\) \uff0c\u4e0e\u6b63\u96f6\u7684\u8865\u7801\u76f8\u540c\u3002\u8fd9\u610f\u5473\u7740\u5728\u8865\u7801\u8868\u793a\u4e2d\u53ea\u5b58\u5728\u4e00\u4e2a\u96f6\uff0c\u6b63\u8d1f\u96f6\u6b67\u4e49\u4ece\u800c\u5f97\u5230\u89e3\u51b3\u3002

        \u8fd8\u5269\u6700\u540e\u4e00\u4e2a\u7591\u60d1\uff1abyte \u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u662f \\([-128, 127]\\) \uff0c\u591a\u51fa\u6765\u7684\u4e00\u4e2a\u8d1f\u6570 \\(-128\\) \u662f\u5982\u4f55\u5f97\u5230\u7684\u5462\uff1f\u6211\u4eec\u6ce8\u610f\u5230\uff0c\u533a\u95f4 \\([-127, +127]\\) \u5185\u7684\u6240\u6709\u6574\u6570\u90fd\u6709\u5bf9\u5e94\u7684\u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\uff0c\u5e76\u4e14\u539f\u7801\u548c\u8865\u7801\u4e4b\u95f4\u53ef\u4ee5\u4e92\u76f8\u8f6c\u6362\u3002

        \u7136\u800c\uff0c\u8865\u7801 \\(1000 \\; 0000\\) \u662f\u4e00\u4e2a\u4f8b\u5916\uff0c\u5b83\u5e76\u6ca1\u6709\u5bf9\u5e94\u7684\u539f\u7801\u3002\u6839\u636e\u8f6c\u6362\u65b9\u6cd5\uff0c\u6211\u4eec\u5f97\u5230\u8be5\u8865\u7801\u7684\u539f\u7801\u4e3a \\(0000 \\; 0000\\) \u3002\u8fd9\u663e\u7136\u662f\u77db\u76fe\u7684\uff0c\u56e0\u4e3a\u8be5\u539f\u7801\u8868\u793a\u6570\u5b57 \\(0\\) \uff0c\u5b83\u7684\u8865\u7801\u5e94\u8be5\u662f\u81ea\u8eab\u3002\u8ba1\u7b97\u673a\u89c4\u5b9a\u8fd9\u4e2a\u7279\u6b8a\u7684\u8865\u7801 \\(1000 \\; 0000\\) \u4ee3\u8868 \\(-128\\) \u3002\u5b9e\u9645\u4e0a\uff0c\\((-1) + (-127)\\) \u5728\u8865\u7801\u4e0b\u7684\u8ba1\u7b97\u7ed3\u679c\u5c31\u662f \\(-128\\) \u3002

        \\[ \\begin{aligned} & (-127) + (-1) \\newline & \\rightarrow 1111 \\; 1111 \\; \\text{(\u539f\u7801)} + 1000 \\; 0001 \\; \\text{(\u539f\u7801)} \\newline & = 1000 \\; 0000 \\; \\text{(\u53cd\u7801)} + 1111 \\; 1110 \\; \\text{(\u53cd\u7801)} \\newline & = 1000 \\; 0001 \\; \\text{(\u8865\u7801)} + 1111 \\; 1111 \\; \\text{(\u8865\u7801)} \\newline & = 1000 \\; 0000 \\; \\text{(\u8865\u7801)} \\newline & \\rightarrow -128 \\end{aligned} \\]

        \u4f60\u53ef\u80fd\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u4e0a\u8ff0\u6240\u6709\u8ba1\u7b97\u90fd\u662f\u52a0\u6cd5\u8fd0\u7b97\u3002\u8fd9\u6697\u793a\u7740\u4e00\u4e2a\u91cd\u8981\u4e8b\u5b9e\uff1a\u8ba1\u7b97\u673a\u5185\u90e8\u7684\u786c\u4ef6\u7535\u8def\u4e3b\u8981\u662f\u57fa\u4e8e\u52a0\u6cd5\u8fd0\u7b97\u8bbe\u8ba1\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u52a0\u6cd5\u8fd0\u7b97\u76f8\u5bf9\u4e8e\u5176\u4ed6\u8fd0\u7b97\uff08\u6bd4\u5982\u4e58\u6cd5\u3001\u9664\u6cd5\u548c\u51cf\u6cd5\uff09\u6765\u8bf4\uff0c\u786c\u4ef6\u5b9e\u73b0\u8d77\u6765\u66f4\u7b80\u5355\uff0c\u66f4\u5bb9\u6613\u8fdb\u884c\u5e76\u884c\u5316\u5904\u7406\uff0c\u8fd0\u7b97\u901f\u5ea6\u66f4\u5feb\u3002

        \u8bf7\u6ce8\u610f\uff0c\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u8ba1\u7b97\u673a\u53ea\u80fd\u505a\u52a0\u6cd5\u3002\u901a\u8fc7\u5c06\u52a0\u6cd5\u4e0e\u4e00\u4e9b\u57fa\u672c\u903b\u8f91\u8fd0\u7b97\u7ed3\u5408\uff0c\u8ba1\u7b97\u673a\u80fd\u591f\u5b9e\u73b0\u5404\u79cd\u5176\u4ed6\u7684\u6570\u5b66\u8fd0\u7b97\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u51cf\u6cd5 \\(a - b\\) \u53ef\u4ee5\u8f6c\u6362\u4e3a\u8ba1\u7b97\u52a0\u6cd5 \\(a + (-b)\\) \uff1b\u8ba1\u7b97\u4e58\u6cd5\u548c\u9664\u6cd5\u53ef\u4ee5\u8f6c\u6362\u4e3a\u8ba1\u7b97\u591a\u6b21\u52a0\u6cd5\u6216\u51cf\u6cd5\u3002

        \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u8ba1\u7b97\u673a\u4f7f\u7528\u8865\u7801\u7684\u539f\u56e0\uff1a\u57fa\u4e8e\u8865\u7801\u8868\u793a\uff0c\u8ba1\u7b97\u673a\u53ef\u4ee5\u7528\u540c\u6837\u7684\u7535\u8def\u548c\u64cd\u4f5c\u6765\u5904\u7406\u6b63\u6570\u548c\u8d1f\u6570\u7684\u52a0\u6cd5\uff0c\u4e0d\u9700\u8981\u8bbe\u8ba1\u7279\u6b8a\u7684\u786c\u4ef6\u7535\u8def\u6765\u5904\u7406\u51cf\u6cd5\uff0c\u5e76\u4e14\u65e0\u987b\u7279\u522b\u5904\u7406\u6b63\u8d1f\u96f6\u7684\u6b67\u4e49\u95ee\u9898\u3002\u8fd9\u5927\u5927\u7b80\u5316\u4e86\u786c\u4ef6\u8bbe\u8ba1\uff0c\u63d0\u9ad8\u4e86\u8fd0\u7b97\u6548\u7387\u3002

        \u8865\u7801\u7684\u8bbe\u8ba1\u975e\u5e38\u7cbe\u5999\uff0c\u56e0\u7bc7\u5e45\u5173\u7cfb\u6211\u4eec\u5c31\u5148\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u5efa\u8bae\u6709\u5174\u8da3\u7684\u8bfb\u8005\u8fdb\u4e00\u6b65\u6df1\u5165\u4e86\u89e3\u3002

        "},{"location":"chapter_data_structure/number_encoding/#332","title":"3.3.2 \u00a0 \u6d6e\u70b9\u6570\u7f16\u7801","text":"

        \u7ec6\u5fc3\u7684\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\uff1aint \u548c float \u957f\u5ea6\u76f8\u540c\uff0c\u90fd\u662f 4 bytes \uff0c\u4f46\u4e3a\u4ec0\u4e48 float \u7684\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e int \uff1f\u8fd9\u975e\u5e38\u53cd\u76f4\u89c9\uff0c\u56e0\u4e3a\u6309\u7406\u8bf4 float \u9700\u8981\u8868\u793a\u5c0f\u6570\uff0c\u53d6\u503c\u8303\u56f4\u5e94\u8be5\u53d8\u5c0f\u624d\u5bf9\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8fd9\u662f\u56e0\u4e3a\u6d6e\u70b9\u6570 float \u91c7\u7528\u4e86\u4e0d\u540c\u7684\u8868\u793a\u65b9\u5f0f\u3002\u8bb0\u4e00\u4e2a 32-bit \u957f\u5ea6\u7684\u4e8c\u8fdb\u5236\u6570\u4e3a\uff1a

        \\[ b_{31} b_{30} b_{29} \\ldots b_2 b_1 b_0 \\]

        \u6839\u636e IEEE 754 \u6807\u51c6\uff0c32-bit \u957f\u5ea6\u7684 float \u7531\u4ee5\u4e0b\u4e09\u4e2a\u90e8\u5206\u6784\u6210\u3002

        • \u7b26\u53f7\u4f4d \\(\\mathrm{S}\\) \uff1a\u5360 1 bit \uff0c\u5bf9\u5e94 \\(b_{31}\\) \u3002
        • \u6307\u6570\u4f4d \\(\\mathrm{E}\\) \uff1a\u5360 8 bits \uff0c\u5bf9\u5e94 \\(b_{30} b_{29} \\ldots b_{23}\\) \u3002
        • \u5206\u6570\u4f4d \\(\\mathrm{N}\\) \uff1a\u5360 23 bits \uff0c\u5bf9\u5e94 \\(b_{22} b_{21} \\ldots b_0\\) \u3002

        \u4e8c\u8fdb\u5236\u6570 float \u5bf9\u5e94\u503c\u7684\u8ba1\u7b97\u65b9\u6cd5\u4e3a\uff1a

        \\[ \\text {val} = (-1)^{b_{31}} \\times 2^{\\left(b_{30} b_{29} \\ldots b_{23}\\right)_2-127} \\times\\left(1 . b_{22} b_{21} \\ldots b_0\\right)_2 \\]

        \u8f6c\u5316\u5230\u5341\u8fdb\u5236\u4e0b\u7684\u8ba1\u7b97\u516c\u5f0f\u4e3a\uff1a

        \\[ \\text {val}=(-1)^{\\mathrm{S}} \\times 2^{\\mathrm{E} -127} \\times (1 + \\mathrm{N}) \\]

        \u5176\u4e2d\u5404\u9879\u7684\u53d6\u503c\u8303\u56f4\u4e3a\uff1a

        \\[ \\begin{aligned} \\mathrm{S} \\in & \\{ 0, 1\\}, \\quad \\mathrm{E} \\in \\{ 1, 2, \\dots, 254 \\} \\newline (1 + \\mathrm{N}) = & (1 + \\sum_{i=1}^{23} b_{23-i} 2^{-i}) \\subset [1, 2 - 2^{-23}] \\end{aligned} \\]

        \u56fe 3-5 \u00a0 IEEE 754 \u6807\u51c6\u4e0b\u7684 float \u7684\u8ba1\u7b97\u793a\u4f8b

        \u89c2\u5bdf\u56fe 3-5 \uff0c\u7ed9\u5b9a\u4e00\u4e2a\u793a\u4f8b\u6570\u636e \\(\\mathrm{S} = 0\\) \uff0c \\(\\mathrm{E} = 124\\) \uff0c\\(\\mathrm{N} = 2^{-2} + 2^{-3} = 0.375\\) \uff0c\u5219\u6709\uff1a

        \\[ \\text { val } = (-1)^0 \\times 2^{124 - 127} \\times (1 + 0.375) = 0.171875 \\]

        \u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u56de\u7b54\u6700\u521d\u7684\u95ee\u9898\uff1afloat \u7684\u8868\u793a\u65b9\u5f0f\u5305\u542b\u6307\u6570\u4f4d\uff0c\u5bfc\u81f4\u5176\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e int \u3002\u6839\u636e\u4ee5\u4e0a\u8ba1\u7b97\uff0cfloat \u53ef\u8868\u793a\u7684\u6700\u5927\u6b63\u6570\u4e3a \\(2^{254 - 127} \\times (2 - 2^{-23}) \\approx 3.4 \\times 10^{38}\\) \uff0c\u5207\u6362\u7b26\u53f7\u4f4d\u4fbf\u53ef\u5f97\u5230\u6700\u5c0f\u8d1f\u6570\u3002

        \u5c3d\u7ba1\u6d6e\u70b9\u6570 float \u6269\u5c55\u4e86\u53d6\u503c\u8303\u56f4\uff0c\u4f46\u5176\u526f\u4f5c\u7528\u662f\u727a\u7272\u4e86\u7cbe\u5ea6\u3002\u6574\u6570\u7c7b\u578b int \u5c06\u5168\u90e8 32 \u4f4d\u7528\u4e8e\u8868\u793a\u6570\u5b57\uff0c\u6570\u5b57\u662f\u5747\u5300\u5206\u5e03\u7684\uff1b\u800c\u7531\u4e8e\u6307\u6570\u4f4d\u7684\u5b58\u5728\uff0c\u6d6e\u70b9\u6570 float \u7684\u6570\u503c\u8d8a\u5927\uff0c\u76f8\u90bb\u4e24\u4e2a\u6570\u5b57\u4e4b\u95f4\u7684\u5dee\u503c\u5c31\u4f1a\u8d8b\u5411\u8d8a\u5927\u3002

        \u5982\u8868 3-2 \u6240\u793a\uff0c\u6307\u6570\u4f4d \\(E = 0\\) \u548c \\(E = 255\\) \u5177\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u7528\u4e8e\u8868\u793a\u96f6\u3001\u65e0\u7a77\u5927\u3001\\(\\mathrm{NaN}\\) \u7b49\u3002

        \u8868 3-2 \u00a0 \u6307\u6570\u4f4d\u542b\u4e49

        \u6307\u6570\u4f4d E \u5206\u6570\u4f4d \\(\\mathrm{N} = 0\\) \u5206\u6570\u4f4d \\(\\mathrm{N} \\ne 0\\) \u8ba1\u7b97\u516c\u5f0f \\(0\\) \\(\\pm 0\\) \u6b21\u6b63\u89c4\u6570 \\((-1)^{\\mathrm{S}} \\times 2^{-126} \\times (0.\\mathrm{N})\\) \\(1, 2, \\dots, 254\\) \u6b63\u89c4\u6570 \u6b63\u89c4\u6570 \\((-1)^{\\mathrm{S}} \\times 2^{(\\mathrm{E} -127)} \\times (1.\\mathrm{N})\\) \\(255\\) \\(\\pm \\infty\\) \\(\\mathrm{NaN}\\)

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6b21\u6b63\u89c4\u6570\u663e\u8457\u63d0\u5347\u4e86\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u3002\u6700\u5c0f\u6b63\u6b63\u89c4\u6570\u4e3a \\(2^{-126}\\) \uff0c\u6700\u5c0f\u6b63\u6b21\u6b63\u89c4\u6570\u4e3a \\(2^{-126} \\times 2^{-23}\\) \u3002

        \u53cc\u7cbe\u5ea6 double \u4e5f\u91c7\u7528\u7c7b\u4f3c\u4e8e float \u7684\u8868\u793a\u65b9\u6cd5\uff0c\u5728\u6b64\u4e0d\u505a\u8d58\u8ff0\u3002

        "},{"location":"chapter_data_structure/summary/","title":"3.5 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_data_structure/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u4ece\u903b\u8f91\u7ed3\u6784\u548c\u7269\u7406\u7ed3\u6784\u4e24\u4e2a\u89d2\u5ea6\u8fdb\u884c\u5206\u7c7b\u3002\u903b\u8f91\u7ed3\u6784\u63cf\u8ff0\u4e86\u6570\u636e\u5143\u7d20\u4e4b\u95f4\u7684\u903b\u8f91\u5173\u7cfb\uff0c\u800c\u7269\u7406\u7ed3\u6784\u63cf\u8ff0\u4e86\u6570\u636e\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\u65b9\u5f0f\u3002
        • \u5e38\u89c1\u7684\u903b\u8f91\u7ed3\u6784\u5305\u62ec\u7ebf\u6027\u3001\u6811\u72b6\u548c\u7f51\u72b6\u7b49\u3002\u901a\u5e38\u6211\u4eec\u6839\u636e\u903b\u8f91\u7ed3\u6784\u5c06\u6570\u636e\u7ed3\u6784\u5206\u4e3a\u7ebf\u6027\uff08\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\uff09\u548c\u975e\u7ebf\u6027\uff08\u6811\u3001\u56fe\u3001\u5806\uff09\u4e24\u79cd\u3002\u54c8\u5e0c\u8868\u7684\u5b9e\u73b0\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002
        • \u5f53\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u6570\u636e\u88ab\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\u3002\u6bcf\u4e2a\u5185\u5b58\u7a7a\u95f4\u90fd\u62e5\u6709\u5bf9\u5e94\u7684\u5185\u5b58\u5730\u5740\uff0c\u7a0b\u5e8f\u901a\u8fc7\u8fd9\u4e9b\u5185\u5b58\u5730\u5740\u8bbf\u95ee\u6570\u636e\u3002
        • \u7269\u7406\u7ed3\u6784\u4e3b\u8981\u5206\u4e3a\u8fde\u7eed\u7a7a\u95f4\u5b58\u50a8\uff08\u6570\u7ec4\uff09\u548c\u5206\u6563\u7a7a\u95f4\u5b58\u50a8\uff08\u94fe\u8868\uff09\u3002\u6240\u6709\u6570\u636e\u7ed3\u6784\u90fd\u662f\u7531\u6570\u7ec4\u3001\u94fe\u8868\u6216\u4e24\u8005\u7684\u7ec4\u5408\u5b9e\u73b0\u7684\u3002
        • \u8ba1\u7b97\u673a\u4e2d\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5305\u62ec\u6574\u6570 byte\u3001short\u3001int\u3001long \uff0c\u6d6e\u70b9\u6570 float\u3001double \uff0c\u5b57\u7b26 char \u548c\u5e03\u5c14 boolean \u3002\u5b83\u4eec\u7684\u53d6\u503c\u8303\u56f4\u53d6\u51b3\u4e8e\u5360\u7528\u7a7a\u95f4\u5927\u5c0f\u548c\u8868\u793a\u65b9\u5f0f\u3002
        • \u539f\u7801\u3001\u53cd\u7801\u548c\u8865\u7801\u662f\u5728\u8ba1\u7b97\u673a\u4e2d\u7f16\u7801\u6570\u5b57\u7684\u4e09\u79cd\u65b9\u6cd5\uff0c\u5b83\u4eec\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\u3002\u6574\u6570\u7684\u539f\u7801\u7684\u6700\u9ad8\u4f4d\u662f\u7b26\u53f7\u4f4d\uff0c\u5176\u4f59\u4f4d\u662f\u6570\u5b57\u7684\u503c\u3002
        • \u6574\u6570\u5728\u8ba1\u7b97\u673a\u4e2d\u662f\u4ee5\u8865\u7801\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\u3002\u5728\u8865\u7801\u8868\u793a\u4e0b\uff0c\u8ba1\u7b97\u673a\u53ef\u4ee5\u5bf9\u6b63\u6570\u548c\u8d1f\u6570\u7684\u52a0\u6cd5\u4e00\u89c6\u540c\u4ec1\uff0c\u4e0d\u9700\u8981\u4e3a\u51cf\u6cd5\u64cd\u4f5c\u5355\u72ec\u8bbe\u8ba1\u7279\u6b8a\u7684\u786c\u4ef6\u7535\u8def\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u6b63\u8d1f\u96f6\u6b67\u4e49\u7684\u95ee\u9898\u3002
        • \u6d6e\u70b9\u6570\u7684\u7f16\u7801\u7531 1 \u4f4d\u7b26\u53f7\u4f4d\u30018 \u4f4d\u6307\u6570\u4f4d\u548c 23 \u4f4d\u5206\u6570\u4f4d\u6784\u6210\u3002\u7531\u4e8e\u5b58\u5728\u6307\u6570\u4f4d\uff0c\u56e0\u6b64\u6d6e\u70b9\u6570\u7684\u53d6\u503c\u8303\u56f4\u8fdc\u5927\u4e8e\u6574\u6570\uff0c\u4ee3\u4ef7\u662f\u727a\u7272\u4e86\u7cbe\u5ea6\u3002
        • ASCII \u7801\u662f\u6700\u65e9\u51fa\u73b0\u7684\u82f1\u6587\u5b57\u7b26\u96c6\uff0c\u957f\u5ea6\u4e3a 1 \u5b57\u8282\uff0c\u5171\u6536\u5f55 127 \u4e2a\u5b57\u7b26\u3002GBK \u5b57\u7b26\u96c6\u662f\u5e38\u7528\u7684\u4e2d\u6587\u5b57\u7b26\u96c6\uff0c\u5171\u6536\u5f55\u4e24\u4e07\u591a\u4e2a\u6c49\u5b57\u3002Unicode \u81f4\u529b\u4e8e\u63d0\u4f9b\u4e00\u4e2a\u5b8c\u6574\u7684\u5b57\u7b26\u96c6\u6807\u51c6\uff0c\u6536\u5f55\u4e16\u754c\u5185\u5404\u79cd\u8bed\u8a00\u7684\u5b57\u7b26\uff0c\u4ece\u800c\u89e3\u51b3\u7531\u4e8e\u5b57\u7b26\u7f16\u7801\u65b9\u6cd5\u4e0d\u4e00\u81f4\u800c\u5bfc\u81f4\u7684\u4e71\u7801\u95ee\u9898\u3002
        • UTF-8 \u662f\u6700\u53d7\u6b22\u8fce\u7684 Unicode \u7f16\u7801\u65b9\u6cd5\uff0c\u901a\u7528\u6027\u975e\u5e38\u597d\u3002\u5b83\u662f\u4e00\u79cd\u53d8\u957f\u7684\u7f16\u7801\u65b9\u6cd5\uff0c\u5177\u6709\u5f88\u597d\u7684\u6269\u5c55\u6027\uff0c\u6709\u6548\u63d0\u5347\u4e86\u5b58\u50a8\u7a7a\u95f4\u7684\u4f7f\u7528\u6548\u7387\u3002UTF-16 \u548c UTF-32 \u662f\u7b49\u957f\u7684\u7f16\u7801\u65b9\u6cd5\u3002\u5728\u7f16\u7801\u4e2d\u6587\u65f6\uff0cUTF-16 \u6bd4 UTF-8 \u7684\u5360\u7528\u7a7a\u95f4\u66f4\u5c0f\u3002Java \u548c C# \u7b49\u7f16\u7a0b\u8bed\u8a00\u9ed8\u8ba4\u4f7f\u7528 UTF-16 \u7f16\u7801\u3002
        "},{"location":"chapter_data_structure/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u4e3a\u4ec0\u4e48\u54c8\u5e0c\u8868\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff1f

        \u54c8\u5e0c\u8868\u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u800c\u4e3a\u4e86\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u4f7f\u7528\u201c\u94fe\u5f0f\u5730\u5740\u201d\uff08\u540e\u7eed\u54c8\u5e0c\u8868\u7ae0\u8282\u4f1a\u8bb2\uff09\uff1a\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6876\u6307\u5411\u4e00\u4e2a\u94fe\u8868\uff0c\u5f53\u94fe\u8868\u957f\u5ea6\u8d85\u8fc7\u4e00\u5b9a\u9608\u503c\u65f6\uff0c\u53c8\u53ef\u80fd\u88ab\u8f6c\u5316\u4e3a\u6811\uff08\u901a\u5e38\u4e3a\u7ea2\u9ed1\u6811\uff09\u3002 \u4ece\u5b58\u50a8\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u54c8\u5e0c\u8868\u7684\u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u6876\u69fd\u4f4d\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u503c\uff0c\u4e5f\u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u94fe\u8868\u6216\u6811\u3002\u56e0\u6b64\uff0c\u54c8\u5e0c\u8868\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\uff08\u6570\u7ec4\u3001\u94fe\u8868\uff09\u548c\u975e\u7ebf\u6027\uff08\u6811\uff09\u6570\u636e\u7ed3\u6784\u3002

        char \u7c7b\u578b\u7684\u957f\u5ea6\u662f 1 byte \u5417\uff1f

        char \u7c7b\u578b\u7684\u957f\u5ea6\u7531\u7f16\u7a0b\u8bed\u8a00\u91c7\u7528\u7684\u7f16\u7801\u65b9\u6cd5\u51b3\u5b9a\u3002\u4f8b\u5982\uff0cJava\u3001JavaScript\u3001TypeScript\u3001C# \u90fd\u91c7\u7528 UTF-16 \u7f16\u7801\uff08\u4fdd\u5b58 Unicode \u7801\u70b9\uff09\uff0c\u56e0\u6b64 char \u7c7b\u578b\u7684\u957f\u5ea6\u4e3a 2 bytes \u3002

        \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u88ab\u79f0\u4e3a\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d \u662f\u5426\u6709\u6b67\u4e49\uff1f\u56e0\u4e3a\u6808\u4e5f\u53ef\u4ee5\u8fdb\u884c\u51fa\u6808\u548c\u5165\u6808\u7b49\u64cd\u4f5c\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u201c\u52a8\u6001\u201d\u7684\u3002

        \u6808\u786e\u5b9e\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u7684\u6570\u636e\u64cd\u4f5c\uff0c\u4f46\u6570\u636e\u7ed3\u6784\u4ecd\u7136\u662f\u201c\u9759\u6001\u201d\uff08\u957f\u5ea6\u4e0d\u53ef\u53d8\uff09\u7684\u3002\u5c3d\u7ba1\u57fa\u4e8e\u6570\u7ec4\u7684\u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u52a8\u6001\u5730\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\uff0c\u4f46\u5b83\u4eec\u7684\u5bb9\u91cf\u662f\u56fa\u5b9a\u7684\u3002\u5982\u679c\u6570\u636e\u91cf\u8d85\u51fa\u4e86\u9884\u5206\u914d\u7684\u5927\u5c0f\uff0c\u5c31\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u66f4\u5927\u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u8001\u6570\u7ec4\u7684\u5185\u5bb9\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002

        \u5728\u6784\u5efa\u6808\uff08\u961f\u5217\uff09\u7684\u65f6\u5019\uff0c\u672a\u6307\u5b9a\u5b83\u7684\u5927\u5c0f\uff0c\u4e3a\u4ec0\u4e48\u5b83\u4eec\u662f\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d\u5462\uff1f

        \u5728\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6211\u4eec\u65e0\u987b\u4eba\u5de5\u6307\u5b9a\u6808\uff08\u961f\u5217\uff09\u7684\u521d\u59cb\u5bb9\u91cf\uff0c\u8fd9\u4e2a\u5de5\u4f5c\u662f\u7531\u7c7b\u5185\u90e8\u81ea\u52a8\u5b8c\u6210\u7684\u3002\u4f8b\u5982\uff0cJava \u7684 ArrayList \u7684\u521d\u59cb\u5bb9\u91cf\u901a\u5e38\u4e3a 10 \u3002\u53e6\u5916\uff0c\u6269\u5bb9\u64cd\u4f5c\u4e5f\u662f\u81ea\u52a8\u5b9e\u73b0\u7684\u3002\u8be6\u89c1\u672c\u4e66\u7684\u201c\u5217\u8868\u201d\u7ae0\u8282\u3002

        "},{"location":"chapter_divide_and_conquer/","title":"\u7b2c 12 \u7ae0 \u00a0 \u5206\u6cbb","text":"

        Abstract

        \u96be\u9898\u88ab\u9010\u5c42\u62c6\u89e3\uff0c\u6bcf\u4e00\u6b21\u7684\u62c6\u89e3\u90fd\u4f7f\u5b83\u53d8\u5f97\u66f4\u4e3a\u7b80\u5355\u3002

        \u5206\u800c\u6cbb\u4e4b\u63ed\u793a\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u4e8b\u5b9e\uff1a\u4ece\u7b80\u5355\u505a\u8d77\uff0c\u4e00\u5207\u90fd\u4e0d\u518d\u590d\u6742\u3002

        "},{"location":"chapter_divide_and_conquer/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 12.1 \u00a0 \u5206\u6cbb\u7b97\u6cd5
        • 12.2 \u00a0 \u5206\u6cbb\u641c\u7d22\u7b56\u7565
        • 12.3 \u00a0 \u6784\u5efa\u6811\u95ee\u9898
        • 12.4 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898
        • 12.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_divide_and_conquer/binary_search_recur/","title":"12.2 \u00a0 \u5206\u6cbb\u641c\u7d22\u7b56\u7565","text":"

        \u6211\u4eec\u5df2\u7ecf\u5b66\u8fc7\uff0c\u641c\u7d22\u7b97\u6cd5\u5206\u4e3a\u4e24\u5927\u7c7b\u3002

        • \u66b4\u529b\u641c\u7d22\uff1a\u5b83\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002
        • \u81ea\u9002\u5e94\u641c\u7d22\uff1a\u5b83\u5229\u7528\u7279\u6709\u7684\u6570\u636e\u7ec4\u7ec7\u5f62\u5f0f\u6216\u5148\u9a8c\u4fe1\u606f\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \u3002

        \u5b9e\u9645\u4e0a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u7684\u641c\u7d22\u7b97\u6cd5\u901a\u5e38\u662f\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u5b9e\u73b0\u7684\uff0c\u4f8b\u5982\u4e8c\u5206\u67e5\u627e\u548c\u6811\u3002

        • \u4e8c\u5206\u67e5\u627e\u7684\u6bcf\u4e00\u6b65\u90fd\u5c06\u95ee\u9898\uff08\u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff09\u5206\u89e3\u4e3a\u4e00\u4e2a\u5c0f\u95ee\u9898\uff08\u5728\u6570\u7ec4\u7684\u4e00\u534a\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff09\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e00\u76f4\u6301\u7eed\u5230\u6570\u7ec4\u4e3a\u7a7a\u6216\u627e\u5230\u76ee\u6807\u5143\u7d20\u4e3a\u6b62\u3002
        • \u6811\u662f\u5206\u6cbb\u601d\u60f3\u7684\u4ee3\u8868\uff0c\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u3001AVL \u6811\u3001\u5806\u7b49\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7686\u4e3a \\(O(\\log n)\\) \u3002

        \u4e8c\u5206\u67e5\u627e\u7684\u5206\u6cbb\u7b56\u7565\u5982\u4e0b\u6240\u793a\u3002

        • \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u4e8c\u5206\u67e5\u627e\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\uff08\u5728\u6570\u7ec4\u4e2d\u8fdb\u884c\u67e5\u627e\uff09\u5206\u89e3\u4e3a\u5b50\u95ee\u9898\uff08\u5728\u6570\u7ec4\u7684\u4e00\u534a\u4e2d\u8fdb\u884c\u67e5\u627e\uff09\uff0c\u8fd9\u662f\u901a\u8fc7\u6bd4\u8f83\u4e2d\u95f4\u5143\u7d20\u548c\u76ee\u6807\u5143\u7d20\u6765\u5b9e\u73b0\u7684\u3002
        • \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5728\u4e8c\u5206\u67e5\u627e\u4e2d\uff0c\u6bcf\u8f6e\u53ea\u5904\u7406\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u5b83\u4e0d\u53d7\u5176\u4ed6\u5b50\u95ee\u9898\u7684\u5f71\u54cd\u3002
        • \u5b50\u95ee\u9898\u7684\u89e3\u65e0\u987b\u5408\u5e76\uff1a\u4e8c\u5206\u67e5\u627e\u65e8\u5728\u67e5\u627e\u4e00\u4e2a\u7279\u5b9a\u5143\u7d20\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\u3002\u5f53\u5b50\u95ee\u9898\u5f97\u5230\u89e3\u51b3\u65f6\uff0c\u539f\u95ee\u9898\u4e5f\u4f1a\u540c\u65f6\u5f97\u5230\u89e3\u51b3\u3002

        \u5206\u6cbb\u80fd\u591f\u63d0\u5347\u641c\u7d22\u6548\u7387\uff0c\u672c\u8d28\u4e0a\u662f\u56e0\u4e3a\u66b4\u529b\u641c\u7d22\u6bcf\u8f6e\u53ea\u80fd\u6392\u9664\u4e00\u4e2a\u9009\u9879\uff0c\u800c\u5206\u6cbb\u641c\u7d22\u6bcf\u8f6e\u53ef\u4ee5\u6392\u9664\u4e00\u534a\u9009\u9879\u3002

        "},{"location":"chapter_divide_and_conquer/binary_search_recur/#1","title":"1. \u00a0 \u57fa\u4e8e\u5206\u6cbb\u5b9e\u73b0\u4e8c\u5206\u67e5\u627e","text":"

        \u5728\u4e4b\u524d\u7684\u7ae0\u8282\u4e2d\uff0c\u4e8c\u5206\u67e5\u627e\u662f\u57fa\u4e8e\u9012\u63a8\uff08\u8fed\u4ee3\uff09\u5b9e\u73b0\u7684\u3002\u73b0\u5728\u6211\u4eec\u57fa\u4e8e\u5206\u6cbb\uff08\u9012\u5f52\uff09\u6765\u5b9e\u73b0\u5b83\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u662f\u552f\u4e00\u7684\uff0c\u8bf7\u67e5\u627e\u5143\u7d20 target \u3002

        \u4ece\u5206\u6cbb\u89d2\u5ea6\uff0c\u6211\u4eec\u5c06\u641c\u7d22\u533a\u95f4 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u8bb0\u4e3a \\(f(i, j)\\) \u3002

        \u4ee5\u539f\u95ee\u9898 \\(f(0, n-1)\\) \u4e3a\u8d77\u59cb\u70b9\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\u3002

        1. \u8ba1\u7b97\u641c\u7d22\u533a\u95f4 \\([i, j]\\) \u7684\u4e2d\u70b9 \\(m\\) \uff0c\u6839\u636e\u5b83\u6392\u9664\u4e00\u534a\u641c\u7d22\u533a\u95f4\u3002
        2. \u9012\u5f52\u6c42\u89e3\u89c4\u6a21\u51cf\u5c0f\u4e00\u534a\u7684\u5b50\u95ee\u9898\uff0c\u53ef\u80fd\u4e3a \\(f(i, m-1)\\) \u6216 \\(f(m+1, j)\\) \u3002
        3. \u5faa\u73af\u7b2c 1. \u6b65\u548c\u7b2c 2. \u6b65\uff0c\u76f4\u81f3\u627e\u5230 target \u6216\u533a\u95f4\u4e3a\u7a7a\u65f6\u8fd4\u56de\u3002

        \u56fe 12-4 \u5c55\u793a\u4e86\u5728\u6570\u7ec4\u4e2d\u4e8c\u5206\u67e5\u627e\u5143\u7d20 \\(6\\) \u7684\u5206\u6cbb\u8fc7\u7a0b\u3002

        \u56fe 12-4 \u00a0 \u4e8c\u5206\u67e5\u627e\u7684\u5206\u6cbb\u8fc7\u7a0b

        \u5728\u5b9e\u73b0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs() \u6765\u6c42\u89e3\u95ee\u9898 \\(f(i, j)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_recur.py
        def dfs(nums: list[int], target: int, i: int, j: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j)\"\"\"\n# \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j:\nreturn -1\n# \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm = (i + j) // 2\nif nums[m] < target:\n# \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j)\nelif nums[m] > target:\n# \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1)\nelse:\n# \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\ndef binary_search(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\"\"\"\nn = len(nums)\n# \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1)\n
        binary_search_recur.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(vector<int> &nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(vector<int> &nums, int target) {\nint n = nums.size();\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.java
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(int[] nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int[] nums, int target) {\nint n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.cs
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint DFS(int[] nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn DFS(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn DFS(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint BinarySearch(int[] nums, int target) {\nint n = nums.Length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn DFS(nums, target, 0, n - 1);\n}\n
        binary_search_recur.go
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunc dfs(nums []int, target, i, j int) int {\n// \u5982\u679c\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u6ca1\u6709\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j {\nreturn -1\n}\n//    \u8ba1\u7b97\u7d22\u5f15\u4e2d\u70b9\nm := i + ((j - i) >> 1)\n//\u5224\u65ad\u4e2d\u70b9\u4e0e\u76ee\u6807\u5143\u7d20\u5927\u5c0f\nif nums[m] < target {\n// \u5c0f\u4e8e\u5219\u9012\u5f52\u53f3\u534a\u6570\u7ec4\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m+1, j)\n} else if nums[m] > target {\n// \u5c0f\u4e8e\u5219\u9012\u5f52\u5de6\u534a\u6570\u7ec4\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m-1)\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums []int, target int) int {\nn := len(nums)\nreturn dfs(nums, target, 0, n-1)\n}\n
        binary_search_recur.swift
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunc dfs(nums: [Int], target: Int, i: Int, j: Int) -> Int {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j {\nreturn -1\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nlet m = (i + j) / 2\nif nums[m] < target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums: nums, target: target, i: m + 1, j: j)\n} else if nums[m] > target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums: nums, target: target, i: i, j: m - 1)\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\nlet n = nums.count\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums: nums, target: target, i: 0, j: n - 1)\n}\n
        binary_search_recur.js
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunction dfs(nums, target, i, j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = i + ((j - i) >> 1);\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums, target) {\nconst n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.ts
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfunction dfs(nums: number[], target: number, i: number, j: number): number {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = i + ((j - i) >> 1);\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums: number[], target: number): number {\nconst n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.dart
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(List<int> nums, int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) ~/ 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(List<int> nums, int target) {\nint n = nums.length;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.rs
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nfn dfs(nums: &[i32], target: i32, i: i32, j: i32) -> i32 {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif i > j { return -1; }\nlet m: i32 = (i + j) / 2;\nif nums[m as usize] < target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if nums[m as usize] > target {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\nlet n = nums.len() as i32;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\ndfs(nums, target, 0, n - 1)\n}\n
        binary_search_recur.c
        /* \u4e8c\u5206\u67e5\u627e\uff1a\u95ee\u9898 f(i, j) */\nint dfs(int nums[], int target, int i, int j) {\n// \u82e5\u533a\u95f4\u4e3a\u7a7a\uff0c\u4ee3\u8868\u65e0\u76ee\u6807\u5143\u7d20\uff0c\u5219\u8fd4\u56de -1\nif (i > j) {\nreturn -1;\n}\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nint m = (i + j) / 2;\nif (nums[m] < target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\nreturn dfs(nums, target, m + 1, j);\n} else if (nums[m] > target) {\n// \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\nreturn dfs(nums, target, i, m - 1);\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int nums[], int target, int numsSize) {\nint n = numsSize;\n// \u6c42\u89e3\u95ee\u9898 f(0, n-1)\nreturn dfs(nums, target, 0, n - 1);\n}\n
        binary_search_recur.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{binarySearch}\n
        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/","title":"12.3 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u68f5\u4e8c\u53c9\u6811\u7684\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \uff0c\u8bf7\u4ece\u4e2d\u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u8fd4\u56de\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u3002\u5047\u8bbe\u4e8c\u53c9\u6811\u4e2d\u6ca1\u6709\u503c\u91cd\u590d\u7684\u8282\u70b9\u3002

        \u56fe 12-5 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#1","title":"1. \u00a0 \u5224\u65ad\u662f\u5426\u4e3a\u5206\u6cbb\u95ee\u9898","text":"

        \u539f\u95ee\u9898\u5b9a\u4e49\u4e3a\u4ece preorder \u548c inorder \u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u662f\u4e00\u4e2a\u5178\u578b\u7684\u5206\u6cbb\u95ee\u9898\u3002

        • \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u4ece\u5206\u6cbb\u7684\u89d2\u5ea6\u5207\u5165\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u539f\u95ee\u9898\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\u3001\u6784\u5efa\u53f3\u5b50\u6811\uff0c\u52a0\u4e0a\u4e00\u6b65\u64cd\u4f5c\uff1a\u521d\u59cb\u5316\u6839\u8282\u70b9\u3002\u800c\u5bf9\u4e8e\u6bcf\u68f5\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u590d\u7528\u4ee5\u4e0a\u5212\u5206\u65b9\u6cd5\uff0c\u5c06\u5176\u5212\u5206\u4e3a\u66f4\u5c0f\u7684\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u76f4\u81f3\u8fbe\u5230\u6700\u5c0f\u5b50\u95ee\u9898\uff08\u7a7a\u5b50\u6811\uff09\u65f6\u7ec8\u6b62\u3002
        • \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u5b83\u4eec\u4e4b\u95f4\u6ca1\u6709\u4ea4\u96c6\u3002\u5728\u6784\u5efa\u5de6\u5b50\u6811\u65f6\uff0c\u6211\u4eec\u53ea\u9700\u5173\u6ce8\u4e2d\u5e8f\u904d\u5386\u548c\u524d\u5e8f\u904d\u5386\u4e2d\u4e0e\u5de6\u5b50\u6811\u5bf9\u5e94\u7684\u90e8\u5206\u3002\u53f3\u5b50\u6811\u540c\u7406\u3002
        • \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u4e00\u65e6\u5f97\u5230\u4e86\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u5b83\u4eec\u94fe\u63a5\u5230\u6839\u8282\u70b9\u4e0a\uff0c\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002
        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#2","title":"2. \u00a0 \u5982\u4f55\u5212\u5206\u5b50\u6811","text":"

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u8fd9\u9053\u9898\u53ef\u4ee5\u4f7f\u7528\u5206\u6cbb\u6765\u6c42\u89e3\uff0c\u4f46\u5982\u4f55\u901a\u8fc7\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \u6765\u5212\u5206\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u5462\uff1f

        \u6839\u636e\u5b9a\u4e49\uff0cpreorder \u548c inorder \u90fd\u53ef\u4ee5\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\u3002

        • \u524d\u5e8f\u904d\u5386\uff1a[ \u6839\u8282\u70b9 | \u5de6\u5b50\u6811 | \u53f3\u5b50\u6811 ] \uff0c\u4f8b\u5982\u56fe 12-5 \u7684\u6811\u5bf9\u5e94 [ 3 | 9 | 2 1 7 ] \u3002
        • \u4e2d\u5e8f\u904d\u5386\uff1a[ \u5de6\u5b50\u6811 | \u6839\u8282\u70b9 \uff5c \u53f3\u5b50\u6811 ] \uff0c\u4f8b\u5982\u56fe 12-5 \u7684\u6811\u5bf9\u5e94 [ 9 | 3 | 1 2 7 ] \u3002

        \u4ee5\u4e0a\u56fe\u6570\u636e\u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u56fe 12-6 \u6240\u793a\u7684\u6b65\u9aa4\u5f97\u5230\u5212\u5206\u7ed3\u679c\u3002

        1. \u524d\u5e8f\u904d\u5386\u7684\u9996\u5143\u7d20 3 \u662f\u6839\u8282\u70b9\u7684\u503c\u3002
        2. \u67e5\u627e\u6839\u8282\u70b9 3 \u5728 inorder \u4e2d\u7684\u7d22\u5f15\uff0c\u5229\u7528\u8be5\u7d22\u5f15\u53ef\u5c06 inorder \u5212\u5206\u4e3a [ 9 | 3 \uff5c 1 2 7 ] \u3002
        3. \u6839\u636e inorder \u5212\u5206\u7ed3\u679c\uff0c\u6613\u5f97\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u7684\u8282\u70b9\u6570\u91cf\u5206\u522b\u4e3a 1 \u548c 3 \uff0c\u4ece\u800c\u53ef\u5c06 preorder \u5212\u5206\u4e3a [ 3 | 9 | 2 1 7 ] \u3002

        \u56fe 12-6 \u00a0 \u5728\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u4e2d\u5212\u5206\u5b50\u6811

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#3","title":"3. \u00a0 \u57fa\u4e8e\u53d8\u91cf\u63cf\u8ff0\u5b50\u6811\u533a\u95f4","text":"

        \u6839\u636e\u4ee5\u4e0a\u5212\u5206\u65b9\u6cd5\uff0c\u6211\u4eec\u5df2\u7ecf\u5f97\u5230\u6839\u8282\u70b9\u3001\u5de6\u5b50\u6811\u3001\u53f3\u5b50\u6811\u5728 preorder \u548c inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u3002\u800c\u4e3a\u4e86\u63cf\u8ff0\u8fd9\u4e9b\u7d22\u5f15\u533a\u95f4\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u51e0\u4e2a\u6307\u9488\u53d8\u91cf\u3002

        • \u5c06\u5f53\u524d\u6811\u7684\u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15\u8bb0\u4e3a \\(i\\) \u3002
        • \u5c06\u5f53\u524d\u6811\u7684\u6839\u8282\u70b9\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u8bb0\u4e3a \\(m\\) \u3002
        • \u5c06\u5f53\u524d\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u8bb0\u4e3a \\([l, r]\\) \u3002

        \u5982\u8868 12-1 \u6240\u793a\uff0c\u901a\u8fc7\u4ee5\u4e0a\u53d8\u91cf\u5373\u53ef\u8868\u793a\u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15\uff0c\u4ee5\u53ca\u5b50\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4\u3002

        \u8868 12-1 \u00a0 \u6839\u8282\u70b9\u548c\u5b50\u6811\u5728\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u4e2d\u7684\u7d22\u5f15

        \u6839\u8282\u70b9\u5728 preorder \u4e2d\u7684\u7d22\u5f15 \u5b50\u6811\u5728 inorder \u4e2d\u7684\u7d22\u5f15\u533a\u95f4 \u5f53\u524d\u6811 \\(i\\) \\([l, r]\\) \u5de6\u5b50\u6811 \\(i + 1\\) \\([l, m-1]\\) \u53f3\u5b50\u6811 \\(i + 1 + (m - l)\\) \\([m+1, r]\\)

        \u8bf7\u6ce8\u610f\uff0c\u53f3\u5b50\u6811\u6839\u8282\u70b9\u7d22\u5f15\u4e2d\u7684 \\((m-l)\\) \u7684\u542b\u4e49\u662f\u201c\u5de6\u5b50\u6811\u7684\u8282\u70b9\u6570\u91cf\u201d\uff0c\u5efa\u8bae\u914d\u5408\u56fe 12-7 \u7406\u89e3\u3002

        \u56fe 12-7 \u00a0 \u6839\u8282\u70b9\u548c\u5de6\u53f3\u5b50\u6811\u7684\u7d22\u5f15\u533a\u95f4\u8868\u793a

        "},{"location":"chapter_divide_and_conquer/build_binary_tree_problem/#4","title":"4. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u63d0\u5347\u67e5\u8be2 \\(m\\) \u7684\u6548\u7387\uff0c\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 hmap \u6765\u5b58\u50a8\u6570\u7ec4 inorder \u4e2d\u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig build_tree.py
        def dfs(\npreorder: list[int],\ninorder_map: dict[int, int],\ni: int,\nl: int,\nr: int,\n) -> TreeNode | None:\n\"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb\"\"\"\n# \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0:\nreturn None\n# \u521d\u59cb\u5316\u6839\u8282\u70b9\nroot = TreeNode(preorder[i])\n# \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nm = inorder_map[preorder[i]]\n# \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorder_map, i + 1, l, m - 1)\n# \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r)\n# \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\ndef build_tree(preorder: list[int], inorder: list[int]) -> TreeNode | None:\n\"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\"\"\"\n# \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\ninorder_map = {val: i for i, val in enumerate(inorder)}\nroot = dfs(preorder, inorder_map, 0, 0, len(inorder) - 1)\nreturn root\n
        build_tree.cpp
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode *dfs(vector<int> &preorder, unordered_map<int, int> &inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn NULL;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode *root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot->left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nunordered_map<int, int> inorderMap;\nfor (int i = 0; i < inorder.size(); i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode *root = dfs(preorder, inorderMap, 0, 0, inorder.size() - 1);\nreturn root;\n}\n
        build_tree.java
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode dfs(int[] preorder, Map<Integer, Integer> inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode buildTree(int[] preorder, int[] inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nMap<Integer, Integer> inorderMap = new HashMap<>();\nfor (int i = 0; i < inorder.length; i++) {\ninorderMap.put(inorder[i], i);\n}\nTreeNode root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.cs
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? DFS(int[] preorder, Dictionary<int, int> inorderMap, int i, int l, int r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode root = new(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = DFS(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = DFS(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode? BuildTree(int[] preorder, int[] inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nDictionary<int, int> inorderMap = [];\nfor (int i = 0; i < inorder.Length; i++) {\ninorderMap.TryAdd(inorder[i], i);\n}\nTreeNode? root = DFS(preorder, inorderMap, 0, 0, inorder.Length - 1);\nreturn root;\n}\n
        build_tree.go
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunc dfsBuildTree(preorder []int, inorderMap map[int]int, i, l, r int) *TreeNode {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r-l < 0 {\nreturn nil\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nroot := NewTreeNode(preorder[i])\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nm := inorderMap[preorder[i]]\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.Left = dfsBuildTree(preorder, inorderMap, i+1, l, m-1)\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.Right = dfsBuildTree(preorder, inorderMap, i+1+m-l, m+1, r)\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunc buildTree(preorder, inorder []int) *TreeNode {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\ninorderMap := make(map[int]int, len(inorder))\nfor i := 0; i < len(inorder); i++ {\ninorderMap[inorder[i]] = i\n}\nroot := dfsBuildTree(preorder, inorderMap, 0, 0, len(inorder)-1)\nreturn root\n}\n
        build_tree.swift
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunc dfs(preorder: [Int], inorderMap: [Int: Int], i: Int, l: Int, r: Int) -> TreeNode? {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0 {\nreturn nil\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nlet root = TreeNode(x: preorder[i])\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nlet m = inorderMap[preorder[i]]!\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1, l: l, r: m - 1)\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1 + m - l, l: m + 1, r: r)\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunc buildTree(preorder: [Int], inorder: [Int]) -> TreeNode? {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = inorder.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }\nreturn dfs(preorder: preorder, inorderMap: inorderMap, i: 0, l: 0, r: inorder.count - 1)\n}\n
        build_tree.js
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(preorder, inorderMap, i, l, r) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) return null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nconst root = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nconst m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunction buildTree(preorder, inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = new Map();\nfor (let i = 0; i < inorder.length; i++) {\ninorderMap.set(inorder[i], i);\n}\nconst root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.ts
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(\npreorder: number[],\ninorderMap: Map<number, number>,\ni: number,\nl: number,\nr: number\n): TreeNode | null {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) return null;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nconst root: TreeNode = new TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nconst m = inorderMap.get(preorder[i]);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfunction buildTree(preorder: number[], inorder: number[]): TreeNode | null {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet inorderMap = new Map<number, number>();\nfor (let i = 0; i < inorder.length; i++) {\ninorderMap.set(inorder[i], i);\n}\nconst root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.dart
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? dfs(\nList<int> preorder,\nMap<int, int> inorderMap,\nint i,\nint l,\nint r,\n) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0) {\nreturn null;\n}\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode? root = TreeNode(preorder[i]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]]!;\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode? buildTree(List<int> preorder, List<int> inorder) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nMap<int, int> inorderMap = {};\nfor (int i = 0; i < inorder.length; i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode? root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\nreturn root;\n}\n
        build_tree.rs
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfn dfs(preorder: &[i32], inorder_map: &HashMap<i32, i32>, i: i32, l: i32, r: i32) -> Option<Rc<RefCell<TreeNode>>> {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif r - l < 0 { return None; }\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nlet root = TreeNode::new(preorder[i as usize]);\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nlet m = inorder_map.get(&preorder[i as usize]).unwrap();\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot.borrow_mut().left = dfs(preorder, inorder_map, i + 1, l, m - 1);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot.borrow_mut().right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r);\n// \u8fd4\u56de\u6839\u8282\u70b9\nSome(root)\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nfn build_tree(preorder: &[i32], inorder: &[i32]) -> Option<Rc<RefCell<TreeNode>>> {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nlet mut inorder_map: HashMap<i32, i32> = HashMap::new();\nfor i in 0..inorder.len() {\ninorder_map.insert(inorder[i], i as i32);\n}\nlet root = dfs(preorder, &inorder_map, 0, 0, inorder.len() as i32 - 1);\nroot\n}\n
        build_tree.c
        /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode *dfs(int *preorder, int *inorderMap, int i, int l, int r, int size) {\n// \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\nif (r - l < 0)\nreturn NULL;\n// \u521d\u59cb\u5316\u6839\u8282\u70b9\nTreeNode *root = (TreeNode *)malloc(sizeof(TreeNode));\nroot->val = preorder[i];\nroot->left = NULL;\nroot->right = NULL;\n// \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\nint m = inorderMap[preorder[i]];\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\nroot->left = dfs(preorder, inorderMap, i + 1, l, m - 1, size);\n// \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\nroot->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r, size);\n// \u8fd4\u56de\u6839\u8282\u70b9\nreturn root;\n}\n/* \u6784\u5efa\u4e8c\u53c9\u6811 */\nTreeNode *buildTree(int *preorder, int preorderSize, int *inorder, int inorderSize) {\n// \u521d\u59cb\u5316\u54c8\u5e0c\u8868\uff0c\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\nint *inorderMap = (int *)malloc(sizeof(int) * MAX_SIZE);\nfor (int i = 0; i < inorderSize; i++) {\ninorderMap[inorder[i]] = i;\n}\nTreeNode *root = dfs(preorder, inorderMap, 0, 0, inorderSize - 1, inorderSize);\nfree(inorderMap);\nreturn root;\n}\n
        build_tree.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{buildTree}\n

        \u56fe 12-8 \u5c55\u793a\u4e86\u6784\u5efa\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b\uff0c\u5404\u4e2a\u8282\u70b9\u662f\u5728\u5411\u4e0b\u201c\u9012\u201d\u7684\u8fc7\u7a0b\u4e2d\u5efa\u7acb\u7684\uff0c\u800c\u5404\u6761\u8fb9\uff08\u5f15\u7528\uff09\u662f\u5728\u5411\u4e0a\u201c\u5f52\u201d\u7684\u8fc7\u7a0b\u4e2d\u5efa\u7acb\u7684\u3002

        <1><2><3><4><5><6><7><8><9>

        \u56fe 12-8 \u00a0 \u6784\u5efa\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b

        \u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u5185\u7684\u524d\u5e8f\u904d\u5386 preorder \u548c\u4e2d\u5e8f\u904d\u5386 inorder \u7684\u5212\u5206\u7ed3\u679c\u5982\u56fe 12-9 \u6240\u793a\u3002

        \u56fe 12-9 \u00a0 \u6bcf\u4e2a\u9012\u5f52\u51fd\u6570\u4e2d\u7684\u5212\u5206\u7ed3\u679c

        \u8bbe\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u521d\u59cb\u5316\u6bcf\u4e00\u4e2a\u8282\u70b9\uff08\u6267\u884c\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs() \uff09\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u56e0\u6b64\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u54c8\u5e0c\u8868\u5b58\u50a8 inorder \u5143\u7d20\u5230\u7d22\u5f15\u7684\u6620\u5c04\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u9012\u5f52\u6df1\u5ea6\u8fbe\u5230 \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u7684\u6808\u5e27\u7a7a\u95f4\u3002\u56e0\u6b64\u603b\u4f53\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/","title":"12.1 \u00a0 \u5206\u6cbb\u7b97\u6cd5","text":"

        \u300c\u5206\u6cbb divide and conquer\u300d\uff0c\u5168\u79f0\u5206\u800c\u6cbb\u4e4b\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u91cd\u8981\u4e14\u5e38\u89c1\u7684\u7b97\u6cd5\u7b56\u7565\u3002\u5206\u6cbb\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\uff0c\u5305\u62ec\u201c\u5206\u201d\u548c\u201c\u6cbb\u201d\u4e24\u4e2a\u6b65\u9aa4\u3002

        1. \u5206\uff08\u5212\u5206\u9636\u6bb5\uff09\uff1a\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u4e24\u4e2a\u6216\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u5230\u8fbe\u6700\u5c0f\u5b50\u95ee\u9898\u65f6\u7ec8\u6b62\u3002
        2. \u6cbb\uff08\u5408\u5e76\u9636\u6bb5\uff09\uff1a\u4ece\u5df2\u77e5\u89e3\u7684\u6700\u5c0f\u5b50\u95ee\u9898\u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\uff0c\u4ece\u800c\u6784\u5efa\u51fa\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u5982\u56fe 12-1 \u6240\u793a\uff0c\u201c\u5f52\u5e76\u6392\u5e8f\u201d\u662f\u5206\u6cbb\u7b56\u7565\u7684\u5178\u578b\u5e94\u7528\u4e4b\u4e00\u3002

        1. \u5206\uff1a\u9012\u5f52\u5730\u5c06\u539f\u6570\u7ec4\uff08\u539f\u95ee\u9898\uff09\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\uff09\uff0c\u76f4\u5230\u5b50\u6570\u7ec4\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\uff08\u6700\u5c0f\u5b50\u95ee\u9898\uff09\u3002
        2. \u6cbb\uff1a\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u6709\u5e8f\u7684\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\u8fdb\u884c\u5408\u5e76\uff0c\u4ece\u800c\u5f97\u5230\u6709\u5e8f\u7684\u539f\u6570\u7ec4\uff08\u539f\u95ee\u9898\u7684\u89e3\uff09\u3002

        \u56fe 12-1 \u00a0 \u5f52\u5e76\u6392\u5e8f\u7684\u5206\u6cbb\u7b56\u7565

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1211","title":"12.1.1 \u00a0 \u5982\u4f55\u5224\u65ad\u5206\u6cbb\u95ee\u9898","text":"

        \u4e00\u4e2a\u95ee\u9898\u662f\u5426\u9002\u5408\u4f7f\u7528\u5206\u6cbb\u89e3\u51b3\uff0c\u901a\u5e38\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u51e0\u4e2a\u5224\u65ad\u4f9d\u636e\u3002

        1. \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u539f\u95ee\u9898\u53ef\u4ee5\u5206\u89e3\u6210\u89c4\u6a21\u66f4\u5c0f\u3001\u7c7b\u4f3c\u7684\u5b50\u95ee\u9898\uff0c\u4ee5\u53ca\u80fd\u591f\u4ee5\u76f8\u540c\u65b9\u5f0f\u9012\u5f52\u5730\u8fdb\u884c\u5212\u5206\u3002
        2. \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u5b50\u95ee\u9898\u4e4b\u95f4\u6ca1\u6709\u91cd\u53e0\uff0c\u4e92\u4e0d\u4f9d\u8d56\uff0c\u53ef\u4ee5\u72ec\u7acb\u89e3\u51b3\u3002
        3. \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u539f\u95ee\u9898\u7684\u89e3\u901a\u8fc7\u5408\u5e76\u5b50\u95ee\u9898\u7684\u89e3\u5f97\u6765\u3002

        \u663e\u7136\uff0c\u5f52\u5e76\u6392\u5e8f\u6ee1\u8db3\u4ee5\u4e0a\u4e09\u6761\u5224\u65ad\u4f9d\u636e\u3002

        1. \u95ee\u9898\u53ef\u4ee5\u5206\u89e3\uff1a\u9012\u5f52\u5730\u5c06\u6570\u7ec4\uff08\u539f\u95ee\u9898\uff09\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\uff09\u3002
        2. \u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff1a\u6bcf\u4e2a\u5b50\u6570\u7ec4\u90fd\u53ef\u4ee5\u72ec\u7acb\u5730\u8fdb\u884c\u6392\u5e8f\uff08\u5b50\u95ee\u9898\u53ef\u4ee5\u72ec\u7acb\u8fdb\u884c\u6c42\u89e3\uff09\u3002
        3. \u5b50\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u5408\u5e76\uff1a\u4e24\u4e2a\u6709\u5e8f\u5b50\u6570\u7ec4\uff08\u5b50\u95ee\u9898\u7684\u89e3\uff09\u53ef\u4ee5\u5408\u5e76\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\uff08\u539f\u95ee\u9898\u7684\u89e3\uff09\u3002
        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1212","title":"12.1.2 \u00a0 \u901a\u8fc7\u5206\u6cbb\u63d0\u5347\u6548\u7387","text":"

        \u5206\u6cbb\u4e0d\u4ec5\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u7b97\u6cd5\u95ee\u9898\uff0c\u5f80\u5f80\u8fd8\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002\u5728\u6392\u5e8f\u7b97\u6cd5\u4e2d\uff0c\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u76f8\u8f83\u4e8e\u9009\u62e9\u3001\u5192\u6ce1\u3001\u63d2\u5165\u6392\u5e8f\u66f4\u5feb\uff0c\u5c31\u662f\u56e0\u4e3a\u5b83\u4eec\u5e94\u7528\u4e86\u5206\u6cbb\u7b56\u7565\u3002

        \u90a3\u4e48\uff0c\u6211\u4eec\u4e0d\u7981\u53d1\u95ee\uff1a\u4e3a\u4ec0\u4e48\u5206\u6cbb\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\uff0c\u5176\u5e95\u5c42\u903b\u8f91\u662f\u4ec0\u4e48\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06\u5927\u95ee\u9898\u5206\u89e3\u4e3a\u591a\u4e2a\u5b50\u95ee\u9898\u3001\u89e3\u51b3\u5b50\u95ee\u9898\u3001\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u5408\u5e76\u4e3a\u539f\u95ee\u9898\u7684\u89e3\uff0c\u8fd9\u51e0\u6b65\u7684\u6548\u7387\u4e3a\u4ec0\u4e48\u6bd4\u76f4\u63a5\u89e3\u51b3\u539f\u95ee\u9898\u7684\u6548\u7387\u66f4\u9ad8\uff1f\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u4ece\u64cd\u4f5c\u6570\u91cf\u548c\u5e76\u884c\u8ba1\u7b97\u4e24\u65b9\u9762\u6765\u8ba8\u8bba\u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1","title":"1. \u00a0 \u64cd\u4f5c\u6570\u91cf\u4f18\u5316","text":"

        \u4ee5\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u4e3a\u4f8b\uff0c\u5176\u5904\u7406\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\u9700\u8981 \\(O(n^2)\\) \u65f6\u95f4\u3002\u5047\u8bbe\u6211\u4eec\u6309\u7167\u56fe 12-2 \u6240\u793a\u7684\u65b9\u5f0f\uff0c\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u5219\u5212\u5206\u9700\u8981 \\(O(n)\\) \u65f6\u95f4\uff0c\u6392\u5e8f\u6bcf\u4e2a\u5b50\u6570\u7ec4\u9700\u8981 \\(O((n / 2)^2)\\) \u65f6\u95f4\uff0c\u5408\u5e76\u4e24\u4e2a\u5b50\u6570\u7ec4\u9700\u8981 \\(O(n)\\) \u65f6\u95f4\uff0c\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\uff1a

        \\[ O(n + (\\frac{n}{2})^2 \\times 2 + n) = O(\\frac{n^2}{2} + 2n) \\]

        \u56fe 12-2 \u00a0 \u5212\u5206\u6570\u7ec4\u524d\u540e\u7684\u5192\u6ce1\u6392\u5e8f

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8ba1\u7b97\u4ee5\u4e0b\u4e0d\u7b49\u5f0f\uff0c\u5176\u5de6\u8fb9\u548c\u53f3\u8fb9\u5206\u522b\u4e3a\u5212\u5206\u524d\u548c\u5212\u5206\u540e\u7684\u64cd\u4f5c\u603b\u6570\uff1a

        \\[ \\begin{aligned} n^2 & > \\frac{n^2}{2} + 2n \\newline n^2 - \\frac{n^2}{2} - 2n & > 0 \\newline n(n - 4) & > 0 \\end{aligned} \\]

        \u8fd9\u610f\u5473\u7740\u5f53 \\(n > 4\\) \u65f6\uff0c\u5212\u5206\u540e\u7684\u64cd\u4f5c\u6570\u91cf\u66f4\u5c11\uff0c\u6392\u5e8f\u6548\u7387\u5e94\u8be5\u66f4\u9ad8\u3002\u8bf7\u6ce8\u610f\uff0c\u5212\u5206\u540e\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u7136\u662f\u5e73\u65b9\u9636 \\(O(n^2)\\) \uff0c\u53ea\u662f\u590d\u6742\u5ea6\u4e2d\u7684\u5e38\u6570\u9879\u53d8\u5c0f\u4e86\u3002

        \u8fdb\u4e00\u6b65\u60f3\uff0c\u5982\u679c\u6211\u4eec\u628a\u5b50\u6570\u7ec4\u4e0d\u65ad\u5730\u518d\u4ece\u4e2d\u70b9\u5904\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\u65f6\u505c\u6b62\u5212\u5206\u5462\uff1f\u8fd9\u79cd\u601d\u8def\u5b9e\u9645\u4e0a\u5c31\u662f\u201c\u5f52\u5e76\u6392\u5e8f\u201d\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u518d\u601d\u8003\uff0c\u5982\u679c\u6211\u4eec\u591a\u8bbe\u7f6e\u51e0\u4e2a\u5212\u5206\u70b9\uff0c\u5c06\u539f\u6570\u7ec4\u5e73\u5747\u5212\u5206\u4e3a \\(k\\) \u4e2a\u5b50\u6570\u7ec4\u5462\uff1f\u8fd9\u79cd\u60c5\u51b5\u4e0e\u201c\u6876\u6392\u5e8f\u201d\u975e\u5e38\u7c7b\u4f3c\uff0c\u5b83\u975e\u5e38\u9002\u5408\u6392\u5e8f\u6d77\u91cf\u6570\u636e\uff0c\u7406\u8bba\u4e0a\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230 \\(O(n + k)\\) \u3002

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#2","title":"2. \u00a0 \u5e76\u884c\u8ba1\u7b97\u4f18\u5316","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u5206\u6cbb\u751f\u6210\u7684\u5b50\u95ee\u9898\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u56e0\u6b64\u901a\u5e38\u53ef\u4ee5\u5e76\u884c\u89e3\u51b3\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5206\u6cbb\u4e0d\u4ec5\u53ef\u4ee5\u964d\u4f4e\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u8fd8\u6709\u5229\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e76\u884c\u4f18\u5316\u3002

        \u5e76\u884c\u4f18\u5316\u5728\u591a\u6838\u6216\u591a\u5904\u7406\u5668\u7684\u73af\u5883\u4e2d\u5c24\u5176\u6709\u6548\uff0c\u56e0\u4e3a\u7cfb\u7edf\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u5b50\u95ee\u9898\uff0c\u66f4\u52a0\u5145\u5206\u5730\u5229\u7528\u8ba1\u7b97\u8d44\u6e90\uff0c\u4ece\u800c\u663e\u8457\u51cf\u5c11\u603b\u4f53\u7684\u8fd0\u884c\u65f6\u95f4\u3002

        \u6bd4\u5982\u5728\u56fe 12-3 \u6240\u793a\u7684\u201c\u6876\u6392\u5e8f\u201d\u4e2d\uff0c\u6211\u4eec\u5c06\u6d77\u91cf\u7684\u6570\u636e\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff0c\u5219\u53ef\u6240\u6709\u6876\u7684\u6392\u5e8f\u4efb\u52a1\u5206\u6563\u5230\u5404\u4e2a\u8ba1\u7b97\u5355\u5143\uff0c\u5b8c\u6210\u540e\u518d\u5408\u5e76\u7ed3\u679c\u3002

        \u56fe 12-3 \u00a0 \u6876\u6392\u5e8f\u7684\u5e76\u884c\u8ba1\u7b97

        "},{"location":"chapter_divide_and_conquer/divide_and_conquer/#1213","title":"12.1.3 \u00a0 \u5206\u6cbb\u5e38\u89c1\u5e94\u7528","text":"

        \u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u53ef\u4ee5\u7528\u6765\u89e3\u51b3\u8bb8\u591a\u7ecf\u5178\u7b97\u6cd5\u95ee\u9898\u3002

        • \u5bfb\u627e\u6700\u8fd1\u70b9\u5bf9\uff1a\u8be5\u7b97\u6cd5\u9996\u5148\u5c06\u70b9\u96c6\u5206\u6210\u4e24\u90e8\u5206\uff0c\u7136\u540e\u5206\u522b\u627e\u51fa\u4e24\u90e8\u5206\u4e2d\u7684\u6700\u8fd1\u70b9\u5bf9\uff0c\u6700\u540e\u627e\u51fa\u8de8\u8d8a\u4e24\u90e8\u5206\u7684\u6700\u8fd1\u70b9\u5bf9\u3002
        • \u5927\u6574\u6570\u4e58\u6cd5\uff1a\u4f8b\u5982 Karatsuba \u7b97\u6cd5\uff0c\u5b83\u5c06\u5927\u6574\u6570\u4e58\u6cd5\u5206\u89e3\u4e3a\u51e0\u4e2a\u8f83\u5c0f\u7684\u6574\u6570\u7684\u4e58\u6cd5\u548c\u52a0\u6cd5\u3002
        • \u77e9\u9635\u4e58\u6cd5\uff1a\u4f8b\u5982 Strassen \u7b97\u6cd5\uff0c\u5b83\u5c06\u5927\u77e9\u9635\u4e58\u6cd5\u5206\u89e3\u4e3a\u591a\u4e2a\u5c0f\u77e9\u9635\u7684\u4e58\u6cd5\u548c\u52a0\u6cd5\u3002
        • \u6c49\u8bfa\u5854\u95ee\u9898\uff1a\u6c49\u8bfa\u5854\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u89e3\u51b3\uff0c\u8fd9\u662f\u5178\u578b\u7684\u5206\u6cbb\u7b56\u7565\u5e94\u7528\u3002
        • \u6c42\u89e3\u9006\u5e8f\u5bf9\uff1a\u5728\u4e00\u4e2a\u5e8f\u5217\u4e2d\uff0c\u5982\u679c\u524d\u9762\u7684\u6570\u5b57\u5927\u4e8e\u540e\u9762\u7684\u6570\u5b57\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u6570\u5b57\u6784\u6210\u4e00\u4e2a\u9006\u5e8f\u5bf9\u3002\u6c42\u89e3\u9006\u5e8f\u5bf9\u95ee\u9898\u53ef\u4ee5\u5229\u7528\u5206\u6cbb\u7684\u601d\u60f3\uff0c\u501f\u52a9\u5f52\u5e76\u6392\u5e8f\u8fdb\u884c\u6c42\u89e3\u3002

        \u53e6\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u5728\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u7684\u8bbe\u8ba1\u4e2d\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\u3002

        • \u4e8c\u5206\u67e5\u627e\uff1a\u4e8c\u5206\u67e5\u627e\u662f\u5c06\u6709\u5e8f\u6570\u7ec4\u4ece\u4e2d\u70b9\u7d22\u5f15\u5904\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u7136\u540e\u6839\u636e\u76ee\u6807\u503c\u4e0e\u4e2d\u95f4\u5143\u7d20\u503c\u6bd4\u8f83\u7ed3\u679c\uff0c\u51b3\u5b9a\u6392\u9664\u54ea\u4e00\u534a\u533a\u95f4\uff0c\u5e76\u5728\u5269\u4f59\u533a\u95f4\u6267\u884c\u76f8\u540c\u7684\u4e8c\u5206\u64cd\u4f5c\u3002
        • \u5f52\u5e76\u6392\u5e8f\uff1a\u672c\u8282\u5f00\u5934\u5df2\u4ecb\u7ecd\uff0c\u4e0d\u518d\u8d58\u8ff0\u3002
        • \u5feb\u901f\u6392\u5e8f\uff1a\u5feb\u901f\u6392\u5e8f\u662f\u9009\u53d6\u4e00\u4e2a\u57fa\u51c6\u503c\uff0c\u7136\u540e\u628a\u6570\u7ec4\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u4e00\u4e2a\u5b50\u6570\u7ec4\u7684\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5c0f\uff0c\u53e6\u4e00\u5b50\u6570\u7ec4\u7684\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5927\uff0c\u518d\u5bf9\u8fd9\u4e24\u90e8\u5206\u8fdb\u884c\u76f8\u540c\u7684\u5212\u5206\u64cd\u4f5c\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u53ea\u5269\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002
        • \u6876\u6392\u5e8f\uff1a\u6876\u6392\u5e8f\u7684\u57fa\u672c\u601d\u60f3\u662f\u5c06\u6570\u636e\u5206\u6563\u5230\u591a\u4e2a\u6876\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u6876\u5185\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u540e\u5c06\u5404\u4e2a\u6876\u7684\u5143\u7d20\u4f9d\u6b21\u53d6\u51fa\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002
        • \u6811\uff1a\u4f8b\u5982\u4e8c\u53c9\u641c\u7d22\u6811\u3001AVL \u6811\u3001\u7ea2\u9ed1\u6811\u3001B \u6811\u3001B+ \u6811\u7b49\uff0c\u5b83\u4eec\u7684\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u7b49\u64cd\u4f5c\u90fd\u53ef\u4ee5\u89c6\u4e3a\u5206\u6cbb\u7b56\u7565\u7684\u5e94\u7528\u3002
        • \u5806\uff1a\u5806\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u5176\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u63d2\u5165\u3001\u5220\u9664\u548c\u5806\u5316\uff0c\u5b9e\u9645\u4e0a\u90fd\u9690\u542b\u4e86\u5206\u6cbb\u7684\u601d\u60f3\u3002
        • \u54c8\u5e0c\u8868\uff1a\u867d\u7136\u54c8\u5e0c\u8868\u6765\u5e76\u4e0d\u76f4\u63a5\u5e94\u7528\u5206\u6cbb\uff0c\u4f46\u67d0\u4e9b\u54c8\u5e0c\u51b2\u7a81\u89e3\u51b3\u65b9\u6848\u95f4\u63a5\u5e94\u7528\u4e86\u5206\u6cbb\u7b56\u7565\uff0c\u4f8b\u5982\uff0c\u94fe\u5f0f\u5730\u5740\u4e2d\u7684\u957f\u94fe\u8868\u4f1a\u88ab\u8f6c\u5316\u4e3a\u7ea2\u9ed1\u6811\uff0c\u4ee5\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002

        \u53ef\u4ee5\u770b\u51fa\uff0c\u5206\u6cbb\u662f\u4e00\u79cd\u201c\u6da6\u7269\u7ec6\u65e0\u58f0\u201d\u7684\u7b97\u6cd5\u601d\u60f3\uff0c\u9690\u542b\u5728\u5404\u79cd\u7b97\u6cd5\u4e0e\u6570\u636e\u7ed3\u6784\u4e4b\u4e2d\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/","title":"12.4 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898","text":"

        \u5728\u5f52\u5e76\u6392\u5e8f\u548c\u6784\u5efa\u4e8c\u53c9\u6811\u4e2d\uff0c\u6211\u4eec\u90fd\u662f\u5c06\u539f\u95ee\u9898\u5206\u89e3\u4e3a\u4e24\u4e2a\u89c4\u6a21\u4e3a\u539f\u95ee\u9898\u4e00\u534a\u7684\u5b50\u95ee\u9898\u3002\u7136\u800c\u5bf9\u4e8e\u6c49\u8bfa\u5854\u95ee\u9898\uff0c\u6211\u4eec\u91c7\u7528\u4e0d\u540c\u7684\u5206\u89e3\u7b56\u7565\u3002

        Question

        \u7ed9\u5b9a\u4e09\u6839\u67f1\u5b50\uff0c\u8bb0\u4e3a A\u3001B \u548c C \u3002\u8d77\u59cb\u72b6\u6001\u4e0b\uff0c\u67f1\u5b50 A \u4e0a\u5957\u7740 \\(n\\) \u4e2a\u5706\u76d8\uff0c\u5b83\u4eec\u4ece\u4e0a\u5230\u4e0b\u6309\u7167\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u6392\u5217\u3002\u6211\u4eec\u7684\u4efb\u52a1\u662f\u8981\u628a\u8fd9 \\(n\\) \u4e2a\u5706\u76d8\u79fb\u5230\u67f1\u5b50 C \u4e0a\uff0c\u5e76\u4fdd\u6301\u5b83\u4eec\u7684\u539f\u6709\u987a\u5e8f\u4e0d\u53d8\uff08\u5982\u56fe 12-10 \u6240\u793a\uff09\u3002\u5728\u79fb\u52a8\u5706\u76d8\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219\u3002

        1. \u5706\u76d8\u53ea\u80fd\u4ece\u4e00\u6839\u67f1\u5b50\u9876\u90e8\u62ff\u51fa\uff0c\u4ece\u53e6\u4e00\u6839\u67f1\u5b50\u9876\u90e8\u653e\u5165\u3002
        2. \u6bcf\u6b21\u53ea\u80fd\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\u3002
        3. \u5c0f\u5706\u76d8\u5fc5\u987b\u65f6\u523b\u4f4d\u4e8e\u5927\u5706\u76d8\u4e4b\u4e0a\u3002

        \u56fe 12-10 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898\u793a\u4f8b

        \u6211\u4eec\u5c06\u89c4\u6a21\u4e3a \\(i\\) \u7684\u6c49\u8bfa\u5854\u95ee\u9898\u8bb0\u4f5c \\(f(i)\\) \u3002\u4f8b\u5982 \\(f(3)\\) \u4ee3\u8868\u5c06 \\(3\\) \u4e2a\u5706\u76d8\u4ece A \u79fb\u52a8\u81f3 C \u7684\u6c49\u8bfa\u5854\u95ee\u9898\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#1","title":"1. \u00a0 \u8003\u8651\u57fa\u672c\u60c5\u51b5","text":"

        \u5982\u56fe 12-11 \u6240\u793a\uff0c\u5bf9\u4e8e\u95ee\u9898 \\(f(1)\\) \uff0c\u5373\u5f53\u53ea\u6709\u4e00\u4e2a\u5706\u76d8\u65f6\uff0c\u6211\u4eec\u5c06\u5b83\u76f4\u63a5\u4ece A \u79fb\u52a8\u81f3 C \u5373\u53ef\u3002

        <1><2>

        \u56fe 12-11 \u00a0 \u89c4\u6a21\u4e3a 1 \u95ee\u9898\u7684\u89e3

        \u5982\u56fe 12-12 \u6240\u793a\uff0c\u5bf9\u4e8e\u95ee\u9898 \\(f(2)\\) \uff0c\u5373\u5f53\u6709\u4e24\u4e2a\u5706\u76d8\u65f6\uff0c\u7531\u4e8e\u8981\u65f6\u523b\u6ee1\u8db3\u5c0f\u5706\u76d8\u5728\u5927\u5706\u76d8\u4e4b\u4e0a\uff0c\u56e0\u6b64\u9700\u8981\u501f\u52a9 B \u6765\u5b8c\u6210\u79fb\u52a8\u3002

        1. \u5148\u5c06\u4e0a\u9762\u7684\u5c0f\u5706\u76d8\u4ece A \u79fb\u81f3 B \u3002
        2. \u518d\u5c06\u5927\u5706\u76d8\u4ece A \u79fb\u81f3 C \u3002
        3. \u6700\u540e\u5c06\u5c0f\u5706\u76d8\u4ece B \u79fb\u81f3 C \u3002
        <1><2><3><4>

        \u56fe 12-12 \u00a0 \u89c4\u6a21\u4e3a 2 \u95ee\u9898\u7684\u89e3

        \u89e3\u51b3\u95ee\u9898 \\(f(2)\\) \u7684\u8fc7\u7a0b\u53ef\u603b\u7ed3\u4e3a\uff1a\u5c06\u4e24\u4e2a\u5706\u76d8\u501f\u52a9 B \u4ece A \u79fb\u81f3 C \u3002\u5176\u4e2d\uff0cC \u79f0\u4e3a\u76ee\u6807\u67f1\u3001B \u79f0\u4e3a\u7f13\u51b2\u67f1\u3002

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#2","title":"2. \u00a0 \u5b50\u95ee\u9898\u5206\u89e3","text":"

        \u5bf9\u4e8e\u95ee\u9898 \\(f(3)\\) \uff0c\u5373\u5f53\u6709\u4e09\u4e2a\u5706\u76d8\u65f6\uff0c\u60c5\u51b5\u53d8\u5f97\u7a0d\u5fae\u590d\u6742\u4e86\u4e00\u4e9b\u3002

        \u56e0\u4e3a\u5df2\u77e5 \\(f(1)\\) \u548c \\(f(2)\\) \u7684\u89e3\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ece\u5206\u6cbb\u89d2\u5ea6\u601d\u8003\uff0c\u5c06 A \u9876\u90e8\u7684\u4e24\u4e2a\u5706\u76d8\u770b\u4f5c\u4e00\u4e2a\u6574\u4f53\uff0c\u6267\u884c\u56fe 12-13 \u6240\u793a\u7684\u6b65\u9aa4\u3002\u8fd9\u6837\u4e09\u4e2a\u5706\u76d8\u5c31\u88ab\u987a\u5229\u5730\u4ece A \u79fb\u81f3 C \u4e86\u3002

        1. \u4ee4 B \u4e3a\u76ee\u6807\u67f1\u3001C \u4e3a\u7f13\u51b2\u67f1\uff0c\u5c06\u4e24\u4e2a\u5706\u76d8\u4ece A \u79fb\u81f3 B \u3002
        2. \u5c06 A \u4e2d\u5269\u4f59\u7684\u4e00\u4e2a\u5706\u76d8\u4ece A \u76f4\u63a5\u79fb\u52a8\u81f3 C \u3002
        3. \u4ee4 C \u4e3a\u76ee\u6807\u67f1\u3001A \u4e3a\u7f13\u51b2\u67f1\uff0c\u5c06\u4e24\u4e2a\u5706\u76d8\u4ece B \u79fb\u81f3 C \u3002
        <1><2><3><4>

        \u56fe 12-13 \u00a0 \u89c4\u6a21\u4e3a 3 \u95ee\u9898\u7684\u89e3

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u6211\u4eec\u5c06\u95ee\u9898 \\(f(3)\\) \u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(2)\\) \u548c\u5b50\u95ee\u9898 \\(f(1)\\) \u3002\u6309\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u4e4b\u540e\uff0c\u539f\u95ee\u9898\u968f\u4e4b\u5f97\u5230\u89e3\u51b3\u3002\u8fd9\u8bf4\u660e\u5b50\u95ee\u9898\u662f\u72ec\u7acb\u7684\uff0c\u800c\u4e14\u89e3\u53ef\u4ee5\u5408\u5e76\u3002

        \u81f3\u6b64\uff0c\u6211\u4eec\u53ef\u603b\u7ed3\u51fa\u56fe 12-14 \u6240\u793a\u7684\u89e3\u51b3\u6c49\u8bfa\u5854\u95ee\u9898\u7684\u5206\u6cbb\u7b56\u7565\uff1a\u5c06\u539f\u95ee\u9898 \\(f(n)\\) \u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(n-1)\\) \u548c\u4e00\u4e2a\u5b50\u95ee\u9898 \\(f(1)\\) \uff0c\u5e76\u6309\u7167\u4ee5\u4e0b\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u3002

        1. \u5c06 \\(n-1\\) \u4e2a\u5706\u76d8\u501f\u52a9 C \u4ece A \u79fb\u81f3 B \u3002
        2. \u5c06\u5269\u4f59 \\(1\\) \u4e2a\u5706\u76d8\u4ece A \u76f4\u63a5\u79fb\u81f3 C \u3002
        3. \u5c06 \\(n-1\\) \u4e2a\u5706\u76d8\u501f\u52a9 A \u4ece B \u79fb\u81f3 C \u3002

        \u5bf9\u4e8e\u8fd9\u4e24\u4e2a\u5b50\u95ee\u9898 \\(f(n-1)\\) \uff0c\u53ef\u4ee5\u901a\u8fc7\u76f8\u540c\u7684\u65b9\u5f0f\u8fdb\u884c\u9012\u5f52\u5212\u5206\uff0c\u76f4\u81f3\u8fbe\u5230\u6700\u5c0f\u5b50\u95ee\u9898 \\(f(1)\\) \u3002\u800c \\(f(1)\\) \u7684\u89e3\u662f\u5df2\u77e5\u7684\uff0c\u53ea\u9700\u4e00\u6b21\u79fb\u52a8\u64cd\u4f5c\u5373\u53ef\u3002

        \u56fe 12-14 \u00a0 \u89e3\u51b3\u6c49\u8bfa\u5854\u95ee\u9898\u7684\u5206\u6cbb\u7b56\u7565

        "},{"location":"chapter_divide_and_conquer/hanota_problem/#3","title":"3. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5728\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u9012\u5f52\u51fd\u6570 dfs(i, src, buf, tar) \uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5c06\u67f1 src \u9876\u90e8\u7684 \\(i\\) \u4e2a\u5706\u76d8\u501f\u52a9\u7f13\u51b2\u67f1 buf \u79fb\u52a8\u81f3\u76ee\u6807\u67f1 tar \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hanota.py
        def move(src: list[int], tar: list[int]):\n\"\"\"\u79fb\u52a8\u4e00\u4e2a\u5706\u76d8\"\"\"\n# \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\npan = src.pop()\n# \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.append(pan)\ndef dfs(i: int, src: list[int], buf: list[int], tar: list[int]):\n\"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i)\"\"\"\n# \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1:\nmove(src, tar)\nreturn\n# \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf)\n# \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar)\n# \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar)\ndef solve_hanota(A: list[int], B: list[int], C: list[int]):\n\"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898\"\"\"\nn = len(A)\n# \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C)\n
        hanota.cpp
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(vector<int> &src, vector<int> &tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src.back();\nsrc.pop_back();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push_back(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, vector<int> &src, vector<int> &buf, vector<int> &tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(vector<int> &A, vector<int> &B, vector<int> &C) {\nint n = A.size();\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.java
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(List<Integer> src, List<Integer> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nInteger pan = src.remove(src.size() - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, List<Integer> src, List<Integer> buf, List<Integer> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<Integer> A, List<Integer> B, List<Integer> C) {\nint n = A.size();\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.cs
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid Move(List<int> src, List<int> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src[^1];\nsrc.RemoveAt(src.Count - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.Add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid DFS(int i, List<int> src, List<int> buf, List<int> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nMove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\nDFS(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nMove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\nDFS(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid SolveHanota(List<int> A, List<int> B, List<int> C) {\nint n = A.Count;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\nDFS(n, A, B, C);\n}\n
        hanota.go
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunc move(src, tar *list.List) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\npan := src.Back()\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.PushBack(pan.Value)\n// \u79fb\u9664 src \u9876\u90e8\u5706\u76d8\nsrc.Remove(pan)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunc dfsHanota(i int, src, buf, tar *list.List) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove(src, tar)\nreturn\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfsHanota(i-1, src, tar, buf)\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar)\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfsHanota(i-1, buf, src, tar)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A, B, C *list.List) {\nn := A.Len()\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfsHanota(n, A, B, C)\n}\n
        hanota.swift
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunc move(src: inout [Int], tar: inout [Int]) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nlet pan = src.popLast()!\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.append(pan)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunc dfs(i: Int, src: inout [Int], buf: inout [Int], tar: inout [Int]) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove(src: &src, tar: &tar)\nreturn\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i: i - 1, src: &src, buf: &tar, tar: &buf)\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src: &src, tar: &tar)\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i: i - 1, src: &buf, buf: &src, tar: &tar)\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A: inout [Int], B: inout [Int], C: inout [Int]) {\nlet n = A.count\n// \u5217\u8868\u5c3e\u90e8\u662f\u67f1\u5b50\u9876\u90e8\n// \u5c06 src \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(i: n, src: &A, buf: &B, tar: &C)\n}\n
        hanota.js
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunction move(src, tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nconst pan = src.pop();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunction dfs(i, src, buf, tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i === 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A, B, C) {\nconst n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.ts
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfunction move(src: number[], tar: number[]): void {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nconst pan = src.pop();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfunction dfs(i: number, src: number[], buf: number[], tar: number[]): void {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i === 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A: number[], B: number[], C: number[]): void {\nconst n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.dart
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(List<int> src, List<int> tar) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src.removeLast();\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.add(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, List<int> src, List<int> buf, List<int> tar) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<int> A, List<int> B, List<int> C) {\nint n = A.length;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.rs
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nfn move_pan(src: &mut Vec<i32>, tar: &mut Vec<i32>) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nlet pan = src.remove(src.len() - 1);\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar.push(pan);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nfn dfs(i: i32, src: &mut Vec<i32>, buf: &mut Vec<i32>, tar: &mut Vec<i32>) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif i == 1 {\nmove_pan(src, tar);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, tar, buf);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove_pan(src, tar);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, src, tar);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfn solve_hanota(A: &mut Vec<i32>, B: &mut Vec<i32>, C: &mut Vec<i32>) {\nlet n = A.len() as i32;\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(n, A, B, C);\n}\n
        hanota.c
        /* \u79fb\u52a8\u4e00\u4e2a\u5706\u76d8 */\nvoid move(int *src, int *srcSize, int *tar, int *tarSize) {\n// \u4ece src \u9876\u90e8\u62ff\u51fa\u4e00\u4e2a\u5706\u76d8\nint pan = src[*srcSize - 1];\nsrc[*srcSize - 1] = 0;\n(*srcSize)--;\n// \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\ntar[*tarSize] = pan;\n(*tarSize)++;\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 f(i) */\nvoid dfs(int i, int *src, int *srcSize, int *buf, int *bufSize, int *tar, int *tarSize) {\n// \u82e5 src \u53ea\u5269\u4e0b\u4e00\u4e2a\u5706\u76d8\uff0c\u5219\u76f4\u63a5\u5c06\u5176\u79fb\u5230 tar\nif (i == 1) {\nmove(src, srcSize, tar, tarSize);\nreturn;\n}\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\ndfs(i - 1, src, srcSize, tar, tarSize, buf, bufSize);\n// \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\nmove(src, srcSize, tar, tarSize);\n// \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 buf \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 src \u79fb\u5230 tar\ndfs(i - 1, buf, bufSize, src, srcSize, tar, tarSize);\n}\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(int *A, int *ASize, int *B, int *BSize, int *C, int *CSize) {\n// \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\ndfs(*ASize, A, ASize, B, BSize, C, CSize);\n}\n
        hanota.zig
        [class]{}-[func]{move}\n[class]{}-[func]{dfs}\n[class]{}-[func]{solveHanota}\n

        \u5982\u56fe 12-15 \u6240\u793a\uff0c\u6c49\u8bfa\u5854\u95ee\u9898\u5f62\u6210\u4e00\u68f5\u9ad8\u5ea6\u4e3a \\(n\\) \u7684\u9012\u5f52\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u5bf9\u5e94\u4e00\u4e2a\u5f00\u542f\u7684 dfs() \u51fd\u6570\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u56fe 12-15 \u00a0 \u6c49\u8bfa\u5854\u95ee\u9898\u7684\u9012\u5f52\u6811

        Quote

        \u6c49\u8bfa\u5854\u95ee\u9898\u6e90\u81ea\u4e00\u4e2a\u53e4\u8001\u7684\u4f20\u8bf4\u3002\u5728\u53e4\u5370\u5ea6\u7684\u4e00\u4e2a\u5bfa\u5e99\u91cc\uff0c\u50e7\u4fa3\u4eec\u6709\u4e09\u6839\u9ad8\u5927\u7684\u94bb\u77f3\u67f1\u5b50\uff0c\u4ee5\u53ca \\(64\\) \u4e2a\u5927\u5c0f\u4e0d\u4e00\u7684\u91d1\u5706\u76d8\u3002\u50e7\u4fa3\u4eec\u4e0d\u65ad\u5730\u79fb\u52a8\u5706\u76d8\uff0c\u4ed6\u4eec\u76f8\u4fe1\u5728\u6700\u540e\u4e00\u4e2a\u5706\u76d8\u88ab\u6b63\u786e\u653e\u7f6e\u7684\u90a3\u4e00\u523b\uff0c\u8fd9\u4e2a\u4e16\u754c\u5c31\u4f1a\u7ed3\u675f\u3002

        \u7136\u800c\uff0c\u5373\u4f7f\u50e7\u4fa3\u4eec\u6bcf\u79d2\u949f\u79fb\u52a8\u4e00\u6b21\uff0c\u603b\u5171\u9700\u8981\u5927\u7ea6 \\(2^{64} \\approx 1.84\u00d710^{19}\\) \u79d2\uff0c\u5408\u7ea6 \\(5850\\) \u4ebf\u5e74\uff0c\u8fdc\u8fdc\u8d85\u8fc7\u4e86\u73b0\u5728\u5bf9\u5b87\u5b99\u5e74\u9f84\u7684\u4f30\u8ba1\u3002\u6240\u4ee5\uff0c\u5018\u82e5\u8fd9\u4e2a\u4f20\u8bf4\u662f\u771f\u7684\uff0c\u6211\u4eec\u5e94\u8be5\u4e0d\u9700\u8981\u62c5\u5fc3\u4e16\u754c\u672b\u65e5\u7684\u5230\u6765\u3002

        "},{"location":"chapter_divide_and_conquer/summary/","title":"12.5 \u00a0 \u5c0f\u7ed3","text":"
        • \u5206\u6cbb\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u7b97\u6cd5\u8bbe\u8ba1\u7b56\u7565\uff0c\u5305\u62ec\u5206\uff08\u5212\u5206\uff09\u548c\u6cbb\uff08\u5408\u5e76\uff09\u4e24\u4e2a\u9636\u6bb5\uff0c\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\u3002
        • \u5224\u65ad\u662f\u5426\u662f\u5206\u6cbb\u7b97\u6cd5\u95ee\u9898\u7684\u4f9d\u636e\u5305\u62ec\uff1a\u95ee\u9898\u80fd\u5426\u5206\u89e3\u3001\u5b50\u95ee\u9898\u662f\u5426\u72ec\u7acb\u3001\u5b50\u95ee\u9898\u80fd\u5426\u5408\u5e76\u3002
        • \u5f52\u5e76\u6392\u5e8f\u662f\u5206\u6cbb\u7b56\u7565\u7684\u5178\u578b\u5e94\u7528\uff0c\u5176\u9012\u5f52\u5730\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u7b49\u957f\u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u76f4\u5230\u53ea\u5269\u4e00\u4e2a\u5143\u7d20\u65f6\u5f00\u59cb\u9010\u5c42\u5408\u5e76\uff0c\u4ece\u800c\u5b8c\u6210\u6392\u5e8f\u3002
        • \u5f15\u5165\u5206\u6cbb\u7b56\u7565\u5f80\u5f80\u53ef\u4ee5\u63d0\u5347\u7b97\u6cd5\u6548\u7387\u3002\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u7b56\u7565\u51cf\u5c11\u4e86\u64cd\u4f5c\u6570\u91cf\uff1b\u53e6\u4e00\u65b9\u9762\uff0c\u5206\u6cbb\u540e\u6709\u5229\u4e8e\u7cfb\u7edf\u7684\u5e76\u884c\u4f18\u5316\u3002
        • \u5206\u6cbb\u65e2\u53ef\u4ee5\u89e3\u51b3\u8bb8\u591a\u7b97\u6cd5\u95ee\u9898\uff0c\u4e5f\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u8bbe\u8ba1\u4e2d\uff0c\u5904\u5904\u53ef\u89c1\u5176\u8eab\u5f71\u3002
        • \u76f8\u8f83\u4e8e\u66b4\u529b\u641c\u7d22\uff0c\u81ea\u9002\u5e94\u641c\u7d22\u6548\u7387\u66f4\u9ad8\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u7684\u641c\u7d22\u7b97\u6cd5\u901a\u5e38\u662f\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u5b9e\u73b0\u7684\u3002
        • \u4e8c\u5206\u67e5\u627e\u662f\u5206\u6cbb\u7b56\u7565\u7684\u53e6\u4e00\u4e2a\u5178\u578b\u5e94\u7528\uff0c\u5b83\u4e0d\u5305\u542b\u5c06\u5b50\u95ee\u9898\u7684\u89e3\u8fdb\u884c\u5408\u5e76\u7684\u6b65\u9aa4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u9012\u5f52\u5206\u6cbb\u5b9e\u73b0\u4e8c\u5206\u67e5\u627e\u3002
        • \u5728\u6784\u5efa\u4e8c\u53c9\u6811\u7684\u95ee\u9898\u4e2d\uff0c\u6784\u5efa\u6811\uff08\u539f\u95ee\u9898\uff09\u53ef\u4ee5\u5212\u5206\u4e3a\u6784\u5efa\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\uff08\u5b50\u95ee\u9898\uff09\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5212\u5206\u524d\u5e8f\u904d\u5386\u548c\u4e2d\u5e8f\u904d\u5386\u7684\u7d22\u5f15\u533a\u95f4\u6765\u5b9e\u73b0\u3002
        • \u5728\u6c49\u8bfa\u5854\u95ee\u9898\u4e2d\uff0c\u4e00\u4e2a\u89c4\u6a21\u4e3a \\(n\\) \u7684\u95ee\u9898\u53ef\u4ee5\u5212\u5206\u4e3a\u4e24\u4e2a\u89c4\u6a21\u4e3a \\(n-1\\) \u7684\u5b50\u95ee\u9898\u548c\u4e00\u4e2a\u89c4\u6a21\u4e3a \\(1\\) \u7684\u5b50\u95ee\u9898\u3002\u6309\u987a\u5e8f\u89e3\u51b3\u8fd9\u4e09\u4e2a\u5b50\u95ee\u9898\u540e\uff0c\u539f\u95ee\u9898\u968f\u4e4b\u5f97\u5230\u89e3\u51b3\u3002
        "},{"location":"chapter_dynamic_programming/","title":"\u7b2c 14 \u7ae0 \u00a0 \u52a8\u6001\u89c4\u5212","text":"

        Abstract

        \u5c0f\u6eaa\u6c47\u5165\u6cb3\u6d41\uff0c\u6c5f\u6cb3\u6c47\u5165\u5927\u6d77\u3002

        \u52a8\u6001\u89c4\u5212\u5c06\u5c0f\u95ee\u9898\u7684\u89e3\u6c47\u96c6\u6210\u5927\u95ee\u9898\u7684\u7b54\u6848\uff0c\u4e00\u6b65\u6b65\u5f15\u9886\u6211\u4eec\u8d70\u5411\u89e3\u51b3\u95ee\u9898\u7684\u5f7c\u5cb8\u3002

        "},{"location":"chapter_dynamic_programming/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 14.1 \u00a0 \u521d\u63a2\u52a8\u6001\u89c4\u5212
        • 14.2 \u00a0 DP \u95ee\u9898\u7279\u6027
        • 14.3 \u00a0 DP \u89e3\u9898\u601d\u8def
        • 14.4 \u00a0 0-1 \u80cc\u5305\u95ee\u9898
        • 14.5 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898
        • 14.6 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898
        • 14.7 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_dynamic_programming/dp_problem_features/","title":"14.2 \u00a0 \u52a8\u6001\u89c4\u5212\u95ee\u9898\u7279\u6027","text":"

        \u5728\u4e0a\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u52a8\u6001\u89c4\u5212\u662f\u5982\u4f55\u901a\u8fc7\u5b50\u95ee\u9898\u5206\u89e3\u6765\u6c42\u89e3\u539f\u95ee\u9898\u7684\u3002\u5b9e\u9645\u4e0a\uff0c\u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u901a\u7528\u7684\u7b97\u6cd5\u601d\u8def\uff0c\u5728\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u3001\u56de\u6eaf\u4e2d\u7684\u4fa7\u91cd\u70b9\u4e0d\u540c\u3002

        • \u5206\u6cbb\u7b97\u6cd5\u9012\u5f52\u5730\u5c06\u539f\u95ee\u9898\u5212\u5206\u4e3a\u591a\u4e2a\u76f8\u4e92\u72ec\u7acb\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u6700\u5c0f\u5b50\u95ee\u9898\uff0c\u5e76\u5728\u56de\u6eaf\u4e2d\u5408\u5e76\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u6700\u7ec8\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002
        • \u52a8\u6001\u89c4\u5212\u4e5f\u5bf9\u95ee\u9898\u8fdb\u884c\u9012\u5f52\u5206\u89e3\uff0c\u4f46\u4e0e\u5206\u6cbb\u7b97\u6cd5\u7684\u4e3b\u8981\u533a\u522b\u662f\uff0c\u52a8\u6001\u89c4\u5212\u4e2d\u7684\u5b50\u95ee\u9898\u662f\u76f8\u4e92\u4f9d\u8d56\u7684\uff0c\u5728\u5206\u89e3\u8fc7\u7a0b\u4e2d\u4f1a\u51fa\u73b0\u8bb8\u591a\u91cd\u53e0\u5b50\u95ee\u9898\u3002
        • \u56de\u6eaf\u7b97\u6cd5\u5728\u5c1d\u8bd5\u548c\u56de\u9000\u4e2d\u7a77\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u89e3\uff0c\u5e76\u901a\u8fc7\u526a\u679d\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u641c\u7d22\u5206\u652f\u3002\u539f\u95ee\u9898\u7684\u89e3\u7531\u4e00\u7cfb\u5217\u51b3\u7b56\u6b65\u9aa4\u6784\u6210\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6bcf\u4e2a\u51b3\u7b56\u6b65\u9aa4\u4e4b\u524d\u7684\u5b50\u5e8f\u5217\u770b\u4f5c\u4e00\u4e2a\u5b50\u95ee\u9898\u3002

        \u5b9e\u9645\u4e0a\uff0c\u52a8\u6001\u89c4\u5212\u5e38\u7528\u6765\u6c42\u89e3\u6700\u4f18\u5316\u95ee\u9898\uff0c\u5b83\u4eec\u4e0d\u4ec5\u5305\u542b\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u8fd8\u5177\u6709\u53e6\u5916\u4e24\u5927\u7279\u6027\uff1a\u6700\u4f18\u5b50\u7ed3\u6784\u3001\u65e0\u540e\u6548\u6027\u3002

        "},{"location":"chapter_dynamic_programming/dp_problem_features/#1421","title":"14.2.1 \u00a0 \u6700\u4f18\u5b50\u7ed3\u6784","text":"

        \u6211\u4eec\u5bf9\u722c\u697c\u68af\u95ee\u9898\u7a0d\u4f5c\u6539\u52a8\uff0c\u4f7f\u4e4b\u66f4\u52a0\u9002\u5408\u5c55\u793a\u6700\u4f18\u5b50\u7ed3\u6784\u6982\u5ff5\u3002

        \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7

        \u7ed9\u5b9a\u4e00\u4e2a\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u6bcf\u4e00\u9636\u697c\u68af\u4e0a\u90fd\u8d34\u6709\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u8868\u793a\u4f60\u5728\u8be5\u53f0\u9636\u6240\u9700\u8981\u4ed8\u51fa\u7684\u4ee3\u4ef7\u3002\u7ed9\u5b9a\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u6570\u7ec4 \\(cost\\) \uff0c\u5176\u4e2d \\(cost[i]\\) \u8868\u793a\u5728\u7b2c \\(i\\) \u4e2a\u53f0\u9636\u9700\u8981\u4ed8\u51fa\u7684\u4ee3\u4ef7\uff0c\\(cost[0]\\) \u4e3a\u5730\u9762\uff08\u8d77\u59cb\u70b9\uff09\u3002\u8bf7\u8ba1\u7b97\u6700\u5c11\u9700\u8981\u4ed8\u51fa\u591a\u5c11\u4ee3\u4ef7\u624d\u80fd\u5230\u8fbe\u9876\u90e8\uff1f

        \u5982\u56fe 14-6 \u6240\u793a\uff0c\u82e5\u7b2c \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u9636\u7684\u4ee3\u4ef7\u5206\u522b\u4e3a \\(1\\)\u3001\\(10\\)\u3001\\(1\\) \uff0c\u5219\u4ece\u5730\u9762\u722c\u5230\u7b2c \\(3\\) \u9636\u7684\u6700\u5c0f\u4ee3\u4ef7\u4e3a \\(2\\) \u3002

        \u56fe 14-6 \u00a0 \u722c\u5230\u7b2c 3 \u9636\u7684\u6700\u5c0f\u4ee3\u4ef7

        \u8bbe \\(dp[i]\\) \u4e3a\u722c\u5230\u7b2c \\(i\\) \u9636\u7d2f\u8ba1\u4ed8\u51fa\u7684\u4ee3\u4ef7\uff0c\u7531\u4e8e\u7b2c \\(i\\) \u9636\u53ea\u53ef\u80fd\u4ece \\(i - 1\\) \u9636\u6216 \\(i - 2\\) \u9636\u8d70\u6765\uff0c\u56e0\u6b64 \\(dp[i]\\) \u53ea\u53ef\u80fd\u7b49\u4e8e \\(dp[i - 1] + cost[i]\\) \u6216 \\(dp[i - 2] + cost[i]\\) \u3002\u4e3a\u4e86\u5c3d\u53ef\u80fd\u51cf\u5c11\u4ee3\u4ef7\uff0c\u6211\u4eec\u5e94\u8be5\u9009\u62e9\u4e24\u8005\u4e2d\u8f83\u5c0f\u7684\u90a3\u4e00\u4e2a\uff1a

        \\[ dp[i] = \\min(dp[i-1], dp[i-2]) + cost[i] \\]

        \u8fd9\u4fbf\u53ef\u4ee5\u5f15\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u542b\u4e49\uff1a\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u662f\u4ece\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6784\u5efa\u5f97\u6765\u7684\u3002

        \u672c\u9898\u663e\u7136\u5177\u6709\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u6211\u4eec\u4ece\u4e24\u4e2a\u5b50\u95ee\u9898\u6700\u4f18\u89e3 \\(dp[i-1]\\) \u548c \\(dp[i-2]\\) \u4e2d\u6311\u9009\u51fa\u8f83\u4f18\u7684\u90a3\u4e00\u4e2a\uff0c\u5e76\u7528\u5b83\u6784\u5efa\u51fa\u539f\u95ee\u9898 \\(dp[i]\\) \u7684\u6700\u4f18\u89e3\u3002

        \u90a3\u4e48\uff0c\u4e0a\u4e00\u8282\u7684\u722c\u697c\u68af\u9898\u76ee\u6709\u6ca1\u6709\u6700\u4f18\u5b50\u7ed3\u6784\u5462\uff1f\u5b83\u7684\u76ee\u6807\u662f\u6c42\u89e3\u65b9\u6848\u6570\u91cf\uff0c\u770b\u4f3c\u662f\u4e00\u4e2a\u8ba1\u6570\u95ee\u9898\uff0c\u4f46\u5982\u679c\u6362\u4e00\u79cd\u95ee\u6cd5\uff1a\u201c\u6c42\u89e3\u6700\u5927\u65b9\u6848\u6570\u91cf\u201d\u3002\u6211\u4eec\u610f\u5916\u5730\u53d1\u73b0\uff0c\u867d\u7136\u9898\u76ee\u4fee\u6539\u524d\u540e\u662f\u7b49\u4ef7\u7684\uff0c\u4f46\u6700\u4f18\u5b50\u7ed3\u6784\u6d6e\u73b0\u51fa\u6765\u4e86\uff1a\u7b2c \\(n\\) \u9636\u6700\u5927\u65b9\u6848\u6570\u91cf\u7b49\u4e8e\u7b2c \\(n-1\\) \u9636\u548c\u7b2c \\(n-2\\) \u9636\u6700\u5927\u65b9\u6848\u6570\u91cf\u4e4b\u548c\u3002\u6240\u4ee5\u8bf4\uff0c\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u89e3\u91ca\u65b9\u5f0f\u6bd4\u8f83\u7075\u6d3b\uff0c\u5728\u4e0d\u540c\u95ee\u9898\u4e2d\u4f1a\u6709\u4e0d\u540c\u7684\u542b\u4e49\u3002

        \u6839\u636e\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u4ee5\u53ca\u521d\u59cb\u72b6\u6001 \\(dp[1] = cost[1]\\) \u548c \\(dp[2] = cost[2]\\) \uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u52a8\u6001\u89c4\u5212\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_cost_climbing_stairs_dp.py
        def min_cost_climbing_stairs_dp(cost: list[int]) -> int:\n\"\"\"\u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(cost) - 1\nif n == 1 or n == 2:\nreturn cost[n]\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [0] * (n + 1)\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1], dp[2] = cost[1], cost[2]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\nreturn dp[n]\n
        min_cost_climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(vector<int> &cost) {\nint n = cost.size() - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<int> dp(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.java
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(int[] cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint MinCostClimbingStairsDP(int[] cost) {\nint n = cost.Length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = Math.Min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.go
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDP(cost []int) int {\nn := len(cost) - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nmin := func(a, b int) int {\nif a < b {\nreturn a\n}\nreturn b\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1]\ndp[2] = cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i] = min(dp[i-1], dp[i-2]) + cost[i]\n}\nreturn dp[n]\n}\n
        min_cost_climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDP(cost: [Int]) -> Int {\nlet n = cost.count - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: 0, count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1]\ndp[2] = cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n}\nreturn dp[n]\n}\n
        min_cost_climbing_stairs_dp.js
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDP(cost) {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDP(cost: Array<number>): number {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(List<int> cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2) return cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<int> dp = List.filled(n + 1, 0);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n
        min_cost_climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nfn min_cost_climbing_stairs_dp(cost: &[i32]) -> i32 {\nlet n = cost.len() - 1;\nif n == 1 || n == 2 { return cost[n]; }\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![-1; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i] = cmp::min(dp[i - 1], dp[i - 2]) + cost[i];\n}\ndp[n]\n}\n
        min_cost_climbing_stairs_dp.c
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDP(int cost[], int costSize) {\nint n = costSize - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint *dp = calloc(n + 1, sizeof(int));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = myMin(dp[i - 1], dp[i - 2]) + cost[i];\n}\nint res = dp[n];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        min_cost_climbing_stairs_dp.zig
        // \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u52a8\u6001\u89c4\u5212\nfn minCostClimbingStairsDP(comptime cost: []i32) i32 {\ncomptime var n = cost.len - 1;\nif (n == 1 or n == 2) {\nreturn cost[n];\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_]i32{-1} ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = cost[1];\ndp[2] = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i] = @min(dp[i - 1], dp[i - 2]) + cost[i];\n}\nreturn dp[n];\n}\n

        \u56fe 14-7 \u5c55\u793a\u4e86\u4ee5\u4e0a\u4ee3\u7801\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b\u3002

        \u56fe 14-7 \u00a0 \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u672c\u9898\u4e5f\u53ef\u4ee5\u8fdb\u884c\u7a7a\u95f4\u4f18\u5316\uff0c\u5c06\u4e00\u7ef4\u538b\u7f29\u81f3\u96f6\u7ef4\uff0c\u4f7f\u5f97\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_cost_climbing_stairs_dp.py
        def min_cost_climbing_stairs_dp_comp(cost: list[int]) -> int:\n\"\"\"\u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(cost) - 1\nif n == 1 or n == 2:\nreturn cost[n]\na, b = cost[1], cost[2]\nfor i in range(3, n + 1):\na, b = b, min(a, b) + cost[i]\nreturn b\n
        min_cost_climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(vector<int> &cost) {\nint n = cost.size() - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.java
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(int[] cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint MinCostClimbingStairsDPComp(int[] cost) {\nint n = cost.Length - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = Math.Min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.go
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDPComp(cost []int) int {\nn := len(cost) - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nmin := func(a, b int) int {\nif a < b {\nreturn a\n}\nreturn b\n}\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\na, b := cost[1], cost[2]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ntmp := b\nb = min(a, tmp) + cost[i]\na = tmp\n}\nreturn b\n}\n
        min_cost_climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minCostClimbingStairsDPComp(cost: [Int]) -> Int {\nlet n = cost.count - 1\nif n == 1 || n == 2 {\nreturn cost[n]\n}\nvar (a, b) = (cost[1], cost[2])\nfor i in stride(from: 3, through: n, by: 1) {\n(a, b) = (b, min(a, b) + cost[i])\n}\nreturn b\n}\n
        min_cost_climbing_stairs_dp.js
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDPComp(cost) {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\nlet a = cost[1],\nb = cost[2];\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minCostClimbingStairsDPComp(cost: Array<number>): number {\nconst n = cost.length - 1;\nif (n === 1 || n === 2) {\nreturn cost[n];\n}\nlet a = cost[1],\nb = cost[2];\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = Math.min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(List<int> cost) {\nint n = cost.length - 1;\nif (n == 1 || n == 2) return cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn min_cost_climbing_stairs_dp_comp(cost: &[i32]) -> i32 {\nlet n = cost.len() - 1;\nif n == 1 || n == 2 { return cost[n] };\nlet (mut a, mut b) = (cost[1], cost[2]);\nfor i in 3..=n {\nlet tmp = b;\nb = cmp::min(a, tmp) + cost[i];\na = tmp;\n}\nb\n}\n
        min_cost_climbing_stairs_dp.c
        /* \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minCostClimbingStairsDPComp(int cost[], int costSize) {\nint n = costSize - 1;\nif (n == 1 || n == 2)\nreturn cost[n];\nint a = cost[1], b = cost[2];\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = myMin(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        min_cost_climbing_stairs_dp.zig
        // \u722c\u697c\u68af\u6700\u5c0f\u4ee3\u4ef7\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn minCostClimbingStairsDPComp(cost: []i32) i32 {\nvar n = cost.len - 1;\nif (n == 1 or n == 2) {\nreturn cost[n];\n}\nvar a = cost[1];\nvar b = cost[2];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\nvar tmp = b;\nb = @min(a, tmp) + cost[i];\na = tmp;\n}\nreturn b;\n}\n
        "},{"location":"chapter_dynamic_programming/dp_problem_features/#1422","title":"14.2.2 \u00a0 \u65e0\u540e\u6548\u6027","text":"

        \u65e0\u540e\u6548\u6027\u662f\u52a8\u6001\u89c4\u5212\u80fd\u591f\u6709\u6548\u89e3\u51b3\u95ee\u9898\u7684\u91cd\u8981\u7279\u6027\u4e4b\u4e00\uff0c\u5176\u5b9a\u4e49\u4e3a\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u786e\u5b9a\u7684\u72b6\u6001\uff0c\u5b83\u7684\u672a\u6765\u53d1\u5c55\u53ea\u4e0e\u5f53\u524d\u72b6\u6001\u6709\u5173\uff0c\u800c\u4e0e\u8fc7\u53bb\u7ecf\u5386\u7684\u6240\u6709\u72b6\u6001\u65e0\u5173\u3002

        \u4ee5\u722c\u697c\u68af\u95ee\u9898\u4e3a\u4f8b\uff0c\u7ed9\u5b9a\u72b6\u6001 \\(i\\) \uff0c\u5b83\u4f1a\u53d1\u5c55\u51fa\u72b6\u6001 \\(i+1\\) \u548c\u72b6\u6001 \\(i+2\\) \uff0c\u5206\u522b\u5bf9\u5e94\u8df3 \\(1\\) \u6b65\u548c\u8df3 \\(2\\) \u6b65\u3002\u5728\u505a\u51fa\u8fd9\u4e24\u79cd\u9009\u62e9\u65f6\uff0c\u6211\u4eec\u65e0\u987b\u8003\u8651\u72b6\u6001 \\(i\\) \u4e4b\u524d\u7684\u72b6\u6001\uff0c\u5b83\u4eec\u5bf9\u72b6\u6001 \\(i\\) \u7684\u672a\u6765\u6ca1\u6709\u5f71\u54cd\u3002

        \u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u7ed9\u722c\u697c\u68af\u95ee\u9898\u6dfb\u52a0\u4e00\u4e2a\u7ea6\u675f\uff0c\u60c5\u51b5\u5c31\u4e0d\u4e00\u6837\u4e86\u3002

        \u5e26\u7ea6\u675f\u722c\u697c\u68af

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u4f46\u4e0d\u80fd\u8fde\u7eed\u4e24\u8f6e\u8df3 \\(1\\) \u9636\uff0c\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5982\u56fe 14-8 \u6240\u793a\uff0c\u722c\u4e0a\u7b2c \\(3\\) \u9636\u4ec5\u5269 \\(2\\) \u79cd\u53ef\u884c\u65b9\u6848\uff0c\u5176\u4e2d\u8fde\u7eed\u4e09\u6b21\u8df3 \\(1\\) \u9636\u7684\u65b9\u6848\u4e0d\u6ee1\u8db3\u7ea6\u675f\u6761\u4ef6\uff0c\u56e0\u6b64\u88ab\u820d\u5f03\u3002

        \u56fe 14-8 \u00a0 \u5e26\u7ea6\u675f\u722c\u5230\u7b2c 3 \u9636\u7684\u65b9\u6848\u6570\u91cf

        \u5728\u8be5\u95ee\u9898\u4e2d\uff0c\u5982\u679c\u4e0a\u4e00\u8f6e\u662f\u8df3 \\(1\\) \u9636\u4e0a\u6765\u7684\uff0c\u90a3\u4e48\u4e0b\u4e00\u8f6e\u5c31\u5fc5\u987b\u8df3 \\(2\\) \u9636\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4e0b\u4e00\u6b65\u9009\u62e9\u4e0d\u80fd\u7531\u5f53\u524d\u72b6\u6001\uff08\u5f53\u524d\u6240\u5728\u697c\u68af\u9636\u6570\uff09\u72ec\u7acb\u51b3\u5b9a\uff0c\u8fd8\u548c\u524d\u4e00\u4e2a\u72b6\u6001\uff08\u4e0a\u8f6e\u6240\u5728\u697c\u68af\u9636\u6570\uff09\u6709\u5173\u3002

        \u4e0d\u96be\u53d1\u73b0\uff0c\u6b64\u95ee\u9898\u5df2\u4e0d\u6ee1\u8db3\u65e0\u540e\u6548\u6027\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b \\(dp[i] = dp[i-1] + dp[i-2]\\) \u4e5f\u5931\u6548\u4e86\uff0c\u56e0\u4e3a \\(dp[i-1]\\) \u4ee3\u8868\u672c\u8f6e\u8df3 \\(1\\) \u9636\uff0c\u4f46\u5176\u4e2d\u5305\u542b\u4e86\u8bb8\u591a\u201c\u4e0a\u4e00\u8f6e\u662f\u8df3 \\(1\\) \u9636\u4e0a\u6765\u7684\u201d\u65b9\u6848\uff0c\u800c\u4e3a\u4e86\u6ee1\u8db3\u7ea6\u675f\uff0c\u6211\u4eec\u5c31\u4e0d\u80fd\u5c06 \\(dp[i-1]\\) \u76f4\u63a5\u8ba1\u5165 \\(dp[i]\\) \u4e2d\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6269\u5c55\u72b6\u6001\u5b9a\u4e49\uff1a\u72b6\u6001 \\([i, j]\\) \u8868\u793a\u5904\u5728\u7b2c \\(i\\) \u9636\u5e76\u4e14\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(j\\) \u9636\uff0c\u5176\u4e2d \\(j \\in \\{1, 2\\}\\) \u3002\u6b64\u72b6\u6001\u5b9a\u4e49\u6709\u6548\u5730\u533a\u5206\u4e86\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(1\\) \u9636\u8fd8\u662f \\(2\\) \u9636\uff0c\u6211\u4eec\u53ef\u4ee5\u636e\u6b64\u6765\u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u4ece\u4f55\u800c\u6765\u7684\u3002

        • \u5f53\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(1\\) \u9636\u65f6\uff0c\u4e0a\u4e0a\u4e00\u8f6e\u53ea\u80fd\u9009\u62e9\u8df3 \\(2\\) \u9636\uff0c\u5373 \\(dp[i, 1]\\) \u53ea\u80fd\u4ece \\(dp[i-1, 2]\\) \u8f6c\u79fb\u8fc7\u6765\u3002
        • \u5f53\u4e0a\u4e00\u8f6e\u8df3\u4e86 \\(2\\) \u9636\u65f6\uff0c\u4e0a\u4e0a\u4e00\u8f6e\u53ef\u9009\u62e9\u8df3 \\(1\\) \u9636\u6216\u8df3 \\(2\\) \u9636\uff0c\u5373 \\(dp[i, 2]\\) \u53ef\u4ee5\u4ece \\(dp[i-2, 1]\\) \u6216 \\(dp[i-2, 2]\\) \u8f6c\u79fb\u8fc7\u6765\u3002

        \u5982\u56fe 14-9 \u6240\u793a\uff0c\u5728\u8be5\u5b9a\u4e49\u4e0b\uff0c\\(dp[i, j]\\) \u8868\u793a\u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u65b9\u6848\u6570\u3002\u6b64\u65f6\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ \\begin{cases} dp[i, 1] = dp[i-1, 2] \\\\ dp[i, 2] = dp[i-2, 1] + dp[i-2, 2] \\end{cases} \\]

        \u56fe 14-9 \u00a0 \u8003\u8651\u7ea6\u675f\u4e0b\u7684\u9012\u63a8\u5173\u7cfb

        \u6700\u7ec8\uff0c\u8fd4\u56de \\(dp[n, 1] + dp[n, 2]\\) \u5373\u53ef\uff0c\u4e24\u8005\u4e4b\u548c\u4ee3\u8868\u722c\u5230\u7b2c \\(n\\) \u9636\u7684\u65b9\u6848\u603b\u6570\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_constraint_dp.py
        def climbing_stairs_constraint_dp(n: int) -> int:\n\"\"\"\u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn 1\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [[0] * 3 for _ in range(n + 1)]\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1], dp[1][2] = 1, 0\ndp[2][1], dp[2][2] = 0, 1\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i][1] = dp[i - 1][2]\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2]\nreturn dp[n][1] + dp[n][2]\n
        climbing_stairs_constraint_dp.cpp
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<vector<int>> dp(n + 1, vector<int>(3, 0));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.java
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[][] dp = new int[n + 1][3];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.cs
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[,] dp = new int[n + 1, 3];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1, 1] = 1;\ndp[1, 2] = 0;\ndp[2, 1] = 0;\ndp[2, 2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i, 1] = dp[i - 1, 2];\ndp[i, 2] = dp[i - 2, 1] + dp[i - 2, 2];\n}\nreturn dp[n, 1] + dp[n, 2];\n}\n
        climbing_stairs_constraint_dp.go
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsConstraintDP(n int) int {\nif n == 1 || n == 2 {\nreturn 1\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([][3]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1\ndp[1][2] = 0\ndp[2][1] = 0\ndp[2][2] = 1\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i][1] = dp[i-1][2]\ndp[i][2] = dp[i-2][1] + dp[i-2][2]\n}\nreturn dp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.swift
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsConstraintDP(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn 1\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: Array(repeating: 0, count: 3), count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1\ndp[1][2] = 0\ndp[2][1] = 0\ndp[2][2] = 1\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i][1] = dp[i - 1][2]\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n}\nreturn dp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.js
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsConstraintDP(n) {\nif (n === 1 || n === 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = Array.from(new Array(n + 1), () => new Array(3));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.ts
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsConstraintDP(n: number): number {\nif (n === 1 || n === 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = Array.from({ length: n + 1 }, () => new Array(3));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.dart
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(3, 0));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n
        climbing_stairs_constraint_dp.rs
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_constraint_dp(n: usize) -> i32 {\nif n == 1 || n == 2 { return 1 };\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![vec![-1; 3]; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\ndp[n][1] + dp[n][2]\n}\n
        climbing_stairs_constraint_dp.c
        /* \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsConstraintDP(int n) {\nif (n == 1 || n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(3, sizeof(int));\n}\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nint res = dp[n][1] + dp[n][2];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        climbing_stairs_constraint_dp.zig
        // \u5e26\u7ea6\u675f\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\nfn climbingStairsConstraintDP(comptime n: usize) i32 {\nif (n == 1 or n == 2) {\nreturn 1;\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_][3]i32{ [_]i32{ -1, -1, -1 } } ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1][1] = 1;\ndp[1][2] = 0;\ndp[2][1] = 0;\ndp[2][2] = 1;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i][1] = dp[i - 1][2];\ndp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n}\nreturn dp[n][1] + dp[n][2];\n}\n

        \u5728\u4e0a\u9762\u7684\u6848\u4f8b\u4e2d\uff0c\u7531\u4e8e\u4ec5\u9700\u591a\u8003\u8651\u524d\u9762\u4e00\u4e2a\u72b6\u6001\uff0c\u56e0\u6b64\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u901a\u8fc7\u6269\u5c55\u72b6\u6001\u5b9a\u4e49\uff0c\u4f7f\u5f97\u95ee\u9898\u91cd\u65b0\u6ee1\u8db3\u65e0\u540e\u6548\u6027\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u95ee\u9898\u5177\u6709\u975e\u5e38\u4e25\u91cd\u7684\u201c\u6709\u540e\u6548\u6027\u201d\u3002

        \u722c\u697c\u68af\u4e0e\u969c\u788d\u751f\u6210

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\u3002\u89c4\u5b9a\u5f53\u722c\u5230\u7b2c \\(i\\) \u9636\u65f6\uff0c\u7cfb\u7edf\u81ea\u52a8\u4f1a\u5728\u7b2c \\(2i\\) \u9636\u4e0a\u653e\u4e0a\u969c\u788d\u7269\uff0c\u4e4b\u540e\u6240\u6709\u8f6e\u90fd\u4e0d\u5141\u8bb8\u8df3\u5230\u7b2c \\(2i\\) \u9636\u4e0a\u3002\u4f8b\u5982\uff0c\u524d\u4e24\u8f6e\u5206\u522b\u8df3\u5230\u4e86\u7b2c \\(2\\)\u3001\\(3\\) \u9636\u4e0a\uff0c\u5219\u4e4b\u540e\u5c31\u4e0d\u80fd\u8df3\u5230\u7b2c \\(4\\)\u3001\\(6\\) \u9636\u4e0a\u3002\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\uff0c\u4e0b\u6b21\u8df3\u8dc3\u4f9d\u8d56\u8fc7\u53bb\u6240\u6709\u7684\u72b6\u6001\uff0c\u56e0\u4e3a\u6bcf\u4e00\u6b21\u8df3\u8dc3\u90fd\u4f1a\u5728\u66f4\u9ad8\u7684\u9636\u68af\u4e0a\u8bbe\u7f6e\u969c\u788d\uff0c\u5e76\u5f71\u54cd\u672a\u6765\u7684\u8df3\u8dc3\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u95ee\u9898\uff0c\u52a8\u6001\u89c4\u5212\u5f80\u5f80\u96be\u4ee5\u89e3\u51b3\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u590d\u6742\u7684\u7ec4\u5408\u4f18\u5316\u95ee\u9898\uff08\u4f8b\u5982\u65c5\u884c\u5546\u95ee\u9898\uff09\u4e0d\u6ee1\u8db3\u65e0\u540e\u6548\u6027\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u95ee\u9898\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9009\u62e9\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\uff0c\u4f8b\u5982\u542f\u53d1\u5f0f\u641c\u7d22\u3001\u9057\u4f20\u7b97\u6cd5\u3001\u5f3a\u5316\u5b66\u4e60\u7b49\uff0c\u4ece\u800c\u5728\u6709\u9650\u65f6\u95f4\u5185\u5f97\u5230\u53ef\u7528\u7684\u5c40\u90e8\u6700\u4f18\u89e3\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/","title":"14.3 \u00a0 \u52a8\u6001\u89c4\u5212\u89e3\u9898\u601d\u8def","text":"

        \u4e0a\u4e24\u8282\u4ecb\u7ecd\u4e86\u52a8\u6001\u89c4\u5212\u95ee\u9898\u7684\u4e3b\u8981\u7279\u5f81\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u8d77\u63a2\u7a76\u4e24\u4e2a\u66f4\u52a0\u5b9e\u7528\u7684\u95ee\u9898\u3002

        1. \u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u95ee\u9898\u662f\u4e0d\u662f\u52a8\u6001\u89c4\u5212\u95ee\u9898\uff1f
        2. \u6c42\u89e3\u52a8\u6001\u89c4\u5212\u95ee\u9898\u8be5\u4ece\u4f55\u5904\u5165\u624b\uff0c\u5b8c\u6574\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f
        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1431","title":"14.3.1 \u00a0 \u95ee\u9898\u5224\u65ad","text":"

        \u603b\u7684\u6765\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u95ee\u9898\u5305\u542b\u91cd\u53e0\u5b50\u95ee\u9898\u3001\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5e76\u6ee1\u8db3\u65e0\u540e\u6548\u6027\uff0c\u90a3\u4e48\u5b83\u901a\u5e38\u9002\u5408\u7528\u52a8\u6001\u89c4\u5212\u6c42\u89e3\u3002\u7136\u800c\uff0c\u6211\u4eec\u5f88\u96be\u4ece\u95ee\u9898\u63cf\u8ff0\u4e2d\u76f4\u63a5\u63d0\u53d6\u51fa\u8fd9\u4e9b\u7279\u6027\u3002\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f1a\u653e\u5bbd\u6761\u4ef6\uff0c\u5148\u89c2\u5bdf\u95ee\u9898\u662f\u5426\u9002\u5408\u4f7f\u7528\u56de\u6eaf\uff08\u7a77\u4e3e\uff09\u89e3\u51b3\u3002

        \u9002\u5408\u7528\u56de\u6eaf\u89e3\u51b3\u7684\u95ee\u9898\u901a\u5e38\u6ee1\u8db3\u201c\u51b3\u7b56\u6811\u6a21\u578b\u201d\uff0c\u8fd9\u79cd\u95ee\u9898\u53ef\u4ee5\u4f7f\u7528\u6811\u5f62\u7ed3\u6784\u6765\u63cf\u8ff0\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u51b3\u7b56\uff0c\u6bcf\u4e00\u6761\u8def\u5f84\u4ee3\u8868\u4e00\u4e2a\u51b3\u7b56\u5e8f\u5217\u3002

        \u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c\u95ee\u9898\u5305\u542b\u660e\u786e\u7684\u51b3\u7b56\u6982\u5ff5\uff0c\u5e76\u4e14\u89e3\u662f\u901a\u8fc7\u4e00\u7cfb\u5217\u51b3\u7b56\u4ea7\u751f\u7684\uff0c\u90a3\u4e48\u5b83\u5c31\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\uff0c\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u56de\u6eaf\u6765\u89e3\u51b3\u3002

        \u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u52a8\u6001\u89c4\u5212\u95ee\u9898\u8fd8\u6709\u4e00\u4e9b\u5224\u65ad\u7684\u201c\u52a0\u5206\u9879\u201d\u3002

        • \u95ee\u9898\u5305\u542b\u6700\u5927\uff08\u5c0f\uff09\u6216\u6700\u591a\uff08\u5c11\uff09\u7b49\u6700\u4f18\u5316\u63cf\u8ff0\u3002
        • \u95ee\u9898\u7684\u72b6\u6001\u80fd\u591f\u4f7f\u7528\u4e00\u4e2a\u5217\u8868\u3001\u591a\u7ef4\u77e9\u9635\u6216\u6811\u6765\u8868\u793a\uff0c\u5e76\u4e14\u4e00\u4e2a\u72b6\u6001\u4e0e\u5176\u5468\u56f4\u7684\u72b6\u6001\u5b58\u5728\u9012\u63a8\u5173\u7cfb\u3002

        \u76f8\u5e94\u5730\uff0c\u4e5f\u5b58\u5728\u4e00\u4e9b\u201c\u51cf\u5206\u9879\u201d\u3002

        • \u95ee\u9898\u7684\u76ee\u6807\u662f\u627e\u51fa\u6240\u6709\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u800c\u4e0d\u662f\u627e\u51fa\u6700\u4f18\u89e3\u3002
        • \u95ee\u9898\u63cf\u8ff0\u4e2d\u6709\u660e\u663e\u7684\u6392\u5217\u7ec4\u5408\u7684\u7279\u5f81\uff0c\u9700\u8981\u8fd4\u56de\u5177\u4f53\u7684\u591a\u4e2a\u65b9\u6848\u3002

        \u5982\u679c\u4e00\u4e2a\u95ee\u9898\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\uff0c\u5e76\u5177\u6709\u8f83\u4e3a\u660e\u663e\u7684\u201c\u52a0\u5206\u9879\u201c\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5047\u8bbe\u5b83\u662f\u4e00\u4e2a\u52a8\u6001\u89c4\u5212\u95ee\u9898\uff0c\u5e76\u5728\u6c42\u89e3\u8fc7\u7a0b\u4e2d\u9a8c\u8bc1\u5b83\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1432","title":"14.3.2 \u00a0 \u95ee\u9898\u6c42\u89e3\u6b65\u9aa4","text":"

        \u52a8\u6001\u89c4\u5212\u7684\u89e3\u9898\u6d41\u7a0b\u4f1a\u56e0\u95ee\u9898\u7684\u6027\u8d28\u548c\u96be\u5ea6\u800c\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u901a\u5e38\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u63cf\u8ff0\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u5efa\u7acb \\(dp\\) \u8868\uff0c\u63a8\u5bfc\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u7b49\u3002

        \u4e3a\u4e86\u66f4\u5f62\u8c61\u5730\u5c55\u793a\u89e3\u9898\u6b65\u9aa4\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\u201c\u6700\u5c0f\u8def\u5f84\u548c\u201d\u6765\u4e3e\u4f8b\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a \\(n \\times m\\) \u7684\u4e8c\u7ef4\u7f51\u683c grid \uff0c\u7f51\u683c\u4e2d\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u5305\u542b\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u8868\u793a\u8be5\u5355\u5143\u683c\u7684\u4ee3\u4ef7\u3002\u673a\u5668\u4eba\u4ee5\u5de6\u4e0a\u89d2\u5355\u5143\u683c\u4e3a\u8d77\u59cb\u70b9\uff0c\u6bcf\u6b21\u53ea\u80fd\u5411\u4e0b\u6216\u8005\u5411\u53f3\u79fb\u52a8\u4e00\u6b65\uff0c\u76f4\u81f3\u5230\u8fbe\u53f3\u4e0b\u89d2\u5355\u5143\u683c\u3002\u8bf7\u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230\u53f3\u4e0b\u89d2\u7684\u6700\u5c0f\u8def\u5f84\u548c\u3002

        \u56fe 14-10 \u5c55\u793a\u4e86\u4e00\u4e2a\u4f8b\u5b50\uff0c\u7ed9\u5b9a\u7f51\u683c\u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e3a \\(13\\) \u3002

        \u56fe 14-10 \u00a0 \u6700\u5c0f\u8def\u5f84\u548c\u793a\u4f8b\u6570\u636e

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u672c\u9898\u7684\u6bcf\u4e00\u8f6e\u7684\u51b3\u7b56\u5c31\u662f\u4ece\u5f53\u524d\u683c\u5b50\u5411\u4e0b\u6216\u5411\u53f3\u8d70\u4e00\u6b65\u3002\u8bbe\u5f53\u524d\u683c\u5b50\u7684\u884c\u5217\u7d22\u5f15\u4e3a \\([i, j]\\) \uff0c\u5219\u5411\u4e0b\u6216\u5411\u53f3\u8d70\u4e00\u6b65\u540e\uff0c\u7d22\u5f15\u53d8\u4e3a \\([i+1, j]\\) \u6216 \\([i, j+1]\\) \u3002\u56e0\u6b64\uff0c\u72b6\u6001\u5e94\u5305\u542b\u884c\u7d22\u5f15\u548c\u5217\u7d22\u5f15\u4e24\u4e2a\u53d8\u91cf\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u4ece\u8d77\u59cb\u70b9 \\([0, 0]\\) \u8d70\u5230 \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\uff0c\u89e3\u8bb0\u4e3a \\(dp[i, j]\\) \u3002

        \u81f3\u6b64\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u56fe 14-11 \u6240\u793a\u7684\u4e8c\u7ef4 \\(dp\\) \u77e9\u9635\uff0c\u5176\u5c3a\u5bf8\u4e0e\u8f93\u5165\u7f51\u683c \\(grid\\) \u76f8\u540c\u3002

        \u56fe 14-11 \u00a0 \u72b6\u6001\u5b9a\u4e49\u4e0e dp \u8868

        Note

        \u52a8\u6001\u89c4\u5212\u548c\u56de\u6eaf\u8fc7\u7a0b\u53ef\u4ee5\u63cf\u8ff0\u4e3a\u4e00\u4e2a\u51b3\u7b56\u5e8f\u5217\uff0c\u800c\u72b6\u6001\u7531\u6240\u6709\u51b3\u7b56\u53d8\u91cf\u6784\u6210\u3002\u5b83\u5e94\u5f53\u5305\u542b\u63cf\u8ff0\u89e3\u9898\u8fdb\u5ea6\u7684\u6240\u6709\u53d8\u91cf\uff0c\u5176\u5305\u542b\u4e86\u8db3\u591f\u7684\u4fe1\u606f\uff0c\u80fd\u591f\u7528\u6765\u63a8\u5bfc\u51fa\u4e0b\u4e00\u4e2a\u72b6\u6001\u3002

        \u6bcf\u4e2a\u72b6\u6001\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5b50\u95ee\u9898\uff0c\u6211\u4eec\u4f1a\u5b9a\u4e49\u4e00\u4e2a \\(dp\\) \u8868\u6765\u5b58\u50a8\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u72b6\u6001\u7684\u6bcf\u4e2a\u72ec\u7acb\u53d8\u91cf\u90fd\u662f \\(dp\\) \u8868\u7684\u4e00\u4e2a\u7ef4\u5ea6\u3002\u4ece\u672c\u8d28\u4e0a\u770b\uff0c\\(dp\\) \u8868\u662f\u72b6\u6001\u548c\u5b50\u95ee\u9898\u7684\u89e3\u4e4b\u95f4\u7684\u6620\u5c04\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u5bf9\u4e8e\u72b6\u6001 \\([i, j]\\) \uff0c\u5b83\u53ea\u80fd\u4ece\u4e0a\u8fb9\u683c\u5b50 \\([i-1, j]\\) \u548c\u5de6\u8fb9\u683c\u5b50 \\([i, j-1]\\) \u8f6c\u79fb\u800c\u6765\u3002\u56e0\u6b64\u6700\u4f18\u5b50\u7ed3\u6784\u4e3a\uff1a\u5230\u8fbe \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u7531 \\([i, j-1]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e0e \\([i-1, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c\u4e2d\u8f83\u5c0f\u7684\u90a3\u4e00\u4e2a\u51b3\u5b9a\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u53ef\u63a8\u51fa\u56fe 14-12 \u6240\u793a\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a

        \\[ dp[i, j] = \\min(dp[i-1, j], dp[i, j-1]) + grid[i, j] \\]

        \u56fe 14-12 \u00a0 \u6700\u4f18\u5b50\u7ed3\u6784\u4e0e\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        Note

        \u6839\u636e\u5b9a\u4e49\u597d\u7684 \\(dp\\) \u8868\uff0c\u601d\u8003\u539f\u95ee\u9898\u548c\u5b50\u95ee\u9898\u7684\u5173\u7cfb\uff0c\u627e\u51fa\u901a\u8fc7\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6765\u6784\u9020\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u7684\u65b9\u6cd5\uff0c\u5373\u6700\u4f18\u5b50\u7ed3\u6784\u3002

        \u4e00\u65e6\u6211\u4eec\u627e\u5230\u4e86\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u6784\u5efa\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5728\u672c\u9898\u4e2d\uff0c\u5904\u5728\u9996\u884c\u7684\u72b6\u6001\u53ea\u80fd\u4ece\u5176\u5de6\u8fb9\u7684\u72b6\u6001\u5f97\u6765\uff0c\u5904\u5728\u9996\u5217\u7684\u72b6\u6001\u53ea\u80fd\u4ece\u5176\u4e0a\u8fb9\u7684\u72b6\u6001\u5f97\u6765\uff0c\u56e0\u6b64\u9996\u884c \\(i = 0\\) \u548c\u9996\u5217 \\(j = 0\\) \u662f\u8fb9\u754c\u6761\u4ef6\u3002

        \u5982\u56fe 14-13 \u6240\u793a\uff0c\u7531\u4e8e\u6bcf\u4e2a\u683c\u5b50\u662f\u7531\u5176\u5de6\u65b9\u683c\u5b50\u548c\u4e0a\u65b9\u683c\u5b50\u8f6c\u79fb\u800c\u6765\uff0c\u56e0\u6b64\u6211\u4eec\u4f7f\u7528\u5faa\u73af\u6765\u904d\u5386\u77e9\u9635\uff0c\u5916\u5faa\u73af\u904d\u5386\u5404\u884c\uff0c\u5185\u5faa\u73af\u904d\u5386\u5404\u5217\u3002

        \u56fe 14-13 \u00a0 \u8fb9\u754c\u6761\u4ef6\u4e0e\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        Note

        \u8fb9\u754c\u6761\u4ef6\u5728\u52a8\u6001\u89c4\u5212\u4e2d\u7528\u4e8e\u521d\u59cb\u5316 \\(dp\\) \u8868\uff0c\u5728\u641c\u7d22\u4e2d\u7528\u4e8e\u526a\u679d\u3002

        \u72b6\u6001\u8f6c\u79fb\u987a\u5e8f\u7684\u6838\u5fc3\u662f\u8981\u4fdd\u8bc1\u5728\u8ba1\u7b97\u5f53\u524d\u95ee\u9898\u7684\u89e3\u65f6\uff0c\u6240\u6709\u5b83\u4f9d\u8d56\u7684\u66f4\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u90fd\u5df2\u7ecf\u88ab\u6b63\u786e\u5730\u8ba1\u7b97\u51fa\u6765\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u76f4\u63a5\u5199\u51fa\u52a8\u6001\u89c4\u5212\u4ee3\u7801\u3002\u7136\u800c\u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u4ece\u9876\u81f3\u5e95\u7684\u601d\u60f3\uff0c\u56e0\u6b64\u6309\u7167\u201c\u66b4\u529b\u641c\u7d22 \\(\\rightarrow\\) \u8bb0\u5fc6\u5316\u641c\u7d22 \\(\\rightarrow\\) \u52a8\u6001\u89c4\u5212\u201d\u7684\u987a\u5e8f\u5b9e\u73b0\u66f4\u52a0\u7b26\u5408\u601d\u7ef4\u4e60\u60ef\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#1","title":"1. \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u4ece\u72b6\u6001 \\([i, j]\\) \u5f00\u59cb\u641c\u7d22\uff0c\u4e0d\u65ad\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u72b6\u6001 \\([i-1, j]\\) \u548c \\([i, j-1]\\) \uff0c\u9012\u5f52\u51fd\u6570\u5305\u62ec\u4ee5\u4e0b\u8981\u7d20\u3002

        • \u9012\u5f52\u53c2\u6570\uff1a\u72b6\u6001 \\([i, j]\\) \u3002
        • \u8fd4\u56de\u503c\uff1a\u4ece \\([0, 0]\\) \u5230 \\([i, j]\\) \u7684\u6700\u5c0f\u8def\u5f84\u548c \\(dp[i, j]\\) \u3002
        • \u7ec8\u6b62\u6761\u4ef6\uff1a\u5f53 \\(i = 0\\) \u4e14 \\(j = 0\\) \u65f6\uff0c\u8fd4\u56de\u4ee3\u4ef7 \\(grid[0, 0]\\) \u3002
        • \u526a\u679d\uff1a\u5f53 \\(i < 0\\) \u65f6\u6216 \\(j < 0\\) \u65f6\u7d22\u5f15\u8d8a\u754c\uff0c\u6b64\u65f6\u8fd4\u56de\u4ee3\u4ef7 \\(+\\infty\\) \uff0c\u4ee3\u8868\u4e0d\u53ef\u884c\u3002

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dfs(grid: list[list[int]], i: int, j: int) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22\"\"\"\n# \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 and j == 0:\nreturn grid[0][0]\n# \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 or j < 0:\nreturn inf\n# \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup = min_path_sum_dfs(grid, i - 1, j)\nleft = min_path_sum_dfs(grid, i, j - 1)\n# \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(vector<vector<int>> &grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(int[][] grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Integer.MAX_VALUE;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint MinPathSumDFS(int[][] grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn int.MaxValue;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = MinPathSumDFS(grid, i - 1, j);\nint left = MinPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.Min(left, up) + grid[i][j];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc minPathSumDFS(grid [][]int, i, j int) int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn math.MaxInt\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup := minPathSumDFS(grid, i-1, j)\nleft := minPathSumDFS(grid, i, j-1)\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn int(math.Min(float64(left), float64(up))) + grid[i][j]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc minPathSumDFS(grid: [[Int]], i: Int, j: Int) -> Int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0, j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn .max\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = minPathSumDFS(grid: grid, i: i - 1, j: j)\nlet left = minPathSumDFS(grid: grid, i: i, j: j - 1)\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction minPathSumDFS(grid, i, j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFS(grid, i - 1, j);\nconst left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction minPathSumDFS(\ngrid: Array<Array<number>>,\ni: number,\nj: number\n): number {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFS(grid, i - 1, j);\nconst left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn Math.min(left, up) + grid[i][j];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(List<List<int>> grid, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\n// \u5728 Dart \u4e2d\uff0cint \u7c7b\u578b\u662f\u56fa\u5b9a\u8303\u56f4\u7684\u6574\u6570\uff0c\u4e0d\u5b58\u5728\u8868\u793a\u201c\u65e0\u7a77\u5927\u201d\u7684\u503c\nreturn BigInt.from(2).pow(31).toInt();\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn min(left, up) + grid[i][j];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nfn min_path_sum_dfs(grid: &Vec<Vec<i32>>, i: i32, j: i32) -> i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn i32::MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = min_path_sum_dfs(grid, i - 1, j);\nlet left = min_path_sum_dfs(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nstd::cmp::min(left, up) + grid[i as usize][j as usize]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22 */\nint minPathSumDFS(int grid[MAX_SIZE][MAX_SIZE], int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFS(grid, i - 1, j);\nint left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u66b4\u529b\u641c\u7d22\nfn minPathSumDFS(grid: anytype, i: i32, j: i32) i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 and j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 or j < 0) {\nreturn std.math.maxInt(i32);\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nvar up = minPathSumDFS(grid, i - 1, j);\nvar left = minPathSumDFS(grid, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nreturn @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n

        \u56fe 14-14 \u7ed9\u51fa\u4e86\u4ee5 \\(dp[2, 1]\\) \u4e3a\u6839\u8282\u70b9\u7684\u9012\u5f52\u6811\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e9b\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u5176\u6570\u91cf\u4f1a\u968f\u7740\u7f51\u683c grid \u7684\u5c3a\u5bf8\u53d8\u5927\u800c\u6025\u5267\u589e\u591a\u3002

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u9020\u6210\u91cd\u53e0\u5b50\u95ee\u9898\u7684\u539f\u56e0\u4e3a\uff1a\u5b58\u5728\u591a\u6761\u8def\u5f84\u53ef\u4ee5\u4ece\u5de6\u4e0a\u89d2\u5230\u8fbe\u67d0\u4e00\u5355\u5143\u683c\u3002

        \u56fe 14-14 \u00a0 \u66b4\u529b\u641c\u7d22\u9012\u5f52\u6811

        \u6bcf\u4e2a\u72b6\u6001\u90fd\u6709\u5411\u4e0b\u548c\u5411\u53f3\u4e24\u79cd\u9009\u62e9\uff0c\u4ece\u5de6\u4e0a\u89d2\u8d70\u5230\u53f3\u4e0b\u89d2\u603b\u5171\u9700\u8981 \\(m + n - 2\\) \u6b65\uff0c\u6240\u4ee5\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^{m + n})\\) \u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u79cd\u8ba1\u7b97\u65b9\u5f0f\u672a\u8003\u8651\u4e34\u8fd1\u7f51\u683c\u8fb9\u754c\u7684\u60c5\u51b5\uff0c\u5f53\u5230\u8fbe\u7f51\u7edc\u8fb9\u754c\u65f6\u53ea\u5269\u4e0b\u4e00\u79cd\u9009\u62e9\uff0c\u56e0\u6b64\u5b9e\u9645\u7684\u8def\u5f84\u6570\u91cf\u4f1a\u5c11\u4e00\u4e9b\u3002

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#2","title":"2. \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u6211\u4eec\u5f15\u5165\u4e00\u4e2a\u548c\u7f51\u683c grid \u76f8\u540c\u5c3a\u5bf8\u7684\u8bb0\u5fc6\u5217\u8868 mem \uff0c\u7528\u4e8e\u8bb0\u5f55\u5404\u4e2a\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5e76\u5c06\u91cd\u53e0\u5b50\u95ee\u9898\u8fdb\u884c\u526a\u679d\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dfs_mem(\ngrid: list[list[int]], mem: list[list[int]], i: int, j: int\n) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 and j == 0:\nreturn grid[0][0]\n# \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 or j < 0:\nreturn inf\n# \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1:\nreturn mem[i][j]\n# \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup = min_path_sum_dfs_mem(grid, mem, i - 1, j)\nleft = min_path_sum_dfs_mem(grid, mem, i, j - 1)\n# \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j]\nreturn mem[i][j]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(vector<vector<int>> &grid, vector<vector<int>> &mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\nreturn mem[i][j];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(int[][] grid, int[][] mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Integer.MAX_VALUE;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint MinPathSumDFSMem(int[][] grid, int[][] mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn int.MaxValue;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = MinPathSumDFSMem(grid, mem, i - 1, j);\nint left = MinPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.Min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc minPathSumDFSMem(grid, mem [][]int, i, j int) int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn math.MaxInt\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1 {\nreturn mem[i][j]\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nup := minPathSumDFSMem(grid, mem, i-1, j)\nleft := minPathSumDFSMem(grid, mem, i, j-1)\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = int(math.Min(float64(left), float64(up))) + grid[i][j]\nreturn mem[i][j]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc minPathSumDFSMem(grid: [[Int]], mem: inout [[Int]], i: Int, j: Int) -> Int {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0, j == 0 {\nreturn grid[0][0]\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn .max\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][j] != -1 {\nreturn mem[i][j]\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = minPathSumDFSMem(grid: grid, mem: &mem, i: i - 1, j: j)\nlet left = minPathSumDFSMem(grid: grid, mem: &mem, i: i, j: j - 1)\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j]\nreturn mem[i][j]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(grid, mem, i, j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] !== -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFSMem(grid, mem, i - 1, j);\nconst left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(\ngrid: Array<Array<number>>,\nmem: Array<Array<number>>,\ni: number,\nj: number\n): number {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i === 0 && j === 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn Infinity;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nconst up = minPathSumDFSMem(grid, mem, i - 1, j);\nconst left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = Math.min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(List<List<int>> grid, List<List<int>> mem, int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\n// \u5728 Dart \u4e2d\uff0cint \u7c7b\u578b\u662f\u56fa\u5b9a\u8303\u56f4\u7684\u6574\u6570\uff0c\u4e0d\u5b58\u5728\u8868\u793a\u201c\u65e0\u7a77\u5927\u201d\u7684\u503c\nreturn BigInt.from(2).pow(31).toInt();\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = min(left, up) + grid[i][j];\nreturn mem[i][j];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn min_path_sum_dfs_mem(grid: &Vec<Vec<i32>>, mem: &mut Vec<Vec<i32>>, i: i32, j: i32) -> i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif i == 0 && j == 0 {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif i < 0 || j < 0 {\nreturn i32::MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i as usize][j as usize] != -1 {\nreturn mem[i as usize][j as usize];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nlet up = min_path_sum_dfs_mem(grid, mem, i - 1, j);\nlet left = min_path_sum_dfs_mem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i as usize][j as usize] = std::cmp::min(left, up) + grid[i as usize][j as usize];\nmem[i as usize][j as usize]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint minPathSumDFSMem(int grid[MAX_SIZE][MAX_SIZE], int mem[MAX_SIZE][MAX_SIZE], int i, int j) {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 && j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 || j < 0) {\nreturn INT_MAX;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][j] != -1) {\nreturn mem[i][j];\n}\n// \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nint up = minPathSumDFSMem(grid, mem, i - 1, j);\nint left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[i][j] = myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\nreturn mem[i][j];\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn minPathSumDFSMem(grid: anytype, mem: anytype, i: i32, j: i32) i32 {\n// \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\nif (i == 0 and j == 0) {\nreturn grid[0][0];\n}\n// \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\nif (i < 0 or j < 0) {\nreturn std.math.maxInt(i32);\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] != -1) {\nreturn mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n// \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nvar up = minPathSumDFSMem(grid, mem, i - 1, j);\nvar left = minPathSumDFSMem(grid, mem, i, j - 1);\n// \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\nmem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] = @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\nreturn mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n}\n

        \u5982\u56fe 14-15 \u6240\u793a\uff0c\u5728\u5f15\u5165\u8bb0\u5fc6\u5316\u540e\uff0c\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\u53ea\u9700\u8ba1\u7b97\u4e00\u6b21\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u72b6\u6001\u603b\u6570\uff0c\u5373\u7f51\u683c\u5c3a\u5bf8 \\(O(nm)\\) \u3002

        \u56fe 14-15 \u00a0 \u8bb0\u5fc6\u5316\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#3","title":"3. \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u57fa\u4e8e\u8fed\u4ee3\u5b9e\u73b0\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dp(grid: list[list[int]]) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(grid), len(grid[0])\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * m for _ in range(n)]\ndp[0][0] = grid[0][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in range(1, m):\ndp[0][j] = dp[0][j - 1] + grid[0][j]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in range(1, n):\ndp[i][0] = dp[i - 1][0] + grid[i][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n):\nfor j in range(1, m):\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\nreturn dp[n - 1][m - 1]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(vector<vector<int>> &grid) {\nint n = grid.size(), m = grid[0].size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n, vector<int>(m));\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(int[][] grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n][m];\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint MinPathSumDP(int[][] grid) {\nint n = grid.Length, m = grid[0].Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n, m];\ndp[0, 0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0, j] = dp[0, j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i, 0] = dp[i - 1, 0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i, j] = Math.Min(dp[i, j - 1], dp[i - 1, j]) + grid[i][j];\n}\n}\nreturn dp[n - 1, m - 1];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDP(grid [][]int) int {\nn, m := len(grid), len(grid[0])\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n)\nfor i := 0; i < n; i++ {\ndp[i] = make([]int, m)\n}\ndp[0][0] = grid[0][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j := 1; j < m; j++ {\ndp[0][j] = dp[0][j-1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i := 1; i < n; i++ {\ndp[i][0] = dp[i-1][0] + grid[i][0]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i < n; i++ {\nfor j := 1; j < m; j++ {\ndp[i][j] = int(math.Min(float64(dp[i][j-1]), float64(dp[i-1][j]))) + grid[i][j]\n}\n}\nreturn dp[n-1][m-1]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDP(grid: [[Int]]) -> Int {\nlet n = grid.count\nlet m = grid[0].count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: m), count: n)\ndp[0][0] = grid[0][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in stride(from: 1, to: m, by: 1) {\ndp[0][j] = dp[0][j - 1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in stride(from: 1, to: n, by: 1) {\ndp[i][0] = dp[i - 1][0] + grid[i][0]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, to: n, by: 1) {\nfor j in stride(from: 1, to: m, by: 1) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n}\n}\nreturn dp[n - 1][m - 1]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid) {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n }, () =>\nArray.from({ length: m }, () => 0)\n);\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (let i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i < n; i++) {\nfor (let j = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid: Array<Array<number>>): number {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n }, () =>\nArray.from({ length: m }, () => 0)\n);\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (let i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i < n; i++) {\nfor (let j: number = 1; j < m; j++) {\ndp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(List<List<int>> grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n, (i) => List.filled(m, 0));\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfn min_path_sum_dp(grid: &Vec<Vec<i32>>) -> i32 {\nlet (n, m) = (grid.len(), grid[0].len());\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; m]; n];\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in 1..m {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor i in 1..n {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..n {\nfor j in 1..m {\ndp[i][j] = std::cmp::min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\ndp[n - 1][m - 1]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nint minPathSumDP(int grid[MAX_SIZE][MAX_SIZE], int n, int m) {\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc(n * sizeof(int *));\nfor (int i = 0; i < n; i++) {\ndp[i] = calloc(m, sizeof(int));\n}\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (int i = 1; i < n; i++) {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i < n; i++) {\nfor (int j = 1; j < m; j++) {\ndp[i][j] = myMin(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nint res = dp[n - 1][m - 1];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i < n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\nfn minPathSumDP(comptime grid: anytype) i32 {\ncomptime var n = grid.len;\ncomptime var m = grid[0].len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][m]i32{[_]i32{0} ** m} ** n;\ndp[0][0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (1..m) |j| {\ndp[0][j] = dp[0][j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nfor (1..n) |i| {\ndp[i][0] = dp[i - 1][0] + grid[i][0];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n) |i| {\nfor (1..m) |j| {\ndp[i][j] = @min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n}\n}\nreturn dp[n - 1][m - 1];\n}\n

        \u56fe 14-16 \u5c55\u793a\u4e86\u6700\u5c0f\u8def\u5f84\u548c\u7684\u72b6\u6001\u8f6c\u79fb\u8fc7\u7a0b\uff0c\u5176\u904d\u5386\u4e86\u6574\u4e2a\u7f51\u683c\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nm)\\) \u3002

        \u6570\u7ec4 dp \u5927\u5c0f\u4e3a \\(n \\times m\\) \uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nm)\\) \u3002

        <1><2><3><4><5><6><7><8><9><10><11><12>

        \u56fe 14-16 \u00a0 \u6700\u5c0f\u8def\u5f84\u548c\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/dp_solution_pipeline/#4","title":"4. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u6bcf\u4e2a\u683c\u5b50\u53ea\u4e0e\u5176\u5de6\u8fb9\u548c\u4e0a\u8fb9\u7684\u683c\u5b50\u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u53ea\u7528\u4e00\u4e2a\u5355\u884c\u6570\u7ec4\u6765\u5b9e\u73b0 \\(dp\\) \u8868\u3002

        \u8bf7\u6ce8\u610f\uff0c\u56e0\u4e3a\u6570\u7ec4 dp \u53ea\u80fd\u8868\u793a\u4e00\u884c\u7684\u72b6\u6001\uff0c\u6240\u4ee5\u6211\u4eec\u65e0\u6cd5\u63d0\u524d\u521d\u59cb\u5316\u9996\u5217\u72b6\u6001\uff0c\u800c\u662f\u5728\u904d\u5386\u6bcf\u884c\u65f6\u66f4\u65b0\u5b83\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig min_path_sum.py
        def min_path_sum_dp_comp(grid: list[list[int]]) -> int:\n\"\"\"\u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(grid), len(grid[0])\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * m\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j in range(1, m):\ndp[j] = dp[j - 1] + grid[0][j]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in range(1, n):\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in range(1, m):\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\nreturn dp[m - 1]\n
        min_path_sum.cpp
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(vector<vector<int>> &grid) {\nint n = grid.size(), m = grid[0].size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.java
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(int[][] grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[m];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.cs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint MinPathSumDPComp(int[][] grid) {\nint n = grid.Length, m = grid[0].Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[m];\ndp[0] = grid[0][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = Math.Min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.go
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDPComp(grid [][]int) int {\nn, m := len(grid), len(grid[0])\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, m)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j := 1; j < m; j++ {\ndp[j] = dp[j-1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i < n; i++ {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j := 1; j < m; j++ {\ndp[j] = int(math.Min(float64(dp[j-1]), float64(dp[j]))) + grid[i][j]\n}\n}\nreturn dp[m-1]\n}\n
        min_path_sum.swift
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc minPathSumDPComp(grid: [[Int]]) -> Int {\nlet n = grid.count\nlet m = grid[0].count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: m)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0]\nfor j in stride(from: 1, to: m, by: 1) {\ndp[j] = dp[j - 1] + grid[0][j]\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in stride(from: 1, to: n, by: 1) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0]\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in stride(from: 1, to: m, by: 1) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n}\n}\nreturn dp[m - 1]\n}\n
        min_path_sum.js
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDPComp(grid) {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = new Array(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (let j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.ts
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDPComp(grid: Array<Array<number>>): number {\nconst n = grid.length,\nm = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = new Array(m);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (let j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j < m; j++) {\ndp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.dart
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(List<List<int>> grid) {\nint n = grid.length, m = grid[0].length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(m, 0);\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        min_path_sum.rs
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn min_path_sum_dp_comp(grid: &Vec<Vec<i32>>) -> i32 {\nlet (n, m) = (grid.len(), grid[0].len());\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; m];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor j in 1..m {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in 1..n {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in 1..m {\ndp[j] = std::cmp::min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\ndp[m - 1]\n}\n
        min_path_sum.c
        /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint minPathSumDPComp(int grid[MAX_SIZE][MAX_SIZE], int n, int m) {\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(m, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (int j = 1; j < m; j++) {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i < n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j < m; j++) {\ndp[j] = myMin(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nint res = dp[m - 1];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        min_path_sum.zig
        // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn minPathSumDPComp(comptime grid: anytype) i32 {\ncomptime var n = grid.len;\ncomptime var m = grid[0].len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** m;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\ndp[0] = grid[0][0];\nfor (1..m) |j| {\ndp[j] = dp[j - 1] + grid[0][j];\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (1..n) |i| {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\ndp[0] = dp[0] + grid[i][0];\nfor (1..m) |j| {\ndp[j] = @min(dp[j - 1], dp[j]) + grid[i][j];\n}\n}\nreturn dp[m - 1];\n}\n
        "},{"location":"chapter_dynamic_programming/edit_distance_problem/","title":"14.6 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898","text":"

        \u7f16\u8f91\u8ddd\u79bb\uff0c\u4e5f\u79f0 Levenshtein \u8ddd\u79bb\uff0c\u6307\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u4e92\u76f8\u8f6c\u6362\u7684\u6700\u5c11\u4fee\u6539\u6b21\u6570\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4fe1\u606f\u68c0\u7d22\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u5ea6\u91cf\u4e24\u4e2a\u5e8f\u5217\u7684\u76f8\u4f3c\u5ea6\u3002

        Question

        \u8f93\u5165\u4e24\u4e2a\u5b57\u7b26\u4e32 \\(s\\) \u548c \\(t\\) \uff0c\u8fd4\u56de\u5c06 \\(s\\) \u8f6c\u6362\u4e3a \\(t\\) \u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002

        \u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u8fdb\u884c\u4e09\u79cd\u7f16\u8f91\u64cd\u4f5c\uff1a\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u3001\u5220\u9664\u4e00\u4e2a\u5b57\u7b26\u3001\u5c06\u5b57\u7b26\u66ff\u6362\u4e3a\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002

        \u5982\u56fe 14-27 \u6240\u793a\uff0c\u5c06 kitten \u8f6c\u6362\u4e3a sitting \u9700\u8981\u7f16\u8f91 3 \u6b65\uff0c\u5305\u62ec 2 \u6b21\u66ff\u6362\u64cd\u4f5c\u4e0e 1 \u6b21\u6dfb\u52a0\u64cd\u4f5c\uff1b\u5c06 hello \u8f6c\u6362\u4e3a algo \u9700\u8981 3 \u6b65\uff0c\u5305\u62ec 2 \u6b21\u66ff\u6362\u64cd\u4f5c\u548c 1 \u6b21\u5220\u9664\u64cd\u4f5c\u3002

        \u56fe 14-27 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u793a\u4f8b\u6570\u636e

        \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u53ef\u4ee5\u5f88\u81ea\u7136\u5730\u7528\u51b3\u7b56\u6811\u6a21\u578b\u6765\u89e3\u91ca\u3002\u5b57\u7b26\u4e32\u5bf9\u5e94\u6811\u8282\u70b9\uff0c\u4e00\u8f6e\u51b3\u7b56\uff08\u4e00\u6b21\u7f16\u8f91\u64cd\u4f5c\uff09\u5bf9\u5e94\u6811\u7684\u4e00\u6761\u8fb9\u3002

        \u5982\u56fe 14-28 \u6240\u793a\uff0c\u5728\u4e0d\u9650\u5236\u64cd\u4f5c\u7684\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u6d3e\u751f\u51fa\u8bb8\u591a\u6761\u8fb9\uff0c\u6bcf\u6761\u8fb9\u5bf9\u5e94\u4e00\u79cd\u64cd\u4f5c\uff0c\u8fd9\u610f\u5473\u7740\u4ece hello \u8f6c\u6362\u5230 algo \u6709\u8bb8\u591a\u79cd\u53ef\u80fd\u7684\u8def\u5f84\u3002

        \u4ece\u51b3\u7b56\u6811\u7684\u89d2\u5ea6\u770b\uff0c\u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u8282\u70b9 hello \u548c\u8282\u70b9 algo \u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002

        \u56fe 14-28 \u00a0 \u57fa\u4e8e\u51b3\u7b56\u6811\u6a21\u578b\u8868\u793a\u7f16\u8f91\u8ddd\u79bb\u95ee\u9898

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u6bcf\u4e00\u8f6e\u7684\u51b3\u7b56\u662f\u5bf9\u5b57\u7b26\u4e32 \\(s\\) \u8fdb\u884c\u4e00\u6b21\u7f16\u8f91\u64cd\u4f5c\u3002

        \u6211\u4eec\u5e0c\u671b\u5728\u7f16\u8f91\u64cd\u4f5c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u95ee\u9898\u7684\u89c4\u6a21\u9010\u6e10\u7f29\u5c0f\uff0c\u8fd9\u6837\u624d\u80fd\u6784\u5efa\u5b50\u95ee\u9898\u3002\u8bbe\u5b57\u7b26\u4e32 \\(s\\) \u548c \\(t\\) \u7684\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\) \u548c \\(m\\) \uff0c\u6211\u4eec\u5148\u8003\u8651\u4e24\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u5b57\u7b26 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u3002

        • \u82e5 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u76f8\u540c\uff0c\u6211\u4eec\u53ef\u4ee5\u8df3\u8fc7\u5b83\u4eec\uff0c\u76f4\u63a5\u8003\u8651 \\(s[n-2]\\) \u548c \\(t[m-2]\\) \u3002
        • \u82e5 \\(s[n-1]\\) \u548c \\(t[m-1]\\) \u4e0d\u540c\uff0c\u6211\u4eec\u9700\u8981\u5bf9 \\(s\\) \u8fdb\u884c\u4e00\u6b21\u7f16\u8f91\uff08\u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\uff09\uff0c\u4f7f\u5f97\u4e24\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u5b57\u7b26\u76f8\u540c\uff0c\u4ece\u800c\u53ef\u4ee5\u8df3\u8fc7\u5b83\u4eec\uff0c\u8003\u8651\u89c4\u6a21\u66f4\u5c0f\u7684\u95ee\u9898\u3002

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5728\u5b57\u7b26\u4e32 \\(s\\) \u4e2d\u8fdb\u884c\u7684\u6bcf\u4e00\u8f6e\u51b3\u7b56\uff08\u7f16\u8f91\u64cd\u4f5c\uff09\uff0c\u90fd\u4f1a\u4f7f\u5f97 \\(s\\) \u548c \\(t\\) \u4e2d\u5269\u4f59\u7684\u5f85\u5339\u914d\u5b57\u7b26\u53d1\u751f\u53d8\u5316\u3002\u56e0\u6b64\uff0c\u72b6\u6001\u4e3a\u5f53\u524d\u5728 \\(s\\) \u548c \\(t\\) \u4e2d\u8003\u8651\u7684\u7b2c \\(i\\) \u548c\u7b2c \\(j\\) \u4e2a\u5b57\u7b26\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u72b6\u6001 \\([i, j]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\uff1a\u5c06 \\(s\\) \u7684\u524d \\(i\\) \u4e2a\u5b57\u7b26\u66f4\u6539\u4e3a \\(t\\) \u7684\u524d \\(j\\) \u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002

        \u81f3\u6b64\uff0c\u5f97\u5230\u4e00\u4e2a\u5c3a\u5bf8\u4e3a \\((i+1) \\times (j+1)\\) \u7684\u4e8c\u7ef4 \\(dp\\) \u8868\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u8003\u8651\u5b50\u95ee\u9898 \\(dp[i, j]\\) \uff0c\u5176\u5bf9\u5e94\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5c3e\u90e8\u5b57\u7b26\u4e3a \\(s[i-1]\\) \u548c \\(t[j-1]\\) \uff0c\u53ef\u6839\u636e\u4e0d\u540c\u7f16\u8f91\u64cd\u4f5c\u5206\u4e3a\u56fe 14-29 \u6240\u793a\u7684\u4e09\u79cd\u60c5\u51b5\u3002

        1. \u5728 \\(s[i-1]\\) \u4e4b\u540e\u6dfb\u52a0 \\(t[j-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i, j-1]\\) \u3002
        2. \u5220\u9664 \\(s[i-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i-1, j]\\) \u3002
        3. \u5c06 \\(s[i-1]\\) \u66ff\u6362\u4e3a \\(t[j-1]\\) \uff0c\u5219\u5269\u4f59\u5b50\u95ee\u9898 \\(dp[i-1, j-1]\\) \u3002

        \u56fe 14-29 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u72b6\u6001\u8f6c\u79fb

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u53ef\u5f97\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\\(dp[i, j]\\) \u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(dp[i, j-1]\\)\u3001\\(dp[i-1, j]\\)\u3001\\(dp[i-1, j-1]\\) \u4e09\u8005\u4e2d\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\uff0c\u518d\u52a0\u4e0a\u672c\u6b21\u7684\u7f16\u8f91\u6b65\u6570 \\(1\\) \u3002\u5bf9\u5e94\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, j] = \\min(dp[i, j-1], dp[i-1, j], dp[i-1, j-1]) + 1 \\]

        \u8bf7\u6ce8\u610f\uff0c\u5f53 \\(s[i-1]\\) \u548c \\(t[j-1]\\) \u76f8\u540c\u65f6\uff0c\u65e0\u987b\u7f16\u8f91\u5f53\u524d\u5b57\u7b26\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, j] = dp[i-1, j-1] \\]

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u4e24\u5b57\u7b26\u4e32\u90fd\u4e3a\u7a7a\u65f6\uff0c\u7f16\u8f91\u6b65\u6570\u4e3a \\(0\\) \uff0c\u5373 \\(dp[0, 0] = 0\\) \u3002\u5f53 \\(s\\) \u4e3a\u7a7a\u4f46 \\(t\\) \u4e0d\u4e3a\u7a7a\u65f6\uff0c\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(t\\) \u7684\u957f\u5ea6\uff0c\u5373\u9996\u884c \\(dp[0, j] = j\\) \u3002\u5f53 \\(s\\) \u4e0d\u4e3a\u7a7a\u4f46 \\(t\\) \u4e3a\u7a7a\u65f6\uff0c\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u7b49\u4e8e \\(s\\) \u7684\u957f\u5ea6\uff0c\u5373\u9996\u5217 \\(dp[i, 0] = i\\) \u3002

        \u89c2\u5bdf\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff0c\u89e3 \\(dp[i, j]\\) \u4f9d\u8d56\u5de6\u65b9\u3001\u4e0a\u65b9\u3001\u5de6\u4e0a\u65b9\u7684\u89e3\uff0c\u56e0\u6b64\u901a\u8fc7\u4e24\u5c42\u5faa\u73af\u6b63\u5e8f\u904d\u5386\u6574\u4e2a \\(dp\\) \u8868\u5373\u53ef\u3002

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig edit_distance.py
        def edit_distance_dp(s: str, t: str) -> int:\n\"\"\"\u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(s), len(t)\ndp = [[0] * (m + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in range(1, n + 1):\ndp[i][0] = i\nfor j in range(1, m + 1):\ndp[0][j] = j\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n + 1):\nfor j in range(1, m + 1):\nif s[i - 1] == t[j - 1]:\n# \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1]\nelse:\n# \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1\nreturn dp[n][m]\n
        edit_distance.cpp
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(string s, string t) {\nint n = s.length(), m = t.length();\nvector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.java
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\nint n = s.length(), m = t.length();\nint[][] dp = new int[n + 1][m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s.charAt(i - 1) == t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.cs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDP(string s, string t) {\nint n = s.Length, m = t.Length;\nint[,] dp = new int[n + 1, m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i, 0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0, j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i, j] = dp[i - 1, j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i, j] = Math.Min(Math.Min(dp[i, j - 1], dp[i - 1, j]), dp[i - 1, j - 1]) + 1;\n}\n}\n}\nreturn dp[n, m];\n}\n
        edit_distance.go
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s string, t string) int {\nn := len(s)\nm := len(t)\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, m+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i := 1; i <= n; i++ {\ndp[i][0] = i\n}\nfor j := 1; j <= m; j++ {\ndp[0][j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor j := 1; j <= m; j++ {\nif s[i-1] == t[j-1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i-1][j-1]\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = MinInt(MinInt(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1]) + 1\n}\n}\n}\nreturn dp[n][m]\n}\n
        edit_distance.swift
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s: String, t: String) -> Int {\nlet n = s.utf8CString.count\nlet m = t.utf8CString.count\nvar dp = Array(repeating: Array(repeating: 0, count: m + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in stride(from: 1, through: n, by: 1) {\ndp[i][0] = i\n}\nfor j in stride(from: 1, through: m, by: 1) {\ndp[0][j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, through: n, by: 1) {\nfor j in stride(from: 1, through: m, by: 1) {\nif s.utf8CString[i - 1] == t.utf8CString[j - 1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1]\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1\n}\n}\n}\nreturn dp[n][m]\n}\n
        edit_distance.js
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s, t) {\nconst n = s.length,\nm = t.length;\nconst dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (let j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let j = 1; j <= m; j++) {\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] =\nMath.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.ts
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s: string, t: string): number {\nconst n = s.length,\nm = t.length;\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: m + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (let j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let j = 1; j <= m; j++) {\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] =\nMath.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.dart
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\nint n = s.length, m = t.length;\nList<List<int>> dp = List.generate(n + 1, (_) => List.filled(m + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n
        edit_distance.rs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfn edit_distance_dp(s: &str, t: &str) -> i32 {\nlet (n, m) = (s.len(), t.len());\nlet mut dp = vec![vec![0; m + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor i in 1..= n {\ndp[i][0] = i as i32;\n}\nfor j in 1..m {\ndp[0][j] = j as i32;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..=n {\nfor j in 1..=m {\nif s.chars().nth(i - 1) == t.chars().nth(j - 1) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = std::cmp::min(std::cmp::min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\ndp[n][m]\n}\n
        edit_distance.c
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(char *s, char *t, int n, int m) {\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(m + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int i = 1; i <= n; i++) {\ndp[i][0] = i;\n}\nfor (int j = 1; j <= m; j++) {\ndp[0][j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int j = 1; j <= m; j++) {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = myMin(myMin(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nint res = dp[n][m];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        edit_distance.zig
        // \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212\nfn editDistanceDP(comptime s: []const u8, comptime t: []const u8) i32 {\ncomptime var n = s.len;\ncomptime var m = t.len;\nvar dp = [_][m + 1]i32{[_]i32{0} ** (m + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (1..n + 1) |i| {\ndp[i][0] = @intCast(i);\n}\nfor (1..m + 1) |j| {\ndp[0][j] = @intCast(j);\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n + 1) |i| {\nfor (1..m + 1) |j| {\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[i][j] = dp[i - 1][j - 1];\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[i][j] = @min(@min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n}\n}\n}\nreturn dp[n][m];\n}\n

        \u5982\u56fe 14-30 \u6240\u793a\uff0c\u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u7684\u72b6\u6001\u8f6c\u79fb\u8fc7\u7a0b\u4e0e\u80cc\u5305\u95ee\u9898\u975e\u5e38\u7c7b\u4f3c\uff0c\u90fd\u53ef\u4ee5\u770b\u4f5c\u586b\u5199\u4e00\u4e2a\u4e8c\u7ef4\u7f51\u683c\u7684\u8fc7\u7a0b\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14><15>

        \u56fe 14-30 \u00a0 \u7f16\u8f91\u8ddd\u79bb\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/edit_distance_problem/#3","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e \\(dp[i,j]\\) \u662f\u7531\u4e0a\u65b9 \\(dp[i-1, j]\\)\u3001\u5de6\u65b9 \\(dp[i, j-1]\\)\u3001\u5de6\u4e0a\u65b9 \\(dp[i-1, j-1]\\) \u8f6c\u79fb\u800c\u6765\u7684\uff0c\u800c\u6b63\u5e8f\u904d\u5386\u4f1a\u4e22\u5931\u5de6\u4e0a\u65b9 \\(dp[i-1, j-1]\\) \uff0c\u5012\u5e8f\u904d\u5386\u65e0\u6cd5\u63d0\u524d\u6784\u5efa \\(dp[i, j-1]\\) \uff0c\u56e0\u6b64\u4e24\u79cd\u904d\u5386\u987a\u5e8f\u90fd\u4e0d\u53ef\u53d6\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf leftup \u6765\u6682\u5b58\u5de6\u4e0a\u65b9\u7684\u89e3 \\(dp[i-1, j-1]\\) \uff0c\u4ece\u800c\u53ea\u9700\u8003\u8651\u5de6\u65b9\u548c\u4e0a\u65b9\u7684\u89e3\u3002\u6b64\u65f6\u7684\u60c5\u51b5\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u76f8\u540c\uff0c\u53ef\u4f7f\u7528\u6b63\u5e8f\u904d\u5386\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig edit_distance.py
        def edit_distance_dp_comp(s: str, t: str) -> int:\n\"\"\"\u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn, m = len(s), len(t)\ndp = [0] * (m + 1)\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in range(1, m + 1):\ndp[j] = j\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in range(1, n + 1):\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nleftup = dp[0]  # \u6682\u5b58 dp[i-1, j-1]\ndp[0] += 1\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in range(1, m + 1):\ntemp = dp[j]\nif s[i - 1] == t[j - 1]:\n# \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup\nelse:\n# \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(dp[j - 1], dp[j], leftup) + 1\nleftup = temp  # \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\nreturn dp[m]\n
        edit_distance.cpp
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(string s, string t) {\nint n = s.length(), m = t.length();\nvector<int> dp(m + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.java
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(String s, String t) {\nint n = s.length(), m = t.length();\nint[] dp = new int[m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s.charAt(i - 1) == t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(Math.min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.cs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDPComp(string s, string t) {\nint n = s.Length, m = t.Length;\nint[] dp = new int[m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.Min(Math.Min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.go
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDPComp(s string, t string) int {\nn := len(s)\nm := len(t)\ndp := make([]int, m+1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j := 1; j <= m; j++ {\ndp[j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i := 1; i <= n; i++ {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nleftUp := dp[0] // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j := 1; j <= m; j++ {\ntemp := dp[j]\nif s[i-1] == t[j-1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftUp\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = MinInt(MinInt(dp[j-1], dp[j]), leftUp) + 1\n}\nleftUp = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m]\n}\n
        edit_distance.swift
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDPComp(s: String, t: String) -> Int {\nlet n = s.utf8CString.count\nlet m = t.utf8CString.count\nvar dp = Array(repeating: 0, count: m + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in stride(from: 1, through: m, by: 1) {\ndp[j] = j\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in stride(from: 1, through: n, by: 1) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nvar leftup = dp[0] // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in stride(from: 1, through: m, by: 1) {\nlet temp = dp[j]\nif s.utf8CString[i - 1] == t.utf8CString[j - 1] {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1\n}\nleftup = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m]\n}\n
        edit_distance.js
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDPComp(s, t) {\nconst n = s.length,\nm = t.length;\nconst dp = new Array(m + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j <= m; j++) {\nconst temp = dp[j];\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.ts
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDPComp(s: string, t: string): number {\nconst n = s.length,\nm = t.length;\nconst dp = new Array(m + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (let j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (let i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (let j = 1; j <= m; j++) {\nconst temp = dp[j];\nif (s.charAt(i - 1) === t.charAt(j - 1)) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.dart
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(String s, String t) {\nint n = s.length, m = t.length;\nList<int> dp = List.filled(m + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        edit_distance.rs
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn edit_distance_dp_comp(s: &str, t: &str) -> i32 {\nlet (n, m) = (s.len(), t.len());\nlet mut dp = vec![0; m + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor j in 1..m {\ndp[j] = j as i32;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor i in 1..=n {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nlet mut leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i as i32;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor j in 1..=m {\nlet temp = dp[j];\nif s.chars().nth(i - 1) == t.chars().nth(j - 1) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = std::cmp::min(std::cmp::min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\ndp[m]\n}\n
        edit_distance.c
        /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint editDistanceDPComp(char *s, char *t, int n, int m) {\nint *dp = calloc(m + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (int j = 1; j <= m; j++) {\ndp[j] = j;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (int i = 1; i <= n; i++) {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nint leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = i;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (int j = 1; j <= m; j++) {\nint temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = myMin(myMin(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nint res = dp[m];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        edit_distance.zig
        // \u7f16\u8f91\u8ddd\u79bb\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn editDistanceDPComp(comptime s: []const u8, comptime t: []const u8) i32 {\ncomptime var n = s.len;\ncomptime var m = t.len;\nvar dp = [_]i32{0} ** (m + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\nfor (1..m + 1) |j| {\ndp[j] = @intCast(j);\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\nfor (1..n + 1) |i| {\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\nvar leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\ndp[0] = @intCast(i);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\nfor (1..m + 1) |j| {\nvar temp = dp[j];\nif (s[i - 1] == t[j - 1]) {\n// \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\ndp[j] = leftup;\n} else {\n// \u6700\u5c11\u7f16\u8f91\u6b65\u6570 = \u63d2\u5165\u3001\u5220\u9664\u3001\u66ff\u6362\u8fd9\u4e09\u79cd\u64cd\u4f5c\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570 + 1\ndp[j] = @min(@min(dp[j - 1], dp[j]), leftup) + 1;\n}\nleftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n}\n}\nreturn dp[m];\n}\n
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/","title":"14.1 \u00a0 \u521d\u63a2\u52a8\u6001\u89c4\u5212","text":"

        \u300c\u52a8\u6001\u89c4\u5212 dynamic programming\u300d\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u7b97\u6cd5\u8303\u5f0f\uff0c\u5b83\u5c06\u4e00\u4e2a\u95ee\u9898\u5206\u89e3\u4e3a\u4e00\u7cfb\u5217\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u5e76\u901a\u8fc7\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\u6765\u907f\u514d\u91cd\u590d\u8ba1\u7b97\uff0c\u4ece\u800c\u5927\u5e45\u63d0\u5347\u65f6\u95f4\u6548\u7387\u3002

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u4ece\u4e00\u4e2a\u7ecf\u5178\u4f8b\u9898\u5165\u624b\uff0c\u5148\u7ed9\u51fa\u5b83\u7684\u66b4\u529b\u56de\u6eaf\u89e3\u6cd5\uff0c\u89c2\u5bdf\u5176\u4e2d\u5305\u542b\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u518d\u9010\u6b65\u5bfc\u51fa\u66f4\u9ad8\u6548\u7684\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u3002

        \u722c\u697c\u68af

        \u7ed9\u5b9a\u4e00\u4e2a\u5171\u6709 \\(n\\) \u9636\u7684\u697c\u68af\uff0c\u4f60\u6bcf\u6b65\u53ef\u4ee5\u4e0a \\(1\\) \u9636\u6216\u8005 \\(2\\) \u9636\uff0c\u8bf7\u95ee\u6709\u591a\u5c11\u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\uff1f

        \u5982\u56fe 14-1 \u6240\u793a\uff0c\u5bf9\u4e8e\u4e00\u4e2a \\(3\\) \u9636\u697c\u68af\uff0c\u5171\u6709 \\(3\\) \u79cd\u65b9\u6848\u53ef\u4ee5\u722c\u5230\u697c\u9876\u3002

        \u56fe 14-1 \u00a0 \u722c\u5230\u7b2c 3 \u9636\u7684\u65b9\u6848\u6570\u91cf

        \u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u65b9\u6848\u6570\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u901a\u8fc7\u56de\u6eaf\u6765\u7a77\u4e3e\u6240\u6709\u53ef\u80fd\u6027\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5c06\u722c\u697c\u68af\u60f3\u8c61\u4e3a\u4e00\u4e2a\u591a\u8f6e\u9009\u62e9\u7684\u8fc7\u7a0b\uff1a\u4ece\u5730\u9762\u51fa\u53d1\uff0c\u6bcf\u8f6e\u9009\u62e9\u4e0a \\(1\\) \u9636\u6216 \\(2\\) \u9636\uff0c\u6bcf\u5f53\u5230\u8fbe\u697c\u68af\u9876\u90e8\u65f6\u5c31\u5c06\u65b9\u6848\u6570\u91cf\u52a0 \\(1\\) \uff0c\u5f53\u8d8a\u8fc7\u697c\u68af\u9876\u90e8\u65f6\u5c31\u5c06\u5176\u526a\u679d\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_backtrack.py
        def backtrack(choices: list[int], state: int, n: int, res: list[int]) -> int:\n\"\"\"\u56de\u6eaf\"\"\"\n# \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n:\nres[0] += 1\n# \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices:\n# \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n:\ncontinue\n# \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res)\n# \u56de\u9000\ndef climbing_stairs_backtrack(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u56de\u6eaf\"\"\"\nchoices = [1, 2]  # \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nstate = 0  # \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nres = [0]  # \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res)\nreturn res[0]\n
        climbing_stairs_backtrack.cpp
        /* \u56de\u6eaf */\nvoid backtrack(vector<int> &choices, int state, int n, vector<int> &res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (auto &choice : choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nvector<int> choices = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0;                // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvector<int> res = {0};        // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.java
        /* \u56de\u6eaf */\nvoid backtrack(List<Integer> choices, int state, int n, List<Integer> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (Integer choice : choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nList<Integer> choices = Arrays.asList(1, 2); // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<Integer> res = new ArrayList<>();\nres.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.cs
        /* \u56de\u6eaf */\nvoid Backtrack(List<int> choices, int state, int n, List<int> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nforeach (int choice in choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nBacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint ClimbingStairsBacktrack(int n) {\nList<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<int> res = [0]; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nBacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.go
        /* \u56de\u6eaf */\nfunc backtrack(choices []int, state, n int, res []int) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n {\nres[0] = res[0] + 1\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor _, choice := range choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state+choice > n {\ncontinue\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state+choice, n, res)\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n int) int {\n// \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nchoices := []int{1, 2}\n// \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nstate := 0\nres := make([]int, 1)\n// \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nres[0] = 0\nbacktrack(choices, state, n, res)\nreturn res[0]\n}\n
        climbing_stairs_backtrack.swift
        /* \u56de\u6eaf */\nfunc backtrack(choices: [Int], state: Int, n: Int, res: inout [Int]) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n {\nres[0] += 1\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor choice in choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n {\ncontinue\n}\nbacktrack(choices: choices, state: state + choice, n: n, res: &res)\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n: Int) -> Int {\nlet choices = [1, 2] // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nlet state = 0 // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvar res: [Int] = []\nres.append(0) // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices: choices, state: state, n: n, res: &res)\nreturn res[0]\n}\n
        climbing_stairs_backtrack.js
        /* \u56de\u6eaf */\nfunction backtrack(choices, state, n, res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state === n) res.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n) {\nconst choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nconst state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nconst res = new Map();\nres.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.ts
        /* \u56de\u6eaf */\nfunction backtrack(\nchoices: number[],\nstate: number,\nn: number,\nres: Map<0, any>\n): void {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state === n) res.set(0, res.get(0) + 1);\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (const choice of choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n: number): number {\nconst choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nconst state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nconst res = new Map();\nres.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res.get(0);\n}\n
        climbing_stairs_backtrack.dart
        /* \u56de\u6eaf */\nvoid backtrack(List<int> choices, int state, int n, List<int> res) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n) {\nres[0]++;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int choice in choices) {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) continue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nList<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nList<int> res = [];\nres.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(choices, state, n, res);\nreturn res[0];\n}\n
        climbing_stairs_backtrack.rs
        /* \u56de\u6eaf */\nfn backtrack(choices: &[i32], state: i32, n: i32, res: &mut [i32]) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif state == n { res[0] = res[0] + 1; }\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor &choice in choices {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif state + choice > n { continue; }\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfn climbing_stairs_backtrack(n: usize) -> i32 {\nlet choices = vec![ 1, 2 ]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nlet state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nlet mut res = Vec::new();\nres.push(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(&choices, state, n as i32, &mut res);\nres[0]\n}\n
        climbing_stairs_backtrack.c
        /* \u56de\u6eaf */\nvoid backtrack(int *choices, int state, int n, int *res, int len) {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n)\nres[0]++;\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (int i = 0; i < len; i++) {\nint choice = choices[i];\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n)\ncontinue;\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res, len);\n// \u56de\u9000\n}\n}\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\nint choices[2] = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nint state = 0;           // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nint *res = (int *)malloc(sizeof(int));\n*res = 0; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nint len = sizeof(choices) / sizeof(int);\nbacktrack(choices, state, n, res, len);\nint result = *res;\nfree(res);\nreturn result;\n}\n
        climbing_stairs_backtrack.zig
        // \u56de\u6eaf\nfn backtrack(choices: []i32, state: i32, n: i32, res: std.ArrayList(i32)) void {\n// \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\nif (state == n) {\nres.items[0] = res.items[0] + 1;\n}\n// \u904d\u5386\u6240\u6709\u9009\u62e9\nfor (choices) |choice| {\n// \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\nif (state + choice > n) {\ncontinue;\n}\n// \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\nbacktrack(choices, state + choice, n, res);\n// \u56de\u9000\n}\n}\n// \u722c\u697c\u68af\uff1a\u56de\u6eaf\nfn climbingStairsBacktrack(n: usize) !i32 {\nvar choices = [_]i32{ 1, 2 }; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\nvar state: i32 = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\nvar res = std.ArrayList(i32).init(std.heap.page_allocator);\ndefer res.deinit();\ntry res.append(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\nbacktrack(&choices, state, @intCast(n), res);\nreturn res.items[0];\n}\n
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1411","title":"14.1.1 \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u56de\u6eaf\u7b97\u6cd5\u901a\u5e38\u5e76\u4e0d\u663e\u5f0f\u5730\u5bf9\u95ee\u9898\u8fdb\u884c\u62c6\u89e3\uff0c\u800c\u662f\u5c06\u6c42\u89e3\u95ee\u9898\u770b\u4f5c\u4e00\u7cfb\u5217\u51b3\u7b56\u6b65\u9aa4\uff0c\u901a\u8fc7\u8bd5\u63a2\u548c\u526a\u679d\uff0c\u641c\u7d22\u6240\u6709\u53ef\u80fd\u7684\u89e3\u3002

        \u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u4ece\u95ee\u9898\u5206\u89e3\u7684\u89d2\u5ea6\u5206\u6790\u8fd9\u9053\u9898\u3002\u8bbe\u722c\u5230\u7b2c \\(i\\) \u9636\u5171\u6709 \\(dp[i]\\) \u79cd\u65b9\u6848\uff0c\u90a3\u4e48 \\(dp[i]\\) \u5c31\u662f\u539f\u95ee\u9898\uff0c\u5176\u5b50\u95ee\u9898\u5305\u62ec\uff1a

        \\[ dp[i-1], dp[i-2], \\dots, dp[2], dp[1] \\]

        \u7531\u4e8e\u6bcf\u8f6e\u53ea\u80fd\u4e0a \\(1\\) \u9636\u6216 \\(2\\) \u9636\uff0c\u56e0\u6b64\u5f53\u6211\u4eec\u7ad9\u5728\u7b2c \\(i\\) \u9636\u697c\u68af\u4e0a\u65f6\uff0c\u4e0a\u4e00\u8f6e\u53ea\u53ef\u80fd\u7ad9\u5728\u7b2c \\(i - 1\\) \u9636\u6216\u7b2c \\(i - 2\\) \u9636\u4e0a\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u53ea\u80fd\u4ece\u7b2c \\(i -1\\) \u9636\u6216\u7b2c \\(i - 2\\) \u9636\u8fc8\u5411\u7b2c \\(i\\) \u9636\u3002

        \u7531\u6b64\u4fbf\u53ef\u5f97\u51fa\u4e00\u4e2a\u91cd\u8981\u63a8\u8bba\uff1a\u722c\u5230\u7b2c \\(i - 1\\) \u9636\u7684\u65b9\u6848\u6570\u52a0\u4e0a\u722c\u5230\u7b2c \\(i - 2\\) \u9636\u7684\u65b9\u6848\u6570\u5c31\u7b49\u4e8e\u722c\u5230\u7b2c \\(i\\) \u9636\u7684\u65b9\u6848\u6570\u3002\u516c\u5f0f\u5982\u4e0b\uff1a

        \\[ dp[i] = dp[i-1] + dp[i-2] \\]

        \u8fd9\u610f\u5473\u7740\u5728\u722c\u697c\u68af\u95ee\u9898\u4e2d\uff0c\u5404\u4e2a\u5b50\u95ee\u9898\u4e4b\u95f4\u5b58\u5728\u9012\u63a8\u5173\u7cfb\uff0c\u539f\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u7531\u5b50\u95ee\u9898\u7684\u89e3\u6784\u5efa\u5f97\u6765\u3002\u56fe 14-2 \u5c55\u793a\u4e86\u8be5\u9012\u63a8\u5173\u7cfb\u3002

        \u56fe 14-2 \u00a0 \u65b9\u6848\u6570\u91cf\u9012\u63a8\u5173\u7cfb

        \u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9012\u63a8\u516c\u5f0f\u5f97\u5230\u66b4\u529b\u641c\u7d22\u89e3\u6cd5\u3002\u4ee5 \\(dp[n]\\) \u4e3a\u8d77\u59cb\u70b9\uff0c\u9012\u5f52\u5730\u5c06\u4e00\u4e2a\u8f83\u5927\u95ee\u9898\u62c6\u89e3\u4e3a\u4e24\u4e2a\u8f83\u5c0f\u95ee\u9898\u7684\u548c\uff0c\u76f4\u81f3\u5230\u8fbe\u6700\u5c0f\u5b50\u95ee\u9898 \\(dp[1]\\) \u548c \\(dp[2]\\) \u65f6\u8fd4\u56de\u3002\u5176\u4e2d\uff0c\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u662f\u5df2\u77e5\u7684\uff0c\u5373 \\(dp[1] = 1\\)\u3001\\(dp[2] = 2\\) \uff0c\u8868\u793a\u722c\u5230\u7b2c \\(1\\)\u3001\\(2\\) \u9636\u5206\u522b\u6709 \\(1\\)\u3001\\(2\\) \u79cd\u65b9\u6848\u3002

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5b83\u548c\u6807\u51c6\u56de\u6eaf\u4ee3\u7801\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff0c\u4f46\u66f4\u52a0\u7b80\u6d01\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dfs.py
        def dfs(i: int) -> int:\n\"\"\"\u641c\u7d22\"\"\"\n# \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 or i == 2:\nreturn i\n# dp[i] = dp[i-1] + dp[i-2]\ncount = dfs(i - 1) + dfs(i - 2)\nreturn count\ndef climbing_stairs_dfs(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u641c\u7d22\"\"\"\nreturn dfs(n)\n
        climbing_stairs_dfs.cpp
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.java
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.cs
        /* \u641c\u7d22 */\nint DFS(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = DFS(i - 1) + DFS(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint ClimbingStairsDFS(int n) {\nreturn DFS(n);\n}\n
        climbing_stairs_dfs.go
        /* \u641c\u7d22 */\nfunc dfs(i int) int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// dp[i] = dp[i-1] + dp[i-2]\ncount := dfs(i-1) + dfs(i-2)\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n int) int {\nreturn dfs(n)\n}\n
        climbing_stairs_dfs.swift
        /* \u641c\u7d22 */\nfunc dfs(i: Int) -> Int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i: i - 1) + dfs(i: i - 2)\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n: Int) -> Int {\ndfs(i: n)\n}\n
        climbing_stairs_dfs.js
        /* \u641c\u7d22 */\nfunction dfs(i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.ts
        /* \u641c\u7d22 */\nfunction dfs(i: number): number {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n: number): number {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.dart
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2) return i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.rs
        /* \u641c\u7d22 */\nfn dfs(i: usize) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 { return i as i32; }\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i - 1) + dfs(i - 2);\ncount\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfn climbing_stairs_dfs(n: usize) -> i32 {\ndfs(n) }\n
        climbing_stairs_dfs.c
        /* \u641c\u7d22 */\nint dfs(int i) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\nreturn dfs(n);\n}\n
        climbing_stairs_dfs.zig
        // \u641c\u7d22\nfn dfs(i: usize) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 or i == 2) {\nreturn @intCast(i);\n}\n// dp[i] = dp[i-1] + dp[i-2]\nvar count = dfs(i - 1) + dfs(i - 2);\nreturn count;\n}\n// \u722c\u697c\u68af\uff1a\u641c\u7d22\nfn climbingStairsDFS(comptime n: usize) i32 {\nreturn dfs(n);\n}\n

        \u56fe 14-3 \u5c55\u793a\u4e86\u66b4\u529b\u641c\u7d22\u5f62\u6210\u7684\u9012\u5f52\u6811\u3002\u5bf9\u4e8e\u95ee\u9898 \\(dp[n]\\) \uff0c\u5176\u9012\u5f52\u6811\u7684\u6df1\u5ea6\u4e3a \\(n\\) \uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002\u6307\u6570\u9636\u5c5e\u4e8e\u7206\u70b8\u5f0f\u589e\u957f\uff0c\u5982\u679c\u6211\u4eec\u8f93\u5165\u4e00\u4e2a\u6bd4\u8f83\u5927\u7684 \\(n\\) \uff0c\u5219\u4f1a\u9677\u5165\u6f2b\u957f\u7684\u7b49\u5f85\u4e4b\u4e2d\u3002

        \u56fe 14-3 \u00a0 \u722c\u697c\u68af\u5bf9\u5e94\u9012\u5f52\u6811

        \u89c2\u5bdf\u56fe 14-3 \uff0c\u6307\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u201c\u91cd\u53e0\u5b50\u95ee\u9898\u201d\u5bfc\u81f4\u7684\u3002\u4f8b\u5982 \\(dp[9]\\) \u88ab\u5206\u89e3\u4e3a \\(dp[8]\\) \u548c \\(dp[7]\\) \uff0c\\(dp[8]\\) \u88ab\u5206\u89e3\u4e3a \\(dp[7]\\) \u548c \\(dp[6]\\) \uff0c\u4e24\u8005\u90fd\u5305\u542b\u5b50\u95ee\u9898 \\(dp[7]\\) \u3002

        \u4ee5\u6b64\u7c7b\u63a8\uff0c\u5b50\u95ee\u9898\u4e2d\u5305\u542b\u66f4\u5c0f\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u5b50\u5b50\u5b59\u5b59\u65e0\u7a77\u5c3d\u4e5f\u3002\u7edd\u5927\u90e8\u5206\u8ba1\u7b97\u8d44\u6e90\u90fd\u6d6a\u8d39\u5728\u8fd9\u4e9b\u91cd\u53e0\u7684\u95ee\u9898\u4e0a\u3002

        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1412","title":"14.1.2 \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u4e3a\u4e86\u63d0\u5347\u7b97\u6cd5\u6548\u7387\uff0c\u6211\u4eec\u5e0c\u671b\u6240\u6709\u7684\u91cd\u53e0\u5b50\u95ee\u9898\u90fd\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u6570\u7ec4 mem \u6765\u8bb0\u5f55\u6bcf\u4e2a\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5e76\u5728\u641c\u7d22\u8fc7\u7a0b\u4e2d\u5c06\u91cd\u53e0\u5b50\u95ee\u9898\u526a\u679d\u3002

        1. \u5f53\u9996\u6b21\u8ba1\u7b97 \\(dp[i]\\) \u65f6\uff0c\u6211\u4eec\u5c06\u5176\u8bb0\u5f55\u81f3 mem[i] \uff0c\u4ee5\u4fbf\u4e4b\u540e\u4f7f\u7528\u3002
        2. \u5f53\u518d\u6b21\u9700\u8981\u8ba1\u7b97 \\(dp[i]\\) \u65f6\uff0c\u6211\u4eec\u4fbf\u53ef\u76f4\u63a5\u4ece mem[i] \u4e2d\u83b7\u53d6\u7ed3\u679c\uff0c\u4ece\u800c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u8be5\u5b50\u95ee\u9898\u3002

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dfs_mem.py
        def dfs(i: int, mem: list[int]) -> int:\n\"\"\"\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 or i == 2:\nreturn i\n# \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1:\nreturn mem[i]\n# dp[i] = dp[i-1] + dp[i-2]\ncount = dfs(i - 1, mem) + dfs(i - 2, mem)\n# \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\ndef climbing_stairs_dfs_mem(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nmem = [-1] * (n + 1)\nreturn dfs(n, mem)\n
        climbing_stairs_dfs_mem.cpp
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, vector<int> &mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvector<int> mem(n + 1, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.java
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, int[] mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint[] mem = new int[n + 1];\nArrays.fill(mem, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.cs
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint DFS(int i, int[] mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = DFS(i - 1, mem) + DFS(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint ClimbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint[] mem = new int[n + 1];\nArray.Fill(mem, -1);\nreturn DFS(n, mem);\n}\n
        climbing_stairs_dfs_mem.go
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc dfsMem(i int, mem []int) int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 {\nreturn mem[i]\n}\n// dp[i] = dp[i-1] + dp[i-2]\ncount := dfsMem(i-1, mem) + dfsMem(i-2, mem)\n// \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc climbingStairsDFSMem(n int) int {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nmem := make([]int, n+1)\nfor i := range mem {\nmem[i] = -1\n}\nreturn dfsMem(n, mem)\n}\n
        climbing_stairs_dfs_mem.swift
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc dfs(i: Int, mem: inout [Int]) -> Int {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 {\nreturn i\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 {\nreturn mem[i]\n}\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i: i - 1, mem: &mem) + dfs(i: i - 2, mem: &mem)\n// \u8bb0\u5f55 dp[i]\nmem[i] = count\nreturn count\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc climbingStairsDFSMem(n: Int) -> Int {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvar mem = Array(repeating: -1, count: n + 1)\nreturn dfs(i: n, mem: &mem)\n}\n
        climbing_stairs_dfs_mem.js
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction dfs(i, mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction climbingStairsDFSMem(n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nconst mem = new Array(n + 1).fill(-1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.ts
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction dfs(i: number, mem: number[]): number {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i === 1 || i === 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nconst count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction climbingStairsDFSMem(n: number): number {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nconst mem = new Array(n + 1).fill(-1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.dart
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, List<int> mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2) return i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) return mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nList<int> mem = List.filled(n + 1, -1);\nreturn dfs(n, mem);\n}\n
        climbing_stairs_dfs_mem.rs
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn dfs(i: usize, mem: &mut [i32]) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif i == 1 || i == 2 { return i as i32; }\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif mem[i] != -1 { return mem[i]; }\n// dp[i] = dp[i-1] + dp[i-2]\nlet count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\ncount\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn climbing_stairs_dfs_mem(n: usize) -> i32 {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nlet mut mem = vec![-1; n + 1];\ndfs(n, &mut mem)\n}\n
        climbing_stairs_dfs_mem.c
        /* \u8bb0\u5fc6\u5316\u641c\u7d22 */\nint dfs(int i, int *mem) {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 || i == 2)\nreturn i;\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1)\nreturn mem[i];\n// dp[i] = dp[i-1] + dp[i-2]\nint count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n/* \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint climbingStairsDFSMem(int n) {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nint *mem = (int *)malloc((n + 1) * sizeof(int));\nfor (int i = 0; i <= n; i++) {\nmem[i] = -1;\n}\nint result = dfs(n, mem);\nfree(mem);\nreturn result;\n}\n
        climbing_stairs_dfs_mem.zig
        // \u8bb0\u5fc6\u5316\u641c\u7d22\nfn dfs(i: usize, mem: []i32) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (i == 1 or i == 2) {\nreturn @intCast(i);\n}\n// \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\nif (mem[i] != -1) {\nreturn mem[i];\n}\n// dp[i] = dp[i-1] + dp[i-2]\nvar count = dfs(i - 1, mem) + dfs(i - 2, mem);\n// \u8bb0\u5f55 dp[i]\nmem[i] = count;\nreturn count;\n}\n// \u722c\u697c\u68af\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn climbingStairsDFSMem(comptime n: usize) i32 {\n// mem[i] \u8bb0\u5f55\u722c\u5230\u7b2c i \u9636\u7684\u65b9\u6848\u603b\u6570\uff0c-1 \u4ee3\u8868\u65e0\u8bb0\u5f55\nvar mem = [_]i32{ -1 } ** (n + 1);\nreturn dfs(n, &mem);\n}\n

        \u89c2\u5bdf\u56fe 14-4 \uff0c\u7ecf\u8fc7\u8bb0\u5fc6\u5316\u5904\u7406\u540e\uff0c\u6240\u6709\u91cd\u53e0\u5b50\u95ee\u9898\u90fd\u53ea\u9700\u8ba1\u7b97\u4e00\u6b21\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(n)\\) \uff0c\u8fd9\u662f\u4e00\u4e2a\u5de8\u5927\u7684\u98de\u8dc3\u3002

        \u56fe 14-4 \u00a0 \u8bb0\u5fc6\u5316\u641c\u7d22\u5bf9\u5e94\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1413","title":"14.1.3 \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u8bb0\u5fc6\u5316\u641c\u7d22\u662f\u4e00\u79cd\u201c\u4ece\u9876\u81f3\u5e95\u201d\u7684\u65b9\u6cd5\uff1a\u6211\u4eec\u4ece\u539f\u95ee\u9898\uff08\u6839\u8282\u70b9\uff09\u5f00\u59cb\uff0c\u9012\u5f52\u5730\u5c06\u8f83\u5927\u5b50\u95ee\u9898\u5206\u89e3\u4e3a\u8f83\u5c0f\u5b50\u95ee\u9898\uff0c\u76f4\u81f3\u89e3\u5df2\u77e5\u7684\u6700\u5c0f\u5b50\u95ee\u9898\uff08\u53f6\u8282\u70b9\uff09\u3002\u4e4b\u540e\uff0c\u901a\u8fc7\u56de\u6eaf\u9010\u5c42\u6536\u96c6\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u6784\u5efa\u51fa\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u4e0e\u4e4b\u76f8\u53cd\uff0c\u52a8\u6001\u89c4\u5212\u662f\u4e00\u79cd\u201c\u4ece\u5e95\u81f3\u9876\u201d\u7684\u65b9\u6cd5\uff1a\u4ece\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\u5f00\u59cb\uff0c\u8fed\u4ee3\u5730\u6784\u5efa\u66f4\u5927\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u76f4\u81f3\u5f97\u5230\u539f\u95ee\u9898\u7684\u89e3\u3002

        \u7531\u4e8e\u52a8\u6001\u89c4\u5212\u4e0d\u5305\u542b\u56de\u6eaf\u8fc7\u7a0b\uff0c\u56e0\u6b64\u53ea\u9700\u4f7f\u7528\u5faa\u73af\u8fed\u4ee3\u5b9e\u73b0\uff0c\u65e0\u987b\u4f7f\u7528\u9012\u5f52\u3002\u5728\u4ee5\u4e0b\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521d\u59cb\u5316\u4e00\u4e2a\u6570\u7ec4 dp \u6765\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5b83\u8d77\u5230\u4e86\u4e0e\u8bb0\u5fc6\u5316\u641c\u7d22\u4e2d\u6570\u7ec4 mem \u76f8\u540c\u7684\u8bb0\u5f55\u4f5c\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dp.py
        def climbing_stairs_dp(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn n\n# \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp = [0] * (n + 1)\n# \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1], dp[2] = 1, 2\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in range(3, n + 1):\ndp[i] = dp[i - 1] + dp[i - 2]\nreturn dp[n]\n
        climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvector<int> dp(n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.java
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint[] dp = new int[n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.go
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n int) int {\nif n == 1 || n == 2 {\nreturn n\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\ndp := make([]int, n+1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1\ndp[2] = 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\ndp[i] = dp[i-1] + dp[i-2]\n}\nreturn dp[n]\n}\n
        climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn n\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = Array(repeating: 0, count: n + 1)\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1\ndp[2] = 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in stride(from: 3, through: n, by: 1) {\ndp[i] = dp[i - 1] + dp[i - 2]\n}\nreturn dp[n]\n}\n
        climbing_stairs_dp.js
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n) {\nif (n === 1 || n === 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1).fill(-1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n: number): number {\nif (n === 1 || n === 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nconst dp = new Array(n + 1).fill(-1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (let i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2) return n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nList<int> dp = List.filled(n + 1, 0);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n
        climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_dp(n: usize) -> i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif n == 1 || n == 2 { return n as i32; }\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nlet mut dp = vec![-1; n + 1];\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i in 3..=n {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\ndp[n]\n}\n
        climbing_stairs_dp.c
        /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\nif (n == 1 || n == 2)\nreturn n;\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nint *dp = (int *)malloc((n + 1) * sizeof(int));\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (int i = 3; i <= n; i++) {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nint result = dp[n];\nfree(dp);\nreturn result;\n}\n
        climbing_stairs_dp.zig
        // \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212\nfn climbingStairsDP(comptime n: usize) i32 {\n// \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\nif (n == 1 or n == 2) {\nreturn @intCast(n);\n}\n// \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\nvar dp = [_]i32{-1} ** (n + 1);\n// \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\ndp[1] = 1;\ndp[2] = 2;\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor (3..n + 1) |i| {\ndp[i] = dp[i - 1] + dp[i - 2];\n}\nreturn dp[n];\n}\n

        \u56fe 14-5 \u6a21\u62df\u4e86\u4ee5\u4e0a\u4ee3\u7801\u7684\u6267\u884c\u8fc7\u7a0b\u3002

        \u56fe 14-5 \u00a0 \u722c\u697c\u68af\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u4e0e\u56de\u6eaf\u7b97\u6cd5\u4e00\u6837\uff0c\u52a8\u6001\u89c4\u5212\u4e5f\u4f7f\u7528\u201c\u72b6\u6001\u201d\u6982\u5ff5\u6765\u8868\u793a\u95ee\u9898\u6c42\u89e3\u7684\u7279\u5b9a\u9636\u6bb5\uff0c\u6bcf\u4e2a\u72b6\u6001\u90fd\u5bf9\u5e94\u4e00\u4e2a\u5b50\u95ee\u9898\u4ee5\u53ca\u76f8\u5e94\u7684\u5c40\u90e8\u6700\u4f18\u89e3\u3002\u4f8b\u5982\uff0c\u722c\u697c\u68af\u95ee\u9898\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u5f53\u524d\u6240\u5728\u697c\u68af\u9636\u6570 \\(i\\) \u3002

        \u6839\u636e\u4ee5\u4e0a\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u52a8\u6001\u89c4\u5212\u7684\u5e38\u7528\u672f\u8bed\u3002

        • \u5c06\u6570\u7ec4 dp \u79f0\u4e3a\u300c\\(dp\\) \u8868\u300d\uff0c\\(dp[i]\\) \u8868\u793a\u72b6\u6001 \\(i\\) \u5bf9\u5e94\u5b50\u95ee\u9898\u7684\u89e3\u3002
        • \u5c06\u6700\u5c0f\u5b50\u95ee\u9898\u5bf9\u5e94\u7684\u72b6\u6001\uff08\u7b2c \\(1\\) \u9636\u548c\u7b2c \\(2\\) \u9636\u697c\u68af\uff09\u79f0\u4e3a\u300c\u521d\u59cb\u72b6\u6001\u300d\u3002
        • \u5c06\u9012\u63a8\u516c\u5f0f \\(dp[i] = dp[i-1] + dp[i-2]\\) \u79f0\u4e3a\u300c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u300d\u3002
        "},{"location":"chapter_dynamic_programming/intro_to_dynamic_programming/#1414","title":"14.1.4 \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7ec6\u5fc3\u7684\u8bfb\u8005\u53ef\u80fd\u53d1\u73b0\u4e86\uff0c\u7531\u4e8e \\(dp[i]\\) \u53ea\u4e0e \\(dp[i-1]\\) \u548c \\(dp[i-2]\\) \u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u987b\u4f7f\u7528\u4e00\u4e2a\u6570\u7ec4 dp \u6765\u5b58\u50a8\u6240\u6709\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u800c\u53ea\u9700\u4e24\u4e2a\u53d8\u91cf\u6eda\u52a8\u524d\u8fdb\u5373\u53ef\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig climbing_stairs_dp.py
        def climbing_stairs_dp_comp(n: int) -> int:\n\"\"\"\u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nif n == 1 or n == 2:\nreturn n\na, b = 1, 2\nfor _ in range(3, n + 1):\na, b = b, a + b\nreturn b\n
        climbing_stairs_dp.cpp
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.java
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.cs
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.go
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDPComp(n int) int {\nif n == 1 || n == 2 {\nreturn n\n}\na, b := 1, 2\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\nfor i := 3; i <= n; i++ {\na, b = b, a+b\n}\nreturn b\n}\n
        climbing_stairs_dp.swift
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDPComp(n: Int) -> Int {\nif n == 1 || n == 2 {\nreturn n\n}\nvar a = 1\nvar b = 2\nfor _ in stride(from: 3, through: n, by: 1) {\n(a, b) = (b, a + b)\n}\nreturn b\n}\n
        climbing_stairs_dp.js
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n) {\nif (n === 1 || n === 2) return n;\nlet a = 1,\nb = 2;\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.ts
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n: number): number {\nif (n === 1 || n === 2) return n;\nlet a = 1,\nb = 2;\nfor (let i = 3; i <= n; i++) {\nconst tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.dart
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2) return n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.rs
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn climbing_stairs_dp_comp(n: usize) -> i32 {\nif n == 1 || n == 2 { return n as i32; }\nlet (mut a, mut b) = (1, 2);\nfor _ in 3..=n {\nlet tmp = b;\nb = a + b;\na = tmp;\n}\nb\n}\n
        climbing_stairs_dp.c
        /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\nif (n == 1 || n == 2)\nreturn n;\nint a = 1, b = 2;\nfor (int i = 3; i <= n; i++) {\nint tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n
        climbing_stairs_dp.zig
        // \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn climbingStairsDPComp(comptime n: usize) i32 {\nif (n == 1 or n == 2) {\nreturn @intCast(n);\n}\nvar a: i32 = 1;\nvar b: i32 = 2;\nfor (3..n + 1) |_| {\nvar tmp = b;\nb = a + b;\na = tmp;\n}\nreturn b;\n}\n

        \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u7531\u4e8e\u7701\u53bb\u4e86\u6570\u7ec4 dp \u5360\u7528\u7684\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \u3002

        \u5728\u52a8\u6001\u89c4\u5212\u95ee\u9898\u4e2d\uff0c\u5f53\u524d\u72b6\u6001\u5f80\u5f80\u4ec5\u4e0e\u524d\u9762\u6709\u9650\u4e2a\u72b6\u6001\u6709\u5173\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u53ea\u4fdd\u7559\u5fc5\u8981\u7684\u72b6\u6001\uff0c\u901a\u8fc7\u201c\u964d\u7ef4\u201d\u6765\u8282\u7701\u5185\u5b58\u7a7a\u95f4\u3002\u8fd9\u79cd\u7a7a\u95f4\u4f18\u5316\u6280\u5de7\u88ab\u79f0\u4e3a\u201c\u6eda\u52a8\u53d8\u91cf\u201d\u6216\u201c\u6eda\u52a8\u6570\u7ec4\u201d\u3002

        "},{"location":"chapter_dynamic_programming/knapsack_problem/","title":"14.4 \u00a0 0-1 \u80cc\u5305\u95ee\u9898","text":"

        \u80cc\u5305\u95ee\u9898\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u52a8\u6001\u89c4\u5212\u5165\u95e8\u9898\u76ee\uff0c\u662f\u52a8\u6001\u89c4\u5212\u4e2d\u6700\u5e38\u89c1\u7684\u95ee\u9898\u5f62\u5f0f\u3002\u5176\u5177\u6709\u5f88\u591a\u53d8\u79cd\uff0c\u4f8b\u5982 0-1 \u80cc\u5305\u95ee\u9898\u3001\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u3001\u591a\u91cd\u80cc\u5305\u95ee\u9898\u7b49\u3002

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5148\u6765\u6c42\u89e3\u6700\u5e38\u89c1\u7684 0-1 \u80cc\u5305\u95ee\u9898\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ea\u80fd\u9009\u62e9\u4e00\u6b21\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002

        \u89c2\u5bdf\u56fe 14-17 \uff0c\u7531\u4e8e\u7269\u54c1\u7f16\u53f7 \\(i\\) \u4ece \\(1\\) \u5f00\u59cb\u8ba1\u6570\uff0c\u6570\u7ec4\u7d22\u5f15\u4ece \\(0\\) \u5f00\u59cb\u8ba1\u6570\uff0c\u56e0\u6b64\u7269\u54c1 \\(i\\) \u5bf9\u5e94\u91cd\u91cf \\(wgt[i-1]\\) \u548c\u4ef7\u503c \\(val[i-1]\\) \u3002

        \u56fe 14-17 \u00a0 0-1 \u80cc\u5305\u7684\u793a\u4f8b\u6570\u636e

        \u6211\u4eec\u53ef\u4ee5\u5c06 0-1 \u80cc\u5305\u95ee\u9898\u770b\u4f5c\u4e00\u4e2a\u7531 \\(n\\) \u8f6e\u51b3\u7b56\u7ec4\u6210\u7684\u8fc7\u7a0b\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u7269\u4f53\u90fd\u6709\u4e0d\u653e\u5165\u548c\u653e\u5165\u4e24\u79cd\u51b3\u7b56\uff0c\u56e0\u6b64\u8be5\u95ee\u9898\u6ee1\u8db3\u51b3\u7b56\u6811\u6a21\u578b\u3002

        \u8be5\u95ee\u9898\u7684\u76ee\u6807\u662f\u6c42\u89e3\u201c\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u201d\uff0c\u56e0\u6b64\u8f83\u5927\u6982\u7387\u662f\u4e00\u4e2a\u52a8\u6001\u89c4\u5212\u95ee\u9898\u3002

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u5bf9\u4e8e\u6bcf\u4e2a\u7269\u54c1\u6765\u8bf4\uff0c\u4e0d\u653e\u5165\u80cc\u5305\uff0c\u80cc\u5305\u5bb9\u91cf\u4e0d\u53d8\uff1b\u653e\u5165\u80cc\u5305\uff0c\u80cc\u5305\u5bb9\u91cf\u51cf\u5c0f\u3002\u7531\u6b64\u53ef\u5f97\u72b6\u6001\u5b9a\u4e49\uff1a\u5f53\u524d\u7269\u54c1\u7f16\u53f7 \\(i\\) \u548c\u5269\u4f59\u80cc\u5305\u5bb9\u91cf \\(c\\) \uff0c\u8bb0\u4e3a \\([i, c]\\) \u3002

        \u72b6\u6001 \\([i, c]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u524d \\(i\\) \u4e2a\u7269\u54c1\u5728\u5269\u4f59\u5bb9\u91cf\u4e3a \\(c\\) \u7684\u80cc\u5305\u4e2d\u7684\u6700\u5927\u4ef7\u503c\uff0c\u8bb0\u4e3a \\(dp[i, c]\\) \u3002

        \u5f85\u6c42\u89e3\u7684\u662f \\(dp[n, cap]\\) \uff0c\u56e0\u6b64\u9700\u8981\u4e00\u4e2a\u5c3a\u5bf8\u4e3a \\((n+1) \\times (cap+1)\\) \u7684\u4e8c\u7ef4 \\(dp\\) \u8868\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u5f53\u6211\u4eec\u505a\u51fa\u7269\u54c1 \\(i\\) \u7684\u51b3\u7b56\u540e\uff0c\u5269\u4f59\u7684\u662f\u524d \\(i-1\\) \u4e2a\u7269\u54c1\u7684\u51b3\u7b56\uff0c\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\u3002

        • \u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u80cc\u5305\u5bb9\u91cf\u4e0d\u53d8\uff0c\u72b6\u6001\u53d8\u5316\u4e3a \\([i-1, c]\\) \u3002
        • \u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u80cc\u5305\u5bb9\u91cf\u51cf\u5c11 \\(wgt[i-1]\\) \uff0c\u4ef7\u503c\u589e\u52a0 \\(val[i-1]\\) \uff0c\u72b6\u6001\u53d8\u5316\u4e3a \\([i-1, c-wgt[i-1]]\\) \u3002

        \u4e0a\u8ff0\u5206\u6790\u5411\u6211\u4eec\u63ed\u793a\u4e86\u672c\u9898\u7684\u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u6700\u5927\u4ef7\u503c \\(dp[i, c]\\) \u7b49\u4e8e\u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \u548c\u653e\u5165\u7269\u54c1 \\(i\\) \u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\u3002\u7531\u6b64\u53ef\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a

        \\[ dp[i, c] = \\max(dp[i-1, c], dp[i-1, c - wgt[i-1]] + val[i-1]) \\]

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u82e5\u5f53\u524d\u7269\u54c1\u91cd\u91cf \\(wgt[i - 1]\\) \u8d85\u51fa\u5269\u4f59\u80cc\u5305\u5bb9\u91cf \\(c\\) \uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\u3002

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u65e0\u7269\u54c1\u6216\u65e0\u5269\u4f59\u80cc\u5305\u5bb9\u91cf\u65f6\u6700\u5927\u4ef7\u503c\u4e3a \\(0\\) \uff0c\u5373\u9996\u5217 \\(dp[i, 0]\\) \u548c\u9996\u884c \\(dp[0, c]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        \u5f53\u524d\u72b6\u6001 \\([i, c]\\) \u4ece\u4e0a\u65b9\u7684\u72b6\u6001 \\([i-1, c]\\) \u548c\u5de6\u4e0a\u65b9\u7684\u72b6\u6001 \\([i-1, c-wgt[i-1]]\\) \u8f6c\u79fb\u800c\u6765\uff0c\u56e0\u6b64\u901a\u8fc7\u4e24\u5c42\u5faa\u73af\u6b63\u5e8f\u904d\u5386\u6574\u4e2a \\(dp\\) \u8868\u5373\u53ef\u3002

        \u6839\u636e\u4ee5\u4e0a\u5206\u6790\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u6309\u987a\u5e8f\u5b9e\u73b0\u66b4\u529b\u641c\u7d22\u3001\u8bb0\u5fc6\u5316\u641c\u7d22\u3001\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u3002

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#1","title":"1. \u00a0 \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u641c\u7d22","text":"

        \u641c\u7d22\u4ee3\u7801\u5305\u542b\u4ee5\u4e0b\u8981\u7d20\u3002

        • \u9012\u5f52\u53c2\u6570\uff1a\u72b6\u6001 \\([i, c]\\) \u3002
        • \u8fd4\u56de\u503c\uff1a\u5b50\u95ee\u9898\u7684\u89e3 \\(dp[i, c]\\) \u3002
        • \u7ec8\u6b62\u6761\u4ef6\uff1a\u5f53\u7269\u54c1\u7f16\u53f7\u8d8a\u754c \\(i = 0\\) \u6216\u80cc\u5305\u5269\u4f59\u5bb9\u91cf\u4e3a \\(0\\) \u65f6\uff0c\u7ec8\u6b62\u9012\u5f52\u5e76\u8fd4\u56de\u4ef7\u503c \\(0\\) \u3002
        • \u526a\u679d\uff1a\u82e5\u5f53\u524d\u7269\u54c1\u91cd\u91cf\u8d85\u51fa\u80cc\u5305\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dfs(wgt: list[int], val: list[int], i: int, c: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22\"\"\"\n# \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 or c == 0:\nreturn 0\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c:\nreturn knapsack_dfs(wgt, val, i - 1, c)\n# \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno = knapsack_dfs(wgt, val, i - 1, c)\nyes = knapsack_dfs(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1]\n# \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes)\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(vector<int> &wgt, vector<int> &val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes);\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(int[] wgt, int[] val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint KnapsackDFS(int[] weight, int[] val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (weight[i - 1] > c) {\nreturn KnapsackDFS(weight, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = KnapsackDFS(weight, val, i - 1, c);\nint yes = KnapsackDFS(weight, val, i - 1, c - weight[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.Max(no, yes);\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc knapsackDFS(wgt, val []int, i, c int) int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i-1] > c {\nreturn knapsackDFS(wgt, val, i-1, c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno := knapsackDFS(wgt, val, i-1, c)\nyes := knapsackDFS(wgt, val, i-1, c-wgt[i-1]) + val[i-1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn int(math.Max(float64(no), float64(yes)))\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunc knapsackDFS(wgt: [Int], val: [Int], i: Int, c: Int) -> Int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c {\nreturn knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\nlet yes = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c - wgt[i - 1]) + val[i - 1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes)\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(wgt, val, i, c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFS(wgt, val, i - 1, c);\nconst yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(\nwgt: Array<number>,\nval: Array<number>,\ni: number,\nc: number\n): number {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFS(wgt, val, i - 1, c);\nconst yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn Math.max(no, yes);\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(List<int> wgt, List<int> val, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn max(no, yes);\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfn knapsack_dfs(wgt: &[i32], val: &[i32], i: usize, c: usize) -> i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c as i32 {\nreturn knapsack_dfs(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsack_dfs(wgt, val, i - 1, c);\nlet yes = knapsack_dfs(wgt, val, i - 1, c - wgt[i - 1] as usize) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nstd::cmp::max(no, yes)\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nint knapsackDFS(int wgt[], int val[], int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFS(wgt, val, i - 1, c);\nint yes = knapsackDFS(wgt, val, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn myMax(no, yes);\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22\nfn knapsackDFS(wgt: []i32, val: []i32, i: usize, c: usize) i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 or c == 0) {\nreturn 0;\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFS(wgt, val, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nvar no = knapsackDFS(wgt, val, i - 1, c);\nvar yes = knapsackDFS(wgt, val, i - 1, c - @as(usize, @intCast(wgt[i - 1]))) + val[i - 1];\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nreturn @max(no, yes);\n}\n

        \u5982\u56fe 14-18 \u6240\u793a\uff0c\u7531\u4e8e\u6bcf\u4e2a\u7269\u54c1\u90fd\u4f1a\u4ea7\u751f\u4e0d\u9009\u548c\u9009\u4e24\u6761\u641c\u7d22\u5206\u652f\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(2^n)\\) \u3002

        \u89c2\u5bdf\u9012\u5f52\u6811\uff0c\u5bb9\u6613\u53d1\u73b0\u5176\u4e2d\u5b58\u5728\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u4f8b\u5982 \\(dp[1, 10]\\) \u7b49\u3002\u800c\u5f53\u7269\u54c1\u8f83\u591a\u3001\u80cc\u5305\u5bb9\u91cf\u8f83\u5927\uff0c\u5c24\u5176\u662f\u76f8\u540c\u91cd\u91cf\u7684\u7269\u54c1\u8f83\u591a\u65f6\uff0c\u91cd\u53e0\u5b50\u95ee\u9898\u7684\u6570\u91cf\u5c06\u4f1a\u5927\u5e45\u589e\u591a\u3002

        \u56fe 14-18 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u66b4\u529b\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#2","title":"2. \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22","text":"

        \u4e3a\u4e86\u4fdd\u8bc1\u91cd\u53e0\u5b50\u95ee\u9898\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\uff0c\u6211\u4eec\u501f\u52a9\u8bb0\u5fc6\u5217\u8868 mem \u6765\u8bb0\u5f55\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u5176\u4e2d mem[i][c] \u5bf9\u5e94 \\(dp[i, c]\\) \u3002

        \u5f15\u5165\u8bb0\u5fc6\u5316\u4e4b\u540e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u5b50\u95ee\u9898\u6570\u91cf\uff0c\u4e5f\u5c31\u662f \\(O(n \\times cap)\\) \u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dfs_mem(\nwgt: list[int], val: list[int], mem: list[list[int]], i: int, c: int\n) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\"\"\"\n# \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 or c == 0:\nreturn 0\n# \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1:\nreturn mem[i][c]\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c:\nreturn knapsack_dfs_mem(wgt, val, mem, i - 1, c)\n# \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno = knapsack_dfs_mem(wgt, val, mem, i - 1, c)\nyes = knapsack_dfs_mem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1]\n# \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes)\nreturn mem[i][c]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(vector<int> &wgt, vector<int> &val, vector<vector<int>> &mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(int[] wgt, int[] val, int[][] mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint KnapsackDFSMem(int[] weight, int[] val, int[][] mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (weight[i - 1] > c) {\nreturn KnapsackDFSMem(weight, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = KnapsackDFSMem(weight, val, mem, i - 1, c);\nint yes = KnapsackDFSMem(weight, val, mem, i - 1, c - weight[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.Max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc knapsackDFSMem(wgt, val []int, mem [][]int, i, c int) int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c]\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i-1] > c {\nreturn knapsackDFSMem(wgt, val, mem, i-1, c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nno := knapsackDFSMem(wgt, val, mem, i-1, c)\nyes := knapsackDFSMem(wgt, val, mem, i-1, c-wgt[i-1]) + val[i-1]\n// \u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = int(math.Max(float64(no), float64(yes)))\nreturn mem[i][c]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunc knapsackDFSMem(wgt: [Int], val: [Int], mem: inout [[Int]], i: Int, c: Int) -> Int {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c]\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c {\nreturn knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\nlet yes = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c - wgt[i - 1]) + val[i - 1]\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes)\nreturn mem[i][c]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(wgt, val, mem, i, c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] !== -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nconst yes =\nknapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(\nwgt: Array<number>,\nval: Array<number>,\nmem: Array<Array<number>>,\ni: number,\nc: number\n): number {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i === 0 || c === 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] !== -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nconst no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nconst yes =\nknapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = Math.max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(\nList<int> wgt,\nList<int> val,\nList<List<int>> mem,\nint i,\nint c,\n) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = max(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfn knapsack_dfs_mem(wgt: &[i32], val: &[i32], mem: &mut Vec<Vec<i32>>, i: usize, c: usize) -> i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif i == 0 || c == 0 {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif mem[i][c] != -1 {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif wgt[i - 1] > c as i32 {\nreturn knapsack_dfs_mem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nlet no = knapsack_dfs_mem(wgt, val, mem, i - 1, c);\nlet yes = knapsack_dfs_mem(wgt, val, mem, i - 1, c - wgt[i - 1] as usize) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = std::cmp::max(no, yes);\nmem[i][c]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(int wgt[], int val[], int memCols, int **mem, int i, int c) {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 || c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nint no = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\nint yes = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c - wgt[i - 1]) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = myMax(no, yes);\nreturn mem[i][c];\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22\nfn knapsackDFSMem(wgt: []i32, val: []i32, mem: anytype, i: usize, c: usize) i32 {\n// \u82e5\u5df2\u9009\u5b8c\u6240\u6709\u7269\u54c1\u6216\u80cc\u5305\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u5219\u8fd4\u56de\u4ef7\u503c 0\nif (i == 0 or c == 0) {\nreturn 0;\n}\n// \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (mem[i][c] != -1) {\nreturn mem[i][c];\n}\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\nif (wgt[i - 1] > c) {\nreturn knapsackDFSMem(wgt, val, mem, i - 1, c);\n}\n// \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\nvar no = knapsackDFSMem(wgt, val, mem, i - 1, c);\nvar yes = knapsackDFSMem(wgt, val, mem, i - 1, c - @as(usize, @intCast(wgt[i - 1]))) + val[i - 1];\n// \u8bb0\u5f55\u5e76\u8fd4\u56de\u4e24\u79cd\u65b9\u6848\u4e2d\u4ef7\u503c\u66f4\u5927\u7684\u90a3\u4e00\u4e2a\nmem[i][c] = @max(no, yes);\nreturn mem[i][c];\n}\n

        \u56fe 14-19 \u5c55\u793a\u4e86\u5728\u8bb0\u5fc6\u5316\u641c\u7d22\u4e2d\u88ab\u526a\u6389\u7684\u641c\u7d22\u5206\u652f\u3002

        \u56fe 14-19 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u8bb0\u5fc6\u5316\u641c\u7d22\u9012\u5f52\u6811

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#3","title":"3. \u00a0 \u65b9\u6cd5\u4e09\uff1a\u52a8\u6001\u89c4\u5212","text":"

        \u52a8\u6001\u89c4\u5212\u5b9e\u8d28\u4e0a\u5c31\u662f\u5728\u72b6\u6001\u8f6c\u79fb\u4e2d\u586b\u5145 \\(dp\\) \u8868\u7684\u8fc7\u7a0b\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (cap + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\nreturn dp[n][cap]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint KnapsackDP(int[] weight, int[] val, int cap) {\nint n = weight.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (weight[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i, c] = dp[i - 1, c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i, c] = Math.Max(dp[i - 1, c - weight[i - 1]] + val[i - 1], dp[i - 1, c]);\n}\n}\n}\nreturn dp[n, cap];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, cap+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i-1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i-1][c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[n][cap]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[n][cap]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(n + 1)\n.fill(0)\n.map(() => Array(cap + 1).fill(0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i - 1][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i - 1][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfn knapsack_dp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; cap + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = std::cmp::max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[n][cap]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(cap + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = myMax(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[n][cap];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\nfn knapsackDP(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = @max(dp[i - 1][c], dp[i - 1][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n

        \u5982\u56fe 14-20 \u6240\u793a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u90fd\u7531\u6570\u7ec4 dp \u5927\u5c0f\u51b3\u5b9a\uff0c\u5373 \\(O(n \\times cap)\\) \u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14>

        \u56fe 14-20 \u00a0 0-1 \u80cc\u5305\u95ee\u9898\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/knapsack_problem/#4","title":"4. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u6bcf\u4e2a\u72b6\u6001\u90fd\u53ea\u4e0e\u5176\u4e0a\u4e00\u884c\u7684\u72b6\u6001\u6709\u5173\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u6570\u7ec4\u6eda\u52a8\u524d\u8fdb\uff0c\u5c06\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n^2)\\) \u964d\u81f3 \\(O(n)\\) \u3002

        \u8fdb\u4e00\u6b65\u601d\u8003\uff0c\u6211\u4eec\u80fd\u5426\u4ec5\u7528\u4e00\u4e2a\u6570\u7ec4\u5b9e\u73b0\u7a7a\u95f4\u4f18\u5316\u5462\uff1f\u89c2\u5bdf\u53ef\u77e5\uff0c\u6bcf\u4e2a\u72b6\u6001\u90fd\u662f\u7531\u6b63\u4e0a\u65b9\u6216\u5de6\u4e0a\u65b9\u7684\u683c\u5b50\u8f6c\u79fb\u8fc7\u6765\u7684\u3002\u5047\u8bbe\u53ea\u6709\u4e00\u4e2a\u6570\u7ec4\uff0c\u5f53\u5f00\u59cb\u904d\u5386\u7b2c \\(i\\) \u884c\u65f6\uff0c\u8be5\u6570\u7ec4\u5b58\u50a8\u7684\u4ecd\u7136\u662f\u7b2c \\(i-1\\) \u884c\u7684\u72b6\u6001\u3002

        • \u5982\u679c\u91c7\u53d6\u6b63\u5e8f\u904d\u5386\uff0c\u90a3\u4e48\u904d\u5386\u5230 \\(dp[i, j]\\) \u65f6\uff0c\u5de6\u4e0a\u65b9 \\(dp[i-1, 1]\\) ~ \\(dp[i-1, j-1]\\) \u503c\u53ef\u80fd\u5df2\u7ecf\u88ab\u8986\u76d6\uff0c\u6b64\u65f6\u5c31\u65e0\u6cd5\u5f97\u5230\u6b63\u786e\u7684\u72b6\u6001\u8f6c\u79fb\u7ed3\u679c\u3002
        • \u5982\u679c\u91c7\u53d6\u5012\u5e8f\u904d\u5386\uff0c\u5219\u4e0d\u4f1a\u53d1\u751f\u8986\u76d6\u95ee\u9898\uff0c\u72b6\u6001\u8f6c\u79fb\u53ef\u4ee5\u6b63\u786e\u8fdb\u884c\u3002

        \u56fe 14-21 \u5c55\u793a\u4e86\u5728\u5355\u4e2a\u6570\u7ec4\u4e0b\u4ece\u7b2c \\(i = 1\\) \u884c\u8f6c\u6362\u81f3\u7b2c \\(i = 2\\) \u884c\u7684\u8fc7\u7a0b\u3002\u8bf7\u601d\u8003\u6b63\u5e8f\u904d\u5386\u548c\u5012\u5e8f\u904d\u5386\u7684\u533a\u522b\u3002

        <1><2><3><4><5><6>

        \u56fe 14-21 \u00a0 0-1 \u80cc\u5305\u7684\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u4ec5\u9700\u5c06\u6570\u7ec4 dp \u7684\u7b2c\u4e00\u7ef4 \\(i\\) \u76f4\u63a5\u5220\u9664\uff0c\u5e76\u4e14\u628a\u5185\u5faa\u73af\u66f4\u6539\u4e3a\u5012\u5e8f\u904d\u5386\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig knapsack.py
        def knapsack_dp_comp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (cap + 1)\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u5012\u5e8f\u904d\u5386\nfor c in range(cap, 0, -1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\nreturn dp[cap]\n
        knapsack.cpp
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.java
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.cs
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint KnapsackDPComp(int[] weight, int[] val, int cap) {\nint n = weight.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c > 0; c--) {\nif (weight[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.Max(dp[c], dp[c - weight[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.go
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDPComp(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, cap+1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor c := cap; c >= 1; c-- {\nif wgt[i-1] <= c {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[cap]\n}\n
        knapsack.swift
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDPComp(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: cap + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\n// \u5012\u5e8f\u904d\u5386\nfor c in stride(from: cap, through: 1, by: -1) {\nif wgt[i - 1] <= c {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[cap]\n}\n
        knapsack.js
        /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(cap + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (let c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.ts
        /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array(cap + 1).fill(0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (let c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.dart
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        knapsack.rs
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn knapsack_dp_comp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\n// \u5012\u5e8f\u904d\u5386\nfor c in (1..=cap).rev() {\nif wgt[i - 1] <= c as i32 {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[cap]\n}\n
        knapsack.c
        /* 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint knapsackDPComp(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(cap + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\n// \u5012\u5e8f\u904d\u5386\nfor (int c = cap; c >= 1; c--) {\nif (wgt[i - 1] <= c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[cap];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        knapsack.zig
        // 0-1 \u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn knapsackDPComp(wgt: []i32, val: []i32, comptime cap: usize) i32 {\nvar n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (cap + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\n// \u5012\u5e8f\u904d\u5386\nvar c = cap;\nwhile (c > 0) : (c -= 1) {\nif (wgt[i - 1] < c) {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        "},{"location":"chapter_dynamic_programming/summary/","title":"14.7 \u00a0 \u5c0f\u7ed3","text":"
        • \u52a8\u6001\u89c4\u5212\u5bf9\u95ee\u9898\u8fdb\u884c\u5206\u89e3\uff0c\u5e76\u901a\u8fc7\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\u6765\u89c4\u907f\u91cd\u590d\u8ba1\u7b97\uff0c\u63d0\u9ad8 \u8ba1\u7b97\u6548\u7387\u3002
        • \u4e0d\u8003\u8651\u65f6\u95f4\u7684\u524d\u63d0\u4e0b\uff0c\u6240\u6709\u52a8\u6001\u89c4\u5212\u95ee\u9898\u90fd\u53ef\u4ee5\u7528\u56de\u6eaf\uff08\u66b4\u529b\u641c\u7d22\uff09\u8fdb\u884c\u6c42\u89e3\uff0c\u4f46\u9012\u5f52\u6811\u4e2d\u5b58\u5728\u5927\u91cf\u7684\u91cd\u53e0\u5b50\u95ee\u9898\uff0c\u6548\u7387\u6781\u4f4e\u3002\u901a\u8fc7\u5f15\u5165\u8bb0\u5fc6\u5316\u5217\u8868\uff0c\u53ef\u4ee5\u5b58\u50a8\u6240\u6709\u8ba1\u7b97\u8fc7\u7684\u5b50\u95ee\u9898\u7684\u89e3\uff0c\u4ece\u800c\u4fdd\u8bc1\u91cd\u53e0\u5b50\u95ee\u9898\u53ea\u88ab\u8ba1\u7b97\u4e00\u6b21\u3002
        • \u8bb0\u5fc6\u5316\u9012\u5f52\u662f\u4e00\u79cd\u4ece\u9876\u81f3\u5e95\u7684\u9012\u5f52\u5f0f\u89e3\u6cd5\uff0c\u800c\u4e0e\u4e4b\u5bf9\u5e94\u7684\u52a8\u6001\u89c4\u5212\u662f\u4e00\u79cd\u4ece\u5e95\u81f3\u9876\u7684\u9012\u63a8\u5f0f\u89e3\u6cd5\uff0c\u5176\u5982\u540c\u201c\u586b\u5199\u8868\u683c\u201d\u4e00\u6837\u3002\u7531\u4e8e\u5f53\u524d\u72b6\u6001\u4ec5\u4f9d\u8d56\u67d0\u4e9b\u5c40\u90e8\u72b6\u6001\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u6d88\u9664 \\(dp\\) \u8868\u7684\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u4ece\u800c\u964d\u4f4e\u7a7a\u95f4\u590d\u6742\u5ea6\u3002
        • \u5b50\u95ee\u9898\u5206\u89e3\u662f\u4e00\u79cd\u901a\u7528\u7684\u7b97\u6cd5\u601d\u8def\uff0c\u5728\u5206\u6cbb\u3001\u52a8\u6001\u89c4\u5212\u3001\u56de\u6eaf\u4e2d\u5177\u6709\u4e0d\u540c\u7684\u6027\u8d28\u3002
        • \u52a8\u6001\u89c4\u5212\u95ee\u9898\u6709\u4e09\u5927\u7279\u6027\uff1a\u91cd\u53e0\u5b50\u95ee\u9898\u3001\u6700\u4f18\u5b50\u7ed3\u6784\u3001\u65e0\u540e\u6548\u6027\u3002
        • \u5982\u679c\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u53ef\u4ee5\u4ece\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u6784\u5efa\u5f97\u6765\uff0c\u5219\u5b83\u5c31\u5177\u6709\u6700\u4f18\u5b50\u7ed3\u6784\u3002
        • \u65e0\u540e\u6548\u6027\u6307\u5bf9\u4e8e\u4e00\u4e2a\u72b6\u6001\uff0c\u5176\u672a\u6765\u53d1\u5c55\u53ea\u4e0e\u8be5\u72b6\u6001\u6709\u5173\uff0c\u800c\u4e0e\u8fc7\u53bb\u7ecf\u5386\u7684\u6240\u6709\u72b6\u6001\u65e0\u5173\u3002\u8bb8\u591a\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u4e0d\u5177\u6709\u65e0\u540e\u6548\u6027\uff0c\u65e0\u6cd5\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u5feb\u901f\u6c42\u89e3\u3002

        \u80cc\u5305\u95ee\u9898

        • \u80cc\u5305\u95ee\u9898\u662f\u6700\u5178\u578b\u7684\u52a8\u6001\u89c4\u5212\u95ee\u9898\u4e4b\u4e00\uff0c\u5177\u6709 0-1 \u80cc\u5305\u3001\u5b8c\u5168\u80cc\u5305\u3001\u591a\u91cd\u80cc\u5305\u7b49\u53d8\u79cd\u3002
        • 0-1 \u80cc\u5305\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u524d \\(i\\) \u4e2a\u7269\u54c1\u5728\u5269\u4f59\u5bb9\u91cf\u4e3a \\(c\\) \u7684\u80cc\u5305\u4e2d\u7684\u6700\u5927\u4ef7\u503c\u3002\u6839\u636e\u4e0d\u653e\u5165\u80cc\u5305\u548c\u653e\u5165\u80cc\u5305\u4e24\u79cd\u51b3\u7b56\uff0c\u53ef\u5f97\u5230\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u5e76\u6784\u5efa\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u5728\u7a7a\u95f4\u4f18\u5316\u4e2d\uff0c\u7531\u4e8e\u6bcf\u4e2a\u72b6\u6001\u4f9d\u8d56\u6b63\u4e0a\u65b9\u548c\u5de6\u4e0a\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u9700\u8981\u5012\u5e8f\u904d\u5386\u5217\u8868\uff0c\u907f\u514d\u5de6\u4e0a\u65b9\u72b6\u6001\u88ab\u8986\u76d6\u3002
        • \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u6bcf\u79cd\u7269\u54c1\u7684\u9009\u53d6\u6570\u91cf\u65e0\u9650\u5236\uff0c\u56e0\u6b64\u9009\u62e9\u653e\u5165\u7269\u54c1\u7684\u72b6\u6001\u8f6c\u79fb\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u4e0d\u540c\u3002\u7531\u4e8e\u72b6\u6001\u4f9d\u8d56\u6b63\u4e0a\u65b9\u548c\u6b63\u5de6\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u5728\u7a7a\u95f4\u4f18\u5316\u4e2d\u5e94\u5f53\u6b63\u5e8f\u904d\u5386\u3002
        • \u96f6\u94b1\u5151\u6362\u95ee\u9898\u662f\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u4e00\u4e2a\u53d8\u79cd\u3002\u5b83\u4ece\u6c42\u201c\u6700\u5927\u201d\u4ef7\u503c\u53d8\u4e3a\u6c42\u201c\u6700\u5c0f\u201d\u786c\u5e01\u6570\u91cf\uff0c\u56e0\u6b64\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(\\max()\\) \u5e94\u6539\u4e3a \\(\\min()\\) \u3002\u4ece\u8ffd\u6c42\u201c\u4e0d\u8d85\u8fc7\u201d\u80cc\u5305\u5bb9\u91cf\u5230\u8ffd\u6c42\u201c\u6070\u597d\u201d\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u4f7f\u7528 \\(amt + 1\\) \u6765\u8868\u793a\u201c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u201d\u7684\u65e0\u6548\u89e3\u3002
        • \u96f6\u94b1\u5151\u6362 II \u95ee\u9898\u4ece\u6c42\u201c\u6700\u5c11\u786c\u5e01\u6570\u91cf\u201d\u6539\u4e3a\u6c42\u201c\u786c\u5e01\u7ec4\u5408\u6570\u91cf\u201d\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u76f8\u5e94\u5730\u4ece \\(\\min()\\) \u6539\u4e3a\u6c42\u548c\u8fd0\u7b97\u7b26\u3002

        \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898

        • \u7f16\u8f91\u8ddd\u79bb\uff08Levenshtein \u8ddd\u79bb\uff09\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\uff0c\u5176\u5b9a\u4e49\u4e3a\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u5230\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\uff0c\u7f16\u8f91\u64cd\u4f5c\u5305\u62ec\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66ff\u6362\u3002
        • \u7f16\u8f91\u8ddd\u79bb\u95ee\u9898\u7684\u72b6\u6001\u5b9a\u4e49\u4e3a\u5c06 \\(s\\) \u7684\u524d \\(i\\) \u4e2a\u5b57\u7b26\u66f4\u6539\u4e3a \\(t\\) \u7684\u524d \\(j\\) \u4e2a\u5b57\u7b26\u6240\u9700\u7684\u6700\u5c11\u7f16\u8f91\u6b65\u6570\u3002\u5f53 \\(s[i] \\ne t[j]\\) \u65f6\uff0c\u5177\u6709\u4e09\u79cd\u51b3\u7b56\uff1a\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66ff\u6362\uff0c\u5b83\u4eec\u90fd\u6709\u76f8\u5e94\u7684\u5269\u4f59\u5b50\u95ee\u9898\u3002\u636e\u6b64\u4fbf\u53ef\u4ee5\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\u4e0e\u6784\u5efa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u3002\u800c\u5f53 \\(s[i] = t[j]\\) \u65f6\uff0c\u65e0\u987b\u7f16\u8f91\u5f53\u524d\u5b57\u7b26\u3002
        • \u5728\u7f16\u8f91\u8ddd\u79bb\u4e2d\uff0c\u72b6\u6001\u4f9d\u8d56\u5176\u6b63\u4e0a\u65b9\u3001\u6b63\u5de6\u65b9\u3001\u5de6\u4e0a\u65b9\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u7a7a\u95f4\u4f18\u5316\u540e\u6b63\u5e8f\u6216\u5012\u5e8f\u904d\u5386\u90fd\u65e0\u6cd5\u6b63\u786e\u5730\u8fdb\u884c\u72b6\u6001\u8f6c\u79fb\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5229\u7528\u4e00\u4e2a\u53d8\u91cf\u6682\u5b58\u5de6\u4e0a\u65b9\u72b6\u6001\uff0c\u4ece\u800c\u8f6c\u5316\u5230\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7b49\u4ef7\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u5728\u7a7a\u95f4\u4f18\u5316\u540e\u8fdb\u884c\u6b63\u5e8f\u904d\u5386\u3002
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/","title":"14.5 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898","text":"

        \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5148\u6c42\u89e3\u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u80cc\u5305\u95ee\u9898\uff1a\u5b8c\u5168\u80cc\u5305\uff0c\u518d\u4e86\u89e3\u5b83\u7684\u4e00\u79cd\u7279\u4f8b\uff1a\u96f6\u94b1\u5151\u6362\u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1451","title":"14.5.1 \u00a0 \u5b8c\u5168\u80cc\u5305","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80fd\u653e\u5165\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002\u793a\u4f8b\u5982\u56fe 14-22 \u6240\u793a\u3002

        \u56fe 14-22 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u548c 0-1 \u80cc\u5305\u95ee\u9898\u975e\u5e38\u76f8\u4f3c\uff0c\u533a\u522b\u4ec5\u5728\u4e8e\u4e0d\u9650\u5236\u7269\u54c1\u7684\u9009\u62e9\u6b21\u6570\u3002

        • \u5728 0-1 \u80cc\u5305\u95ee\u9898\u4e2d\uff0c\u6bcf\u79cd\u7269\u54c1\u53ea\u6709\u4e00\u4e2a\uff0c\u56e0\u6b64\u5c06\u7269\u54c1 \\(i\\) \u653e\u5165\u80cc\u5305\u540e\uff0c\u53ea\u80fd\u4ece\u524d \\(i-1\\) \u4e2a\u7269\u54c1\u4e2d\u9009\u62e9\u3002
        • \u5728\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u4e2d\uff0c\u6bcf\u79cd\u7269\u54c1\u7684\u6570\u91cf\u662f\u65e0\u9650\u7684\uff0c\u56e0\u6b64\u5c06\u7269\u54c1 \\(i\\) \u653e\u5165\u80cc\u5305\u540e\uff0c\u4ecd\u53ef\u4ee5\u4ece\u524d \\(i\\) \u4e2a\u7269\u54c1\u4e2d\u9009\u62e9\u3002

        \u5728\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u89c4\u5b9a\u4e0b\uff0c\u72b6\u6001 \\([i, c]\\) \u7684\u53d8\u5316\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\u3002

        • \u4e0d\u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u76f8\u540c\uff0c\u8f6c\u79fb\u81f3 \\([i-1, c]\\) \u3002
        • \u653e\u5165\u7269\u54c1 \\(i\\) \uff1a\u4e0e 0-1 \u80cc\u5305\u95ee\u9898\u4e0d\u540c\uff0c\u8f6c\u79fb\u81f3 \\([i, c-wgt[i-1]]\\) \u3002

        \u4ece\u800c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u53d8\u4e3a\uff1a

        \\[ dp[i, c] = \\max(dp[i-1, c], dp[i, c - wgt[i-1]] + val[i-1]) \\]"},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5bf9\u6bd4\u4e24\u9053\u9898\u76ee\u7684\u4ee3\u7801\uff0c\u72b6\u6001\u8f6c\u79fb\u4e2d\u6709\u4e00\u5904\u4ece \\(i-1\\) \u53d8\u4e3a \\(i\\) \uff0c\u5176\u4f59\u5b8c\u5168\u4e00\u81f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig unbounded_knapsack.py
        def unbounded_knapsack_dp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (cap + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\nreturn dp[n][cap]\n
        unbounded_knapsack.cpp
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.java
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.cs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint UnboundedKnapsackDP(int[] wgt, int[] val, int cap) {\nint n = wgt.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i, c] = dp[i - 1, c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i, c] = Math.Max(dp[i - 1, c], dp[i, c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n, cap];\n}\n
        unbounded_knapsack.go
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDP(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, cap+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i-1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i][c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[n][cap]\n}\n
        unbounded_knapsack.swift
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDP(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[n][cap]\n}\n
        unbounded_knapsack.js
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.ts
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: cap + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = Math.max(\ndp[i - 1][c],\ndp[i][c - wgt[i - 1]] + val[i - 1]\n);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.dart
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.rs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfn unbounded_knapsack_dp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; cap + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = std::cmp::max(dp[i - 1][c], dp[i][c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        unbounded_knapsack.c
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDP(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(cap + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = myMax(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[n][cap];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nreturn res;\n}\n
        unbounded_knapsack.zig
        // \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212\nfn unboundedKnapsackDP(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[i][c] = dp[i - 1][c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[i][c] = @max(dp[i - 1][c], dp[i][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[n][cap];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7531\u4e8e\u5f53\u524d\u72b6\u6001\u662f\u4ece\u5de6\u8fb9\u548c\u4e0a\u8fb9\u7684\u72b6\u6001\u8f6c\u79fb\u800c\u6765\u7684\uff0c\u56e0\u6b64\u7a7a\u95f4\u4f18\u5316\u540e\u5e94\u8be5\u5bf9 \\(dp\\) \u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u8fdb\u884c\u6b63\u5e8f\u904d\u5386\u3002

        \u8fd9\u4e2a\u904d\u5386\u987a\u5e8f\u4e0e 0-1 \u80cc\u5305\u6b63\u597d\u76f8\u53cd\u3002\u8bf7\u501f\u52a9\u56fe 14-23 \u6765\u7406\u89e3\u4e24\u8005\u7684\u533a\u522b\u3002

        <1><2><3><4><5><6>

        \u56fe 14-23 \u00a0 \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u5728\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        \u4ee3\u7801\u5b9e\u73b0\u6bd4\u8f83\u7b80\u5355\uff0c\u4ec5\u9700\u5c06\u6570\u7ec4 dp \u7684\u7b2c\u4e00\u7ef4\u5220\u9664\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig unbounded_knapsack.py
        def unbounded_knapsack_dp_comp(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(wgt)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (cap + 1)\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor c in range(1, cap + 1):\nif wgt[i - 1] > c:\n# \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\nelse:\n# \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\nreturn dp[cap]\n
        unbounded_knapsack.cpp
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(vector<int> &wgt, vector<int> &val, int cap) {\nint n = wgt.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.java
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.cs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint UnboundedKnapsackDPComp(int[] wgt, int[] val, int cap) {\nint n = wgt.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.Max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.go
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDPComp(wgt, val []int, cap int) int {\nn := len(wgt)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, cap+1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\nfor c := 1; c <= cap; c++ {\nif wgt[i-1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n}\n}\n}\nreturn dp[cap]\n}\n
        unbounded_knapsack.swift
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc unboundedKnapsackDPComp(wgt: [Int], val: [Int], cap: Int) -> Int {\nlet n = wgt.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: cap + 1)\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor c in stride(from: 1, through: cap, by: 1) {\nif wgt[i - 1] > c {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c]\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n}\n}\n}\nreturn dp[cap]\n}\n
        unbounded_knapsack.js
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(wgt, val, cap) {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: cap + 1 }, () => 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.ts
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(\nwgt: Array<number>,\nval: Array<number>,\ncap: number\n): number {\nconst n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: cap + 1 }, () => 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.dart
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(List<int> wgt, List<int> val, int cap) {\nint n = wgt.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(cap + 1, 0);\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        unbounded_knapsack.rs
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn unbounded_knapsack_dp_comp(wgt: &[i32], val: &[i32], cap: usize) -> i32 {\nlet n = wgt.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; cap + 1];\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor c in 1..=cap {\nif wgt[i - 1] > c as i32 {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n}\n}\n}\ndp[cap]\n}\n
        unbounded_knapsack.c
        /* \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint unboundedKnapsackDPComp(int wgt[], int val[], int cap, int wgtSize) {\nint n = wgtSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(cap + 1, sizeof(int));\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int c = 1; c <= cap; c++) {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n}\n}\n}\nint res = dp[cap];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        unbounded_knapsack.zig
        // \u5b8c\u5168\u80cc\u5305\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn unboundedKnapsackDPComp(comptime wgt: []i32, val: []i32, comptime cap: usize) i32 {\ncomptime var n = wgt.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (cap + 1);\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..cap + 1) |c| {\nif (wgt[i - 1] > c) {\n// \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\ndp[c] = dp[c];\n} else {\n// \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\ndp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n}\n}\n}\nreturn dp[cap];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1452","title":"14.5.2 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898","text":"

        \u80cc\u5305\u95ee\u9898\u662f\u4e00\u5927\u7c7b\u52a8\u6001\u89c4\u5212\u95ee\u9898\u7684\u4ee3\u8868\uff0c\u5176\u62e5\u6709\u5f88\u591a\u53d8\u79cd\uff0c\u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u80fd\u591f\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002\u793a\u4f8b\u5982\u56fe 14-24 \u6240\u793a\u3002

        \u56fe 14-24 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1_1","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u96f6\u94b1\u5151\u6362\u53ef\u4ee5\u770b\u4f5c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u4e00\u79cd\u7279\u6b8a\u60c5\u51b5\uff0c\u4e24\u8005\u5177\u6709\u4ee5\u4e0b\u8054\u7cfb\u4e0e\u4e0d\u540c\u70b9\u3002

        • \u4e24\u9053\u9898\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\uff0c\u201c\u7269\u54c1\u201d\u5bf9\u5e94\u201c\u786c\u5e01\u201d\u3001\u201c\u7269\u54c1\u91cd\u91cf\u201d\u5bf9\u5e94\u201c\u786c\u5e01\u9762\u503c\u201d\u3001\u201c\u80cc\u5305\u5bb9\u91cf\u201d\u5bf9\u5e94\u201c\u76ee\u6807\u91d1\u989d\u201d\u3002
        • \u4f18\u5316\u76ee\u6807\u76f8\u53cd\uff0c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u662f\u8981\u6700\u5927\u5316\u7269\u54c1\u4ef7\u503c\uff0c\u96f6\u94b1\u5151\u6362\u95ee\u9898\u662f\u8981\u6700\u5c0f\u5316\u786c\u5e01\u6570\u91cf\u3002
        • \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u662f\u6c42\u201c\u4e0d\u8d85\u8fc7\u201d\u80cc\u5305\u5bb9\u91cf\u4e0b\u7684\u89e3\uff0c\u96f6\u94b1\u5151\u6362\u662f\u6c42\u201c\u6070\u597d\u201d\u51d1\u5230\u76ee\u6807\u91d1\u989d\u7684\u89e3\u3002

        \u7b2c\u4e00\u6b65\uff1a\u601d\u8003\u6bcf\u8f6e\u7684\u51b3\u7b56\uff0c\u5b9a\u4e49\u72b6\u6001\uff0c\u4ece\u800c\u5f97\u5230 \\(dp\\) \u8868

        \u72b6\u6001 \\([i, a]\\) \u5bf9\u5e94\u7684\u5b50\u95ee\u9898\u4e3a\uff1a\u524d \\(i\\) \u79cd\u786c\u5e01\u80fd\u591f\u51d1\u51fa\u91d1\u989d \\(a\\) \u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\uff0c\u8bb0\u4e3a \\(dp[i, a]\\) \u3002

        \u4e8c\u7ef4 \\(dp\\) \u8868\u7684\u5c3a\u5bf8\u4e3a \\((n+1) \\times (amt+1)\\) \u3002

        \u7b2c\u4e8c\u6b65\uff1a\u627e\u51fa\u6700\u4f18\u5b50\u7ed3\u6784\uff0c\u8fdb\u800c\u63a8\u5bfc\u51fa\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b

        \u672c\u9898\u4e0e\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u7684\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u5b58\u5728\u4ee5\u4e0b\u4e24\u70b9\u5dee\u5f02\u3002

        • \u672c\u9898\u8981\u6c42\u6700\u5c0f\u503c\uff0c\u56e0\u6b64\u9700\u5c06\u8fd0\u7b97\u7b26 \\(\\max()\\) \u66f4\u6539\u4e3a \\(\\min()\\) \u3002
        • \u4f18\u5316\u4e3b\u4f53\u662f\u786c\u5e01\u6570\u91cf\u800c\u975e\u5546\u54c1\u4ef7\u503c\uff0c\u56e0\u6b64\u5728\u9009\u4e2d\u786c\u5e01\u65f6\u6267\u884c \\(+1\\) \u5373\u53ef\u3002
        \\[ dp[i, a] = \\min(dp[i-1, a], dp[i, a - coins[i-1]] + 1) \\]

        \u7b2c\u4e09\u6b65\uff1a\u786e\u5b9a\u8fb9\u754c\u6761\u4ef6\u548c\u72b6\u6001\u8f6c\u79fb\u987a\u5e8f

        \u5f53\u76ee\u6807\u91d1\u989d\u4e3a \\(0\\) \u65f6\uff0c\u51d1\u51fa\u5b83\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u4e3a \\(0\\) \uff0c\u5373\u9996\u5217\u6240\u6709 \\(dp[i, 0]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        \u5f53\u65e0\u786c\u5e01\u65f6\uff0c\u65e0\u6cd5\u51d1\u51fa\u4efb\u610f \\(> 0\\) \u7684\u76ee\u6807\u91d1\u989d\uff0c\u5373\u662f\u65e0\u6548\u89e3\u3002\u4e3a\u4f7f\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(\\min()\\) \u51fd\u6570\u80fd\u591f\u8bc6\u522b\u5e76\u8fc7\u6ee4\u65e0\u6548\u89e3\uff0c\u6211\u4eec\u8003\u8651\u4f7f\u7528 \\(+ \\infty\\) \u6765\u8868\u793a\u5b83\u4eec\uff0c\u5373\u4ee4\u9996\u884c\u6240\u6709 \\(dp[0, a]\\) \u90fd\u7b49\u4e8e \\(+ \\infty\\) \u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2_1","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u5e76\u672a\u63d0\u4f9b \\(+ \\infty\\) \u53d8\u91cf\uff0c\u53ea\u80fd\u4f7f\u7528\u6574\u578b int \u7684\u6700\u5927\u503c\u6765\u4ee3\u66ff\u3002\u800c\u8fd9\u53c8\u4f1a\u5bfc\u81f4\u5927\u6570\u8d8a\u754c\uff1a\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e2d\u7684 \\(+ 1\\) \u64cd\u4f5c\u53ef\u80fd\u53d1\u751f\u6ea2\u51fa\u3002

        \u4e3a\u6b64\uff0c\u6211\u4eec\u91c7\u7528\u6570\u5b57 \\(amt + 1\\) \u6765\u8868\u793a\u65e0\u6548\u89e3\uff0c\u56e0\u4e3a\u51d1\u51fa \\(amt\\) \u7684\u786c\u5e01\u6570\u91cf\u6700\u591a\u4e3a \\(amt\\) \u3002\u6700\u540e\u8fd4\u56de\u524d\uff0c\u5224\u65ad \\(dp[n, amt]\\) \u662f\u5426\u7b49\u4e8e \\(amt + 1\\) \uff0c\u82e5\u662f\u5219\u8fd4\u56de \\(-1\\) \uff0c\u4ee3\u8868\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change.py
        def coin_change_dp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\nMAX = amt + 1\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (amt + 1) for _ in range(n + 1)]\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in range(1, amt + 1):\ndp[0][a] = MAX\n# \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in range(1, n + 1):\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\nreturn dp[n][amt] if dp[n][amt] != MAX else -1\n
        coin_change.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(vector<int> &coins, int amt) {\nint n = coins.size();\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(int[] coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][amt + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint CoinChangeDP(int[] coins, int amt) {\nint n = coins.Length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, amt + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0, a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i, a] = dp[i - 1, a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i, a] = Math.Min(dp[i - 1, a], dp[i, a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n, amt] != MAX ? dp[n, amt] : -1;\n}\n
        coin_change.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins []int, amt int) int {\nn := len(coins)\nmax := amt + 1\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, amt+1)\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a := 1; a <= amt; a++ {\ndp[0][a] = max\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i-1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = int(math.Min(float64(dp[i-1][a]), float64(dp[i][a-coins[i-1]]+1)))\n}\n}\n}\nif dp[n][amt] != max {\nreturn dp[n][amt]\n}\nreturn -1\n}\n
        coin_change.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\nlet MAX = amt + 1\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in stride(from: 1, through: amt, by: 1) {\ndp[0][a] = MAX\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1\n}\n
        coin_change.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDP(coins, amt) {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] !== MAX ? dp[n][amt] : -1;\n}\n
        coin_change.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDP(coins: Array<number>, amt: number): number {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (let a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] !== MAX ? dp[n][amt] : -1;\n}\n
        coin_change.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(List<int> coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[n][amt] != MAX ? dp[n][amt] : -1;\n}\n
        coin_change.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfn coin_change_dp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\nlet max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; amt + 1]; n + 1];\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor a in 1..= amt {\ndp[0][a] = max;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = std::cmp::min(dp[i - 1][a], dp[i][a - coins[i - 1] as usize] + 1);\n}\n}\n}\nif dp[n][amt] != max { return dp[n][amt] as i32; } else { -1 }\n}\n
        coin_change.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeDP(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(amt + 1, sizeof(int));\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (int a = 1; a <= amt; a++) {\ndp[0][a] = MAX;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = myMin(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n}\n}\n}\nint res = dp[n][amt] != MAX ? dp[n][amt] : -1;\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        coin_change.zig
        // \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeDP(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\ncomptime var max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\nfor (1..amt + 1) |a| {\ndp[0][a] = max;\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = @min(dp[i - 1][a], dp[i][a - @as(usize, @intCast(coins[i - 1]))] + 1);\n}\n}\n}\nif (dp[n][amt] != max) {\nreturn @intCast(dp[n][amt]);\n} else {\nreturn -1;\n}\n}\n

        \u56fe 14-25 \u5c55\u793a\u4e86\u96f6\u94b1\u5151\u6362\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b\uff0c\u548c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u975e\u5e38\u76f8\u4f3c\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12><13><14><15>

        \u56fe 14-25 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898\u7684\u52a8\u6001\u89c4\u5212\u8fc7\u7a0b

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3_1","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u96f6\u94b1\u5151\u6362\u7684\u7a7a\u95f4\u4f18\u5316\u7684\u5904\u7406\u65b9\u5f0f\u548c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u4e00\u81f4\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change.py
        def coin_change_dp_comp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\nMAX = amt + 1\n# \u521d\u59cb\u5316 dp \u8868\ndp = [MAX] * (amt + 1)\ndp[0] = 0\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\nreturn dp[amt] if dp[amt] != MAX else -1\n
        coin_change.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(vector<int> &coins, int amt) {\nint n = coins.size();\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(amt + 1, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(int[] coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\nArrays.fill(dp, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint CoinChangeDPComp(int[] coins, int amt) {\nint n = coins.Length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\nArray.Fill(dp, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.Min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDPComp(coins []int, amt int) int {\nn := len(coins)\nmax := amt + 1\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, amt+1)\nfor i := 1; i <= amt; i++ {\ndp[i] = max\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = int(math.Min(float64(dp[a]), float64(dp[a-coins[i-1]]+1)))\n}\n}\n}\nif dp[amt] != max {\nreturn dp[amt]\n}\nreturn -1\n}\n
        coin_change.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDPComp(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\nlet MAX = amt + 1\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: MAX, count: amt + 1)\ndp[0] = 0\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1\n}\n
        coin_change.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDPComp(coins, amt) {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] !== MAX ? dp[amt] : -1;\n}\n
        coin_change.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeDPComp(coins: Array<number>, amt: number): number {\nconst n = coins.length;\nconst MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] !== MAX ? dp[amt] : -1;\n}\n
        coin_change.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(List<int> coins, int amt) {\nint n = coins.length;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(amt + 1, MAX);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nreturn dp[amt] != MAX ? dp[amt] : -1;\n}\n
        coin_change.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn coin_change_dp_comp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\nlet max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; amt + 1];\ndp.fill(max);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = std::cmp::min(dp[a], dp[a - coins[i - 1] as usize] + 1);\n}\n}\n}\nif dp[amt] != max { return dp[amt] as i32; } else { -1 }\n}\n
        coin_change.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeDPComp(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\nint MAX = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(amt + 1, sizeof(int));\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = myMin(dp[a], dp[a - coins[i - 1]] + 1);\n}\n}\n}\nint res = dp[amt] != MAX ? dp[amt] : -1;\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        coin_change.zig
        // \u96f6\u94b1\u5151\u6362\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn coinChangeDPComp(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\ncomptime var max = amt + 1;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (amt + 1);\n@memset(&dp, max);\ndp[0] = 0;\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = @min(dp[a], dp[a - @as(usize, @intCast(coins[i - 1]))] + 1);\n}\n}\n}\nif (dp[amt] != max) {\nreturn @intCast(dp[amt]);\n} else {\nreturn -1;\n}\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1453-ii","title":"14.5.3 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898 II","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u786c\u5e01\u7ec4\u5408\u6570\u91cf\u3002\u793a\u4f8b\u5982\u56fe 14-26 \u6240\u793a\u3002

        \u56fe 14-26 \u00a0 \u96f6\u94b1\u5151\u6362\u95ee\u9898 II \u7684\u793a\u4f8b\u6570\u636e

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#1_2","title":"1. \u00a0 \u52a8\u6001\u89c4\u5212\u601d\u8def","text":"

        \u76f8\u6bd4\u4e8e\u4e0a\u4e00\u9898\uff0c\u672c\u9898\u76ee\u6807\u662f\u6c42\u7ec4\u5408\u6570\u91cf\uff0c\u56e0\u6b64\u5b50\u95ee\u9898\u53d8\u4e3a\uff1a\u524d \\(i\\) \u79cd\u786c\u5e01\u80fd\u591f\u51d1\u51fa\u91d1\u989d \\(a\\) \u7684\u7ec4\u5408\u6570\u91cf\u3002\u800c \\(dp\\) \u8868\u4ecd\u7136\u662f\u5c3a\u5bf8\u4e3a \\((n+1) \\times (amt + 1)\\) \u7684\u4e8c\u7ef4\u77e9\u9635\u3002

        \u5f53\u524d\u72b6\u6001\u7684\u7ec4\u5408\u6570\u91cf\u7b49\u4e8e\u4e0d\u9009\u5f53\u524d\u786c\u5e01\u4e0e\u9009\u5f53\u524d\u786c\u5e01\u8fd9\u4e24\u79cd\u51b3\u7b56\u7684\u7ec4\u5408\u6570\u91cf\u4e4b\u548c\u3002\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u4e3a\uff1a

        \\[ dp[i, a] = dp[i-1, a] + dp[i, a - coins[i-1]] \\]

        \u5f53\u76ee\u6807\u91d1\u989d\u4e3a \\(0\\) \u65f6\uff0c\u65e0\u987b\u9009\u62e9\u4efb\u4f55\u786c\u5e01\u5373\u53ef\u51d1\u51fa\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u5e94\u5c06\u9996\u5217\u6240\u6709 \\(dp[i, 0]\\) \u90fd\u521d\u59cb\u5316\u4e3a \\(1\\) \u3002\u5f53\u65e0\u786c\u5e01\u65f6\uff0c\u65e0\u6cd5\u51d1\u51fa\u4efb\u4f55 \\(>0\\) \u7684\u76ee\u6807\u91d1\u989d\uff0c\u56e0\u6b64\u9996\u884c\u6240\u6709 \\(dp[0, a]\\) \u90fd\u7b49\u4e8e \\(0\\) \u3002

        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#2_2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_ii.py
        def coin_change_ii_dp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [[0] * (amt + 1) for _ in range(n + 1)]\n# \u521d\u59cb\u5316\u9996\u5217\nfor i in range(n + 1):\ndp[i][0] = 1\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\nreturn dp[n][amt]\n
        coin_change_ii.cpp
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(vector<int> &coins, int amt) {\nint n = coins.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.java
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(int[] coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[][] dp = new int[n + 1][amt + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.cs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint CoinChangeIIDP(int[] coins, int amt) {\nint n = coins.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[,] dp = new int[n + 1, amt + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i, 0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i, a] = dp[i - 1, a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i, a] = dp[i - 1, a] + dp[i, a - coins[i - 1]];\n}\n}\n}\nreturn dp[n, amt];\n}\n
        coin_change_ii.go
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDP(coins []int, amt int) int {\nn := len(coins)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([][]int, n+1)\nfor i := 0; i <= n; i++ {\ndp[i] = make([]int, amt+1)\n}\n// \u521d\u59cb\u5316\u9996\u5217\nfor i := 0; i <= n; i++ {\ndp[i][0] = 1\n}\n// \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\nfor i := 1; i <= n; i++ {\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i-1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i-1][a] + dp[i][a-coins[i-1]]\n}\n}\n}\nreturn dp[n][amt]\n}\n
        coin_change_ii.swift
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDP(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n// \u521d\u59cb\u5316\u9996\u5217\nfor i in stride(from: 0, through: n, by: 1) {\ndp[i][0] = 1\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n}\n}\n}\nreturn dp[n][amt]\n}\n
        coin_change_ii.js
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins, amt) {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (let i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.ts
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins: Array<number>, amt: number): number {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: n + 1 }, () =>\nArray.from({ length: amt + 1 }, () => 0)\n);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (let i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.dart
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(List<int> coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        coin_change_ii.rs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfn coin_change_ii_dp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![vec![0; amt + 1]; n + 1];\n// \u521d\u59cb\u5316\u9996\u5217\nfor i in 0..= n {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1] as usize];\n}\n}\n}\ndp[n][amt]\n}\n
        coin_change_ii.c
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDP(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\n// \u521d\u59cb\u5316 dp \u8868\nint **dp = malloc((n + 1) * sizeof(int *));\nfor (int i = 0; i <= n; i++) {\ndp[i] = calloc(amt + 1, sizeof(int));\n}\n// \u521d\u59cb\u5316\u9996\u5217\nfor (int i = 0; i <= n; i++) {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n}\n}\n}\nint res = dp[n][amt];\n// \u91ca\u653e\u5185\u5b58\nfor (int i = 0; i <= n; i++) {\nfree(dp[i]);\n}\nfree(dp);\nreturn res;\n}\n
        coin_change_ii.zig
        // \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeIIDP(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n// \u521d\u59cb\u5316\u9996\u5217\nfor (0..n + 1) |i| {\ndp[i][0] = 1;\n}\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[i][a] = dp[i - 1][a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[i][a] = dp[i - 1][a] + dp[i][a - @as(usize, @intCast(coins[i - 1]))];\n}\n}\n}\nreturn dp[n][amt];\n}\n
        "},{"location":"chapter_dynamic_programming/unbounded_knapsack_problem/#3_2","title":"3. \u00a0 \u7a7a\u95f4\u4f18\u5316","text":"

        \u7a7a\u95f4\u4f18\u5316\u5904\u7406\u65b9\u5f0f\u76f8\u540c\uff0c\u5220\u9664\u786c\u5e01\u7ef4\u5ea6\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_ii.py
        def coin_change_ii_dp_comp(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\"\"\"\nn = len(coins)\n# \u521d\u59cb\u5316 dp \u8868\ndp = [0] * (amt + 1)\ndp[0] = 1\n# \u72b6\u6001\u8f6c\u79fb\nfor i in range(1, n + 1):\n# \u6b63\u5e8f\u904d\u5386\nfor a in range(1, amt + 1):\nif coins[i - 1] > a:\n# \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\nelse:\n# \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]]\nreturn dp[amt]\n
        coin_change_ii.cpp
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(vector<int> &coins, int amt) {\nint n = coins.size();\n// \u521d\u59cb\u5316 dp \u8868\nvector<int> dp(amt + 1, 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.java
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(int[] coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.cs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint CoinChangeIIDPComp(int[] coins, int amt) {\nint n = coins.Length;\n// \u521d\u59cb\u5316 dp \u8868\nint[] dp = new int[amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.go
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDPComp(coins []int, amt int) int {\nn := len(coins)\n// \u521d\u59cb\u5316 dp \u8868\ndp := make([]int, amt+1)\ndp[0] = 1\n// \u72b6\u6001\u8f6c\u79fb\nfor i := 1; i <= n; i++ {\n// \u5012\u5e8f\u904d\u5386\nfor a := 1; a <= amt; a++ {\nif coins[i-1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a-coins[i-1]]\n}\n}\n}\nreturn dp[amt]\n}\n
        coin_change_ii.swift
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeIIDPComp(coins: [Int], amt: Int) -> Int {\nlet n = coins.count\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = Array(repeating: 0, count: amt + 1)\ndp[0] = 1\n// \u72b6\u6001\u8f6c\u79fb\nfor i in stride(from: 1, through: n, by: 1) {\nfor a in stride(from: 1, through: amt, by: 1) {\nif coins[i - 1] > a {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a]\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]]\n}\n}\n}\nreturn dp[amt]\n}\n
        coin_change_ii.js
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDPComp(coins, amt) {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.ts
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDPComp(coins: Array<number>, amt: number): number {\nconst n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nconst dp = Array.from({ length: amt + 1 }, () => 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (let i = 1; i <= n; i++) {\nfor (let a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.dart
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(List<int> coins, int amt) {\nint n = coins.length;\n// \u521d\u59cb\u5316 dp \u8868\nList<int> dp = List.filled(amt + 1, 0);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nreturn dp[amt];\n}\n
        coin_change_ii.rs
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfn coin_change_ii_dp_comp(coins: &[i32], amt: usize) -> i32 {\nlet n = coins.len();\n// \u521d\u59cb\u5316 dp \u8868\nlet mut dp = vec![0; amt + 1];\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor i in 1..=n {\nfor a in 1..=amt {\nif coins[i - 1] > a as i32 {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = dp[a] + dp[a - coins[i - 1] as usize];\n}\n}\n}\ndp[amt]\n}\n
        coin_change_ii.c
        /* \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint coinChangeIIDPComp(int coins[], int amt, int coinsSize) {\nint n = coinsSize;\n// \u521d\u59cb\u5316 dp \u8868\nint *dp = calloc(amt + 1, sizeof(int));\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (int i = 1; i <= n; i++) {\nfor (int a = 1; a <= amt; a++) {\nif (coins[i - 1] > a) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\ndp[a] = dp[a] + dp[a - coins[i - 1]];\n}\n}\n}\nint res = dp[amt];\n// \u91ca\u653e\u5185\u5b58\nfree(dp);\nreturn res;\n}\n
        coin_change_ii.zig
        // \u96f6\u94b1\u5151\u6362 II\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212\nfn coinChangeIIDPComp(comptime coins: []i32, comptime amt: usize) i32 {\ncomptime var n = coins.len;\n// \u521d\u59cb\u5316 dp \u8868\nvar dp = [_]i32{0} ** (amt + 1);\ndp[0] = 1;\n// \u72b6\u6001\u8f6c\u79fb\nfor (1..n + 1) |i| {\nfor (1..amt + 1) |a| {\nif (coins[i - 1] > @as(i32, @intCast(a))) {\n// \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\ndp[a] = dp[a];\n} else {\n// \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\ndp[a] = dp[a] + dp[a - @as(usize, @intCast(coins[i - 1]))];\n}\n}\n}\nreturn dp[amt];\n}\n
        "},{"location":"chapter_graph/","title":"\u7b2c 9 \u7ae0 \u00a0 \u56fe","text":"

        Abstract

        \u5728\u751f\u547d\u65c5\u9014\u4e2d\uff0c\u6211\u4eec\u5c31\u50cf\u662f\u4e00\u4e2a\u4e2a\u8282\u70b9\uff0c\u88ab\u65e0\u6570\u770b\u4e0d\u89c1\u7684\u8fb9\u76f8\u8fde\u3002

        \u6bcf\u4e00\u6b21\u7684\u76f8\u8bc6\u4e0e\u76f8\u79bb\uff0c\u90fd\u5728\u8fd9\u5f20\u5de8\u5927\u7684\u7f51\u7edc\u56fe\u4e2d\u7559\u4e0b\u72ec\u7279\u7684\u5370\u8bb0\u3002

        "},{"location":"chapter_graph/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 9.1 \u00a0 \u56fe
        • 9.2 \u00a0 \u56fe\u57fa\u7840\u64cd\u4f5c
        • 9.3 \u00a0 \u56fe\u7684\u904d\u5386
        • 9.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_graph/graph/","title":"9.1 \u00a0 \u56fe","text":"

        \u300c\u56fe graph\u300d\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u7531\u300c\u9876\u70b9 vertex\u300d\u548c\u300c\u8fb9 edge\u300d\u7ec4\u6210\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u56fe \\(G\\) \u62bd\u8c61\u5730\u8868\u793a\u4e3a\u4e00\u7ec4\u9876\u70b9 \\(V\\) \u548c\u4e00\u7ec4\u8fb9 \\(E\\) \u7684\u96c6\u5408\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u4e00\u4e2a\u5305\u542b 5 \u4e2a\u9876\u70b9\u548c 7 \u6761\u8fb9\u7684\u56fe\u3002

        \\[ \\begin{aligned} V & = \\{ 1, 2, 3, 4, 5 \\} \\newline E & = \\{ (1,2), (1,3), (1,5), (2,3), (2,4), (2,5), (4,5) \\} \\newline G & = \\{ V, E \\} \\newline \\end{aligned} \\]

        \u5982\u679c\u5c06\u9876\u70b9\u770b\u4f5c\u8282\u70b9\uff0c\u5c06\u8fb9\u770b\u4f5c\u8fde\u63a5\u5404\u4e2a\u8282\u70b9\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u56fe\u770b\u4f5c\u4e00\u79cd\u4ece\u94fe\u8868\u62d3\u5c55\u800c\u6765\u7684\u6570\u636e\u7ed3\u6784\u3002\u5982\u56fe 9-1 \u6240\u793a\uff0c\u76f8\u8f83\u4e8e\u7ebf\u6027\u5173\u7cfb\uff08\u94fe\u8868\uff09\u548c\u5206\u6cbb\u5173\u7cfb\uff08\u6811\uff09\uff0c\u7f51\u7edc\u5173\u7cfb\uff08\u56fe\uff09\u7684\u81ea\u7531\u5ea6\u66f4\u9ad8\uff0c\u56e0\u800c\u66f4\u4e3a\u590d\u6742\u3002

        \u56fe 9-1 \u00a0 \u94fe\u8868\u3001\u6811\u3001\u56fe\u4e4b\u95f4\u7684\u5173\u7cfb

        "},{"location":"chapter_graph/graph/#911","title":"9.1.1 \u00a0 \u56fe\u5e38\u89c1\u7c7b\u578b\u4e0e\u672f\u8bed","text":"

        \u6839\u636e\u8fb9\u662f\u5426\u5177\u6709\u65b9\u5411\uff0c\u53ef\u5206\u4e3a\u300c\u65e0\u5411\u56fe undirected graph\u300d\u548c\u300c\u6709\u5411\u56fe directed graph\u300d\uff0c\u5982\u56fe 9-2 \u6240\u793a\u3002

        • \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u8fb9\u8868\u793a\u4e24\u9876\u70b9\u4e4b\u95f4\u7684\u201c\u53cc\u5411\u201d\u8fde\u63a5\u5173\u7cfb\uff0c\u4f8b\u5982\u5fae\u4fe1\u6216 QQ \u4e2d\u7684\u201c\u597d\u53cb\u5173\u7cfb\u201d\u3002
        • \u5728\u6709\u5411\u56fe\u4e2d\uff0c\u8fb9\u5177\u6709\u65b9\u5411\u6027\uff0c\u5373 \\(A \\rightarrow B\\) \u548c \\(A \\leftarrow B\\) \u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u4f8b\u5982\u5fae\u535a\u6216\u6296\u97f3\u4e0a\u7684\u201c\u5173\u6ce8\u201d\u4e0e\u201c\u88ab\u5173\u6ce8\u201d\u5173\u7cfb\u3002

        \u56fe 9-2 \u00a0 \u6709\u5411\u56fe\u4e0e\u65e0\u5411\u56fe

        \u6839\u636e\u6240\u6709\u9876\u70b9\u662f\u5426\u8fde\u901a\uff0c\u53ef\u5206\u4e3a\u300c\u8fde\u901a\u56fe connected graph\u300d\u548c\u300c\u975e\u8fde\u901a\u56fe disconnected graph\u300d\uff0c\u5982\u56fe 9-3 \u6240\u793a\u3002

        • \u5bf9\u4e8e\u8fde\u901a\u56fe\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u53ef\u4ee5\u5230\u8fbe\u5176\u4f59\u4efb\u610f\u9876\u70b9\u3002
        • \u5bf9\u4e8e\u975e\u8fde\u901a\u56fe\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u9876\u70b9\u65e0\u6cd5\u5230\u8fbe\u3002

        \u56fe 9-3 \u00a0 \u8fde\u901a\u56fe\u4e0e\u975e\u8fde\u901a\u56fe

        \u6211\u4eec\u8fd8\u53ef\u4ee5\u4e3a\u8fb9\u6dfb\u52a0\u201c\u6743\u91cd\u201d\u53d8\u91cf\uff0c\u4ece\u800c\u5f97\u5230\u5982\u56fe 9-4 \u6240\u793a\u7684\u300c\u6709\u6743\u56fe weighted graph\u300d\u3002\u4f8b\u5982\u5728\u201c\u738b\u8005\u8363\u8000\u201d\u7b49\u624b\u6e38\u4e2d\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e\u5171\u540c\u6e38\u620f\u65f6\u95f4\u6765\u8ba1\u7b97\u73a9\u5bb6\u4e4b\u95f4\u7684\u201c\u4eb2\u5bc6\u5ea6\u201d\uff0c\u8fd9\u79cd\u4eb2\u5bc6\u5ea6\u7f51\u7edc\u5c31\u53ef\u4ee5\u7528\u6709\u6743\u56fe\u6765\u8868\u793a\u3002

        \u56fe 9-4 \u00a0 \u6709\u6743\u56fe\u4e0e\u65e0\u6743\u56fe

        \u56fe\u6570\u636e\u7ed3\u6784\u5305\u542b\u4ee5\u4e0b\u5e38\u7528\u672f\u8bed\u3002

        • \u300c\u90bb\u63a5 adjacency\u300d\uff1a\u5f53\u4e24\u9876\u70b9\u4e4b\u95f4\u5b58\u5728\u8fb9\u76f8\u8fde\u65f6\uff0c\u79f0\u8fd9\u4e24\u9876\u70b9\u201c\u90bb\u63a5\u201d\u3002\u5728\u56fe 9-4 \u4e2d\uff0c\u9876\u70b9 1 \u7684\u90bb\u63a5\u9876\u70b9\u4e3a\u9876\u70b9 2\u30013\u30015\u3002
        • \u300c\u8def\u5f84 path\u300d\uff1a\u4ece\u9876\u70b9 A \u5230\u9876\u70b9 B \u7ecf\u8fc7\u7684\u8fb9\u6784\u6210\u7684\u5e8f\u5217\u88ab\u79f0\u4e3a\u4ece A \u5230 B \u7684\u201c\u8def\u5f84\u201d\u3002\u5728\u56fe 9-4 \u4e2d\uff0c\u8fb9\u5e8f\u5217 1-5-2-4 \u662f\u9876\u70b9 1 \u5230\u9876\u70b9 4 \u7684\u4e00\u6761\u8def\u5f84\u3002
        • \u300c\u5ea6 degree\u300d\uff1a\u4e00\u4e2a\u9876\u70b9\u62e5\u6709\u7684\u8fb9\u6570\u3002\u5bf9\u4e8e\u6709\u5411\u56fe\uff0c\u300c\u5165\u5ea6 in-degree\u300d\u8868\u793a\u6709\u591a\u5c11\u6761\u8fb9\u6307\u5411\u8be5\u9876\u70b9\uff0c\u300c\u51fa\u5ea6 out-degree\u300d\u8868\u793a\u6709\u591a\u5c11\u6761\u8fb9\u4ece\u8be5\u9876\u70b9\u6307\u51fa\u3002
        "},{"location":"chapter_graph/graph/#912","title":"9.1.2 \u00a0 \u56fe\u7684\u8868\u793a","text":"

        \u56fe\u7684\u5e38\u7528\u8868\u793a\u65b9\u5f0f\u5305\u62ec\u201c\u90bb\u63a5\u77e9\u9635\u201d\u548c\u201c\u90bb\u63a5\u8868\u201d\u3002\u4ee5\u4e0b\u4f7f\u7528\u65e0\u5411\u56fe\u8fdb\u884c\u4e3e\u4f8b\u3002

        "},{"location":"chapter_graph/graph/#1","title":"1. \u00a0 \u90bb\u63a5\u77e9\u9635","text":"

        \u8bbe\u56fe\u7684\u9876\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u300c\u90bb\u63a5\u77e9\u9635 adjacency matrix\u300d\u4f7f\u7528\u4e00\u4e2a \\(n \\times n\\) \u5927\u5c0f\u7684\u77e9\u9635\u6765\u8868\u793a\u56fe\uff0c\u6bcf\u4e00\u884c\uff08\u5217\uff09\u4ee3\u8868\u4e00\u4e2a\u9876\u70b9\uff0c\u77e9\u9635\u5143\u7d20\u4ee3\u8868\u8fb9\uff0c\u7528 \\(1\\) \u6216 \\(0\\) \u8868\u793a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u8fb9\u3002

        \u5982\u56fe 9-5 \u6240\u793a\uff0c\u8bbe\u90bb\u63a5\u77e9\u9635\u4e3a \\(M\\)\u3001\u9876\u70b9\u5217\u8868\u4e3a \\(V\\) \uff0c\u90a3\u4e48\u77e9\u9635\u5143\u7d20 \\(M[i, j] = 1\\) \u8868\u793a\u9876\u70b9 \\(V[i]\\) \u5230\u9876\u70b9 \\(V[j]\\) \u4e4b\u95f4\u5b58\u5728\u8fb9\uff0c\u53cd\u4e4b \\(M[i, j] = 0\\) \u8868\u793a\u4e24\u9876\u70b9\u4e4b\u95f4\u65e0\u8fb9\u3002

        \u56fe 9-5 \u00a0 \u56fe\u7684\u90bb\u63a5\u77e9\u9635\u8868\u793a

        \u90bb\u63a5\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u9876\u70b9\u4e0d\u80fd\u4e0e\u81ea\u8eab\u76f8\u8fde\uff0c\u56e0\u6b64\u90bb\u63a5\u77e9\u9635\u4e3b\u5bf9\u89d2\u7ebf\u5143\u7d20\u6ca1\u6709\u610f\u4e49\u3002
        • \u5bf9\u4e8e\u65e0\u5411\u56fe\uff0c\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u7b49\u4ef7\uff0c\u6b64\u65f6\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\u3002
        • \u5c06\u90bb\u63a5\u77e9\u9635\u7684\u5143\u7d20\u4ece \\(1\\) \u548c \\(0\\) \u66ff\u6362\u4e3a\u6743\u91cd\uff0c\u5219\u53ef\u8868\u793a\u6709\u6743\u56fe\u3002

        \u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u8868\u793a\u56fe\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u77e9\u9635\u5143\u7d20\u4ee5\u83b7\u53d6\u8fb9\uff0c\u56e0\u6b64\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u7684\u6548\u7387\u5f88\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(1)\\) \u3002\u7136\u800c\uff0c\u77e9\u9635\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u5185\u5b58\u5360\u7528\u8f83\u591a\u3002

        "},{"location":"chapter_graph/graph/#2","title":"2. \u00a0 \u90bb\u63a5\u8868","text":"

        \u300c\u90bb\u63a5\u8868 adjacency list\u300d\u4f7f\u7528 \\(n\\) \u4e2a\u94fe\u8868\u6765\u8868\u793a\u56fe\uff0c\u94fe\u8868\u8282\u70b9\u8868\u793a\u9876\u70b9\u3002\u7b2c \\(i\\) \u4e2a\u94fe\u8868\u5bf9\u5e94\u9876\u70b9 \\(i\\) \uff0c\u5176\u4e2d\u5b58\u50a8\u4e86\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff08\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u9876\u70b9\uff09\u3002\u56fe 9-6 \u5c55\u793a\u4e86\u4e00\u4e2a\u4f7f\u7528\u90bb\u63a5\u8868\u5b58\u50a8\u7684\u56fe\u7684\u793a\u4f8b\u3002

        \u56fe 9-6 \u00a0 \u56fe\u7684\u90bb\u63a5\u8868\u8868\u793a

        \u90bb\u63a5\u8868\u4ec5\u5b58\u50a8\u5b9e\u9645\u5b58\u5728\u7684\u8fb9\uff0c\u800c\u8fb9\u7684\u603b\u6570\u901a\u5e38\u8fdc\u5c0f\u4e8e \\(n^2\\) \uff0c\u56e0\u6b64\u5b83\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\u3002\u7136\u800c\uff0c\u5728\u90bb\u63a5\u8868\u4e2d\u9700\u8981\u901a\u8fc7\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u8fb9\uff0c\u56e0\u6b64\u5176\u65f6\u95f4\u6548\u7387\u4e0d\u5982\u90bb\u63a5\u77e9\u9635\u3002

        \u89c2\u5bdf\u56fe 9-6 \uff0c\u90bb\u63a5\u8868\u7ed3\u6784\u4e0e\u54c8\u5e0c\u8868\u4e2d\u7684\u201c\u94fe\u5f0f\u5730\u5740\u201d\u975e\u5e38\u76f8\u4f3c\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u53ef\u4ee5\u91c7\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\u6765\u4f18\u5316\u6548\u7387\u3002\u6bd4\u5982\u5f53\u94fe\u8868\u8f83\u957f\u65f6\uff0c\u53ef\u4ee5\u5c06\u94fe\u8868\u8f6c\u5316\u4e3a AVL \u6811\u6216\u7ea2\u9ed1\u6811\uff0c\u4ece\u800c\u5c06\u65f6\u95f4\u6548\u7387\u4ece \\(O(n)\\) \u4f18\u5316\u81f3 \\(O(\\log n)\\) \uff1b\u8fd8\u53ef\u4ee5\u628a\u94fe\u8868\u8f6c\u6362\u4e3a\u54c8\u5e0c\u8868\uff0c\u4ece\u800c\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u964d\u81f3 \\(O(1)\\) \u3002

        "},{"location":"chapter_graph/graph/#913","title":"9.1.3 \u00a0 \u56fe\u5e38\u89c1\u5e94\u7528","text":"

        \u5982\u8868 9-1 \u6240\u793a\uff0c\u8bb8\u591a\u73b0\u5b9e\u7cfb\u7edf\u53ef\u4ee5\u7528\u56fe\u6765\u5efa\u6a21\uff0c\u76f8\u5e94\u7684\u95ee\u9898\u4e5f\u53ef\u4ee5\u7ea6\u5316\u4e3a\u56fe\u8ba1\u7b97\u95ee\u9898\u3002

        \u8868 9-1 \u00a0 \u73b0\u5b9e\u751f\u6d3b\u4e2d\u5e38\u89c1\u7684\u56fe

        \u9876\u70b9 \u8fb9 \u56fe\u8ba1\u7b97\u95ee\u9898 \u793e\u4ea4\u7f51\u7edc \u7528\u6237 \u597d\u53cb\u5173\u7cfb \u6f5c\u5728\u597d\u53cb\u63a8\u8350 \u5730\u94c1\u7ebf\u8def \u7ad9\u70b9 \u7ad9\u70b9\u95f4\u7684\u8fde\u901a\u6027 \u6700\u77ed\u8def\u7ebf\u63a8\u8350 \u592a\u9633\u7cfb \u661f\u4f53 \u661f\u4f53\u95f4\u7684\u4e07\u6709\u5f15\u529b\u4f5c\u7528 \u884c\u661f\u8f68\u9053\u8ba1\u7b97"},{"location":"chapter_graph/graph_operations/","title":"9.2 \u00a0 \u56fe\u57fa\u7840\u64cd\u4f5c","text":"

        \u56fe\u7684\u57fa\u7840\u64cd\u4f5c\u53ef\u5206\u4e3a\u5bf9\u201c\u8fb9\u201d\u7684\u64cd\u4f5c\u548c\u5bf9\u201c\u9876\u70b9\u201d\u7684\u64cd\u4f5c\u3002\u5728\u201c\u90bb\u63a5\u77e9\u9635\u201d\u548c\u201c\u90bb\u63a5\u8868\u201d\u4e24\u79cd\u8868\u793a\u65b9\u6cd5\u4e0b\uff0c\u5b9e\u73b0\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002

        "},{"location":"chapter_graph/graph_operations/#921","title":"9.2.1 \u00a0 \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u7684\u5b9e\u73b0","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u9876\u70b9\u6570\u91cf\u4e3a \\(n\\) \u7684\u65e0\u5411\u56fe\uff0c\u5219\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u65b9\u5f0f\u5982\u56fe 9-7 \u6240\u793a\u3002

        • \u6dfb\u52a0\u6216\u5220\u9664\u8fb9\uff1a\u76f4\u63a5\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u4fee\u6539\u6307\u5b9a\u7684\u8fb9\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u800c\u7531\u4e8e\u662f\u65e0\u5411\u56fe\uff0c\u56e0\u6b64\u9700\u8981\u540c\u65f6\u66f4\u65b0\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u6dfb\u52a0\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u77e9\u9635\u7684\u5c3e\u90e8\u6dfb\u52a0\u4e00\u884c\u4e00\u5217\uff0c\u5e76\u5168\u90e8\u586b \\(0\\) \u5373\u53ef\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u4e00\u884c\u4e00\u5217\u3002\u5f53\u5220\u9664\u9996\u884c\u9996\u5217\u65f6\u8fbe\u5230\u6700\u5dee\u60c5\u51b5\uff0c\u9700\u8981\u5c06 \\((n-1)^2\\) \u4e2a\u5143\u7d20\u201c\u5411\u5de6\u4e0a\u79fb\u52a8\u201d\uff0c\u4ece\u800c\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u521d\u59cb\u5316\uff1a\u4f20\u5165 \\(n\\) \u4e2a\u9876\u70b9\uff0c\u521d\u59cb\u5316\u957f\u5ea6\u4e3a \\(n\\) \u7684\u9876\u70b9\u5217\u8868 vertices \uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\uff1b\u521d\u59cb\u5316 \\(n \\times n\\) \u5927\u5c0f\u7684\u90bb\u63a5\u77e9\u9635 adjMat \uff0c\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        \u521d\u59cb\u5316\u90bb\u63a5\u77e9\u9635\u6dfb\u52a0\u8fb9\u5220\u9664\u8fb9\u6dfb\u52a0\u9876\u70b9\u5220\u9664\u9876\u70b9

        \u56fe 9-7 \u00a0 \u90bb\u63a5\u77e9\u9635\u7684\u521d\u59cb\u5316\u3001\u589e\u5220\u8fb9\u3001\u589e\u5220\u9876\u70b9

        \u4ee5\u4e0b\u662f\u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u8868\u793a\u56fe\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_adjacency_matrix.py
        class GraphAdjMat:\n\"\"\"\u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\"\"\"\ndef __init__(self, vertices: list[int], edges: list[list[int]]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nself.vertices: list[int] = []\n# \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\nself.adj_mat: list[list[int]] = []\n# \u6dfb\u52a0\u9876\u70b9\nfor val in vertices:\nself.add_vertex(val)\n# \u6dfb\u52a0\u8fb9\n# \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor e in edges:\nself.add_edge(e[0], e[1])\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\nreturn len(self.vertices)\ndef add_vertex(self, val: int):\n\"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\nn = self.size()\n# \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nself.vertices.append(val)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nnew_row = [0] * n\nself.adj_mat.append(new_row)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor row in self.adj_mat:\nrow.append(0)\ndef remove_vertex(self, index: int):\n\"\"\"\u5220\u9664\u9876\u70b9\"\"\"\nif index >= self.size():\nraise IndexError()\n# \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nself.vertices.pop(index)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nself.adj_mat.pop(index)\n# \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor row in self.adj_mat:\nrow.pop(index)\ndef add_edge(self, i: int, j: int):\n\"\"\"\u6dfb\u52a0\u8fb9\"\"\"\n# \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n# \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\nraise IndexError()\n# \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nself.adj_mat[i][j] = 1\nself.adj_mat[j][i] = 1\ndef remove_edge(self, i: int, j: int):\n\"\"\"\u5220\u9664\u8fb9\"\"\"\n# \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n# \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\nraise IndexError()\nself.adj_mat[i][j] = 0\nself.adj_mat[j][i] = 0\ndef print(self):\n\"\"\"\u6253\u5370\u90bb\u63a5\u77e9\u9635\"\"\"\nprint(\"\u9876\u70b9\u5217\u8868 =\", self.vertices)\nprint(\"\u90bb\u63a5\u77e9\u9635 =\")\nprint_matrix(self.adj_mat)\n
        graph_adjacency_matrix.cpp
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvector<int> vertices;       // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nvector<vector<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjMat(const vector<int> &vertices, const vector<vector<int>> &edges) {\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val : vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const vector<int> &edge : edges) {\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() const {\nreturn vertices.size();\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.push_back(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nadjMat.emplace_back(vector<int>(n, 0));\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (vector<int> &row : adjMat) {\nrow.push_back(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(int index) {\nif (index >= size()) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.erase(vertices.begin() + index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.erase(adjMat.begin() + index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (vector<int> &row : adjMat) {\nrow.erase(row.begin() + index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n}\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid print() {\ncout << \"\u9876\u70b9\u5217\u8868 = \";\nprintVector(vertices);\ncout << \"\u90bb\u63a5\u77e9\u9635 =\" << endl;\nprintVectorMatrix(adjMat);\n}\n};\n
        graph_adjacency_matrix.java
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<Integer> vertices; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<Integer>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\npublic GraphAdjMat(int[] vertices, int[][] edges) {\nthis.vertices = new ArrayList<>();\nthis.adjMat = new ArrayList<>();\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val : vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (int[] e : edges) {\naddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic int size() {\nreturn vertices.size();\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<Integer> newRow = new ArrayList<>(n);\nfor (int j = 0; j < n; j++) {\nnewRow.add(0);\n}\nadjMat.add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (List<Integer> row : adjMat) {\nrow.add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void removeVertex(int index) {\nif (index >= size())\nthrow new IndexOutOfBoundsException();\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (List<Integer> row : adjMat) {\nrow.remove(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\nthrow new IndexOutOfBoundsException();\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat.get(i).set(j, 1);\nadjMat.get(j).set(i, 1);\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\nthrow new IndexOutOfBoundsException();\nadjMat.get(i).set(j, 0);\nadjMat.get(j).set(i, 0);\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npublic void print() {\nSystem.out.print(\"\u9876\u70b9\u5217\u8868 = \");\nSystem.out.println(vertices);\nSystem.out.println(\"\u90bb\u63a5\u77e9\u9635 =\");\nPrintUtil.printMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.cs
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<int> vertices;     // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\npublic GraphAdjMat(int[] vertices, int[][] edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nforeach (int val in vertices) {\nAddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nforeach (int[] e in edges) {\nAddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint Size() {\nreturn vertices.Count;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void AddVertex(int val) {\nint n = Size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.Add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<int> newRow = new(n);\nfor (int j = 0; j < n; j++) {\nnewRow.Add(0);\n}\nadjMat.Add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nforeach (List<int> row in adjMat) {\nrow.Add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void RemoveVertex(int index) {\nif (index >= Size())\nthrow new IndexOutOfRangeException();\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.RemoveAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.RemoveAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nforeach (List<int> row in adjMat) {\nrow.RemoveAt(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void AddEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\nthrow new IndexOutOfRangeException();\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npublic void RemoveEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\nthrow new IndexOutOfRangeException();\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npublic void Print() {\nConsole.Write(\"\u9876\u70b9\u5217\u8868 = \");\nPrintUtil.PrintList(vertices);\nConsole.WriteLine(\"\u90bb\u63a5\u77e9\u9635 =\");\nPrintUtil.PrintMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.go
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntype graphAdjMat struct {\n// \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nvertices []int\n// \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat [][]int\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {\n// \u6dfb\u52a0\u9876\u70b9\nn := len(vertices)\nadjMat := make([][]int, n)\nfor i := range adjMat {\nadjMat[i] = make([]int, n)\n}\n// \u521d\u59cb\u5316\u56fe\ng := &graphAdjMat{\nvertices: vertices,\nadjMat:   adjMat,\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor i := range edges {\ng.addEdge(edges[i][0], edges[i][1])\n}\nreturn g\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjMat) size() int {\nreturn len(g.vertices)\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjMat) addVertex(val int) {\nn := g.size()\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\ng.vertices = append(g.vertices, val)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nnewRow := make([]int, n)\ng.adjMat = append(g.adjMat, newRow)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor i := range g.adjMat {\ng.adjMat[i] = append(g.adjMat[i], 0)\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjMat) removeVertex(index int) {\nif index >= g.size() {\nreturn\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\ng.vertices = append(g.vertices[:index], g.vertices[index+1:]...)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\ng.adjMat = append(g.adjMat[:index], g.adjMat[index+1:]...)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor i := range g.adjMat {\ng.adjMat[i] = append(g.adjMat[i][:index], g.adjMat[i][index+1:]...)\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc (g *graphAdjMat) addEdge(i, j int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\nfmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\ng.adjMat[i][j] = 1\ng.adjMat[j][i] = 1\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc (g *graphAdjMat) removeEdge(i, j int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\nfmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n}\ng.adjMat[i][j] = 0\ng.adjMat[j][i] = 0\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc (g *graphAdjMat) print() {\nfmt.Printf(\"\\t\u9876\u70b9\u5217\u8868 = %v\\n\", g.vertices)\nfmt.Printf(\"\\t\u90bb\u63a5\u77e9\u9635 = \\n\")\nfor i := range g.adjMat {\nfmt.Printf(\"\\t\\t\\t%v\\n\", g.adjMat[i])\n}\n}\n
        graph_adjacency_matrix.swift
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nprivate var vertices: [Int] // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nprivate var adjMat: [[Int]] // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(vertices: [Int], edges: [[Int]]) {\nself.vertices = []\nadjMat = []\n// \u6dfb\u52a0\u9876\u70b9\nfor val in vertices {\naddVertex(val: val)\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor e in edges {\naddEdge(i: e[0], j: e[1])\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc size() -> Int {\nvertices.count\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc addVertex(val: Int) {\nlet n = size()\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.append(val)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nlet newRow = Array(repeating: 0, count: n)\nadjMat.append(newRow)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor i in adjMat.indices {\nadjMat[i].append(0)\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc removeVertex(index: Int) {\nif index >= size() {\nfatalError(\"\u8d8a\u754c\")\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.remove(at: index)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.remove(at: index)\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor i in adjMat.indices {\nadjMat[i].remove(at: index)\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc addEdge(i: Int, j: Int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= size() || j >= size() || i == j {\nfatalError(\"\u8d8a\u754c\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1\nadjMat[j][i] = 1\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfunc removeEdge(i: Int, j: Int) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i < 0 || j < 0 || i >= size() || j >= size() || i == j {\nfatalError(\"\u8d8a\u754c\")\n}\nadjMat[i][j] = 0\nadjMat[j][i] = 0\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc print() {\nSwift.print(\"\u9876\u70b9\u5217\u8868 = \", terminator: \"\")\nSwift.print(vertices)\nSwift.print(\"\u90bb\u63a5\u77e9\u9635 =\")\nPrintUtil.printMatrix(matrix: adjMat)\n}\n}\n
        graph_adjacency_matrix.js
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvertices; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\nconstructor(vertices, edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (const val of vertices) {\nthis.addVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const e of edges) {\nthis.addEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize() {\nreturn this.vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(val) {\nconst n = this.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nthis.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nconst newRow = [];\nfor (let j = 0; j < n; j++) {\nnewRow.push(0);\n}\nthis.adjMat.push(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (const row of this.adjMat) {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(index) {\nif (index >= this.size()) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nthis.vertices.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nthis.adjMat.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (const row of this.adjMat) {\nrow.splice(index, 1);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\naddEdge(i, j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) === (j, i)\nthis.adjMat[i][j] = 1;\nthis.adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nremoveEdge(i, j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\nthis.adjMat[i][j] = 0;\nthis.adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nprint() {\nconsole.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\nconsole.log('\u90bb\u63a5\u77e9\u9635 =', this.adjMat);\n}\n}\n
        graph_adjacency_matrix.ts
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nvertices: number[]; // \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nadjMat: number[][]; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u51fd\u6570 */\nconstructor(vertices: number[], edges: number[][]) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (const val of vertices) {\nthis.addVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (const e of edges) {\nthis.addEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(val: number): void {\nconst n: number = this.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nthis.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nconst newRow: number[] = [];\nfor (let j: number = 0; j < n; j++) {\nnewRow.push(0);\n}\nthis.adjMat.push(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (const row of this.adjMat) {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(index: number): void {\nif (index >= this.size()) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nthis.vertices.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nthis.adjMat.splice(index, 1);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (const row of this.adjMat) {\nrow.splice(index, 1);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\naddEdge(i: number, j: number): void {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) === (j, i)\nthis.adjMat[i][j] = 1;\nthis.adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nremoveEdge(i: number, j: number): void {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\nthrow new RangeError('Index Out Of Bounds Exception');\n}\nthis.adjMat[i][j] = 0;\nthis.adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nprint(): void {\nconsole.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\nconsole.log('\u90bb\u63a5\u77e9\u9635 =', this.adjMat);\n}\n}\n
        graph_adjacency_matrix.dart
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\nList<int> vertices = []; // \u9876\u70b9\u5143\u7d20\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\nList<List<int>> adjMat = []; //\u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjMat(List<int> vertices, List<List<int>> edges) {\nthis.vertices = [];\nthis.adjMat = [];\n// \u6dfb\u52a0\u9876\u70b9\nfor (int val in vertices) {\naddVertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor (List<int> e in edges) {\naddEdge(e[0], e[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn vertices.length;\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(int val) {\nint n = size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nvertices.add(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nList<int> newRow = List.filled(n, 0, growable: true);\nadjMat.add(newRow);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor (List<int> row in adjMat) {\nrow.add(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(int index) {\nif (index >= size()) {\nthrow IndexError;\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nvertices.removeAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nadjMat.removeAt(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (List<int> row in adjMat) {\nrow.removeAt(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow IndexError;\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nadjMat[i][j] = 1;\nadjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(int i, int j) {\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\nthrow IndexError;\n}\nadjMat[i][j] = 0;\nadjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printAdjMat() {\nprint(\"\u9876\u70b9\u5217\u8868 = $vertices\");\nprint(\"\u90bb\u63a5\u77e9\u9635 = \");\nprintMatrix(adjMat);\n}\n}\n
        graph_adjacency_matrix.rs
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\u578b */\npub struct GraphAdjMat {\n// \u9876\u70b9\u5217\u8868\uff0c\u5143\u7d20\u4ee3\u8868\u201c\u9876\u70b9\u503c\u201d\uff0c\u7d22\u5f15\u4ee3\u8868\u201c\u9876\u70b9\u7d22\u5f15\u201d\npub vertices: Vec<i32>,\n// \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\npub adj_mat: Vec<Vec<i32>>,\n}\nimpl GraphAdjMat {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(vertices: Vec<i32>, edges: Vec<[usize; 2]>) -> Self {\nlet mut graph = GraphAdjMat {\nvertices: vec![],\nadj_mat: vec![],\n};\n// \u6dfb\u52a0\u9876\u70b9\nfor val in vertices {\ngraph.add_vertex(val);\n}\n// \u6dfb\u52a0\u8fb9\n// \u8bf7\u6ce8\u610f\uff0cedges \u5143\u7d20\u4ee3\u8868\u9876\u70b9\u7d22\u5f15\uff0c\u5373\u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nfor edge in edges {\ngraph.add_edge(edge[0], edge[1])\n}\ngraph\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npub fn size(&self) -> usize {\nself.vertices.len()\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npub fn add_vertex(&mut self, val: i32) {\nlet n = self.size();\n// \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\nself.vertices.push(val);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\nself.adj_mat.push(vec![0; n]);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\nfor row in &mut self.adj_mat {\nrow.push(0);\n}\n}\n/* \u5220\u9664\u9876\u70b9 */\npub fn remove_vertex(&mut self, index: usize) {\nif index >= self.size() {\npanic!(\"index error\")\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nself.vertices.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nself.adj_mat.remove(index);\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor row in &mut self.adj_mat {\nrow.remove(index);\n}\n}\n/* \u6dfb\u52a0\u8fb9 */\npub fn add_edge(&mut self, i: usize, j: usize) {\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i >= self.size() || j >= self.size() || i == j {\npanic!(\"index error\")\n}\n// \u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u90bb\u63a5\u77e9\u9635\u5173\u4e8e\u4e3b\u5bf9\u89d2\u7ebf\u5bf9\u79f0\uff0c\u5373\u6ee1\u8db3 (i, j) == (j, i)\nself.adj_mat[i][j] = 1;\nself.adj_mat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\npub fn remove_edge(&mut self, i: usize, j: usize) {\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n// \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\nif i >= self.size() || j >= self.size() || i == j {\npanic!(\"index error\")\n}\nself.adj_mat[i][j] = 0;\nself.adj_mat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\npub fn print(&self) {\nprintln!(\"\u9876\u70b9\u5217\u8868 = {:?}\", self.vertices);\nprintln!(\"\u90bb\u63a5\u77e9\u9635 =\");\nprintln!(\"[\");\nfor row in &self.adj_mat {\nprintln!(\"  {:?},\", row);\n}\nprintln!(\"]\")\n}\n}\n
        graph_adjacency_matrix.c
        /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7ed3\u6784\u4f53 */\ntypedef struct {\nint vertices[MAX_SIZE];\nint adjMat[MAX_SIZE][MAX_SIZE];\nint size;\n} GraphAdjMat;\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjMat *newGraphAdjMat() {\nGraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));\ngraph->size = 0;\nfor (int i = 0; i < MAX_SIZE; i++) {\nfor (int j = 0; j < MAX_SIZE; j++) {\ngraph->adjMat[i][j] = 0;\n}\n}\nreturn graph;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjMat(GraphAdjMat *graph) {\nfree(graph);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjMat *graph, int val) {\nif (graph->size == MAX_SIZE) {\nfprintf(stderr, \"\u56fe\u7684\u9876\u70b9\u6570\u91cf\u5df2\u8fbe\u6700\u5927\u503c\\n\");\nreturn;\n}\n// \u6dfb\u52a0\u7b2c n \u4e2a\u9876\u70b9\uff0c\u5e76\u5c06\u7b2c n \u884c\u548c\u5217\u7f6e\u96f6\nint n = graph->size;\ngraph->vertices[n] = val;\nfor (int i = 0; i <= n; i++) {\ngraph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n}\ngraph->size++;\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\nif (index < 0 || index >= graph->size) {\nfprintf(stderr, \"\u9876\u70b9\u7d22\u5f15\u8d8a\u754c\\n\");\nreturn;\n}\n// \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\nfor (int i = index; i < graph->size - 1; i++) {\ngraph->vertices[i] = graph->vertices[i + 1];\n}\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\nfor (int i = index; i < graph->size - 1; i++) {\nfor (int j = 0; j < graph->size; j++) {\ngraph->adjMat[i][j] = graph->adjMat[i + 1][j];\n}\n}\n// \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\nfor (int i = 0; i < graph->size; i++) {\nfor (int j = index; j < graph->size - 1; j++) {\ngraph->adjMat[i][j] = graph->adjMat[i][j + 1];\n}\n}\ngraph->size--;\n}\n/* \u6dfb\u52a0\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid addEdge(GraphAdjMat *graph, int i, int j) {\nif (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\nfprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\nreturn;\n}\ngraph->adjMat[i][j] = 1;\ngraph->adjMat[j][i] = 1;\n}\n/* \u5220\u9664\u8fb9 */\n// \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\nvoid removeEdge(GraphAdjMat *graph, int i, int j) {\nif (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\nfprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\nreturn;\n}\ngraph->adjMat[i][j] = 0;\ngraph->adjMat[j][i] = 0;\n}\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printGraphAdjMat(GraphAdjMat *graph) {\nprintf(\"\u9876\u70b9\u5217\u8868 = \");\nprintArray(graph->vertices, graph->size);\nprintf(\"\u90bb\u63a5\u77e9\u9635 =\\n\");\nfor (int i = 0; i < graph->size; i++) {\nprintArray(graph->adjMat[i], graph->size);\n}\n}\n
        graph_adjacency_matrix.zig
        [class]{GraphAdjMat}-[func]{}\n
        "},{"location":"chapter_graph/graph_operations/#922","title":"9.2.2 \u00a0 \u57fa\u4e8e\u90bb\u63a5\u8868\u7684\u5b9e\u73b0","text":"

        \u8bbe\u65e0\u5411\u56fe\u7684\u9876\u70b9\u603b\u6570\u4e3a \\(n\\)\u3001\u8fb9\u603b\u6570\u4e3a \\(m\\) \uff0c\u5219\u53ef\u6839\u636e\u56fe 9-8 \u6240\u793a\u7684\u65b9\u6cd5\u5b9e\u73b0\u5404\u79cd\u64cd\u4f5c\u3002

        • \u6dfb\u52a0\u8fb9\uff1a\u5728\u9876\u70b9\u5bf9\u5e94\u94fe\u8868\u7684\u672b\u5c3e\u6dfb\u52a0\u8fb9\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002\u56e0\u4e3a\u662f\u65e0\u5411\u56fe\uff0c\u6240\u4ee5\u9700\u8981\u540c\u65f6\u6dfb\u52a0\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u5220\u9664\u8fb9\uff1a\u5728\u9876\u70b9\u5bf9\u5e94\u94fe\u8868\u4e2d\u67e5\u627e\u5e76\u5220\u9664\u6307\u5b9a\u8fb9\uff0c\u4f7f\u7528 \\(O(m)\\) \u65f6\u95f4\u3002\u5728\u65e0\u5411\u56fe\u4e2d\uff0c\u9700\u8981\u540c\u65f6\u5220\u9664\u4e24\u4e2a\u65b9\u5411\u7684\u8fb9\u3002
        • \u6dfb\u52a0\u9876\u70b9\uff1a\u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u94fe\u8868\uff0c\u5e76\u5c06\u65b0\u589e\u9876\u70b9\u4f5c\u4e3a\u94fe\u8868\u5934\u8282\u70b9\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u9876\u70b9\uff1a\u9700\u904d\u5386\u6574\u4e2a\u90bb\u63a5\u8868\uff0c\u5220\u9664\u5305\u542b\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u8fb9\uff0c\u4f7f\u7528 \\(O(n + m)\\) \u65f6\u95f4\u3002
        • \u521d\u59cb\u5316\uff1a\u5728\u90bb\u63a5\u8868\u4e2d\u521b\u5efa \\(n\\) \u4e2a\u9876\u70b9\u548c \\(2m\\) \u6761\u8fb9\uff0c\u4f7f\u7528 \\(O(n + m)\\) \u65f6\u95f4\u3002
        \u521d\u59cb\u5316\u90bb\u63a5\u8868\u6dfb\u52a0\u8fb9\u5220\u9664\u8fb9\u6dfb\u52a0\u9876\u70b9\u5220\u9664\u9876\u70b9

        \u56fe 9-8 \u00a0 \u90bb\u63a5\u8868\u7684\u521d\u59cb\u5316\u3001\u589e\u5220\u8fb9\u3001\u589e\u5220\u9876\u70b9

        \u4ee5\u4e0b\u662f\u90bb\u63a5\u8868\u7684\u4ee3\u7801\u5b9e\u73b0\u3002\u5bf9\u6bd4\u56fe 9-8 \uff0c\u5b9e\u9645\u4ee3\u7801\u6709\u4ee5\u4e0b\u4e0d\u540c\u3002

        • \u4e3a\u4e86\u65b9\u4fbf\u6dfb\u52a0\u4e0e\u5220\u9664\u9876\u70b9\uff0c\u4ee5\u53ca\u7b80\u5316\u4ee3\u7801\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u6765\u4ee3\u66ff\u94fe\u8868\u3002
        • \u4f7f\u7528\u54c8\u5e0c\u8868\u6765\u5b58\u50a8\u90bb\u63a5\u8868\uff0ckey \u4e3a\u9876\u70b9\u5b9e\u4f8b\uff0cvalue \u4e3a\u8be5\u9876\u70b9\u7684\u90bb\u63a5\u9876\u70b9\u5217\u8868\uff08\u94fe\u8868\uff09\u3002

        \u53e6\u5916\uff0c\u6211\u4eec\u5728\u90bb\u63a5\u8868\u4e2d\u4f7f\u7528 Vertex \u7c7b\u6765\u8868\u793a\u9876\u70b9\uff0c\u8fd9\u6837\u505a\u7684\u539f\u56e0\u662f\uff1a\u5982\u679c\u4e0e\u90bb\u63a5\u77e9\u9635\u4e00\u6837\uff0c\u7528\u5217\u8868\u7d22\u5f15\u6765\u533a\u5206\u4e0d\u540c\u9876\u70b9\uff0c\u90a3\u4e48\u5047\u8bbe\u8981\u5220\u9664\u7d22\u5f15\u4e3a \\(i\\) \u7684\u9876\u70b9\uff0c\u5219\u9700\u904d\u5386\u6574\u4e2a\u90bb\u63a5\u8868\uff0c\u5c06\u6240\u6709\u5927\u4e8e \\(i\\) \u7684\u7d22\u5f15\u5168\u90e8\u51cf \\(1\\) \uff0c\u6548\u7387\u5f88\u4f4e\u3002\u800c\u5982\u679c\u6bcf\u4e2a\u9876\u70b9\u90fd\u662f\u552f\u4e00\u7684 Vertex \u5b9e\u4f8b\uff0c\u5220\u9664\u67d0\u4e00\u9876\u70b9\u4e4b\u540e\u5c31\u65e0\u987b\u6539\u52a8\u5176\u4ed6\u9876\u70b9\u4e86\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_adjacency_list.py
        class GraphAdjList:\n\"\"\"\u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\"\"\"\ndef __init__(self, edges: list[list[Vertex]]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nself.adj_list = dict[Vertex, list[Vertex]]()\n# \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges:\nself.add_vertex(edge[0])\nself.add_vertex(edge[1])\nself.add_edge(edge[0], edge[1])\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\nreturn len(self.adj_list)\ndef add_edge(self, vet1: Vertex, vet2: Vertex):\n\"\"\"\u6dfb\u52a0\u8fb9\"\"\"\nif vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\nraise ValueError()\n# \u6dfb\u52a0\u8fb9 vet1 - vet2\nself.adj_list[vet1].append(vet2)\nself.adj_list[vet2].append(vet1)\ndef remove_edge(self, vet1: Vertex, vet2: Vertex):\n\"\"\"\u5220\u9664\u8fb9\"\"\"\nif vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\nraise ValueError()\n# \u5220\u9664\u8fb9 vet1 - vet2\nself.adj_list[vet1].remove(vet2)\nself.adj_list[vet2].remove(vet1)\ndef add_vertex(self, vet: Vertex):\n\"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\nif vet in self.adj_list:\nreturn\n# \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nself.adj_list[vet] = []\ndef remove_vertex(self, vet: Vertex):\n\"\"\"\u5220\u9664\u9876\u70b9\"\"\"\nif vet not in self.adj_list:\nraise ValueError()\n# \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nself.adj_list.pop(vet)\n# \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor vertex in self.adj_list:\nif vet in self.adj_list[vertex]:\nself.adj_list[vertex].remove(vet)\ndef print(self):\n\"\"\"\u6253\u5370\u90bb\u63a5\u8868\"\"\"\nprint(\"\u90bb\u63a5\u8868 =\")\nfor vertex in self.adj_list:\ntmp = [v.val for v in self.adj_list[vertex]]\nprint(f\"{vertex.val}: {tmp},\")\n
        graph_adjacency_list.cpp
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\npublic:\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nunordered_map<Vertex *, vector<Vertex *>> adjList;\n/* \u5728 vector \u4e2d\u5220\u9664\u6307\u5b9a\u8282\u70b9 */\nvoid remove(vector<Vertex *> &vec, Vertex *vet) {\nfor (int i = 0; i < vec.size(); i++) {\nif (vec[i] == vet) {\nvec.erase(vec.begin() + i);\nbreak;\n}\n}\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjList(const vector<vector<Vertex *>> &edges) {\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const vector<Vertex *> &edge : edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn adjList.size();\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(Vertex *vet1, Vertex *vet2) {\nif (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1].push_back(vet2);\nadjList[vet2].push_back(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(Vertex *vet1, Vertex *vet2) {\nif (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u5220\u9664\u8fb9 vet1 - vet2\nremove(adjList[vet1], vet2);\nremove(adjList[vet2], vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(Vertex *vet) {\nif (adjList.count(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = vector<Vertex *>();\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(Vertex *vet) {\nif (!adjList.count(vet))\nthrow invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.erase(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (auto &adj : adjList) {\nremove(adj.second, vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nvoid print() {\ncout << \"\u90bb\u63a5\u8868 =\" << endl;\nfor (auto &adj : adjList) {\nconst auto &key = adj.first;\nconst auto &vec = adj.second;\ncout << key->val << \": \";\nprintVector(vetsToVals(vec));\n}\n}\n};\n
        graph_adjacency_list.java
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nMap<Vertex, List<Vertex>> adjList;\n/* \u6784\u9020\u65b9\u6cd5 */\npublic GraphAdjList(Vertex[][] edges) {\nthis.adjList = new HashMap<>();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (Vertex[] edge : edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic int size() {\nreturn adjList.size();\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic void addEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\nthrow new IllegalArgumentException();\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList.get(vet1).add(vet2);\nadjList.get(vet2).add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\npublic void removeEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\nthrow new IllegalArgumentException();\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList.get(vet1).remove(vet2);\nadjList.get(vet2).remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void addVertex(Vertex vet) {\nif (adjList.containsKey(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList.put(vet, new ArrayList<>());\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void removeVertex(Vertex vet) {\nif (!adjList.containsKey(vet))\nthrow new IllegalArgumentException();\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (List<Vertex> list : adjList.values()) {\nlist.remove(vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic void print() {\nSystem.out.println(\"\u90bb\u63a5\u8868 =\");\nfor (Map.Entry<Vertex, List<Vertex>> pair : adjList.entrySet()) {\nList<Integer> tmp = new ArrayList<>();\nfor (Vertex vertex : pair.getValue())\ntmp.add(vertex.val);\nSystem.out.println(pair.getKey().val + \": \" + tmp + \",\");\n}\n}\n}\n
        graph_adjacency_list.cs
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npublic Dictionary<Vertex, List<Vertex>> adjList;\n/* \u6784\u9020\u51fd\u6570 */\npublic GraphAdjList(Vertex[][] edges) {\nadjList = [];\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nforeach (Vertex[] edge in edges) {\nAddVertex(edge[0]);\nAddVertex(edge[1]);\nAddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint Size() {\nreturn adjList.Count;\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic void AddEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\nthrow new InvalidOperationException();\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1].Add(vet2);\nadjList[vet2].Add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\npublic void RemoveEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\nthrow new InvalidOperationException();\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1].Remove(vet2);\nadjList[vet2].Remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic void AddVertex(Vertex vet) {\nif (adjList.ContainsKey(vet))\nreturn;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList.Add(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic void RemoveVertex(Vertex vet) {\nif (!adjList.ContainsKey(vet))\nthrow new InvalidOperationException();\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.Remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nforeach (List<Vertex> list in adjList.Values) {\nlist.Remove(vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic void Print() {\nConsole.WriteLine(\"\u90bb\u63a5\u8868 =\");\nforeach (KeyValuePair<Vertex, List<Vertex>> pair in adjList) {\nList<int> tmp = [];\nforeach (Vertex vertex in pair.Value)\ntmp.Add(vertex.val);\nConsole.WriteLine(pair.Key.val + \": [\" + string.Join(\", \", tmp) + \"],\");\n}\n}\n}\n
        graph_adjacency_list.go
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntype graphAdjList struct {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList map[Vertex][]Vertex\n}\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjList(edges [][]Vertex) *graphAdjList {\ng := &graphAdjList{\nadjList: make(map[Vertex][]Vertex),\n}\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor _, edge := range edges {\ng.addVertex(edge[0])\ng.addVertex(edge[1])\ng.addEdge(edge[0], edge[1])\n}\nreturn g\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjList) size() int {\nreturn len(g.adjList)\n}\n/* \u6dfb\u52a0\u8fb9 */\nfunc (g *graphAdjList) addEdge(vet1 Vertex, vet2 Vertex) {\n_, ok1 := g.adjList[vet1]\n_, ok2 := g.adjList[vet2]\nif !ok1 || !ok2 || vet1 == vet2 {\npanic(\"error\")\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2, \u6dfb\u52a0\u533f\u540d struct{},\ng.adjList[vet1] = append(g.adjList[vet1], vet2)\ng.adjList[vet2] = append(g.adjList[vet2], vet1)\n}\n/* \u5220\u9664\u8fb9 */\nfunc (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) {\n_, ok1 := g.adjList[vet1]\n_, ok2 := g.adjList[vet2]\nif !ok1 || !ok2 || vet1 == vet2 {\npanic(\"error\")\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\ng.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2)\ng.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1)\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjList) addVertex(vet Vertex) {\n_, ok := g.adjList[vet]\nif ok {\nreturn\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\ng.adjList[vet] = make([]Vertex, 0)\n}\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjList) removeVertex(vet Vertex) {\n_, ok := g.adjList[vet]\nif !ok {\npanic(\"error\")\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\ndelete(g.adjList, vet)\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor v, list := range g.adjList {\ng.adjList[v] = DeleteSliceElms(list, vet)\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nfunc (g *graphAdjList) print() {\nvar builder strings.Builder\nfmt.Printf(\"\u90bb\u63a5\u8868 = \\n\")\nfor k, v := range g.adjList {\nbuilder.WriteString(\"\\t\\t\" + strconv.Itoa(k.Val) + \": \")\nfor _, vet := range v {\nbuilder.WriteString(strconv.Itoa(vet.Val) + \" \")\n}\nfmt.Println(builder.String())\nbuilder.Reset()\n}\n}\n
        graph_adjacency_list.swift
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npublic private(set) var adjList: [Vertex: [Vertex]]\n/* \u6784\u9020\u65b9\u6cd5 */\npublic init(edges: [[Vertex]]) {\nadjList = [:]\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges {\naddVertex(vet: edge[0])\naddVertex(vet: edge[1])\naddEdge(vet1: edge[0], vet2: edge[1])\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\npublic func size() -> Int {\nadjList.count\n}\n/* \u6dfb\u52a0\u8fb9 */\npublic func addEdge(vet1: Vertex, vet2: Vertex) {\nif adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1]?.append(vet2)\nadjList[vet2]?.append(vet1)\n}\n/* \u5220\u9664\u8fb9 */\npublic func removeEdge(vet1: Vertex, vet2: Vertex) {\nif adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1]?.removeAll(where: { $0 == vet2 })\nadjList[vet2]?.removeAll(where: { $0 == vet1 })\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npublic func addVertex(vet: Vertex) {\nif adjList[vet] != nil {\nreturn\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = []\n}\n/* \u5220\u9664\u9876\u70b9 */\npublic func removeVertex(vet: Vertex) {\nif adjList[vet] == nil {\nfatalError(\"\u53c2\u6570\u9519\u8bef\")\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.removeValue(forKey: vet)\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor key in adjList.keys {\nadjList[key]?.removeAll(where: { $0 == vet })\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npublic func print() {\nSwift.print(\"\u90bb\u63a5\u8868 =\")\nfor pair in adjList {\nvar tmp: [Int] = []\nfor vertex in pair.value {\ntmp.append(vertex.val)\n}\nSwift.print(\"\\(pair.key.val): \\(tmp),\")\n}\n}\n}\n
        graph_adjacency_list.js
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(edges) {\nthis.adjList = new Map();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const edge of edges) {\nthis.addVertex(edge[0]);\nthis.addVertex(edge[1]);\nthis.addEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize() {\nreturn this.adjList.size;\n}\n/* \u6dfb\u52a0\u8fb9 */\naddEdge(vet1, vet2) {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).push(vet2);\nthis.adjList.get(vet2).push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nremoveEdge(vet1, vet2) {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\nthis.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(vet) {\nif (this.adjList.has(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nthis.adjList.set(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(vet) {\nif (!this.adjList.has(vet)) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nthis.adjList.delete(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (const set of this.adjList.values()) {\nconst index = set.indexOf(vet);\nif (index > -1) {\nset.splice(index, 1);\n}\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nprint() {\nconsole.log('\u90bb\u63a5\u8868 =');\nfor (const [key, value] of this.adjList) {\nconst tmp = [];\nfor (const vertex of value) {\ntmp.push(vertex.val);\n}\nconsole.log(key.val + ': ' + tmp.join());\n}\n}\n}\n
        graph_adjacency_list.ts
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nadjList: Map<Vertex, Vertex[]>;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(edges: Vertex[][]) {\nthis.adjList = new Map();\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor (const edge of edges) {\nthis.addVertex(edge[0]);\nthis.addVertex(edge[1]);\nthis.addEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.adjList.size;\n}\n/* \u6dfb\u52a0\u8fb9 */\naddEdge(vet1: Vertex, vet2: Vertex): void {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).push(vet2);\nthis.adjList.get(vet2).push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nremoveEdge(vet1: Vertex, vet2: Vertex): void {\nif (\n!this.adjList.has(vet1) ||\n!this.adjList.has(vet2) ||\nvet1 === vet2\n) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nthis.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\nthis.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\naddVertex(vet: Vertex): void {\nif (this.adjList.has(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nthis.adjList.set(vet, []);\n}\n/* \u5220\u9664\u9876\u70b9 */\nremoveVertex(vet: Vertex): void {\nif (!this.adjList.has(vet)) {\nthrow new Error('Illegal Argument Exception');\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nthis.adjList.delete(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (const set of this.adjList.values()) {\nconst index: number = set.indexOf(vet);\nif (index > -1) {\nset.splice(index, 1);\n}\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nprint(): void {\nconsole.log('\u90bb\u63a5\u8868 =');\nfor (const [key, value] of this.adjList.entries()) {\nconst tmp = [];\nfor (const vertex of value) {\ntmp.push(vertex.val);\n}\nconsole.log(key.val + ': ' + tmp.join());\n}\n}\n}\n
        graph_adjacency_list.dart
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nMap<Vertex, List<Vertex>> adjList = {};\n/* \u6784\u9020\u65b9\u6cd5 */\nGraphAdjList(List<List<Vertex>> edges) {\nfor (List<Vertex> edge in edges) {\naddVertex(edge[0]);\naddVertex(edge[1]);\naddEdge(edge[0], edge[1]);\n}\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nint size() {\nreturn adjList.length;\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) ||\n!adjList.containsKey(vet2) ||\nvet1 == vet2) {\nthrow ArgumentError;\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nadjList[vet1]!.add(vet2);\nadjList[vet2]!.add(vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(Vertex vet1, Vertex vet2) {\nif (!adjList.containsKey(vet1) ||\n!adjList.containsKey(vet2) ||\nvet1 == vet2) {\nthrow ArgumentError;\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nadjList[vet1]!.remove(vet2);\nadjList[vet2]!.remove(vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(Vertex vet) {\nif (adjList.containsKey(vet)) return;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nadjList[vet] = [];\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(Vertex vet) {\nif (!adjList.containsKey(vet)) {\nthrow ArgumentError;\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nadjList.remove(vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nadjList.forEach((key, value) {\nvalue.remove(vet);\n});\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nvoid printAdjList() {\nprint(\"\u90bb\u63a5\u8868 =\");\nadjList.forEach((key, value) {\nList<int> tmp = [];\nfor (Vertex vertex in value) {\ntmp.add(vertex.val);\n}\nprint(\"${key.val}: $tmp,\");\n});\n}\n}\n
        graph_adjacency_list.rs
        /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b\u578b */\npub struct GraphAdjList {\n// \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\npub adj_list: HashMap<Vertex, Vec<Vertex>>,\n}\nimpl GraphAdjList {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(edges: Vec<[Vertex; 2]>) -> Self {\nlet mut graph = GraphAdjList {\nadj_list: HashMap::new(),\n};\n// \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\nfor edge in edges {\ngraph.add_vertex(edge[0]);\ngraph.add_vertex(edge[1]);\ngraph.add_edge(edge[0], edge[1]);\n}\ngraph\n}\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n#[allow(unused)]\npub fn size(&self) -> usize {\nself.adj_list.len()\n}\n/* \u6dfb\u52a0\u8fb9 */\npub fn add_edge(&mut self, vet1: Vertex, vet2: Vertex) {\nif !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n{\npanic!(\"value error\");\n}\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\nself.adj_list.get_mut(&vet1).unwrap().push(vet2);\nself.adj_list.get_mut(&vet2).unwrap().push(vet1);\n}\n/* \u5220\u9664\u8fb9 */\n#[allow(unused)]\npub fn remove_edge(&mut self, vet1: Vertex, vet2: Vertex) {\nif !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n{\npanic!(\"value error\");\n}\n// \u5220\u9664\u8fb9 vet1 - vet2\nself.adj_list\n.get_mut(&vet1)\n.unwrap()\n.retain(|&vet| vet != vet2);\nself.adj_list\n.get_mut(&vet2)\n.unwrap()\n.retain(|&vet| vet != vet1);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\npub fn add_vertex(&mut self, vet: Vertex) {\nif self.adj_list.contains_key(&vet) {\nreturn;\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\nself.adj_list.insert(vet, vec![]);\n}\n/* \u5220\u9664\u9876\u70b9 */\n#[allow(unused)]\npub fn remove_vertex(&mut self, vet: Vertex) {\nif !self.adj_list.contains_key(&vet) {\npanic!(\"value error\");\n}\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nself.adj_list.remove(&vet);\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor list in self.adj_list.values_mut() {\nlist.retain(|&v| v != vet);\n}\n}\n/* \u6253\u5370\u90bb\u63a5\u8868 */\npub fn print(&self) {\nprintln!(\"\u90bb\u63a5\u8868 =\");\nfor (vertex, list) in &self.adj_list {\nlet list = list.iter().map(|vertex| vertex.val).collect::<Vec<i32>>();\nprintln!(\"{}: {:?},\", vertex.val, list);\n}\n}\n}\n
        graph_adjacency_list.c
        /* \u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct AdjListNode {\nVertex *vertex;           // \u9876\u70b9\nstruct AdjListNode *next; // \u540e\u7ee7\u8282\u70b9\n} AdjListNode;\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\nfor (int i = 0; i < graph->size; i++) {\nif (graph->heads[i]->vertex == vet) {\nreturn graph->heads[i];\n}\n}\nreturn NULL;\n}\n/* \u6dfb\u52a0\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid addEdgeHelper(AdjListNode *head, Vertex *vet) {\nAdjListNode *node = (AdjListNode *)malloc(sizeof(AdjListNode));\nnode->vertex = vet;\n// \u5934\u63d2\u6cd5\nnode->next = head->next;\nhead->next = node;\n}\n/* \u5220\u9664\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid removeEdgeHelper(AdjListNode *head, Vertex *vet) {\nAdjListNode *pre = head;\nAdjListNode *cur = head->next;\n// \u5728\u94fe\u8868\u4e2d\u641c\u7d22 vet \u5bf9\u5e94\u8282\u70b9\nwhile (cur != NULL && cur->vertex != vet) {\npre = cur;\ncur = cur->next;\n}\nif (cur == NULL)\nreturn;\n// \u5c06 vet \u5bf9\u5e94\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\npre->next = cur->next;\n// \u91ca\u653e\u5185\u5b58\nfree(cur);\n}\n/* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntypedef struct {\nAdjListNode *heads[MAX_SIZE]; // \u8282\u70b9\u6570\u7ec4\nint size;                     // \u8282\u70b9\u6570\u91cf\n} GraphAdjList;\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjList *newGraphAdjList() {\nGraphAdjList *graph = (GraphAdjList *)malloc(sizeof(GraphAdjList));\nif (!graph) {\nreturn NULL;\n}\ngraph->size = 0;\nfor (int i = 0; i < MAX_SIZE; i++) {\ngraph->heads[i] = NULL;\n}\nreturn graph;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjList(GraphAdjList *graph) {\nfor (int i = 0; i < graph->size; i++) {\nAdjListNode *cur = graph->heads[i];\nwhile (cur != NULL) {\nAdjListNode *next = cur->next;\nif (cur != graph->heads[i]) {\nfree(cur);\n}\ncur = next;\n}\nfree(graph->heads[i]->vertex);\nfree(graph->heads[i]);\n}\nfree(graph);\n}\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\nfor (int i = 0; i < graph->size; i++) {\nif (graph->heads[i]->vertex == vet) {\nreturn graph->heads[i];\n}\n}\nreturn NULL;\n}\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\nAdjListNode *head1 = findNode(graph, vet1);\nAdjListNode *head2 = findNode(graph, vet2);\nassert(head1 != NULL && head2 != NULL && head1 != head2);\n// \u6dfb\u52a0\u8fb9 vet1 - vet2\naddEdgeHelper(head1, vet2);\naddEdgeHelper(head2, vet1);\n}\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\nAdjListNode *head1 = findNode(graph, vet1);\nAdjListNode *head2 = findNode(graph, vet2);\nassert(head1 != NULL && head2 != NULL);\n// \u5220\u9664\u8fb9 vet1 - vet2\nremoveEdgeHelper(head1, head2->vertex);\nremoveEdgeHelper(head2, head1->vertex);\n}\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjList *graph, Vertex *vet) {\nassert(graph != NULL && graph->size < MAX_SIZE);\nAdjListNode *head = (AdjListNode *)malloc(sizeof(AdjListNode));\nhead->vertex = vet;\nhead->next = NULL;\n// \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\ngraph->heads[graph->size++] = head;\n}\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjList *graph, Vertex *vet) {\nAdjListNode *node = findNode(graph, vet);\nassert(node != NULL);\n// \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\nAdjListNode *cur = node, *pre = NULL;\nwhile (cur) {\npre = cur;\ncur = cur->next;\nfree(pre);\n}\n// \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\nfor (int i = 0; i < graph->size; i++) {\ncur = graph->heads[i];\npre = NULL;\nwhile (cur) {\npre = cur;\ncur = cur->next;\nif (cur && cur->vertex == vet) {\npre->next = cur->next;\nfree(cur);\nbreak;\n}\n}\n}\n// \u5c06\u8be5\u9876\u70b9\u4e4b\u540e\u7684\u9876\u70b9\u5411\u524d\u79fb\u52a8\uff0c\u4ee5\u586b\u8865\u7a7a\u7f3a\nint i;\nfor (i = 0; i < graph->size; i++) {\nif (graph->heads[i] == node)\nbreak;\n}\nfor (int j = i; j < graph->size - 1; j++) {\ngraph->heads[j] = graph->heads[j + 1];\n}\ngraph->size--;\nfree(vet);\n}\n
        graph_adjacency_list.zig
        [class]{GraphAdjList}-[func]{}\n
        "},{"location":"chapter_graph/graph_operations/#923","title":"9.2.3 \u00a0 \u6548\u7387\u5bf9\u6bd4","text":"

        \u8bbe\u56fe\u4e2d\u5171\u6709 \\(n\\) \u4e2a\u9876\u70b9\u548c \\(m\\) \u6761\u8fb9\uff0c\u8868 9-2 \u5bf9\u6bd4\u4e86\u90bb\u63a5\u77e9\u9635\u548c\u90bb\u63a5\u8868\u7684\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u3002

        \u8868 9-2 \u00a0 \u90bb\u63a5\u77e9\u9635\u4e0e\u90bb\u63a5\u8868\u5bf9\u6bd4

        \u90bb\u63a5\u77e9\u9635 \u90bb\u63a5\u8868\uff08\u94fe\u8868\uff09 \u90bb\u63a5\u8868\uff08\u54c8\u5e0c\u8868\uff09 \u5224\u65ad\u662f\u5426\u90bb\u63a5 \\(O(1)\\) \\(O(m)\\) \\(O(1)\\) \u6dfb\u52a0\u8fb9 \\(O(1)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u8fb9 \\(O(1)\\) \\(O(m)\\) \\(O(1)\\) \u6dfb\u52a0\u9876\u70b9 \\(O(n)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u9876\u70b9 \\(O(n^2)\\) \\(O(n + m)\\) \\(O(n)\\) \u5185\u5b58\u7a7a\u95f4\u5360\u7528 \\(O(n^2)\\) \\(O(n + m)\\) \\(O(n + m)\\)

        \u89c2\u5bdf\u8868 9-2 \uff0c\u4f3c\u4e4e\u90bb\u63a5\u8868\uff08\u54c8\u5e0c\u8868\uff09\u7684\u65f6\u95f4\u6548\u7387\u4e0e\u7a7a\u95f4\u6548\u7387\u6700\u4f18\u3002\u4f46\u5b9e\u9645\u4e0a\uff0c\u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u64cd\u4f5c\u8fb9\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u53ea\u9700\u4e00\u6b21\u6570\u7ec4\u8bbf\u95ee\u6216\u8d4b\u503c\u64cd\u4f5c\u5373\u53ef\u3002\u7efc\u5408\u6765\u770b\uff0c\u90bb\u63a5\u77e9\u9635\u4f53\u73b0\u4e86\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u7684\u539f\u5219\uff0c\u800c\u90bb\u63a5\u8868\u4f53\u73b0\u4e86\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u7684\u539f\u5219\u3002

        "},{"location":"chapter_graph/graph_traversal/","title":"9.3 \u00a0 \u56fe\u7684\u904d\u5386","text":"

        \u6811\u4ee3\u8868\u7684\u662f\u201c\u4e00\u5bf9\u591a\u201d\u7684\u5173\u7cfb\uff0c\u800c\u56fe\u5219\u5177\u6709\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\uff0c\u53ef\u4ee5\u8868\u793a\u4efb\u610f\u7684\u201c\u591a\u5bf9\u591a\u201d\u5173\u7cfb\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u6811\u770b\u4f5c\u56fe\u7684\u4e00\u79cd\u7279\u4f8b\u3002\u663e\u7136\uff0c\u6811\u7684\u904d\u5386\u64cd\u4f5c\u4e5f\u662f\u56fe\u7684\u904d\u5386\u64cd\u4f5c\u7684\u4e00\u79cd\u7279\u4f8b\u3002

        \u56fe\u548c\u6811\u90fd\u9700\u8981\u5e94\u7528\u641c\u7d22\u7b97\u6cd5\u6765\u5b9e\u73b0\u904d\u5386\u64cd\u4f5c\u3002\u56fe\u7684\u904d\u5386\u65b9\u5f0f\u53ef\u5206\u4e3a\u4e24\u79cd\uff1a\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal\u300d\u3002\u5b83\u4eec\u4e5f\u5e38\u88ab\u79f0\u4e3a\u300c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search\u300d\uff0c\u7b80\u79f0 BFS \u548c DFS \u3002

        "},{"location":"chapter_graph/graph_traversal/#931","title":"9.3.1 \u00a0 \u5e7f\u5ea6\u4f18\u5148\u904d\u5386","text":"

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u7531\u8fd1\u53ca\u8fdc\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u4ece\u67d0\u4e2a\u8282\u70b9\u51fa\u53d1\uff0c\u59cb\u7ec8\u4f18\u5148\u8bbf\u95ee\u8ddd\u79bb\u6700\u8fd1\u7684\u9876\u70b9\uff0c\u5e76\u4e00\u5c42\u5c42\u5411\u5916\u6269\u5f20\u3002\u5982\u56fe 9-9 \u6240\u793a\uff0c\u4ece\u5de6\u4e0a\u89d2\u9876\u70b9\u51fa\u53d1\uff0c\u9996\u5148\u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff0c\u7136\u540e\u904d\u5386\u4e0b\u4e00\u4e2a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u6240\u6709\u9876\u70b9\u8bbf\u95ee\u5b8c\u6bd5\u3002

        \u56fe 9-9 \u00a0 \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386

        "},{"location":"chapter_graph/graph_traversal/#1","title":"1. \u00a0 \u7b97\u6cd5\u5b9e\u73b0","text":"

        BFS \u901a\u5e38\u501f\u52a9\u961f\u5217\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002\u961f\u5217\u5177\u6709\u201c\u5148\u5165\u5148\u51fa\u201d\u7684\u6027\u8d28\uff0c\u8fd9\u4e0e BFS \u7684\u201c\u7531\u8fd1\u53ca\u8fdc\u201d\u7684\u601d\u60f3\u5f02\u66f2\u540c\u5de5\u3002

        1. \u5c06\u904d\u5386\u8d77\u59cb\u9876\u70b9 startVet \u52a0\u5165\u961f\u5217\uff0c\u5e76\u5f00\u542f\u5faa\u73af\u3002
        2. \u5728\u5faa\u73af\u7684\u6bcf\u8f6e\u8fed\u4ee3\u4e2d\uff0c\u5f39\u51fa\u961f\u9996\u9876\u70b9\u5e76\u8bb0\u5f55\u8bbf\u95ee\uff0c\u7136\u540e\u5c06\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\u52a0\u5165\u5230\u961f\u5217\u5c3e\u90e8\u3002
        3. \u5faa\u73af\u6b65\u9aa4 2. \uff0c\u76f4\u5230\u6240\u6709\u9876\u70b9\u88ab\u8bbf\u95ee\u5b8c\u6bd5\u540e\u7ed3\u675f\u3002

        \u4e3a\u4e86\u9632\u6b62\u91cd\u590d\u904d\u5386\u9876\u70b9\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 visited \u6765\u8bb0\u5f55\u54ea\u4e9b\u8282\u70b9\u5df2\u88ab\u8bbf\u95ee\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_bfs.py
        def graph_bfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n\"\"\"\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS\"\"\"\n# \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n# \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres = []\n# \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited = set[Vertex]([start_vet])\n# \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nque = deque[Vertex]([start_vet])\n# \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile len(que) > 0:\nvet = que.popleft()  # \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n# \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adj_vet in graph.adj_list[vet]:\nif adj_vet in visited:\ncontinue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.append(adj_vet)  # \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adj_vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n# \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n
        graph_bfs.cpp
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvector<Vertex *> graphBFS(GraphAdjList &graph, Vertex *startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvector<Vertex *> res;\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nunordered_set<Vertex *> visited = {startVet};\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nqueue<Vertex *> que;\nque.push(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!que.empty()) {\nVertex *vet = que.front();\nque.pop();          // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push_back(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (auto adjVet : graph.adjList[vet]) {\nif (visited.count(adjVet))\ncontinue;            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.push(adjVet);        // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.emplace(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.java
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> graphBFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = new ArrayList<>();\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = new HashSet<>();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = new LinkedList<>();\nque.offer(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!que.isEmpty()) {\nVertex vet = que.poll(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.add(vet);            // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet : graph.adjList.get(vet)) {\nif (visited.contains(adjVet))\ncontinue;        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nque.offer(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.cs
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> GraphBFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nHashSet<Vertex> visited = [startVet];\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = new();\nque.Enqueue(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.Count > 0) {\nVertex vet = que.Dequeue(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.Add(vet);               // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nforeach (Vertex adjVet in graph.adjList[vet]) {\nif (visited.Contains(adjVet)) {\ncontinue;          // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.Enqueue(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.Add(adjVet);   // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.go
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphBFS(g *graphAdjList, startVet Vertex) []Vertex {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres := make([]Vertex, 0)\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited := make(map[Vertex]struct{})\nvisited[startVet] = struct{}{}\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS, \u4f7f\u7528\u5207\u7247\u6a21\u62df\u961f\u5217\nqueue := make([]Vertex, 0)\nqueue = append(queue, startVet)\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nfor len(queue) > 0 {\n// \u961f\u9996\u9876\u70b9\u51fa\u961f\nvet := queue[0]\nqueue = queue[1:]\n// \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nres = append(res, vet)\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor _, adjVet := range g.adjList[vet] {\n_, isExist := visited[adjVet]\n// \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nif !isExist {\nqueue = append(queue, adjVet)\nvisited[adjVet] = struct{}{}\n}\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_bfs.swift
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphBFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvar res: [Vertex] = []\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvar visited: Set<Vertex> = [startVet]\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nvar que: [Vertex] = [startVet]\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile !que.isEmpty {\nlet vet = que.removeFirst() // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adjList[vet] ?? [] {\nif visited.contains(adjVet) {\ncontinue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.append(adjVet) // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.insert(adjVet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_bfs.js
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphBFS(graph, startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited = new Set();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nconst que = [startVet];\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.length) {\nconst vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet) ?? []) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.ts
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphBFS(graph: GraphAdjList, startVet: Vertex): Vertex[] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res: Vertex[] = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited: Set<Vertex> = new Set();\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nconst que = [startVet];\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.length) {\nconst vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet) ?? []) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.dart
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\nList<Vertex> graphBFS(GraphAdjList graph, Vertex startVet) {\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = {};\nvisited.add(startVet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue<Vertex> que = Queue();\nque.add(startVet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (que.isNotEmpty) {\nVertex vet = que.removeFirst(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet in graph.adjList[vet]!) {\nif (visited.contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.add(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res;\n}\n
        graph_bfs.rs
        /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfn graph_bfs(graph: GraphAdjList, start_vet: Vertex) -> Vec<Vertex> {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nlet mut res = vec![];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nlet mut visited = HashSet::new();\nvisited.insert(start_vet);\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nlet mut que = VecDeque::new();\nque.push_back(start_vet);\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile !que.is_empty() {\nlet vet = que.pop_front().unwrap(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nif let Some(adj_vets) = graph.adj_list.get(&vet) {\nfor &adj_vet in adj_vets {\nif visited.contains(&adj_vet) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\nque.push_back(adj_vet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited.insert(adj_vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\n}\n}\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nres\n}\n
        graph_bfs.c
        /* \u8282\u70b9\u961f\u5217\u7ed3\u6784\u4f53 */\ntypedef struct {\nVertex *vertices[MAX_SIZE];\nint front, rear, size;\n} Queue;\n/* \u6784\u9020\u51fd\u6570 */\nQueue *newQueue() {\nQueue *q = (Queue *)malloc(sizeof(Queue));\nq->front = q->rear = q->size = 0;\nreturn q;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nint isEmpty(Queue *q) {\nreturn q->size == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid enqueue(Queue *q, Vertex *vet) {\nq->vertices[q->rear] = vet;\nq->rear = (q->rear + 1) % MAX_SIZE;\nq->size++;\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nVertex *dequeue(Queue *q) {\nVertex *vet = q->vertices[q->front];\nq->front = (q->front + 1) % MAX_SIZE;\nq->size--;\nreturn vet;\n}\n/* \u68c0\u67e5\u9876\u70b9\u662f\u5426\u5df2\u88ab\u8bbf\u95ee */\nint isVisited(Vertex **visited, int size, Vertex *vet) {\n// \u904d\u5386\u67e5\u627e\u8282\u70b9\uff0c\u4f7f\u7528 O(n) \u65f6\u95f4\nfor (int i = 0; i < size; i++) {\nif (visited[i] == vet)\nreturn 1;\n}\nreturn 0;\n}\n/* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 BFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvoid graphBFS(GraphAdjList *graph, Vertex *startVet, Vertex **res, int *resSize, Vertex **visited, int *visitedSize) {\n// \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\nQueue *queue = newQueue();\nenqueue(queue, startVet);\nvisited[(*visitedSize)++] = startVet;\n// \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\nwhile (!isEmpty(queue)) {\nVertex *vet = dequeue(queue); // \u961f\u9996\u9876\u70b9\u51fa\u961f\nres[(*resSize)++] = vet;      // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nAdjListNode *node = findNode(graph, vet);\nwhile (node != NULL) {\n// \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nif (!isVisited(visited, *visitedSize, node->vertex)) {\nenqueue(queue, node->vertex);             // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\nvisited[(*visitedSize)++] = node->vertex; // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n}\nnode = node->next;\n}\n}\n// \u91ca\u653e\u5185\u5b58\nfree(queue);\n}\n
        graph_bfs.zig
        [class]{}-[func]{graphBFS}\n

        \u4ee3\u7801\u76f8\u5bf9\u62bd\u8c61\uff0c\u5efa\u8bae\u5bf9\u7167\u56fe 9-10 \u6765\u52a0\u6df1\u7406\u89e3\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 9-10 \u00a0 \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u6b65\u9aa4

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5e8f\u5217\u662f\u5426\u552f\u4e00\uff1f

        \u4e0d\u552f\u4e00\u3002\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u53ea\u8981\u6c42\u6309\u201c\u7531\u8fd1\u53ca\u8fdc\u201d\u7684\u987a\u5e8f\u904d\u5386\uff0c\u800c\u591a\u4e2a\u76f8\u540c\u8ddd\u79bb\u7684\u9876\u70b9\u7684\u904d\u5386\u987a\u5e8f\u5141\u8bb8\u88ab\u4efb\u610f\u6253\u4e71\u3002\u4ee5\u56fe 9-10 \u4e3a\u4f8b\uff0c\u9876\u70b9 \\(1\\)\u3001\\(3\\) \u7684\u8bbf\u95ee\u987a\u5e8f\u53ef\u4ee5\u4ea4\u6362\uff0c\u9876\u70b9 \\(2\\)\u3001\\(4\\)\u3001\\(6\\) \u7684\u8bbf\u95ee\u987a\u5e8f\u4e5f\u53ef\u4ee5\u4efb\u610f\u4ea4\u6362\u3002

        "},{"location":"chapter_graph/graph_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u6240\u6709\u9876\u70b9\u90fd\u4f1a\u5165\u961f\u5e76\u51fa\u961f\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(|V|)\\) \u65f6\u95f4\uff1b\u5728\u904d\u5386\u90bb\u63a5\u9876\u70b9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7531\u4e8e\u662f\u65e0\u5411\u56fe\uff0c\u56e0\u6b64\u6240\u6709\u8fb9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(2\\) \u6b21\uff0c\u4f7f\u7528 \\(O(2|E|)\\) \u65f6\u95f4\uff1b\u603b\u4f53\u4f7f\u7528 \\(O(|V| + |E|)\\) \u65f6\u95f4\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6\uff1a\u5217\u8868 res \uff0c\u54c8\u5e0c\u8868 visited \uff0c\u961f\u5217 que \u4e2d\u7684\u9876\u70b9\u6570\u91cf\u6700\u591a\u4e3a \\(|V|\\) \uff0c\u4f7f\u7528 \\(O(|V|)\\) \u7a7a\u95f4\u3002

        "},{"location":"chapter_graph/graph_traversal/#932","title":"9.3.2 \u00a0 \u6df1\u5ea6\u4f18\u5148\u904d\u5386","text":"

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u4f18\u5148\u8d70\u5230\u5e95\u3001\u65e0\u8def\u53ef\u8d70\u518d\u56de\u5934\u7684\u904d\u5386\u65b9\u5f0f\u3002\u5982\u56fe 9-11 \u6240\u793a\uff0c\u4ece\u5de6\u4e0a\u89d2\u9876\u70b9\u51fa\u53d1\uff0c\u8bbf\u95ee\u5f53\u524d\u9876\u70b9\u7684\u67d0\u4e2a\u90bb\u63a5\u9876\u70b9\uff0c\u76f4\u5230\u8d70\u5230\u5c3d\u5934\u65f6\u8fd4\u56de\uff0c\u518d\u7ee7\u7eed\u8d70\u5230\u5c3d\u5934\u5e76\u8fd4\u56de\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u6240\u6709\u9876\u70b9\u904d\u5386\u5b8c\u6210\u3002

        \u56fe 9-11 \u00a0 \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386

        "},{"location":"chapter_graph/graph_traversal/#1_1","title":"1. \u00a0 \u7b97\u6cd5\u5b9e\u73b0","text":"

        \u8fd9\u79cd\u201c\u8d70\u5230\u5c3d\u5934\u518d\u8fd4\u56de\u201d\u7684\u7b97\u6cd5\u8303\u5f0f\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u6765\u5b9e\u73b0\u3002\u4e0e\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7c7b\u4f3c\uff0c\u5728\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u4e2d\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868 visited \u6765\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u8bbf\u95ee\u9876\u70b9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig graph_dfs.py
        def dfs(graph: GraphAdjList, visited: set[Vertex], res: list[Vertex], vet: Vertex):\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570\"\"\"\nres.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n# \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adj_list[vet]:\nif adjVet in visited:\ncontinue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n# \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet)\ndef graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS\"\"\"\n# \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n# \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres = []\n# \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited = set[Vertex]()\ndfs(graph, visited, res, start_vet)\nreturn res\n
        graph_dfs.cpp
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList &graph, unordered_set<Vertex *> &visited, vector<Vertex *> &res, Vertex *vet) {\nres.push_back(vet);   // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.emplace(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex *adjVet : graph.adjList[vet]) {\nif (visited.count(adjVet))\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvector<Vertex *> graphDFS(GraphAdjList &graph, Vertex *startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvector<Vertex *> res;\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nunordered_set<Vertex *> visited;\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.java
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList graph, Set<Vertex> visited, List<Vertex> res, Vertex vet) {\nres.add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet : graph.adjList.get(vet)) {\nif (visited.contains(adjVet))\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = new ArrayList<>();\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = new HashSet<>();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.cs
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid DFS(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {\nres.Add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.Add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nforeach (Vertex adjVet in graph.adjList[vet]) {\nif (visited.Contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9                             \n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\nDFS(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nList<Vertex> GraphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nHashSet<Vertex> visited = [];\nDFS(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.go
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunc dfs(g *graphAdjList, visited map[Vertex]struct{}, res *[]Vertex, vet Vertex) {\n// append \u64cd\u4f5c\u4f1a\u8fd4\u56de\u65b0\u7684\u7684\u5f15\u7528\uff0c\u5fc5\u987b\u8ba9\u539f\u5f15\u7528\u91cd\u65b0\u8d4b\u503c\u4e3a\u65b0slice\u7684\u5f15\u7528\n*res = append(*res, vet)\nvisited[vet] = struct{}{}\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor _, adjVet := range g.adjList[vet] {\n_, isExist := visited[adjVet]\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\nif !isExist {\ndfs(g, visited, res, adjVet)\n}\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphDFS(g *graphAdjList, startVet Vertex) []Vertex {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nres := make([]Vertex, 0)\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvisited := make(map[Vertex]struct{})\ndfs(g, visited, &res, startVet)\n// \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\nreturn res\n}\n
        graph_dfs.swift
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunc dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {\nres.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.insert(vet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor adjVet in graph.adjList[vet] ?? [] {\nif visited.contains(adjVet) {\ncontinue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph: graph, visited: &visited, res: &res, vet: adjVet)\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunc graphDFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nvar res: [Vertex] = []\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nvar visited: Set<Vertex> = []\ndfs(graph: graph, visited: &visited, res: &res, vet: startVet)\nreturn res\n}\n
        graph_dfs.js
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction dfs(graph, visited, res, vet) {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet)) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphDFS(graph, startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited = new Set();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.ts
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfunction dfs(\ngraph: GraphAdjList,\nvisited: Set<Vertex>,\nres: Vertex[],\nvet: Vertex\n): void {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (const adjVet of graph.adjList.get(vet)) {\nif (visited.has(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfunction graphDFS(graph: GraphAdjList, startVet: Vertex): Vertex[] {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nconst res: Vertex[] = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nconst visited: Set<Vertex> = new Set();\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.dart
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(\nGraphAdjList graph,\nSet<Vertex> visited,\nList<Vertex> res,\nVertex vet,\n) {\nres.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfor (Vertex adjVet in graph.adjList[vet]!) {\nif (visited.contains(adjVet)) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adjVet);\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nList<Vertex> res = [];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nSet<Vertex> visited = {};\ndfs(graph, visited, res, startVet);\nreturn res;\n}\n
        graph_dfs.rs
        /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nfn dfs(graph: &GraphAdjList, visited: &mut HashSet<Vertex>, res: &mut Vec<Vertex>, vet: Vertex) {\nres.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nvisited.insert(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nif let Some(adj_vets) = graph.adj_list.get(&vet) {\nfor &adj_vet in adj_vets {\nif visited.contains(&adj_vet) {\ncontinue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n}\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, visited, res, adj_vet);\n}\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nfn graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> Vec<Vertex> {\n// \u9876\u70b9\u904d\u5386\u5e8f\u5217\nlet mut res = vec![];\n// \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\nlet mut visited = HashSet::new();\ndfs(&graph, &mut visited, &mut res, start_vet);\nres\n}\n
        graph_dfs.c
        /* \u68c0\u67e5\u9876\u70b9\u662f\u5426\u5df2\u88ab\u8bbf\u95ee */\nint isVisited(Vertex **res, int size, Vertex *vet) {\n// \u904d\u5386\u67e5\u627e\u8282\u70b9\uff0c\u4f7f\u7528 O(n) \u65f6\u95f4\nfor (int i = 0; i < size; i++) {\nif (res[i] == vet) {\nreturn 1;\n}\n}\nreturn 0;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS \u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList *graph, Vertex **res, int *resSize, Vertex *vet) {\n// \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\nres[(*resSize)++] = vet;\n// \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nAdjListNode *node = findNode(graph, vet);\nwhile (node != NULL) {\n// \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\nif (!isVisited(res, *resSize, node->vertex)) {\n// \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\ndfs(graph, res, resSize, node->vertex);\n}\nnode = node->next;\n}\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 DFS */\n// \u4f7f\u7528\u90bb\u63a5\u8868\u6765\u8868\u793a\u56fe\uff0c\u4ee5\u4fbf\u83b7\u53d6\u6307\u5b9a\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\nvoid graphDFS(GraphAdjList *graph, Vertex *startVet, Vertex **res, int *resSize) {\ndfs(graph, res, resSize, startVet);\n}\n
        graph_dfs.zig
        [class]{}-[func]{dfs}\n[class]{}-[func]{graphDFS}\n

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u7b97\u6cd5\u6d41\u7a0b\u5982\u56fe 9-12 \u6240\u793a\u3002

        • \u76f4\u865a\u7ebf\u4ee3\u8868\u5411\u4e0b\u9012\u63a8\uff0c\u8868\u793a\u5f00\u542f\u4e86\u4e00\u4e2a\u65b0\u7684\u9012\u5f52\u65b9\u6cd5\u6765\u8bbf\u95ee\u65b0\u9876\u70b9\u3002
        • \u66f2\u865a\u7ebf\u4ee3\u8868\u5411\u4e0a\u56de\u6eaf\uff0c\u8868\u793a\u6b64\u9012\u5f52\u65b9\u6cd5\u5df2\u7ecf\u8fd4\u56de\uff0c\u56de\u6eaf\u5230\u4e86\u5f00\u542f\u6b64\u65b9\u6cd5\u7684\u4f4d\u7f6e\u3002

        \u4e3a\u4e86\u52a0\u6df1\u7406\u89e3\uff0c\u5efa\u8bae\u5c06\u56fe 9-12 \u4e0e\u4ee3\u7801\u7ed3\u5408\u8d77\u6765\uff0c\u5728\u8111\u4e2d\u6a21\u62df\uff08\u6216\u8005\u7528\u7b14\u753b\u4e0b\u6765\uff09\u6574\u4e2a DFS \u8fc7\u7a0b\uff0c\u5305\u62ec\u6bcf\u4e2a\u9012\u5f52\u65b9\u6cd5\u4f55\u65f6\u5f00\u542f\u3001\u4f55\u65f6\u8fd4\u56de\u3002

        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 9-12 \u00a0 \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u6b65\u9aa4

        \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5e8f\u5217\u662f\u5426\u552f\u4e00\uff1f

        \u4e0e\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u7c7b\u4f3c\uff0c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u5e8f\u5217\u7684\u987a\u5e8f\u4e5f\u4e0d\u662f\u552f\u4e00\u7684\u3002\u7ed9\u5b9a\u67d0\u9876\u70b9\uff0c\u5148\u5f80\u54ea\u4e2a\u65b9\u5411\u63a2\u7d22\u90fd\u53ef\u4ee5\uff0c\u5373\u90bb\u63a5\u9876\u70b9\u7684\u987a\u5e8f\u53ef\u4ee5\u4efb\u610f\u6253\u4e71\uff0c\u90fd\u662f\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u3002

        \u4ee5\u6811\u7684\u904d\u5386\u4e3a\u4f8b\uff0c\u201c\u6839 \\(\\rightarrow\\) \u5de6 \\(\\rightarrow\\) \u53f3\u201d\u201c\u5de6 \\(\\rightarrow\\) \u6839 \\(\\rightarrow\\) \u53f3\u201d\u201c\u5de6 \\(\\rightarrow\\) \u53f3 \\(\\rightarrow\\) \u6839\u201d\u5206\u522b\u5bf9\u5e94\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\uff0c\u5b83\u4eec\u5c55\u793a\u4e86\u4e09\u79cd\u904d\u5386\u4f18\u5148\u7ea7\uff0c\u7136\u800c\u8fd9\u4e09\u8005\u90fd\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u3002

        "},{"location":"chapter_graph/graph_traversal/#2_1","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u6240\u6709\u9876\u70b9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(1\\) \u6b21\uff0c\u4f7f\u7528 \\(O(|V|)\\) \u65f6\u95f4\uff1b\u6240\u6709\u8fb9\u90fd\u4f1a\u88ab\u8bbf\u95ee \\(2\\) \u6b21\uff0c\u4f7f\u7528 \\(O(2|E|)\\) \u65f6\u95f4\uff1b\u603b\u4f53\u4f7f\u7528 \\(O(|V| + |E|)\\) \u65f6\u95f4\u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6\uff1a\u5217\u8868 res \uff0c\u54c8\u5e0c\u8868 visited \u9876\u70b9\u6570\u91cf\u6700\u591a\u4e3a \\(|V|\\) \uff0c\u9012\u5f52\u6df1\u5ea6\u6700\u5927\u4e3a \\(|V|\\) \uff0c\u56e0\u6b64\u4f7f\u7528 \\(O(|V|)\\) \u7a7a\u95f4\u3002

        "},{"location":"chapter_graph/summary/","title":"9.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_graph/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u56fe\u7531\u9876\u70b9\u548c\u8fb9\u7ec4\u6210\uff0c\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u7ec4\u9876\u70b9\u548c\u4e00\u7ec4\u8fb9\u6784\u6210\u7684\u96c6\u5408\u3002
        • \u76f8\u8f83\u4e8e\u7ebf\u6027\u5173\u7cfb\uff08\u94fe\u8868\uff09\u548c\u5206\u6cbb\u5173\u7cfb\uff08\u6811\uff09\uff0c\u7f51\u7edc\u5173\u7cfb\uff08\u56fe\uff09\u5177\u6709\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\uff0c\u56e0\u800c\u66f4\u4e3a\u590d\u6742\u3002
        • \u6709\u5411\u56fe\u7684\u8fb9\u5177\u6709\u65b9\u5411\u6027\uff0c\u8fde\u901a\u56fe\u4e2d\u7684\u4efb\u610f\u9876\u70b9\u5747\u53ef\u8fbe\uff0c\u6709\u6743\u56fe\u7684\u6bcf\u6761\u8fb9\u90fd\u5305\u542b\u6743\u91cd\u53d8\u91cf\u3002
        • \u90bb\u63a5\u77e9\u9635\u5229\u7528\u77e9\u9635\u6765\u8868\u793a\u56fe\uff0c\u6bcf\u4e00\u884c\uff08\u5217\uff09\u4ee3\u8868\u4e00\u4e2a\u9876\u70b9\uff0c\u77e9\u9635\u5143\u7d20\u4ee3\u8868\u8fb9\uff0c\u7528 \\(1\\) \u6216 \\(0\\) \u8868\u793a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u6709\u8fb9\u6216\u65e0\u8fb9\u3002\u90bb\u63a5\u77e9\u9635\u5728\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u4e0a\u6548\u7387\u5f88\u9ad8\uff0c\u4f46\u7a7a\u95f4\u5360\u7528\u8f83\u591a\u3002
        • \u90bb\u63a5\u8868\u4f7f\u7528\u591a\u4e2a\u94fe\u8868\u6765\u8868\u793a\u56fe\uff0c\u7b2c \\(i\\) \u4e2a\u94fe\u8868\u5bf9\u5e94\u9876\u70b9 \\(i\\) \uff0c\u5176\u4e2d\u5b58\u50a8\u4e86\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\u3002\u90bb\u63a5\u8868\u76f8\u5bf9\u4e8e\u90bb\u63a5\u77e9\u9635\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\uff0c\u4f46\u7531\u4e8e\u9700\u8981\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u8fb9\uff0c\u56e0\u6b64\u65f6\u95f4\u6548\u7387\u8f83\u4f4e\u3002
        • \u5f53\u90bb\u63a5\u8868\u4e2d\u7684\u94fe\u8868\u8fc7\u957f\u65f6\uff0c\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u6216\u54c8\u5e0c\u8868\uff0c\u4ece\u800c\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002
        • \u4ece\u7b97\u6cd5\u601d\u60f3\u7684\u89d2\u5ea6\u5206\u6790\uff0c\u90bb\u63a5\u77e9\u9635\u4f53\u73b0\u4e86\u201c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\uff0c\u90bb\u63a5\u8868\u4f53\u73b0\u4e86\u201c\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4\u201d\u3002
        • \u56fe\u53ef\u7528\u4e8e\u5efa\u6a21\u5404\u7c7b\u73b0\u5b9e\u7cfb\u7edf\uff0c\u5982\u793e\u4ea4\u7f51\u7edc\u3001\u5730\u94c1\u7ebf\u8def\u7b49\u3002
        • \u6811\u662f\u56fe\u7684\u4e00\u79cd\u7279\u4f8b\uff0c\u6811\u7684\u904d\u5386\u4e5f\u662f\u56fe\u7684\u904d\u5386\u7684\u4e00\u79cd\u7279\u4f8b\u3002
        • \u56fe\u7684\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u7531\u8fd1\u53ca\u8fdc\u3001\u5c42\u5c42\u6269\u5f20\u7684\u641c\u7d22\u65b9\u5f0f\uff0c\u901a\u5e38\u501f\u52a9\u961f\u5217\u5b9e\u73b0\u3002
        • \u56fe\u7684\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u662f\u4e00\u79cd\u4f18\u5148\u8d70\u5230\u5e95\u3001\u65e0\u8def\u53ef\u8d70\u65f6\u518d\u56de\u6eaf\u7684\u641c\u7d22\u65b9\u5f0f\uff0c\u5e38\u57fa\u4e8e\u9012\u5f52\u6765\u5b9e\u73b0\u3002
        "},{"location":"chapter_graph/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u8def\u5f84\u7684\u5b9a\u4e49\u662f\u9876\u70b9\u5e8f\u5217\u8fd8\u662f\u8fb9\u5e8f\u5217\uff1f

        \u7ef4\u57fa\u767e\u79d1\u4e0a\u4e0d\u540c\u8bed\u8a00\u7248\u672c\u7684\u5b9a\u4e49\u4e0d\u4e00\u81f4\uff1a\u82f1\u6587\u7248\u662f\u201c\u8def\u5f84\u662f\u4e00\u4e2a\u8fb9\u5e8f\u5217\u201d\uff0c\u800c\u4e2d\u6587\u7248\u662f\u201c\u8def\u5f84\u662f\u4e00\u4e2a\u9876\u70b9\u5e8f\u5217\u201d\u3002\u4ee5\u4e0b\u662f\u82f1\u6587\u7248\u539f\u6587\uff1aIn graph theory, a path in a graph is a finite or infinite sequence of edges which joins a sequence of vertices. \u5728\u672c\u6587\u4e2d\uff0c\u8def\u5f84\u88ab\u89c6\u4e3a\u4e00\u4e2a\u8fb9\u5e8f\u5217\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u9876\u70b9\u5e8f\u5217\u3002\u8fd9\u662f\u56e0\u4e3a\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u591a\u6761\u8fb9\u8fde\u63a5\uff0c\u6b64\u65f6\u6bcf\u6761\u8fb9\u90fd\u5bf9\u5e94\u4e00\u6761\u8def\u5f84\u3002

        \u975e\u8fde\u901a\u56fe\u4e2d\u662f\u5426\u4f1a\u6709\u65e0\u6cd5\u904d\u5386\u5230\u7684\u70b9\uff1f

        \u5728\u975e\u8fde\u901a\u56fe\u4e2d\uff0c\u4ece\u67d0\u4e2a\u9876\u70b9\u51fa\u53d1\uff0c\u81f3\u5c11\u6709\u4e00\u4e2a\u9876\u70b9\u65e0\u6cd5\u5230\u8fbe\u3002\u904d\u5386\u975e\u8fde\u901a\u56fe\u9700\u8981\u8bbe\u7f6e\u591a\u4e2a\u8d77\u70b9\uff0c\u4ee5\u904d\u5386\u5230\u56fe\u7684\u6240\u6709\u8fde\u901a\u5206\u91cf\u3002

        \u5728\u90bb\u63a5\u8868\u4e2d\uff0c\u201c\u4e0e\u8be5\u9876\u70b9\u76f8\u8fde\u7684\u6240\u6709\u9876\u70b9\u201d\u7684\u9876\u70b9\u987a\u5e8f\u662f\u5426\u6709\u8981\u6c42\uff1f

        \u53ef\u4ee5\u662f\u4efb\u610f\u987a\u5e8f\u3002\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u6309\u7167\u6307\u5b9a\u89c4\u5219\u6765\u6392\u5e8f\uff0c\u6bd4\u5982\u6309\u7167\u9876\u70b9\u6dfb\u52a0\u7684\u6b21\u5e8f\uff0c\u6216\u8005\u6309\u7167\u9876\u70b9\u503c\u5927\u5c0f\u7684\u987a\u5e8f\u7b49\uff0c\u8fd9\u6837\u6709\u52a9\u4e8e\u5feb\u901f\u67e5\u627e\u201c\u5e26\u6709\u67d0\u79cd\u6781\u503c\u201d\u7684\u9876\u70b9\u3002

        "},{"location":"chapter_greedy/","title":"\u7b2c 15 \u7ae0 \u00a0 \u8d2a\u5fc3","text":"

        Abstract

        \u5411\u65e5\u8475\u671d\u7740\u592a\u9633\u8f6c\u52a8\uff0c\u65f6\u523b\u8ffd\u6c42\u81ea\u8eab\u6210\u957f\u7684\u6700\u5927\u53ef\u80fd\u3002

        \u8d2a\u5fc3\u7b56\u7565\u5728\u4e00\u8f6e\u8f6e\u7684\u7b80\u5355\u9009\u62e9\u4e2d\uff0c\u9010\u6b65\u5bfc\u5411\u6700\u4f73\u7b54\u6848\u3002

        "},{"location":"chapter_greedy/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 15.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5
        • 15.2 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898
        • 15.3 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898
        • 15.4 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898
        • 15.5 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_greedy/fractional_knapsack_problem/","title":"15.2 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a \\(n\\) \u4e2a\u7269\u54c1\uff0c\u7b2c \\(i\\) \u4e2a\u7269\u54c1\u7684\u91cd\u91cf\u4e3a \\(wgt[i-1]\\)\u3001\u4ef7\u503c\u4e3a \\(val[i-1]\\) \uff0c\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3a \\(cap\\) \u7684\u80cc\u5305\u3002\u6bcf\u4e2a\u7269\u54c1\u53ea\u80fd\u9009\u62e9\u4e00\u6b21\uff0c\u4f46\u53ef\u4ee5\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\uff0c\u4ef7\u503c\u6839\u636e\u9009\u62e9\u7684\u91cd\u91cf\u6bd4\u4f8b\u8ba1\u7b97\uff0c\u95ee\u5728\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u80cc\u5305\u4e2d\u7269\u54c1\u7684\u6700\u5927\u4ef7\u503c\u3002\u793a\u4f8b\u5982\u56fe 15-3 \u6240\u793a\u3002

        \u56fe 15-3 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        \u5206\u6570\u80cc\u5305\u95ee\u9898\u548c 0-1 \u80cc\u5305\u95ee\u9898\u6574\u4f53\u4e0a\u975e\u5e38\u76f8\u4f3c\uff0c\u72b6\u6001\u5305\u542b\u5f53\u524d\u7269\u54c1 \\(i\\) \u548c\u5bb9\u91cf \\(c\\) \uff0c\u76ee\u6807\u662f\u6c42\u9650\u5b9a\u80cc\u5305\u5bb9\u91cf\u4e0b\u7684\u6700\u5927\u4ef7\u503c\u3002

        \u4e0d\u540c\u70b9\u5728\u4e8e\uff0c\u672c\u9898\u5141\u8bb8\u53ea\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\u3002\u5982\u56fe 15-4 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u7269\u54c1\u4efb\u610f\u5730\u8fdb\u884c\u5207\u5206\uff0c\u5e76\u6309\u7167\u91cd\u91cf\u6bd4\u4f8b\u6765\u8ba1\u7b97\u76f8\u5e94\u4ef7\u503c\u3002

        1. \u5bf9\u4e8e\u7269\u54c1 \\(i\\) \uff0c\u5b83\u5728\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u4ef7\u503c\u4e3a \\(val[i-1] / wgt[i-1]\\) \uff0c\u7b80\u79f0\u5355\u4f4d\u4ef7\u503c\u3002
        2. \u5047\u8bbe\u653e\u5165\u4e00\u90e8\u5206\u7269\u54c1 \\(i\\) \uff0c\u91cd\u91cf\u4e3a \\(w\\) \uff0c\u5219\u80cc\u5305\u589e\u52a0\u7684\u4ef7\u503c\u4e3a \\(w \\times val[i-1] / wgt[i-1]\\) \u3002

        \u56fe 15-4 \u00a0 \u7269\u54c1\u5728\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u4ef7\u503c

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u6700\u5927\u5316\u80cc\u5305\u5185\u7269\u54c1\u603b\u4ef7\u503c\uff0c\u672c\u8d28\u4e0a\u662f\u6700\u5927\u5316\u5355\u4f4d\u91cd\u91cf\u4e0b\u7684\u7269\u54c1\u4ef7\u503c\u3002\u7531\u6b64\u4fbf\u53ef\u63a8\u7406\u51fa\u56fe 15-5 \u6240\u793a\u7684\u8d2a\u5fc3\u7b56\u7565\u3002

        1. \u5c06\u7269\u54c1\u6309\u7167\u5355\u4f4d\u4ef7\u503c\u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\u3002
        2. \u904d\u5386\u6240\u6709\u7269\u54c1\uff0c\u6bcf\u8f6e\u8d2a\u5fc3\u5730\u9009\u62e9\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\u7684\u7269\u54c1\u3002
        3. \u82e5\u5269\u4f59\u80cc\u5305\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u4f7f\u7528\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u586b\u6ee1\u80cc\u5305\u3002

        \u56fe 15-5 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u8d2a\u5fc3\u7b56\u7565

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u6211\u4eec\u5efa\u7acb\u4e86\u4e00\u4e2a\u7269\u54c1\u7c7b Item \uff0c\u4ee5\u4fbf\u5c06\u7269\u54c1\u6309\u7167\u5355\u4f4d\u4ef7\u503c\u8fdb\u884c\u6392\u5e8f\u3002\u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u5f53\u80cc\u5305\u5df2\u6ee1\u65f6\u8df3\u51fa\u5e76\u8fd4\u56de\u89e3\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig fractional_knapsack.py
        class Item:\n\"\"\"\u7269\u54c1\"\"\"\ndef __init__(self, w: int, v: int):\nself.w = w  # \u7269\u54c1\u91cd\u91cf\nself.v = v  # \u7269\u54c1\u4ef7\u503c\ndef fractional_knapsack(wgt: list[int], val: list[int], cap: int) -> int:\n\"\"\"\u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3\"\"\"\n# \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nitems = [Item(w, v) for w, v in zip(wgt, val)]\n# \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort(key=lambda item: item.v / item.w, reverse=True)\n# \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nres = 0\nfor item in items:\nif item.w <= cap:\n# \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v\ncap -= item.w\nelse:\n# \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap\n# \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\nreturn res\n
        fractional_knapsack.cpp
        /* \u7269\u54c1 */\nclass Item {\npublic:\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\nItem(int w, int v) : w(w), v(v) {\n}\n};\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(vector<int> &wgt, vector<int> &val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nvector<Item> items;\nfor (int i = 0; i < wgt.size(); i++) {\nitems.push_back(Item(wgt[i], val[i]));\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nsort(items.begin(), items.end(), [](Item &a, Item &b) { return (double)a.v / a.w > (double)b.v / b.w; });\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (auto &item : items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double)item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.java
        /* \u7269\u54c1 */\nclass Item {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\npublic Item(int w, int v) {\nthis.w = w;\nthis.v = v;\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(int[] wgt, int[] val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem[] items = new Item[wgt.length];\nfor (int i = 0; i < wgt.length; i++) {\nitems[i] = new Item(wgt[i], val[i]);\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nArrays.sort(items, Comparator.comparingDouble(item -> -((double) item.v / item.w)));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (Item item : items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double) item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.cs
        /* \u7269\u54c1 */\nclass Item(int w, int v) {\npublic int w = w; // \u7269\u54c1\u91cd\u91cf\npublic int v = v; // \u7269\u54c1\u4ef7\u503c\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble FractionalKnapsack(int[] wgt, int[] val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem[] items = new Item[wgt.Length];\nfor (int i = 0; i < wgt.Length; i++) {\nitems[i] = new Item(wgt[i], val[i]);\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nArray.Sort(items, (x, y) => (y.v / y.w).CompareTo(x.v / x.w));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nforeach (Item item in items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (double)item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.go
        /* \u7269\u54c1 */\ntype Item struct {\nw int // \u7269\u54c1\u91cd\u91cf\nv int // \u7269\u54c1\u4ef7\u503c\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunc fractionalKnapsack(wgt []int, val []int, cap int) float64 {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nitems := make([]Item, len(wgt))\nfor i := 0; i < len(wgt); i++ {\nitems[i] = Item{wgt[i], val[i]}\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nsort.Slice(items, func(i, j int) bool {\nreturn float64(items[i].v)/float64(items[i].w) > float64(items[j].v)/float64(items[j].w)\n})\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nres := 0.0\nfor _, item := range items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += float64(item.v)\ncap -= item.w\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += float64(item.v) / float64(item.w) * float64(cap)\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\nreturn res\n}\n
        fractional_knapsack.swift
        /* \u7269\u54c1 */\nclass Item {\nvar w: Int // \u7269\u54c1\u91cd\u91cf\nvar v: Int // \u7269\u54c1\u4ef7\u503c\ninit(w: Int, v: Int) {\nself.w = w\nself.v = v\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunc fractionalKnapsack(wgt: [Int], val: [Int], cap: Int) -> Double {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nvar items = zip(wgt, val).map { Item(w: $0, v: $1) }\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort(by: { -(Double($0.v) / Double($0.w)) < -(Double($1.v) / Double($1.w)) })\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nvar res = 0.0\nvar cap = cap\nfor item in items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += Double(item.v)\ncap -= item.w\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += Double(item.v) / Double(item.w) * Double(cap)\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\nreturn res\n}\n
        fractional_knapsack.js
        /* \u7269\u54c1 */\nclass Item {\nconstructor(w, v) {\nthis.w = w; // \u7269\u54c1\u91cd\u91cf\nthis.v = v; // \u7269\u54c1\u4ef7\u503c\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunction fractionalKnapsack(wgt, val, cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nconst items = wgt.map((w, i) => new Item(w, val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => b.v / b.w - a.v / a.w);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet res = 0;\nfor (const item of items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.ts
        /* \u7269\u54c1 */\nclass Item {\nw: number; // \u7269\u54c1\u91cd\u91cf\nv: number; // \u7269\u54c1\u4ef7\u503c\nconstructor(w: number, v: number) {\nthis.w = w;\nthis.v = v;\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfunction fractionalKnapsack(wgt: number[], val: number[], cap: number): number {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nconst items: Item[] = wgt.map((w, i) => new Item(w, val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => b.v / b.w - a.v / a.w);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet res = 0;\nfor (const item of items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (item.v / item.w) * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.dart
        /* \u7269\u54c1 */\nclass Item {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\nItem(this.w, this.v);\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\ndouble fractionalKnapsack(List<int> wgt, List<int> val, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nList<Item> items = List.generate(wgt.length, (i) => Item(wgt[i], val[i]));\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort((a, b) => (b.v / b.w).compareTo(a.v / a.w));\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\ndouble res = 0;\nfor (Item item in items) {\nif (item.w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += item.v / item.w * cap;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nreturn res;\n}\n
        fractional_knapsack.rs
        /* \u7269\u54c1 */\nstruct Item {\nw: i32, // \u7269\u54c1\u91cd\u91cf\nv: i32, // \u7269\u54c1\u4ef7\u503c\n}\nimpl Item {\nfn new(w: i32, v: i32) -> Self {\nSelf { w, v }\n}\n}\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfn fractional_knapsack(wgt: &[i32], val: &[i32], mut cap: i32) -> f64 {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nlet mut items = wgt\n.iter()\n.zip(val.iter())\n.map(|(&w, &v)| Item::new(w, v))\n.collect::<Vec<Item>>();\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nitems.sort_by(|a, b| {\n(b.v as f64 / b.w as f64)\n.partial_cmp(&(a.v as f64 / a.w as f64))\n.unwrap()\n});\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nlet mut res = 0.0;\nfor item in &items {\nif item.w <= cap {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += item.v as f64;\ncap -= item.w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += item.v as f64 / item.w as f64 * cap as f64;\n// \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\nres\n}\n
        fractional_knapsack.c
        /* \u7269\u54c1 */\ntypedef struct {\nint w; // \u7269\u54c1\u91cd\u91cf\nint v; // \u7269\u54c1\u4ef7\u503c\n} Item;\n/* \u5206\u6570\u80cc\u5305\uff1a\u8d2a\u5fc3 */\nfloat fractionalKnapsack(int wgt[], int val[], int itemCount, int cap) {\n// \u521b\u5efa\u7269\u54c1\u5217\u8868\uff0c\u5305\u542b\u4e24\u4e2a\u5c5e\u6027\uff1a\u91cd\u91cf\u3001\u4ef7\u503c\nItem *items = malloc(sizeof(Item) * itemCount);\nfor (int i = 0; i < itemCount; i++) {\nitems[i] = (Item){.w = wgt[i], .v = val[i]};\n}\n// \u6309\u7167\u5355\u4f4d\u4ef7\u503c item.v / item.w \u4ece\u9ad8\u5230\u4f4e\u8fdb\u884c\u6392\u5e8f\nqsort(items, (size_t)itemCount, sizeof(Item), sortByValueDensity);\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\nfloat res = 0.0;\nfor (int i = 0; i < itemCount; i++) {\nif (items[i].w <= cap) {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\nres += items[i].v;\ncap -= items[i].w;\n} else {\n// \u82e5\u5269\u4f59\u5bb9\u91cf\u4e0d\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u7684\u4e00\u90e8\u5206\u88c5\u8fdb\u80cc\u5305\nres += (float)cap / items[i].w * items[i].v;\ncap = 0;\nbreak;\n}\n}\nfree(items);\nreturn res;\n}\n
        fractional_knapsack.zig
        [class]{Item}-[func]{}\n[class]{}-[func]{fractionalKnapsack}\n

        \u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u904d\u5386\u6574\u4e2a\u7269\u54c1\u5217\u8868\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u7269\u54c1\u6570\u91cf\u3002

        \u7531\u4e8e\u521d\u59cb\u5316\u4e86\u4e00\u4e2a Item \u5bf9\u8c61\u5217\u8868\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        "},{"location":"chapter_greedy/fractional_knapsack_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u91c7\u7528\u53cd\u8bc1\u6cd5\u3002\u5047\u8bbe\u7269\u54c1 \\(x\\) \u662f\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\u7684\u7269\u54c1\uff0c\u4f7f\u7528\u67d0\u7b97\u6cd5\u6c42\u5f97\u6700\u5927\u4ef7\u503c\u4e3a res \uff0c\u4f46\u8be5\u89e3\u4e2d\u4e0d\u5305\u542b\u7269\u54c1 \\(x\\) \u3002

        \u73b0\u5728\u4ece\u80cc\u5305\u4e2d\u62ff\u51fa\u5355\u4f4d\u91cd\u91cf\u7684\u4efb\u610f\u7269\u54c1\uff0c\u5e76\u66ff\u6362\u4e3a\u5355\u4f4d\u91cd\u91cf\u7684\u7269\u54c1 \\(x\\) \u3002\u7531\u4e8e\u7269\u54c1 \\(x\\) \u7684\u5355\u4f4d\u4ef7\u503c\u6700\u9ad8\uff0c\u56e0\u6b64\u66ff\u6362\u540e\u7684\u603b\u4ef7\u503c\u4e00\u5b9a\u5927\u4e8e res \u3002\u8fd9\u4e0e res \u662f\u6700\u4f18\u89e3\u77db\u76fe\uff0c\u8bf4\u660e\u6700\u4f18\u89e3\u4e2d\u5fc5\u987b\u5305\u542b\u7269\u54c1 \\(x\\) \u3002

        \u5bf9\u4e8e\u8be5\u89e3\u4e2d\u7684\u5176\u4ed6\u7269\u54c1\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u6784\u5efa\u51fa\u4e0a\u8ff0\u77db\u76fe\u3002\u603b\u800c\u8a00\u4e4b\uff0c\u5355\u4f4d\u4ef7\u503c\u66f4\u5927\u7684\u7269\u54c1\u603b\u662f\u66f4\u4f18\u9009\u62e9\uff0c\u8fd9\u8bf4\u660e\u8d2a\u5fc3\u7b56\u7565\u662f\u6709\u6548\u7684\u3002

        \u5982\u56fe 15-6 \u6240\u793a\uff0c\u5982\u679c\u5c06\u7269\u54c1\u91cd\u91cf\u548c\u7269\u54c1\u5355\u4f4d\u4ef7\u503c\u5206\u522b\u770b\u4f5c\u4e00\u5f20\u4e8c\u7ef4\u56fe\u8868\u7684\u6a2a\u8f74\u548c\u7eb5\u8f74\uff0c\u5219\u5206\u6570\u80cc\u5305\u95ee\u9898\u53ef\u8f6c\u5316\u4e3a\u201c\u6c42\u5728\u6709\u9650\u6a2a\u8f74\u533a\u95f4\u4e0b\u7684\u6700\u5927\u56f4\u6210\u9762\u79ef\u201d\u3002\u8fd9\u4e2a\u7c7b\u6bd4\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4ece\u51e0\u4f55\u89d2\u5ea6\u7406\u89e3\u8d2a\u5fc3\u7b56\u7565\u7684\u6709\u6548\u6027\u3002

        \u56fe 15-6 \u00a0 \u5206\u6570\u80cc\u5305\u95ee\u9898\u7684\u51e0\u4f55\u8868\u793a

        "},{"location":"chapter_greedy/greedy_algorithm/","title":"15.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5","text":"

        \u300c\u8d2a\u5fc3\u7b97\u6cd5 greedy algorithm\u300d\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u89e3\u51b3\u4f18\u5316\u95ee\u9898\u7684\u7b97\u6cd5\uff0c\u5176\u57fa\u672c\u601d\u60f3\u662f\u5728\u95ee\u9898\u7684\u6bcf\u4e2a\u51b3\u7b56\u9636\u6bb5\uff0c\u90fd\u9009\u62e9\u5f53\u524d\u770b\u8d77\u6765\u6700\u4f18\u7684\u9009\u62e9\uff0c\u5373\u8d2a\u5fc3\u5730\u505a\u51fa\u5c40\u90e8\u6700\u4f18\u7684\u51b3\u7b56\uff0c\u4ee5\u671f\u83b7\u5f97\u5168\u5c40\u6700\u4f18\u89e3\u3002\u8d2a\u5fc3\u7b97\u6cd5\u7b80\u6d01\u4e14\u9ad8\u6548\uff0c\u5728\u8bb8\u591a\u5b9e\u9645\u95ee\u9898\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002

        \u8d2a\u5fc3\u7b97\u6cd5\u548c\u52a8\u6001\u89c4\u5212\u90fd\u5e38\u7528\u4e8e\u89e3\u51b3\u4f18\u5316\u95ee\u9898\u3002\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u76f8\u4f3c\u4e4b\u5904\uff0c\u6bd4\u5982\u90fd\u4f9d\u8d56\u6700\u4f18\u5b50\u7ed3\u6784\u6027\u8d28\uff0c\u4f46\u5de5\u4f5c\u539f\u7406\u4e0d\u540c\u3002

        • \u52a8\u6001\u89c4\u5212\u4f1a\u6839\u636e\u4e4b\u524d\u9636\u6bb5\u7684\u6240\u6709\u51b3\u7b56\u6765\u8003\u8651\u5f53\u524d\u51b3\u7b56\uff0c\u5e76\u4f7f\u7528\u8fc7\u53bb\u5b50\u95ee\u9898\u7684\u89e3\u6765\u6784\u5efa\u5f53\u524d\u5b50\u95ee\u9898\u7684\u89e3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4f1a\u8003\u8651\u8fc7\u53bb\u7684\u51b3\u7b56\uff0c\u800c\u662f\u4e00\u8def\u5411\u524d\u5730\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u4e0d\u65ad\u7f29\u5c0f\u95ee\u9898\u8303\u56f4\uff0c\u76f4\u81f3\u95ee\u9898\u88ab\u89e3\u51b3\u3002

        \u6211\u4eec\u5148\u901a\u8fc7\u4f8b\u9898\u201c\u96f6\u94b1\u5151\u6362\u201d\u4e86\u89e3\u8d2a\u5fc3\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u3002\u8fd9\u9053\u9898\u5df2\u7ecf\u5728\u201c\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u201d\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u76f8\u4fe1\u4f60\u5bf9\u5b83\u5e76\u4e0d\u964c\u751f\u3002

        Question

        \u7ed9\u5b9a \\(n\\) \u79cd\u786c\u5e01\uff0c\u7b2c \\(i\\) \u79cd\u786c\u5e01\u7684\u9762\u503c\u4e3a \\(coins[i - 1]\\) \uff0c\u76ee\u6807\u91d1\u989d\u4e3a \\(amt\\) \uff0c\u6bcf\u79cd\u786c\u5e01\u53ef\u4ee5\u91cd\u590d\u9009\u53d6\uff0c\u95ee\u80fd\u591f\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u7684\u6700\u5c11\u786c\u5e01\u6570\u91cf\u3002\u5982\u679c\u65e0\u6cd5\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u5219\u8fd4\u56de \\(-1\\) \u3002

        \u672c\u9898\u91c7\u53d6\u7684\u8d2a\u5fc3\u7b56\u7565\u5982\u56fe 15-1 \u6240\u793a\u3002\u7ed9\u5b9a\u76ee\u6807\u91d1\u989d\uff0c\u6211\u4eec\u8d2a\u5fc3\u5730\u9009\u62e9\u4e0d\u5927\u4e8e\u4e14\u6700\u63a5\u8fd1\u5b83\u7684\u786c\u5e01\uff0c\u4e0d\u65ad\u5faa\u73af\u8be5\u6b65\u9aa4\uff0c\u76f4\u81f3\u51d1\u51fa\u76ee\u6807\u91d1\u989d\u4e3a\u6b62\u3002

        \u56fe 15-1 \u00a0 \u96f6\u94b1\u5151\u6362\u7684\u8d2a\u5fc3\u7b56\u7565

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\u3002\u4f60\u53ef\u80fd\u4f1a\u4e0d\u7531\u5730\u53d1\u51fa\u611f\u53f9\uff1aSo clean \uff01\u8d2a\u5fc3\u7b97\u6cd5\u4ec5\u7528\u7ea6\u5341\u884c\u4ee3\u7801\u5c31\u89e3\u51b3\u4e86\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig coin_change_greedy.py
        def coin_change_greedy(coins: list[int], amt: int) -> int:\n\"\"\"\u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3\"\"\"\n# \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\ni = len(coins) - 1\ncount = 0\n# \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0:\n# \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 and coins[i] > amt:\ni -= 1\n# \u9009\u62e9 coins[i]\namt -= coins[i]\ncount += 1\n# \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn count if amt == 0 else -1\n
        coin_change_greedy.cpp
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(vector<int> &coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.size() - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.java
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(int[] coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.cs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint CoinChangeGreedy(int[] coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.Length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.go
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunc coinChangeGreedy(coins []int, amt int) int {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\ni := len(coins) - 1\ncount := 0\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nfor amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nfor i > 0 && coins[i] > amt {\ni--\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i]\ncount++\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nif amt != 0 {\nreturn -1\n}\nreturn count\n}\n
        coin_change_greedy.swift
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunc coinChangeGreedy(coins: [Int], amt: Int) -> Int {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nvar i = coins.count - 1\nvar count = 0\nvar amt = amt\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 && coins[i] > amt {\ni -= 1\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i]\ncount += 1\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1\n}\n
        coin_change_greedy.js
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunction coinChangeGreedy(coins, amt) {\n// \u5047\u8bbe coins \u6570\u7ec4\u6709\u5e8f\nlet i = coins.length - 1;\nlet count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt === 0 ? count : -1;\n}\n
        coin_change_greedy.ts
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfunction coinChangeGreedy(coins: number[], amt: number): number {\n// \u5047\u8bbe coins \u6570\u7ec4\u6709\u5e8f\nlet i = coins.length - 1;\nlet count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt === 0 ? count : -1;\n}\n
        coin_change_greedy.dart
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(List<int> coins, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = coins.length - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.rs
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nfn coin_change_greedy(coins: &[i32], mut amt: i32) -> i32 {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nlet mut i = coins.len() - 1;\nlet mut count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile amt > 0 {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile i > 0 && coins[i] > amt {\ni -= 1;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount += 1;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nif amt == 0 {\ncount\n} else {\n-1\n}\n}\n
        coin_change_greedy.c
        /* \u96f6\u94b1\u5151\u6362\uff1a\u8d2a\u5fc3 */\nint coinChangeGreedy(int *coins, int size, int amt) {\n// \u5047\u8bbe coins \u5217\u8868\u6709\u5e8f\nint i = size - 1;\nint count = 0;\n// \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\nwhile (amt > 0) {\n// \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\nwhile (i > 0 && coins[i] > amt) {\ni--;\n}\n// \u9009\u62e9 coins[i]\namt -= coins[i];\ncount++;\n}\n// \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\nreturn amt == 0 ? count : -1;\n}\n
        coin_change_greedy.zig
        [class]{}-[func]{coinChangeGreedy}\n
        "},{"location":"chapter_greedy/greedy_algorithm/#1511","title":"15.1.1 \u00a0 \u8d2a\u5fc3\u7684\u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4ec5\u64cd\u4f5c\u76f4\u63a5\u3001\u5b9e\u73b0\u7b80\u5355\uff0c\u800c\u4e14\u901a\u5e38\u6548\u7387\u4e5f\u5f88\u9ad8\u3002\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u8bb0\u786c\u5e01\u6700\u5c0f\u9762\u503c\u4e3a \\(\\min(coins)\\) \uff0c\u5219\u8d2a\u5fc3\u9009\u62e9\u6700\u591a\u5faa\u73af \\(amt / \\min(coins)\\) \u6b21\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(amt / \\min(coins))\\) \u3002\u8fd9\u6bd4\u52a8\u6001\u89c4\u5212\u89e3\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\times amt)\\) \u63d0\u5347\u4e86\u4e00\u4e2a\u6570\u91cf\u7ea7\u3002

        \u7136\u800c\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u786c\u5e01\u9762\u503c\u7ec4\u5408\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u5e76\u4e0d\u80fd\u627e\u5230\u6700\u4f18\u89e3\u3002\u56fe 15-2 \u7ed9\u51fa\u4e86\u4e24\u4e2a\u793a\u4f8b\u3002

        • \u6b63\u4f8b \\(coins = [1, 5, 10, 20, 50, 100]\\)\uff1a\u5728\u8be5\u786c\u5e01\u7ec4\u5408\u4e0b\uff0c\u7ed9\u5b9a\u4efb\u610f \\(amt\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u90fd\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3\u3002
        • \u53cd\u4f8b \\(coins = [1, 20, 50]\\)\uff1a\u5047\u8bbe \\(amt = 60\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ea\u80fd\u627e\u5230 \\(50 + 1 \\times 10\\) \u7684\u5151\u6362\u7ec4\u5408\uff0c\u5171\u8ba1 \\(11\\) \u679a\u786c\u5e01\uff0c\u4f46\u52a8\u6001\u89c4\u5212\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3 \\(20 + 20 + 20\\) \uff0c\u4ec5\u9700 \\(3\\) \u679a\u786c\u5e01\u3002
        • \u53cd\u4f8b \\(coins = [1, 49, 50]\\)\uff1a\u5047\u8bbe \\(amt = 98\\) \uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ea\u80fd\u627e\u5230 \\(50 + 1 \\times 48\\) \u7684\u5151\u6362\u7ec4\u5408\uff0c\u5171\u8ba1 \\(49\\) \u679a\u786c\u5e01\uff0c\u4f46\u52a8\u6001\u89c4\u5212\u53ef\u4ee5\u627e\u5230\u6700\u4f18\u89e3 \\(49 + 49\\) \uff0c\u4ec5\u9700 \\(2\\) \u679a\u786c\u5e01\u3002

        \u56fe 15-2 \u00a0 \u8d2a\u5fc3\u65e0\u6cd5\u627e\u51fa\u6700\u4f18\u89e3\u7684\u793a\u4f8b

        \u4e5f\u5c31\u662f\u8bf4\uff0c\u5bf9\u4e8e\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u65e0\u6cd5\u4fdd\u8bc1\u627e\u5230\u5168\u5c40\u6700\u4f18\u89e3\uff0c\u5e76\u4e14\u6709\u53ef\u80fd\u627e\u5230\u975e\u5e38\u5dee\u7684\u89e3\u3002\u5b83\u66f4\u9002\u5408\u7528\u52a8\u6001\u89c4\u5212\u89e3\u51b3\u3002

        \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u9002\u7528\u60c5\u51b5\u5206\u4ee5\u4e0b\u4e24\u79cd\u3002

        1. \u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1a\u8d2a\u5fc3\u7b97\u6cd5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5f80\u5f80\u662f\u6700\u4f18\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u5f80\u5f80\u6bd4\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u66f4\u9ad8\u6548\u3002
        2. \u53ef\u4ee5\u627e\u5230\u8fd1\u4f3c\u6700\u4f18\u89e3\uff1a\u8d2a\u5fc3\u7b97\u6cd5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e5f\u662f\u53ef\u7528\u7684\u3002\u5bf9\u4e8e\u5f88\u591a\u590d\u6742\u95ee\u9898\u6765\u8bf4\uff0c\u5bfb\u627e\u5168\u5c40\u6700\u4f18\u89e3\u975e\u5e38\u56f0\u96be\uff0c\u80fd\u4ee5\u8f83\u9ad8\u6548\u7387\u627e\u5230\u6b21\u4f18\u89e3\u4e5f\u662f\u975e\u5e38\u4e0d\u9519\u7684\u3002
        "},{"location":"chapter_greedy/greedy_algorithm/#1512","title":"15.1.2 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\u7279\u6027","text":"

        \u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u4ec0\u4e48\u6837\u7684\u95ee\u9898\u9002\u5408\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u5462\uff1f\u6216\u8005\u8bf4\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1f

        \u76f8\u8f83\u4e8e\u52a8\u6001\u89c4\u5212\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u4f7f\u7528\u6761\u4ef6\u66f4\u52a0\u82db\u523b\uff0c\u5176\u4e3b\u8981\u5173\u6ce8\u95ee\u9898\u7684\u4e24\u4e2a\u6027\u8d28\u3002

        • \u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\uff1a\u53ea\u6709\u5f53\u5c40\u90e8\u6700\u4f18\u9009\u62e9\u59cb\u7ec8\u53ef\u4ee5\u5bfc\u81f4\u5168\u5c40\u6700\u4f18\u89e3\u65f6\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u624d\u80fd\u4fdd\u8bc1\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u6700\u4f18\u5b50\u7ed3\u6784\uff1a\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u5305\u542b\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u3002

        \u6700\u4f18\u5b50\u7ed3\u6784\u5df2\u7ecf\u5728\u201c\u52a8\u6001\u89c4\u5212\u201d\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u4e00\u4e9b\u95ee\u9898\u7684\u6700\u4f18\u5b50\u7ed3\u6784\u5e76\u4e0d\u660e\u663e\uff0c\u4f46\u4ecd\u7136\u53ef\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u89e3\u51b3\u3002

        \u6211\u4eec\u4e3b\u8981\u63a2\u7a76\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u7684\u5224\u65ad\u65b9\u6cd5\u3002\u867d\u7136\u5b83\u7684\u63cf\u8ff0\u770b\u4e0a\u53bb\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u5b9e\u9645\u4e0a\u5bf9\u4e8e\u8bb8\u591a\u95ee\u9898\uff0c\u8bc1\u660e\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u5e76\u975e\u6613\u4e8b\u3002

        \u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\uff0c\u6211\u4eec\u867d\u7136\u80fd\u591f\u5bb9\u6613\u5730\u4e3e\u51fa\u53cd\u4f8b\uff0c\u5bf9\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u8fdb\u884c\u8bc1\u4f2a\uff0c\u4f46\u8bc1\u5b9e\u7684\u96be\u5ea6\u8f83\u5927\u3002\u5982\u679c\u95ee\uff1a\u6ee1\u8db3\u4ec0\u4e48\u6761\u4ef6\u7684\u786c\u5e01\u7ec4\u5408\u53ef\u4ee5\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\uff1f\u6211\u4eec\u5f80\u5f80\u53ea\u80fd\u51ed\u501f\u76f4\u89c9\u6216\u4e3e\u4f8b\u5b50\u6765\u7ed9\u51fa\u4e00\u4e2a\u6a21\u68f1\u4e24\u53ef\u7684\u7b54\u6848\uff0c\u800c\u96be\u4ee5\u7ed9\u51fa\u4e25\u8c28\u7684\u6570\u5b66\u8bc1\u660e\u3002

        Quote

        \u6709\u4e00\u7bc7\u8bba\u6587\u7ed9\u51fa\u4e86\u4e00\u4e2a \\(O(n^3)\\) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7b97\u6cd5\uff0c\u7528\u4e8e\u5224\u65ad\u4e00\u4e2a\u786c\u5e01\u7ec4\u5408\u80fd\u5426\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u627e\u51fa\u4efb\u610f\u91d1\u989d\u7684\u6700\u4f18\u89e3\u3002

        Pearson, David. A polynomial-time algorithm for the change-making problem. Operations Research Letters 33.3 (2005): 231-234.

        "},{"location":"chapter_greedy/greedy_algorithm/#1513","title":"15.1.3 \u00a0 \u8d2a\u5fc3\u89e3\u9898\u6b65\u9aa4","text":"

        \u8d2a\u5fc3\u95ee\u9898\u7684\u89e3\u51b3\u6d41\u7a0b\u5927\u4f53\u53ef\u5206\u4e3a\u4ee5\u4e0b\u4e09\u6b65\u3002

        1. \u95ee\u9898\u5206\u6790\uff1a\u68b3\u7406\u4e0e\u7406\u89e3\u95ee\u9898\u7279\u6027\uff0c\u5305\u62ec\u72b6\u6001\u5b9a\u4e49\u3001\u4f18\u5316\u76ee\u6807\u548c\u7ea6\u675f\u6761\u4ef6\u7b49\u3002\u8fd9\u4e00\u6b65\u5728\u56de\u6eaf\u548c\u52a8\u6001\u89c4\u5212\u4e2d\u90fd\u6709\u6d89\u53ca\u3002
        2. \u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\uff1a\u786e\u5b9a\u5982\u4f55\u5728\u6bcf\u4e00\u6b65\u4e2d\u505a\u51fa\u8d2a\u5fc3\u9009\u62e9\u3002\u8fd9\u4e2a\u7b56\u7565\u80fd\u591f\u5728\u6bcf\u4e00\u6b65\u51cf\u5c0f\u95ee\u9898\u7684\u89c4\u6a21\uff0c\u5e76\u6700\u7ec8\u89e3\u51b3\u6574\u4e2a\u95ee\u9898\u3002
        3. \u6b63\u786e\u6027\u8bc1\u660e\uff1a\u901a\u5e38\u9700\u8981\u8bc1\u660e\u95ee\u9898\u5177\u6709\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u3002\u8fd9\u4e2a\u6b65\u9aa4\u53ef\u80fd\u9700\u8981\u7528\u5230\u6570\u5b66\u8bc1\u660e\uff0c\u4f8b\u5982\u5f52\u7eb3\u6cd5\u6216\u53cd\u8bc1\u6cd5\u7b49\u3002

        \u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u662f\u6c42\u89e3\u95ee\u9898\u7684\u6838\u5fc3\u6b65\u9aa4\uff0c\u4f46\u5b9e\u65bd\u8d77\u6765\u53ef\u80fd\u5e76\u4e0d\u5bb9\u6613\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u4e0d\u540c\u95ee\u9898\u7684\u8d2a\u5fc3\u7b56\u7565\u7684\u5dee\u5f02\u8f83\u5927\u3002\u5bf9\u4e8e\u8bb8\u591a\u95ee\u9898\u6765\u8bf4\uff0c\u8d2a\u5fc3\u7b56\u7565\u6bd4\u8f83\u6d45\u663e\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u4e9b\u5927\u6982\u7684\u601d\u8003\u4e0e\u5c1d\u8bd5\u5c31\u80fd\u5f97\u51fa\u3002\u800c\u5bf9\u4e8e\u4e00\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u8d2a\u5fc3\u7b56\u7565\u53ef\u80fd\u975e\u5e38\u9690\u853d\uff0c\u8fd9\u79cd\u60c5\u51b5\u5c31\u975e\u5e38\u8003\u9a8c\u4e2a\u4eba\u7684\u89e3\u9898\u7ecf\u9a8c\u4e0e\u7b97\u6cd5\u80fd\u529b\u4e86\u3002
        • \u67d0\u4e9b\u8d2a\u5fc3\u7b56\u7565\u5177\u6709\u8f83\u5f3a\u7684\u8ff7\u60d1\u6027\u3002\u5f53\u6211\u4eec\u6ee1\u6000\u4fe1\u5fc3\u8bbe\u8ba1\u597d\u8d2a\u5fc3\u7b56\u7565\uff0c\u5199\u51fa\u89e3\u9898\u4ee3\u7801\u5e76\u63d0\u4ea4\u8fd0\u884c\uff0c\u5f88\u53ef\u80fd\u53d1\u73b0\u90e8\u5206\u6d4b\u8bd5\u6837\u4f8b\u65e0\u6cd5\u901a\u8fc7\u3002\u8fd9\u662f\u56e0\u4e3a\u8bbe\u8ba1\u7684\u8d2a\u5fc3\u7b56\u7565\u53ea\u662f\u201c\u90e8\u5206\u6b63\u786e\u201d\u7684\uff0c\u4e0a\u6587\u4ecb\u7ecd\u7684\u96f6\u94b1\u5151\u6362\u5c31\u662f\u4e00\u4e2a\u5178\u578b\u6848\u4f8b\u3002

        \u4e3a\u4e86\u4fdd\u8bc1\u6b63\u786e\u6027\uff0c\u6211\u4eec\u5e94\u8be5\u5bf9\u8d2a\u5fc3\u7b56\u7565\u8fdb\u884c\u4e25\u8c28\u7684\u6570\u5b66\u8bc1\u660e\uff0c\u901a\u5e38\u9700\u8981\u7528\u5230\u53cd\u8bc1\u6cd5\u6216\u6570\u5b66\u5f52\u7eb3\u6cd5\u3002

        \u7136\u800c\uff0c\u6b63\u786e\u6027\u8bc1\u660e\u4e5f\u5f88\u53ef\u80fd\u4e0d\u662f\u4e00\u4ef6\u6613\u4e8b\u3002\u5982\u82e5\u6ca1\u6709\u5934\u7eea\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u9009\u62e9\u9762\u5411\u6d4b\u8bd5\u7528\u4f8b\u8fdb\u884c\u4ee3\u7801\u8c03\u8bd5\uff0c\u4e00\u6b65\u6b65\u4fee\u6539\u4e0e\u9a8c\u8bc1\u8d2a\u5fc3\u7b56\u7565\u3002

        "},{"location":"chapter_greedy/greedy_algorithm/#1514","title":"15.1.4 \u00a0 \u8d2a\u5fc3\u5178\u578b\u4f8b\u9898","text":"

        \u8d2a\u5fc3\u7b97\u6cd5\u5e38\u5e38\u5e94\u7528\u5728\u6ee1\u8db3\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u7684\u4f18\u5316\u95ee\u9898\u4e2d\uff0c\u4ee5\u4e0b\u5217\u4e3e\u4e86\u4e00\u4e9b\u5178\u578b\u7684\u8d2a\u5fc3\u7b97\u6cd5\u95ee\u9898\u3002

        • \u786c\u5e01\u627e\u96f6\u95ee\u9898\uff1a\u5728\u67d0\u4e9b\u786c\u5e01\u7ec4\u5408\u4e0b\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u603b\u662f\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u533a\u95f4\u8c03\u5ea6\u95ee\u9898\uff1a\u5047\u8bbe\u4f60\u6709\u4e00\u4e9b\u4efb\u52a1\uff0c\u6bcf\u4e2a\u4efb\u52a1\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u8fdb\u884c\uff0c\u4f60\u7684\u76ee\u6807\u662f\u5b8c\u6210\u5c3d\u53ef\u80fd\u591a\u7684\u4efb\u52a1\u3002\u5982\u679c\u6bcf\u6b21\u90fd\u9009\u62e9\u7ed3\u675f\u65f6\u95f4\u6700\u65e9\u7684\u4efb\u52a1\uff0c\u90a3\u4e48\u8d2a\u5fc3\u7b97\u6cd5\u5c31\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u5206\u6570\u80cc\u5305\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u7269\u54c1\u548c\u4e00\u4e2a\u8f7d\u91cd\u91cf\uff0c\u4f60\u7684\u76ee\u6807\u662f\u9009\u62e9\u4e00\u7ec4\u7269\u54c1\uff0c\u4f7f\u5f97\u603b\u91cd\u91cf\u4e0d\u8d85\u8fc7\u8f7d\u91cd\u91cf\uff0c\u4e14\u603b\u4ef7\u503c\u6700\u5927\u3002\u5982\u679c\u6bcf\u6b21\u90fd\u9009\u62e9\u6027\u4ef7\u6bd4\u6700\u9ad8\uff08\u4ef7\u503c / \u91cd\u91cf\uff09\u7684\u7269\u54c1\uff0c\u90a3\u4e48\u8d2a\u5fc3\u7b97\u6cd5\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u5f97\u5230\u6700\u4f18\u89e3\u3002
        • \u80a1\u7968\u4e70\u5356\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u80a1\u7968\u7684\u5386\u53f2\u4ef7\u683c\uff0c\u4f60\u53ef\u4ee5\u8fdb\u884c\u591a\u6b21\u4e70\u5356\uff0c\u4f46\u5982\u679c\u4f60\u5df2\u7ecf\u6301\u6709\u80a1\u7968\uff0c\u90a3\u4e48\u5728\u5356\u51fa\u4e4b\u524d\u4e0d\u80fd\u518d\u4e70\uff0c\u76ee\u6807\u662f\u83b7\u53d6\u6700\u5927\u5229\u6da6\u3002
        • \u970d\u592b\u66fc\u7f16\u7801\uff1a\u970d\u592b\u66fc\u7f16\u7801\u662f\u4e00\u79cd\u7528\u4e8e\u65e0\u635f\u6570\u636e\u538b\u7f29\u7684\u8d2a\u5fc3\u7b97\u6cd5\u3002\u901a\u8fc7\u6784\u5efa\u970d\u592b\u66fc\u6811\uff0c\u6bcf\u6b21\u9009\u62e9\u51fa\u73b0\u9891\u7387\u6700\u4f4e\u7684\u4e24\u4e2a\u8282\u70b9\u5408\u5e76\uff0c\u6700\u540e\u5f97\u5230\u7684\u970d\u592b\u66fc\u6811\u7684\u5e26\u6743\u8def\u5f84\u957f\u5ea6\uff08\u7f16\u7801\u957f\u5ea6\uff09\u6700\u5c0f\u3002
        • Dijkstra \u7b97\u6cd5\uff1a\u5b83\u662f\u4e00\u79cd\u89e3\u51b3\u7ed9\u5b9a\u6e90\u9876\u70b9\u5230\u5176\u4f59\u5404\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u95ee\u9898\u7684\u8d2a\u5fc3\u7b97\u6cd5\u3002
        "},{"location":"chapter_greedy/max_capacity_problem/","title":"15.3 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898","text":"

        Question

        \u8f93\u5165\u4e00\u4e2a\u6570\u7ec4 \\(ht\\) \uff0c\u5176\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e00\u4e2a\u5782\u76f4\u9694\u677f\u7684\u9ad8\u5ea6\u3002\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e24\u4e2a\u9694\u677f\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u7a7a\u95f4\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u5bb9\u5668\u3002

        \u5bb9\u5668\u7684\u5bb9\u91cf\u7b49\u4e8e\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u7684\u4e58\u79ef\uff08\u9762\u79ef\uff09\uff0c\u5176\u4e2d\u9ad8\u5ea6\u7531\u8f83\u77ed\u7684\u9694\u677f\u51b3\u5b9a\uff0c\u5bbd\u5ea6\u662f\u4e24\u4e2a\u9694\u677f\u7684\u6570\u7ec4\u7d22\u5f15\u4e4b\u5dee\u3002

        \u8bf7\u5728\u6570\u7ec4\u4e2d\u9009\u62e9\u4e24\u4e2a\u9694\u677f\uff0c\u4f7f\u5f97\u7ec4\u6210\u7684\u5bb9\u5668\u7684\u5bb9\u91cf\u6700\u5927\uff0c\u8fd4\u56de\u6700\u5927\u5bb9\u91cf\u3002\u793a\u4f8b\u5982\u56fe 15-7 \u6240\u793a\u3002

        \u56fe 15-7 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u7684\u793a\u4f8b\u6570\u636e

        \u5bb9\u5668\u7531\u4efb\u610f\u4e24\u4e2a\u9694\u677f\u56f4\u6210\uff0c\u56e0\u6b64\u672c\u9898\u7684\u72b6\u6001\u4e3a\u4e24\u4e2a\u9694\u677f\u7684\u7d22\u5f15\uff0c\u8bb0\u4e3a \\([i, j]\\) \u3002

        \u6839\u636e\u9898\u610f\uff0c\u5bb9\u91cf\u7b49\u4e8e\u9ad8\u5ea6\u4e58\u4ee5\u5bbd\u5ea6\uff0c\u5176\u4e2d\u9ad8\u5ea6\u7531\u77ed\u677f\u51b3\u5b9a\uff0c\u5bbd\u5ea6\u662f\u4e24\u9694\u677f\u7684\u6570\u7ec4\u7d22\u5f15\u4e4b\u5dee\u3002\u8bbe\u5bb9\u91cf\u4e3a \\(cap[i, j]\\) \uff0c\u5219\u53ef\u5f97\u8ba1\u7b97\u516c\u5f0f\uff1a

        \\[ cap[i, j] = \\min(ht[i], ht[j]) \\times (j - i) \\]

        \u8bbe\u6570\u7ec4\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u4e24\u4e2a\u9694\u677f\u7684\u7ec4\u5408\u6570\u91cf\uff08\u72b6\u6001\u603b\u6570\uff09\u4e3a \\(C_n^2 = \\frac{n(n - 1)}{2}\\) \u4e2a\u3002\u6700\u76f4\u63a5\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u7a77\u4e3e\u6240\u6709\u72b6\u6001\uff0c\u4ece\u800c\u6c42\u5f97\u6700\u5927\u5bb9\u91cf\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_greedy/max_capacity_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u8fd9\u9053\u9898\u8fd8\u6709\u66f4\u9ad8\u6548\u7387\u7684\u89e3\u6cd5\u3002\u5982\u56fe 15-8 \u6240\u793a\uff0c\u73b0\u9009\u53d6\u4e00\u4e2a\u72b6\u6001 \\([i, j]\\) \uff0c\u5176\u6ee1\u8db3\u7d22\u5f15 \\(i < j\\) \u4e14\u9ad8\u5ea6 \\(ht[i] < ht[j]\\) \uff0c\u5373 \\(i\\) \u4e3a\u77ed\u677f\u3001\\(j\\) \u4e3a\u957f\u677f\u3002

        \u56fe 15-8 \u00a0 \u521d\u59cb\u72b6\u6001

        \u5982\u56fe 15-9 \u6240\u793a\uff0c\u82e5\u6b64\u65f6\u5c06\u957f\u677f \\(j\\) \u5411\u77ed\u677f \\(i\\) \u9760\u8fd1\uff0c\u5219\u5bb9\u91cf\u4e00\u5b9a\u53d8\u5c0f\u3002

        \u8fd9\u662f\u56e0\u4e3a\u5728\u79fb\u52a8\u957f\u677f \\(j\\) \u540e\uff0c\u5bbd\u5ea6 \\(j-i\\) \u80af\u5b9a\u53d8\u5c0f\uff1b\u800c\u9ad8\u5ea6\u7531\u77ed\u677f\u51b3\u5b9a\uff0c\u56e0\u6b64\u9ad8\u5ea6\u53ea\u53ef\u80fd\u4e0d\u53d8\uff08 \\(i\\) \u4ecd\u4e3a\u77ed\u677f\uff09\u6216\u53d8\u5c0f\uff08\u79fb\u52a8\u540e\u7684 \\(j\\) \u6210\u4e3a\u77ed\u677f\uff09\u3002

        \u56fe 15-9 \u00a0 \u5411\u5185\u79fb\u52a8\u957f\u677f\u540e\u7684\u72b6\u6001

        \u53cd\u5411\u601d\u8003\uff0c\u6211\u4eec\u53ea\u6709\u5411\u5185\u6536\u7f29\u77ed\u677f \\(i\\) \uff0c\u624d\u6709\u53ef\u80fd\u4f7f\u5bb9\u91cf\u53d8\u5927\u3002\u56e0\u4e3a\u867d\u7136\u5bbd\u5ea6\u4e00\u5b9a\u53d8\u5c0f\uff0c\u4f46\u9ad8\u5ea6\u53ef\u80fd\u4f1a\u53d8\u5927\uff08\u79fb\u52a8\u540e\u7684\u77ed\u677f \\(i\\) \u53ef\u80fd\u4f1a\u53d8\u957f\uff09\u3002\u4f8b\u5982\u5728\u56fe 15-10 \u4e2d\uff0c\u79fb\u52a8\u77ed\u677f\u540e\u9762\u79ef\u53d8\u5927\u3002

        \u56fe 15-10 \u00a0 \u5411\u5185\u79fb\u52a8\u77ed\u677f\u540e\u7684\u72b6\u6001

        \u7531\u6b64\u4fbf\u53ef\u63a8\u51fa\u672c\u9898\u7684\u8d2a\u5fc3\u7b56\u7565\uff1a\u521d\u59cb\u5316\u4e24\u6307\u9488\u5206\u5217\u5bb9\u5668\u4e24\u7aef\uff0c\u6bcf\u8f6e\u5411\u5185\u6536\u7f29\u77ed\u677f\u5bf9\u5e94\u7684\u6307\u9488\uff0c\u76f4\u81f3\u4e24\u6307\u9488\u76f8\u9047\u3002

        \u56fe 15-11 \u5c55\u793a\u4e86\u8d2a\u5fc3\u7b56\u7565\u7684\u6267\u884c\u8fc7\u7a0b\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5206\u5217\u4e0e\u6570\u7ec4\u4e24\u7aef\u3002
        2. \u8ba1\u7b97\u5f53\u524d\u72b6\u6001\u7684\u5bb9\u91cf \\(cap[i, j]\\) \uff0c\u5e76\u66f4\u65b0\u6700\u5927\u5bb9\u91cf\u3002
        3. \u6bd4\u8f83\u677f \\(i\\) \u548c \u677f \\(j\\) \u7684\u9ad8\u5ea6\uff0c\u5e76\u5c06\u77ed\u677f\u5411\u5185\u79fb\u52a8\u4e00\u683c\u3002
        4. \u5faa\u73af\u6267\u884c\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\uff0c\u76f4\u81f3 \\(i\\) \u548c \\(j\\) \u76f8\u9047\u65f6\u7ed3\u675f\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 15-11 \u00a0 \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u7684\u8d2a\u5fc3\u8fc7\u7a0b

        "},{"location":"chapter_greedy/max_capacity_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u4ee3\u7801\u5faa\u73af\u6700\u591a \\(n\\) \u8f6e\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002

        \u53d8\u91cf \\(i\\)\u3001\\(j\\)\u3001\\(res\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig max_capacity.py
        def max_capacity(ht: list[int]) -> int:\n\"\"\"\u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3\"\"\"\n# \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\ni, j = 0, len(ht) - 1\n# \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nres = 0\n# \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j:\n# \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\ncap = min(ht[i], ht[j]) * (j - i)\nres = max(res, cap)\n# \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j]:\ni += 1\nelse:\nj -= 1\nreturn res\n
        max_capacity.cpp
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(vector<int> &ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.size() - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = min(ht[i], ht[j]) * (j - i);\nres = max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.java
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int[] ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.cs
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint MaxCapacity(int[] ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.Length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = Math.Min(ht[i], ht[j]) * (j - i);\nres = Math.Max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.go
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht []int) int {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\ni, j := 0, len(ht)-1\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nres := 0\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nfor i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\ncapacity := int(math.Min(float64(ht[i]), float64(ht[j]))) * (j - i)\nres = int(math.Max(float64(res), float64(capacity)))\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni++\n} else {\nj--\n}\n}\nreturn res\n}\n
        max_capacity.swift
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht: [Int]) -> Int {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nvar i = 0, j = ht.count - 1\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nvar res = 0\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nlet cap = min(ht[i], ht[j]) * (j - i)\nres = max(res, cap)\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni += 1\n} else {\nj -= 1\n}\n}\nreturn res\n}\n
        max_capacity.js
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet i = 0,\nj = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nconst cap = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni += 1;\n} else {\nj -= 1;\n}\n}\nreturn res;\n}\n
        max_capacity.ts
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht: number[]): number {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet i = 0,\nj = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nconst cap: number = Math.min(ht[i], ht[j]) * (j - i);\nres = Math.max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni += 1;\n} else {\nj -= 1;\n}\n}\nreturn res;\n}\n
        max_capacity.dart
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(List<int> ht) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0, j = ht.length - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint cap = min(ht[i], ht[j]) * (j - i);\nres = max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.rs
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfn max_capacity(ht: &[i32]) -> i32 {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nlet mut i = 0;\nlet mut j = ht.len() - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nlet mut res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile i < j {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nlet cap = std::cmp::min(ht[i], ht[j]) * (j - i) as i32;\nres = std::cmp::max(res, cap);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif ht[i] < ht[j] {\ni += 1;\n} else {\nj -= 1;\n}\n}\nres\n}\n
        max_capacity.c
        /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int ht[], int htLength) {\n// \u521d\u59cb\u5316 i, j \u5206\u5217\u6570\u7ec4\u4e24\u7aef\nint i = 0;\nint j = htLength - 1;\n// \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\nint res = 0;\n// \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\nwhile (i < j) {\n// \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\nint capacity = myMin(ht[i], ht[j]) * (j - i);\nres = myMax(res, capacity);\n// \u5411\u5185\u79fb\u52a8\u77ed\u677f\nif (ht[i] < ht[j]) {\ni++;\n} else {\nj--;\n}\n}\nreturn res;\n}\n
        max_capacity.zig
        [class]{}-[func]{maxCapacity}\n
        "},{"location":"chapter_greedy/max_capacity_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u4e4b\u6240\u4ee5\u8d2a\u5fc3\u6bd4\u7a77\u4e3e\u66f4\u5feb\uff0c\u662f\u56e0\u4e3a\u6bcf\u8f6e\u7684\u8d2a\u5fc3\u9009\u62e9\u90fd\u4f1a\u201c\u8df3\u8fc7\u201d\u4e00\u4e9b\u72b6\u6001\u3002

        \u6bd4\u5982\u5728\u72b6\u6001 \\(cap[i, j]\\) \u4e0b\uff0c\\(i\\) \u4e3a\u77ed\u677f\u3001\\(j\\) \u4e3a\u957f\u677f\u3002\u82e5\u8d2a\u5fc3\u5730\u5c06\u77ed\u677f \\(i\\) \u5411\u5185\u79fb\u52a8\u4e00\u683c\uff0c\u4f1a\u5bfc\u81f4\u56fe 15-12 \u6240\u793a\u7684\u72b6\u6001\u88ab\u201c\u8df3\u8fc7\u201d\u3002\u8fd9\u610f\u5473\u7740\u4e4b\u540e\u65e0\u6cd5\u9a8c\u8bc1\u8fd9\u4e9b\u72b6\u6001\u7684\u5bb9\u91cf\u5927\u5c0f\u3002

        \\[ cap[i, i+1], cap[i, i+2], \\dots, cap[i, j-2], cap[i, j-1] \\]

        \u56fe 15-12 \u00a0 \u79fb\u52a8\u77ed\u677f\u5bfc\u81f4\u88ab\u8df3\u8fc7\u7684\u72b6\u6001

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u8fd9\u4e9b\u88ab\u8df3\u8fc7\u7684\u72b6\u6001\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u957f\u677f \\(j\\) \u5411\u5185\u79fb\u52a8\u7684\u6240\u6709\u72b6\u6001\u3002\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u8bc1\u660e\u5185\u79fb\u957f\u677f\u4e00\u5b9a\u4f1a\u5bfc\u81f4\u5bb9\u91cf\u53d8\u5c0f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u88ab\u8df3\u8fc7\u7684\u72b6\u6001\u90fd\u4e0d\u53ef\u80fd\u662f\u6700\u4f18\u89e3\uff0c\u8df3\u8fc7\u5b83\u4eec\u4e0d\u4f1a\u5bfc\u81f4\u9519\u8fc7\u6700\u4f18\u89e3\u3002

        \u4ee5\u4e0a\u5206\u6790\u8bf4\u660e\uff0c\u79fb\u52a8\u77ed\u677f\u7684\u64cd\u4f5c\u662f\u201c\u5b89\u5168\u201d\u7684\uff0c\u8d2a\u5fc3\u7b56\u7565\u662f\u6709\u6548\u7684\u3002

        "},{"location":"chapter_greedy/max_product_cutting_problem/","title":"15.4 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6b63\u6574\u6570 \\(n\\) \uff0c\u5c06\u5176\u5207\u5206\u4e3a\u81f3\u5c11\u4e24\u4e2a\u6b63\u6574\u6570\u7684\u548c\uff0c\u6c42\u5207\u5206\u540e\u6240\u6709\u6574\u6570\u7684\u4e58\u79ef\u6700\u5927\u662f\u591a\u5c11\uff0c\u5982\u56fe 15-13 \u6240\u793a\u3002

        \u56fe 15-13 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u7684\u95ee\u9898\u5b9a\u4e49

        \u5047\u8bbe\u6211\u4eec\u5c06 \\(n\\) \u5207\u5206\u4e3a \\(m\\) \u4e2a\u6574\u6570\u56e0\u5b50\uff0c\u5176\u4e2d\u7b2c \\(i\\) \u4e2a\u56e0\u5b50\u8bb0\u4e3a \\(n_i\\) \uff0c\u5373

        \\[ n = \\sum_{i=1}^{m}n_i \\]

        \u672c\u9898\u7684\u76ee\u6807\u662f\u6c42\u5f97\u6240\u6709\u6574\u6570\u56e0\u5b50\u7684\u6700\u5927\u4e58\u79ef\uff0c\u5373

        \\[ \\max(\\prod_{i=1}^{m}n_i) \\]

        \u6211\u4eec\u9700\u8981\u601d\u8003\u7684\u662f\uff1a\u5207\u5206\u6570\u91cf \\(m\\) \u5e94\u8be5\u591a\u5927\uff0c\u6bcf\u4e2a \\(n_i\\) \u5e94\u8be5\u662f\u591a\u5c11\uff1f

        "},{"location":"chapter_greedy/max_product_cutting_problem/#1","title":"1. \u00a0 \u8d2a\u5fc3\u7b56\u7565\u786e\u5b9a","text":"

        \u6839\u636e\u7ecf\u9a8c\uff0c\u4e24\u4e2a\u6574\u6570\u7684\u4e58\u79ef\u5f80\u5f80\u6bd4\u5b83\u4eec\u7684\u52a0\u548c\u66f4\u5927\u3002\u5047\u8bbe\u4ece \\(n\\) \u4e2d\u5206\u51fa\u4e00\u4e2a\u56e0\u5b50 \\(2\\) \uff0c\u5219\u5b83\u4eec\u7684\u4e58\u79ef\u4e3a \\(2(n-2)\\) \u3002\u6211\u4eec\u5c06\u8be5\u4e58\u79ef\u4e0e \\(n\\) \u4f5c\u6bd4\u8f83\uff1a

        \\[ \\begin{aligned} 2(n-2) & \\geq n \\newline 2n - n - 4 & \\geq 0 \\newline n & \\geq 4 \\end{aligned} \\]

        \u5982\u56fe 15-14 \u6240\u793a\uff0c\u5f53 \\(n \\geq 4\\) \u65f6\uff0c\u5207\u5206\u51fa\u4e00\u4e2a \\(2\\) \u540e\u4e58\u79ef\u4f1a\u53d8\u5927\uff0c\u8fd9\u8bf4\u660e\u5927\u4e8e\u7b49\u4e8e \\(4\\) \u7684\u6574\u6570\u90fd\u5e94\u8be5\u88ab\u5207\u5206\u3002

        \u8d2a\u5fc3\u7b56\u7565\u4e00\uff1a\u5982\u679c\u5207\u5206\u65b9\u6848\u4e2d\u5305\u542b \\(\\geq 4\\) \u7684\u56e0\u5b50\uff0c\u90a3\u4e48\u5b83\u5c31\u5e94\u8be5\u88ab\u7ee7\u7eed\u5207\u5206\u3002\u6700\u7ec8\u7684\u5207\u5206\u65b9\u6848\u53ea\u5e94\u51fa\u73b0 \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u8fd9\u4e09\u79cd\u56e0\u5b50\u3002

        \u56fe 15-14 \u00a0 \u5207\u5206\u5bfc\u81f4\u4e58\u79ef\u53d8\u5927

        \u63a5\u4e0b\u6765\u601d\u8003\u54ea\u4e2a\u56e0\u5b50\u662f\u6700\u4f18\u7684\u3002\u5728 \\(1\\)\u3001\\(2\\)\u3001\\(3\\) \u8fd9\u4e09\u4e2a\u56e0\u5b50\u4e2d\uff0c\u663e\u7136 \\(1\\) \u662f\u6700\u5dee\u7684\uff0c\u56e0\u4e3a \\(1 \\times (n-1) < n\\) \u6052\u6210\u7acb\uff0c\u5373\u5207\u5206\u51fa \\(1\\) \u53cd\u800c\u4f1a\u5bfc\u81f4\u4e58\u79ef\u51cf\u5c0f\u3002

        \u5982\u56fe 15-15 \u6240\u793a\uff0c\u5f53 \\(n = 6\\) \u65f6\uff0c\u6709 \\(3 \\times 3 > 2 \\times 2 \\times 2\\) \u3002\u8fd9\u610f\u5473\u7740\u5207\u5206\u51fa \\(3\\) \u6bd4\u5207\u5206\u51fa \\(2\\) \u66f4\u4f18\u3002

        \u8d2a\u5fc3\u7b56\u7565\u4e8c\uff1a\u5728\u5207\u5206\u65b9\u6848\u4e2d\uff0c\u6700\u591a\u53ea\u5e94\u5b58\u5728\u4e24\u4e2a \\(2\\) \u3002\u56e0\u4e3a\u4e09\u4e2a \\(2\\) \u603b\u662f\u53ef\u4ee5\u66ff\u6362\u4e3a\u4e24\u4e2a \\(3\\) \uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002

        \u56fe 15-15 \u00a0 \u6700\u4f18\u5207\u5206\u56e0\u5b50

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u53ef\u63a8\u7406\u51fa\u4ee5\u4e0b\u8d2a\u5fc3\u7b56\u7565\u3002

        1. \u8f93\u5165\u6574\u6570 \\(n\\) \uff0c\u4ece\u5176\u4e0d\u65ad\u5730\u5207\u5206\u51fa\u56e0\u5b50 \\(3\\) \uff0c\u76f4\u81f3\u4f59\u6570\u4e3a \\(0\\)\u3001\\(1\\)\u3001\\(2\\) \u3002
        2. \u5f53\u4f59\u6570\u4e3a \\(0\\) \u65f6\uff0c\u4ee3\u8868 \\(n\\) \u662f \\(3\\) \u7684\u500d\u6570\uff0c\u56e0\u6b64\u4e0d\u505a\u4efb\u4f55\u5904\u7406\u3002
        3. \u5f53\u4f59\u6570\u4e3a \\(2\\) \u65f6\uff0c\u4e0d\u7ee7\u7eed\u5212\u5206\uff0c\u4fdd\u7559\u4e4b\u3002
        4. \u5f53\u4f59\u6570\u4e3a \\(1\\) \u65f6\uff0c\u7531\u4e8e \\(2 \\times 2 > 1 \\times 3\\) \uff0c\u56e0\u6b64\u5e94\u5c06\u6700\u540e\u4e00\u4e2a \\(3\\) \u66ff\u6362\u4e3a \\(2\\) \u3002
        "},{"location":"chapter_greedy/max_product_cutting_problem/#2","title":"2. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5982\u56fe 15-16 \u6240\u793a\uff0c\u6211\u4eec\u65e0\u987b\u901a\u8fc7\u5faa\u73af\u6765\u5207\u5206\u6574\u6570\uff0c\u800c\u53ef\u4ee5\u5229\u7528\u5411\u4e0b\u6574\u9664\u8fd0\u7b97\u5f97\u5230 \\(3\\) \u7684\u4e2a\u6570 \\(a\\) \uff0c\u7528\u53d6\u6a21\u8fd0\u7b97\u5f97\u5230\u4f59\u6570 \\(b\\) \uff0c\u6b64\u65f6\u6709\uff1a

        \\[ n = 3 a + b \\]

        \u8bf7\u6ce8\u610f\uff0c\u5bf9\u4e8e \\(n \\leq 3\\) \u7684\u8fb9\u754c\u60c5\u51b5\uff0c\u5fc5\u987b\u62c6\u5206\u51fa\u4e00\u4e2a \\(1\\) \uff0c\u4e58\u79ef\u4e3a \\(1 \\times (n - 1)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig max_product_cutting.py
        def max_product_cutting(n: int) -> int:\n\"\"\"\u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3\"\"\"\n# \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3:\nreturn 1 * (n - 1)\n# \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\na, b = n // 3, n % 3\nif b == 1:\n# \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn int(math.pow(3, a - 1)) * 2 * 2\nif b == 2:\n# \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.pow(3, a)) * 2\n# \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.pow(3, a))\n
        max_product_cutting.cpp
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int)pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)pow(3, a);\n}\n
        max_product_cutting.java
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int) Math.pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int) Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int) Math.pow(3, a);\n}\n
        max_product_cutting.cs
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint MaxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (int)Math.Pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)Math.Pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (int)Math.Pow(3, a);\n}\n
        max_product_cutting.go
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunc maxProductCutting(n int) int {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1)\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\na := n / 3\nb := n % 3\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn int(math.Pow(3, float64(a-1))) * 2 * 2\n}\nif b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.Pow(3, float64(a))) * 2\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn int(math.Pow(3, float64(a)))\n}\n
        max_product_cutting.swift
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunc maxProductCutting(n: Int) -> Int {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1)\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = n / 3\nlet b = n % 3\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn pow(3, a - 1) * 2 * 2\n}\nif b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a) * 2\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a)\n}\n
        max_product_cutting.js
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunction maxProductCutting(n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = Math.floor(n / 3);\nlet b = n % 3;\nif (b === 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn Math.pow(3, a - 1) * 2 * 2;\n}\nif (b === 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a);\n}\n
        max_product_cutting.ts
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfunction maxProductCutting(n: number): number {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a: number = Math.floor(n / 3);\nlet b: number = n % 3;\nif (b === 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn Math.pow(3, a - 1) * 2 * 2;\n}\nif (b === 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn Math.pow(3, a);\n}\n
        max_product_cutting.dart
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n ~/ 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn (pow(3, a - 1) * 2 * 2).toInt();\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn (pow(3, a) * 2).toInt();\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a).toInt();\n}\n
        max_product_cutting.rs
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nfn max_product_cutting(n: i32) -> i32 {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif n <= 3 {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nlet a = n / 3;\nlet b = n % 3;\nif b == 1 {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n3_i32.pow(a as u32 - 1) * 2 * 2\n} else if b == 2 {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n3_i32.pow(a as u32) * 2\n} else {\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n3_i32.pow(a as u32)\n}\n}\n
        max_product_cutting.c
        /* \u6700\u5927\u5207\u5206\u4e58\u79ef\uff1a\u8d2a\u5fc3 */\nint maxProductCutting(int n) {\n// \u5f53 n <= 3 \u65f6\uff0c\u5fc5\u987b\u5207\u5206\u51fa\u4e00\u4e2a 1\nif (n <= 3) {\nreturn 1 * (n - 1);\n}\n// \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\nint a = n / 3;\nint b = n % 3;\nif (b == 1) {\n// \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\nreturn pow(3, a - 1) * 2 * 2;\n}\nif (b == 2) {\n// \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a) * 2;\n}\n// \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\nreturn pow(3, a);\n}\n
        max_product_cutting.zig
        [class]{}-[func]{maxProductCutting}\n

        \u56fe 15-16 \u00a0 \u6700\u5927\u5207\u5206\u4e58\u79ef\u7684\u8ba1\u7b97\u65b9\u6cd5

        \u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u5e42\u8fd0\u7b97\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002\u4ee5 Python \u4e3a\u4f8b\uff0c\u5e38\u7528\u7684\u5e42\u8ba1\u7b97\u51fd\u6570\u6709\u4e09\u79cd\u3002

        • \u8fd0\u7b97\u7b26 ** \u548c\u51fd\u6570 pow() \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log\u2061 a)\\) \u3002
        • \u51fd\u6570 math.pow() \u5185\u90e8\u8c03\u7528 C \u8bed\u8a00\u5e93\u7684 pow() \u51fd\u6570\uff0c\u5176\u6267\u884c\u6d6e\u70b9\u53d6\u5e42\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        \u53d8\u91cf \\(a\\) \u548c \\(b\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002

        "},{"location":"chapter_greedy/max_product_cutting_problem/#3","title":"3. \u00a0 \u6b63\u786e\u6027\u8bc1\u660e","text":"

        \u4f7f\u7528\u53cd\u8bc1\u6cd5\uff0c\u53ea\u5206\u6790 \\(n \\geq 3\\) \u7684\u60c5\u51b5\u3002

        1. \u6240\u6709\u56e0\u5b50 \\(\\leq 3\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5b58\u5728 \\(\\geq 4\\) \u7684\u56e0\u5b50 \\(x\\) \uff0c\u90a3\u4e48\u4e00\u5b9a\u53ef\u4ee5\u5c06\u5176\u7ee7\u7eed\u5212\u5206\u4e3a \\(2(x-2)\\) \uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        2. \u5207\u5206\u65b9\u6848\u4e0d\u5305\u542b \\(1\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5b58\u5728\u4e00\u4e2a\u56e0\u5b50 \\(1\\) \uff0c\u90a3\u4e48\u5b83\u4e00\u5b9a\u53ef\u4ee5\u5408\u5e76\u5165\u53e6\u5916\u4e00\u4e2a\u56e0\u5b50\u4e2d\uff0c\u4ee5\u83b7\u5f97\u66f4\u5927\u7684\u4e58\u79ef\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        3. \u5207\u5206\u65b9\u6848\u6700\u591a\u5305\u542b\u4e24\u4e2a \\(2\\) \uff1a\u5047\u8bbe\u6700\u4f18\u5207\u5206\u65b9\u6848\u4e2d\u5305\u542b\u4e09\u4e2a \\(2\\) \uff0c\u90a3\u4e48\u4e00\u5b9a\u53ef\u4ee5\u66ff\u6362\u4e3a\u4e24\u4e2a \\(3\\) \uff0c\u4e58\u79ef\u66f4\u5927\u3002\u8fd9\u4e0e\u5047\u8bbe\u77db\u76fe\u3002
        "},{"location":"chapter_greedy/summary/","title":"15.5 \u00a0 \u5c0f\u7ed3","text":"
        • \u8d2a\u5fc3\u7b97\u6cd5\u901a\u5e38\u7528\u4e8e\u89e3\u51b3\u6700\u4f18\u5316\u95ee\u9898\uff0c\u5176\u539f\u7406\u662f\u5728\u6bcf\u4e2a\u51b3\u7b56\u9636\u6bb5\u90fd\u505a\u51fa\u5c40\u90e8\u6700\u4f18\u7684\u51b3\u7b56\uff0c\u4ee5\u671f\u83b7\u5f97\u5168\u5c40\u6700\u4f18\u89e3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4f1a\u8fed\u4ee3\u5730\u505a\u51fa\u4e00\u4e2a\u53c8\u4e00\u4e2a\u7684\u8d2a\u5fc3\u9009\u62e9\uff0c\u6bcf\u8f6e\u90fd\u5c06\u95ee\u9898\u8f6c\u5316\u6210\u4e00\u4e2a\u89c4\u6a21\u66f4\u5c0f\u7684\u5b50\u95ee\u9898\uff0c\u76f4\u5230\u95ee\u9898\u88ab\u89e3\u51b3\u3002
        • \u8d2a\u5fc3\u7b97\u6cd5\u4e0d\u4ec5\u5b9e\u73b0\u7b80\u5355\uff0c\u8fd8\u5177\u6709\u5f88\u9ad8\u7684\u89e3\u9898\u6548\u7387\u3002\u76f8\u6bd4\u4e8e\u52a8\u6001\u89c4\u5212\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u66f4\u4f4e\u3002
        • \u5728\u96f6\u94b1\u5151\u6362\u95ee\u9898\u4e2d\uff0c\u5bf9\u4e8e\u67d0\u4e9b\u786c\u5e01\u7ec4\u5408\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ef\u4ee5\u4fdd\u8bc1\u627e\u5230\u6700\u4f18\u89e3\uff1b\u5bf9\u4e8e\u53e6\u5916\u4e00\u4e9b\u786c\u5e01\u7ec4\u5408\u5219\u4e0d\u7136\uff0c\u8d2a\u5fc3\u7b97\u6cd5\u53ef\u80fd\u627e\u5230\u5f88\u5dee\u7684\u89e3\u3002
        • \u9002\u5408\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u7684\u95ee\u9898\u5177\u6709\u4e24\u5927\u6027\u8d28\uff1a\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u548c\u6700\u4f18\u5b50\u7ed3\u6784\u3002\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u4ee3\u8868\u8d2a\u5fc3\u7b56\u7565\u7684\u6709\u6548\u6027\u3002
        • \u5bf9\u4e8e\u67d0\u4e9b\u590d\u6742\u95ee\u9898\uff0c\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u7684\u8bc1\u660e\u5e76\u4e0d\u7b80\u5355\u3002\u76f8\u5bf9\u6765\u8bf4\uff0c\u8bc1\u4f2a\u66f4\u52a0\u5bb9\u6613\uff0c\u4f8b\u5982\u96f6\u94b1\u5151\u6362\u95ee\u9898\u3002
        • \u6c42\u89e3\u8d2a\u5fc3\u95ee\u9898\u4e3b\u8981\u5206\u4e3a\u4e09\u6b65\uff1a\u95ee\u9898\u5206\u6790\u3001\u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u3001\u6b63\u786e\u6027\u8bc1\u660e\u3002\u5176\u4e2d\uff0c\u786e\u5b9a\u8d2a\u5fc3\u7b56\u7565\u662f\u6838\u5fc3\u6b65\u9aa4\uff0c\u6b63\u786e\u6027\u8bc1\u660e\u5f80\u5f80\u662f\u96be\u70b9\u3002
        • \u5206\u6570\u80cc\u5305\u95ee\u9898\u5728 0-1 \u80cc\u5305\u7684\u57fa\u7840\u4e0a\uff0c\u5141\u8bb8\u9009\u62e9\u7269\u54c1\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u6b64\u53ef\u4f7f\u7528\u8d2a\u5fc3\u7b97\u6cd5\u6c42\u89e3\u3002\u8d2a\u5fc3\u7b56\u7565\u7684\u6b63\u786e\u6027\u53ef\u4ee5\u4f7f\u7528\u53cd\u8bc1\u6cd5\u6765\u8bc1\u660e\u3002
        • \u6700\u5927\u5bb9\u91cf\u95ee\u9898\u53ef\u4f7f\u7528\u7a77\u4e3e\u6cd5\u6c42\u89e3\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002\u901a\u8fc7\u8bbe\u8ba1\u8d2a\u5fc3\u7b56\u7565\uff0c\u6bcf\u8f6e\u5411\u5185\u79fb\u52a8\u77ed\u677f\uff0c\u53ef\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(n)\\) \u3002
        • \u5728\u6700\u5927\u5207\u5206\u4e58\u79ef\u95ee\u9898\u4e2d\uff0c\u6211\u4eec\u5148\u540e\u63a8\u7406\u51fa\u4e24\u4e2a\u8d2a\u5fc3\u7b56\u7565\uff1a\\(\\geq 4\\) \u7684\u6574\u6570\u90fd\u5e94\u8be5\u7ee7\u7eed\u5207\u5206\u3001\u6700\u4f18\u5207\u5206\u56e0\u5b50\u4e3a \\(3\\) \u3002\u4ee3\u7801\u4e2d\u5305\u542b\u5e42\u8fd0\u7b97\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53d6\u51b3\u4e8e\u5e42\u8fd0\u7b97\u5b9e\u73b0\u65b9\u6cd5\uff0c\u901a\u5e38\u4e3a \\(O(1)\\) \u6216 \\(O(\\log n)\\) \u3002
        "},{"location":"chapter_hashing/","title":"\u7b2c 6 \u7ae0 \u00a0 \u54c8\u5e0c\u8868","text":"

        Abstract

        \u5728\u8ba1\u7b97\u673a\u4e16\u754c\u4e2d\uff0c\u54c8\u5e0c\u8868\u5982\u540c\u4e00\u4f4d\u806a\u6167\u7684\u56fe\u4e66\u7ba1\u7406\u5458\u3002

        \u4ed6\u77e5\u9053\u5982\u4f55\u8ba1\u7b97\u7d22\u4e66\u53f7\uff0c\u4ece\u800c\u53ef\u4ee5\u5feb\u901f\u627e\u5230\u76ee\u6807\u56fe\u4e66\u3002

        "},{"location":"chapter_hashing/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 6.1 \u00a0 \u54c8\u5e0c\u8868
        • 6.2 \u00a0 \u54c8\u5e0c\u51b2\u7a81
        • 6.3 \u00a0 \u54c8\u5e0c\u7b97\u6cd5
        • 6.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_hashing/hash_algorithm/","title":"6.3 \u00a0 \u54c8\u5e0c\u7b97\u6cd5","text":"

        \u524d\u4e24\u8282\u4ecb\u7ecd\u4e86\u54c8\u5e0c\u8868\u7684\u5de5\u4f5c\u539f\u7406\u548c\u54c8\u5e0c\u51b2\u7a81\u7684\u5904\u7406\u65b9\u6cd5\u3002\u7136\u800c\u65e0\u8bba\u662f\u5f00\u653e\u5bfb\u5740\u8fd8\u662f\u94fe\u5f0f\u5730\u5740\uff0c\u5b83\u4eec\u53ea\u80fd\u4fdd\u8bc1\u54c8\u5e0c\u8868\u53ef\u4ee5\u5728\u53d1\u751f\u51b2\u7a81\u65f6\u6b63\u5e38\u5de5\u4f5c\uff0c\u800c\u65e0\u6cd5\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u7684\u53d1\u751f\u3002

        \u5982\u679c\u54c8\u5e0c\u51b2\u7a81\u8fc7\u4e8e\u9891\u7e41\uff0c\u54c8\u5e0c\u8868\u7684\u6027\u80fd\u5219\u4f1a\u6025\u5267\u52a3\u5316\u3002\u5982\u56fe 6-8 \u6240\u793a\uff0c\u5bf9\u4e8e\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\uff0c\u7406\u60f3\u60c5\u51b5\u4e0b\u952e\u503c\u5bf9\u5747\u5300\u5206\u5e03\u5728\u5404\u4e2a\u6876\u4e2d\uff0c\u8fbe\u5230\u6700\u4f73\u67e5\u8be2\u6548\u7387\uff1b\u6700\u5dee\u60c5\u51b5\u4e0b\u6240\u6709\u952e\u503c\u5bf9\u90fd\u5b58\u50a8\u5230\u540c\u4e00\u4e2a\u6876\u4e2d\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u9000\u5316\u81f3 \\(O(n)\\) \u3002

        \u56fe 6-8 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u7684\u6700\u4f73\u60c5\u51b5\u4e0e\u6700\u5dee\u60c5\u51b5

        \u952e\u503c\u5bf9\u7684\u5206\u5e03\u60c5\u51b5\u7531\u54c8\u5e0c\u51fd\u6570\u51b3\u5b9a\u3002\u56de\u5fc6\u54c8\u5e0c\u51fd\u6570\u7684\u8ba1\u7b97\u6b65\u9aa4\uff0c\u5148\u8ba1\u7b97\u54c8\u5e0c\u503c\uff0c\u518d\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21\uff1a

        index = hash(key) % capacity\n

        \u89c2\u5bdf\u4ee5\u4e0a\u516c\u5f0f\uff0c\u5f53\u54c8\u5e0c\u8868\u5bb9\u91cf capacity \u56fa\u5b9a\u65f6\uff0c\u54c8\u5e0c\u7b97\u6cd5 hash() \u51b3\u5b9a\u4e86\u8f93\u51fa\u503c\uff0c\u8fdb\u800c\u51b3\u5b9a\u4e86\u952e\u503c\u5bf9\u5728\u54c8\u5e0c\u8868\u4e2d\u7684\u5206\u5e03\u60c5\u51b5\u3002

        \u8fd9\u610f\u5473\u7740\uff0c\u4e3a\u4e86\u964d\u4f4e\u54c8\u5e0c\u51b2\u7a81\u7684\u53d1\u751f\u6982\u7387\uff0c\u6211\u4eec\u5e94\u5f53\u5c06\u6ce8\u610f\u529b\u96c6\u4e2d\u5728\u54c8\u5e0c\u7b97\u6cd5 hash() \u7684\u8bbe\u8ba1\u4e0a\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#631","title":"6.3.1 \u00a0 \u54c8\u5e0c\u7b97\u6cd5\u7684\u76ee\u6807","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u201c\u65e2\u5feb\u53c8\u7a33\u201d\u7684\u54c8\u5e0c\u8868\u6570\u636e\u7ed3\u6784\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5e94\u5177\u5907\u4ee5\u4e0b\u7279\u70b9\u3002

        • \u786e\u5b9a\u6027\uff1a\u5bf9\u4e8e\u76f8\u540c\u7684\u8f93\u5165\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5e94\u59cb\u7ec8\u4ea7\u751f\u76f8\u540c\u7684\u8f93\u51fa\u3002\u8fd9\u6837\u624d\u80fd\u786e\u4fdd\u54c8\u5e0c\u8868\u662f\u53ef\u9760\u7684\u3002
        • \u6548\u7387\u9ad8\uff1a\u8ba1\u7b97\u54c8\u5e0c\u503c\u7684\u8fc7\u7a0b\u5e94\u8be5\u8db3\u591f\u5feb\u3002\u8ba1\u7b97\u5f00\u9500\u8d8a\u5c0f\uff0c\u54c8\u5e0c\u8868\u7684\u5b9e\u7528\u6027\u8d8a\u9ad8\u3002
        • \u5747\u5300\u5206\u5e03\uff1a\u54c8\u5e0c\u7b97\u6cd5\u5e94\u4f7f\u5f97\u952e\u503c\u5bf9\u5747\u5300\u5206\u5e03\u5728\u54c8\u5e0c\u8868\u4e2d\u3002\u5206\u5e03\u8d8a\u5747\u5300\uff0c\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\u3002

        \u5b9e\u9645\u4e0a\uff0c\u54c8\u5e0c\u7b97\u6cd5\u9664\u4e86\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u54c8\u5e0c\u8868\uff0c\u8fd8\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5176\u4ed6\u9886\u57df\u4e2d\u3002

        • \u5bc6\u7801\u5b58\u50a8\uff1a\u4e3a\u4e86\u4fdd\u62a4\u7528\u6237\u5bc6\u7801\u7684\u5b89\u5168\uff0c\u7cfb\u7edf\u901a\u5e38\u4e0d\u4f1a\u76f4\u63a5\u5b58\u50a8\u7528\u6237\u7684\u660e\u6587\u5bc6\u7801\uff0c\u800c\u662f\u5b58\u50a8\u5bc6\u7801\u7684\u54c8\u5e0c\u503c\u3002\u5f53\u7528\u6237\u8f93\u5165\u5bc6\u7801\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5bf9\u8f93\u5165\u7684\u5bc6\u7801\u8ba1\u7b97\u54c8\u5e0c\u503c\uff0c\u7136\u540e\u4e0e\u5b58\u50a8\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u8005\u5339\u914d\uff0c\u90a3\u4e48\u5bc6\u7801\u5c31\u88ab\u89c6\u4e3a\u6b63\u786e\u3002
        • \u6570\u636e\u5b8c\u6574\u6027\u68c0\u67e5\uff1a\u6570\u636e\u53d1\u9001\u65b9\u53ef\u4ee5\u8ba1\u7b97\u6570\u636e\u7684\u54c8\u5e0c\u503c\u5e76\u5c06\u5176\u4e00\u540c\u53d1\u9001\uff1b\u63a5\u6536\u65b9\u53ef\u4ee5\u91cd\u65b0\u8ba1\u7b97\u63a5\u6536\u5230\u7684\u6570\u636e\u7684\u54c8\u5e0c\u503c\uff0c\u5e76\u4e0e\u63a5\u6536\u5230\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u8005\u5339\u914d\uff0c\u90a3\u4e48\u6570\u636e\u5c31\u88ab\u89c6\u4e3a\u5b8c\u6574\u3002

        \u5bf9\u4e8e\u5bc6\u7801\u5b66\u7684\u76f8\u5173\u5e94\u7528\uff0c\u4e3a\u4e86\u9632\u6b62\u4ece\u54c8\u5e0c\u503c\u63a8\u5bfc\u51fa\u539f\u59cb\u5bc6\u7801\u7b49\u9006\u5411\u5de5\u7a0b\uff0c\u54c8\u5e0c\u7b97\u6cd5\u9700\u8981\u5177\u5907\u66f4\u9ad8\u7b49\u7ea7\u7684\u5b89\u5168\u7279\u6027\u3002

        • \u5355\u5411\u6027\uff1a\u65e0\u6cd5\u901a\u8fc7\u54c8\u5e0c\u503c\u53cd\u63a8\u51fa\u5173\u4e8e\u8f93\u5165\u6570\u636e\u7684\u4efb\u4f55\u4fe1\u606f\u3002
        • \u6297\u78b0\u649e\u6027\uff1a\u5e94\u5f53\u6781\u96be\u627e\u5230\u4e24\u4e2a\u4e0d\u540c\u7684\u8f93\u5165\uff0c\u4f7f\u5f97\u5b83\u4eec\u7684\u54c8\u5e0c\u503c\u76f8\u540c\u3002
        • \u96ea\u5d29\u6548\u5e94\uff1a\u8f93\u5165\u7684\u5fae\u5c0f\u53d8\u5316\u5e94\u5f53\u5bfc\u81f4\u8f93\u51fa\u7684\u663e\u8457\u4e14\u4e0d\u53ef\u9884\u6d4b\u7684\u53d8\u5316\u3002

        \u8bf7\u6ce8\u610f\uff0c\u201c\u5747\u5300\u5206\u5e03\u201d\u4e0e\u201c\u6297\u78b0\u649e\u6027\u201d\u662f\u4e24\u4e2a\u72ec\u7acb\u7684\u6982\u5ff5\uff0c\u6ee1\u8db3\u5747\u5300\u5206\u5e03\u4e0d\u4e00\u5b9a\u6ee1\u8db3\u6297\u78b0\u649e\u6027\u3002\u4f8b\u5982\uff0c\u5728\u968f\u673a\u8f93\u5165 key \u4e0b\uff0c\u54c8\u5e0c\u51fd\u6570 key % 100 \u53ef\u4ee5\u4ea7\u751f\u5747\u5300\u5206\u5e03\u7684\u8f93\u51fa\u3002\u7136\u800c\u8be5\u54c8\u5e0c\u7b97\u6cd5\u8fc7\u4e8e\u7b80\u5355\uff0c\u6240\u6709\u540e\u4e24\u4f4d\u76f8\u7b49\u7684 key \u7684\u8f93\u51fa\u90fd\u76f8\u540c\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u4ece\u54c8\u5e0c\u503c\u53cd\u63a8\u51fa\u53ef\u7528\u7684 key \uff0c\u4ece\u800c\u7834\u89e3\u5bc6\u7801\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#632","title":"6.3.2 \u00a0 \u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1","text":"

        \u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1\u662f\u4e00\u4e2a\u9700\u8981\u8003\u8651\u8bb8\u591a\u56e0\u7d20\u7684\u590d\u6742\u95ee\u9898\u3002\u7136\u800c\u5bf9\u4e8e\u67d0\u4e9b\u8981\u6c42\u4e0d\u9ad8\u7684\u573a\u666f\uff0c\u6211\u4eec\u4e5f\u80fd\u8bbe\u8ba1\u4e00\u4e9b\u7b80\u5355\u7684\u54c8\u5e0c\u7b97\u6cd5\u3002

        • \u52a0\u6cd5\u54c8\u5e0c\uff1a\u5bf9\u8f93\u5165\u7684\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u8fdb\u884c\u76f8\u52a0\uff0c\u5c06\u5f97\u5230\u7684\u603b\u548c\u4f5c\u4e3a\u54c8\u5e0c\u503c\u3002
        • \u4e58\u6cd5\u54c8\u5e0c\uff1a\u5229\u7528\u4e58\u6cd5\u7684\u4e0d\u76f8\u5173\u6027\uff0c\u6bcf\u8f6e\u4e58\u4ee5\u4e00\u4e2a\u5e38\u6570\uff0c\u5c06\u5404\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u7d2f\u79ef\u5230\u54c8\u5e0c\u503c\u4e2d\u3002
        • \u5f02\u6216\u54c8\u5e0c\uff1a\u5c06\u8f93\u5165\u6570\u636e\u7684\u6bcf\u4e2a\u5143\u7d20\u901a\u8fc7\u5f02\u6216\u64cd\u4f5c\u7d2f\u79ef\u5230\u4e00\u4e2a\u54c8\u5e0c\u503c\u4e2d\u3002
        • \u65cb\u8f6c\u54c8\u5e0c\uff1a\u5c06\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\u7d2f\u79ef\u5230\u4e00\u4e2a\u54c8\u5e0c\u503c\u4e2d\uff0c\u6bcf\u6b21\u7d2f\u79ef\u4e4b\u524d\u90fd\u4f1a\u5bf9\u54c8\u5e0c\u503c\u8fdb\u884c\u65cb\u8f6c\u64cd\u4f5c\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig simple_hash.py
        def add_hash(key: str) -> int:\n\"\"\"\u52a0\u6cd5\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash += ord(c)\nreturn hash % modulus\ndef mul_hash(key: str) -> int:\n\"\"\"\u4e58\u6cd5\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash = 31 * hash + ord(c)\nreturn hash % modulus\ndef xor_hash(key: str) -> int:\n\"\"\"\u5f02\u6216\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash ^= ord(c)\nreturn hash % modulus\ndef rot_hash(key: str) -> int:\n\"\"\"\u65cb\u8f6c\u54c8\u5e0c\"\"\"\nhash = 0\nmodulus = 1000000007\nfor c in key:\nhash = (hash << 4) ^ (hash >> 28) ^ ord(c)\nreturn hash % modulus\n
        simple_hash.cpp
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = (hash + (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = (31 * hash + (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(string key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash ^= (int)c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(string key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (unsigned char c : key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (int)c) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.java
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = (hash + (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = (31 * hash + (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash ^= (int) c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\nlong hash = 0;\nfinal int MODULUS = 1000000007;\nfor (char c : key.toCharArray()) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (int) c) % MODULUS;\n}\nreturn (int) hash;\n}\n
        simple_hash.cs
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint AddHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = (hash + c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint MulHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = (31 * hash + c) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint XorHash(string key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash ^= c;\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint RotHash(string key) {\nlong hash = 0;\nconst int MODULUS = 1000000007;\nforeach (char c in key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.go
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = (hash + int64(b)) % modulus\n}\nreturn int(hash)\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = (31*hash + int64(b)) % modulus\n}\nreturn int(hash)\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key string) int {\nhash := 0\nmodulus := 1000000007\nfor _, b := range []byte(key) {\nfmt.Println(int(b))\nhash ^= int(b)\nhash = (31*hash + int(b)) % modulus\n}\nreturn hash & modulus\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key string) int {\nvar hash int64\nvar modulus int64\nmodulus = 1000000007\nfor _, b := range []byte(key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ int64(b)) % modulus\n}\nreturn int(hash)\n}\n
        simple_hash.swift
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = (hash + Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = (31 * hash + Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash ^= Int(scalar.value)\n}\n}\nreturn hash & MODULUS\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key: String) -> Int {\nvar hash = 0\nlet MODULUS = 1_000_000_007\nfor c in key {\nfor scalar in c.unicodeScalars {\nhash = ((hash << 4) ^ (hash >> 28) ^ Int(scalar.value)) % MODULUS\n}\n}\nreturn hash\n}\n
        simple_hash.js
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash ^= c.charCodeAt(0);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key) {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.ts
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash ^= c.charCodeAt(0);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key: string): number {\nlet hash = 0;\nconst MODULUS = 1000000007;\nfor (const c of key) {\nhash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.dart
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = (hash + key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = (31 * hash + key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash ^= key.codeUnitAt(i);\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\nint hash = 0;\nfinal int MODULUS = 1000000007;\nfor (int i = 0; i < key.length; i++) {\nhash = ((hash << 4) ^ (hash >> 28) ^ key.codeUnitAt(i)) % MODULUS;\n}\nreturn hash;\n}\n
        simple_hash.rs
        /* \u52a0\u6cd5\u54c8\u5e0c */\nfn add_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = (hash + c as i64) % MODULUS;\n}\nhash as i32\n} /* \u4e58\u6cd5\u54c8\u5e0c */\nfn mul_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = (31 * hash + c as i64) % MODULUS;\n}\nhash as i32\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nfn xor_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash ^= c as i64;\n}\n(hash & MODULUS) as i32\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfn rot_hash(key: &str) -> i32 {\nlet mut hash = 0_i64;\nconst MODULUS: i64 = 1000000007;\nfor c in key.chars() {\nhash = ((hash << 4) ^ (hash >> 28) ^ c as i64) % MODULUS;\n}\nhash as i32\n}\n
        simple_hash.c
        /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = (hash + (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = (31 * hash + (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(char *key) {\nint hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash ^= (unsigned char)key[i];\n}\nreturn hash & MODULUS;\n}\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(char *key) {\nlong long hash = 0;\nconst int MODULUS = 1000000007;\nfor (int i = 0; i < strlen(key); i++) {\nhash = ((hash << 4) ^ (hash >> 28) ^ (unsigned char)key[i]) % MODULUS;\n}\nreturn (int)hash;\n}\n
        simple_hash.zig
        [class]{}-[func]{addHash}\n[class]{}-[func]{mulHash}\n[class]{}-[func]{xorHash}\n[class]{}-[func]{rotHash}\n

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u6bcf\u79cd\u54c8\u5e0c\u7b97\u6cd5\u7684\u6700\u540e\u4e00\u6b65\u90fd\u662f\u5bf9\u5927\u8d28\u6570 \\(1000000007\\) \u53d6\u6a21\uff0c\u4ee5\u786e\u4fdd\u54c8\u5e0c\u503c\u5728\u5408\u9002\u7684\u8303\u56f4\u5185\u3002\u503c\u5f97\u601d\u8003\u7684\u662f\uff0c\u4e3a\u4ec0\u4e48\u8981\u5f3a\u8c03\u5bf9\u8d28\u6570\u53d6\u6a21\uff0c\u6216\u8005\u8bf4\u5bf9\u5408\u6570\u53d6\u6a21\u7684\u5f0a\u7aef\u662f\u4ec0\u4e48\uff1f\u8fd9\u662f\u4e00\u4e2a\u6709\u8da3\u7684\u95ee\u9898\u3002

        \u5148\u629b\u51fa\u7ed3\u8bba\uff1a\u4f7f\u7528\u5927\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u53ef\u4ee5\u6700\u5927\u5316\u5730\u4fdd\u8bc1\u54c8\u5e0c\u503c\u7684\u5747\u5300\u5206\u5e03\u3002\u56e0\u4e3a\u8d28\u6570\u4e0d\u4e0e\u5176\u4ed6\u6570\u5b57\u5b58\u5728\u516c\u7ea6\u6570\uff0c\u53ef\u4ee5\u51cf\u5c11\u56e0\u53d6\u6a21\u64cd\u4f5c\u800c\u4ea7\u751f\u7684\u5468\u671f\u6027\u6a21\u5f0f\uff0c\u4ece\u800c\u907f\u514d\u54c8\u5e0c\u51b2\u7a81\u3002

        \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u6211\u4eec\u9009\u62e9\u5408\u6570 \\(9\\) \u4f5c\u4e3a\u6a21\u6570\uff0c\u5b83\u53ef\u4ee5\u88ab \\(3\\) \u6574\u9664\uff0c\u90a3\u4e48\u6240\u6709\u53ef\u4ee5\u88ab \\(3\\) \u6574\u9664\u7684 key \u90fd\u4f1a\u88ab\u6620\u5c04\u5230 \\(0\\)\u3001\\(3\\)\u3001\\(6\\) \u8fd9\u4e09\u4e2a\u54c8\u5e0c\u503c\u3002

        \\[ \\begin{aligned} \\text{modulus} & = 9 \\newline \\text{key} & = \\{ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, \\dots \\} \\newline \\text{hash} & = \\{ 0, 3, 6, 0, 3, 6, 0, 3, 6, 0, 3, 6,\\dots \\} \\end{aligned} \\]

        \u5982\u679c\u8f93\u5165 key \u6070\u597d\u6ee1\u8db3\u8fd9\u79cd\u7b49\u5dee\u6570\u5217\u7684\u6570\u636e\u5206\u5e03\uff0c\u90a3\u4e48\u54c8\u5e0c\u503c\u5c31\u4f1a\u51fa\u73b0\u805a\u5806\uff0c\u4ece\u800c\u52a0\u91cd\u54c8\u5e0c\u51b2\u7a81\u3002\u73b0\u5728\uff0c\u5047\u8bbe\u5c06 modulus \u66ff\u6362\u4e3a\u8d28\u6570 \\(13\\) \uff0c\u7531\u4e8e key \u548c modulus \u4e4b\u95f4\u4e0d\u5b58\u5728\u516c\u7ea6\u6570\uff0c\u56e0\u6b64\u8f93\u51fa\u7684\u54c8\u5e0c\u503c\u7684\u5747\u5300\u6027\u4f1a\u660e\u663e\u63d0\u5347\u3002

        \\[ \\begin{aligned} \\text{modulus} & = 13 \\newline \\text{key} & = \\{ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, \\dots \\} \\newline \\text{hash} & = \\{ 0, 3, 6, 9, 12, 2, 5, 8, 11, 1, 4, 7, \\dots \\} \\end{aligned} \\]

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5982\u679c\u80fd\u591f\u4fdd\u8bc1 key \u662f\u968f\u673a\u5747\u5300\u5206\u5e03\u7684\uff0c\u90a3\u4e48\u9009\u62e9\u8d28\u6570\u6216\u8005\u5408\u6570\u4f5c\u4e3a\u6a21\u6570\u90fd\u53ef\u4ee5\uff0c\u5b83\u4eec\u90fd\u80fd\u8f93\u51fa\u5747\u5300\u5206\u5e03\u7684\u54c8\u5e0c\u503c\u3002\u800c\u5f53 key \u7684\u5206\u5e03\u5b58\u5728\u67d0\u79cd\u5468\u671f\u6027\u65f6\uff0c\u5bf9\u5408\u6570\u53d6\u6a21\u66f4\u5bb9\u6613\u51fa\u73b0\u805a\u96c6\u73b0\u8c61\u3002

        \u603b\u800c\u8a00\u4e4b\uff0c\u6211\u4eec\u901a\u5e38\u9009\u53d6\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u5e76\u4e14\u8fd9\u4e2a\u8d28\u6570\u6700\u597d\u8db3\u591f\u5927\uff0c\u4ee5\u5c3d\u53ef\u80fd\u6d88\u9664\u5468\u671f\u6027\u6a21\u5f0f\uff0c\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u7a33\u5065\u6027\u3002

        "},{"location":"chapter_hashing/hash_algorithm/#633","title":"6.3.3 \u00a0 \u5e38\u89c1\u54c8\u5e0c\u7b97\u6cd5","text":"

        \u4e0d\u96be\u53d1\u73b0\uff0c\u4ee5\u4e0a\u4ecb\u7ecd\u7684\u7b80\u5355\u54c8\u5e0c\u7b97\u6cd5\u90fd\u6bd4\u8f83\u201c\u8106\u5f31\u201d\uff0c\u8fdc\u8fdc\u6ca1\u6709\u8fbe\u5230\u54c8\u5e0c\u7b97\u6cd5\u7684\u8bbe\u8ba1\u76ee\u6807\u3002\u4f8b\u5982\uff0c\u7531\u4e8e\u52a0\u6cd5\u548c\u5f02\u6216\u6ee1\u8db3\u4ea4\u6362\u5f8b\uff0c\u56e0\u6b64\u52a0\u6cd5\u54c8\u5e0c\u548c\u5f02\u6216\u54c8\u5e0c\u65e0\u6cd5\u533a\u5206\u5185\u5bb9\u76f8\u540c\u4f46\u987a\u5e8f\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u8fd9\u53ef\u80fd\u4f1a\u52a0\u5267\u54c8\u5e0c\u51b2\u7a81\uff0c\u5e76\u5f15\u8d77\u4e00\u4e9b\u5b89\u5168\u95ee\u9898\u3002

        \u5728\u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u7528\u4e00\u4e9b\u6807\u51c6\u54c8\u5e0c\u7b97\u6cd5\uff0c\u4f8b\u5982 MD5\u3001SHA-1\u3001SHA-2\u3001SHA-3 \u7b49\u3002\u5b83\u4eec\u53ef\u4ee5\u5c06\u4efb\u610f\u957f\u5ea6\u7684\u8f93\u5165\u6570\u636e\u6620\u5c04\u5230\u6052\u5b9a\u957f\u5ea6\u7684\u54c8\u5e0c\u503c\u3002

        \u8fd1\u4e00\u4e2a\u4e16\u7eaa\u4ee5\u6765\uff0c\u54c8\u5e0c\u7b97\u6cd5\u5904\u5728\u4e0d\u65ad\u5347\u7ea7\u4e0e\u4f18\u5316\u7684\u8fc7\u7a0b\u4e2d\u3002\u4e00\u90e8\u5206\u7814\u7a76\u4eba\u5458\u52aa\u529b\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u6027\u80fd\uff0c\u53e6\u4e00\u90e8\u5206\u7814\u7a76\u4eba\u5458\u548c\u9ed1\u5ba2\u5219\u81f4\u529b\u4e8e\u5bfb\u627e\u54c8\u5e0c\u7b97\u6cd5\u7684\u5b89\u5168\u6027\u95ee\u9898\u3002\u8868 6-2 \u5c55\u793a\u4e86\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5\u3002

        • MD5 \u548c SHA-1 \u5df2\u591a\u6b21\u88ab\u6210\u529f\u653b\u51fb\uff0c\u56e0\u6b64\u5b83\u4eec\u88ab\u5404\u7c7b\u5b89\u5168\u5e94\u7528\u5f03\u7528\u3002
        • SHA-2 \u7cfb\u5217\u4e2d\u7684 SHA-256 \u662f\u6700\u5b89\u5168\u7684\u54c8\u5e0c\u7b97\u6cd5\u4e4b\u4e00\uff0c\u4ecd\u672a\u51fa\u73b0\u6210\u529f\u7684\u653b\u51fb\u6848\u4f8b\uff0c\u56e0\u6b64\u5e38\u7528\u5728\u5404\u7c7b\u5b89\u5168\u5e94\u7528\u4e0e\u534f\u8bae\u4e2d\u3002
        • SHA-3 \u76f8\u8f83 SHA-2 \u7684\u5b9e\u73b0\u5f00\u9500\u66f4\u4f4e\u3001\u8ba1\u7b97\u6548\u7387\u66f4\u9ad8\uff0c\u4f46\u76ee\u524d\u4f7f\u7528\u8986\u76d6\u5ea6\u4e0d\u5982 SHA-2 \u7cfb\u5217\u3002

        \u8868 6-2 \u00a0 \u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5

        MD5 SHA-1 SHA-2 SHA-3 \u63a8\u51fa\u65f6\u95f4 1992 1995 2002 2008 \u8f93\u51fa\u957f\u5ea6 128 bits 160 bits 256/512 bits 224/256/384/512 bits \u54c8\u5e0c\u51b2\u7a81 \u8f83\u591a \u8f83\u591a \u5f88\u5c11 \u5f88\u5c11 \u5b89\u5168\u7b49\u7ea7 \u4f4e\uff0c\u5df2\u88ab\u6210\u529f\u653b\u51fb \u4f4e\uff0c\u5df2\u88ab\u6210\u529f\u653b\u51fb \u9ad8 \u9ad8 \u5e94\u7528 \u5df2\u88ab\u5f03\u7528\uff0c\u4ecd\u7528\u4e8e\u6570\u636e\u5b8c\u6574\u6027\u68c0\u67e5 \u5df2\u88ab\u5f03\u7528 \u52a0\u5bc6\u8d27\u5e01\u4ea4\u6613\u9a8c\u8bc1\u3001\u6570\u5b57\u7b7e\u540d\u7b49 \u53ef\u7528\u4e8e\u66ff\u4ee3 SHA-2"},{"location":"chapter_hashing/hash_algorithm/#634","title":"6.3.4 \u00a0 \u6570\u636e\u7ed3\u6784\u7684\u54c8\u5e0c\u503c","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u54c8\u5e0c\u8868\u7684 key \u53ef\u4ee5\u662f\u6574\u6570\u3001\u5c0f\u6570\u6216\u5b57\u7b26\u4e32\u7b49\u6570\u636e\u7c7b\u578b\u3002\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u4e3a\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u5185\u7f6e\u7684\u54c8\u5e0c\u7b97\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u54c8\u5e0c\u8868\u4e2d\u7684\u6876\u7d22\u5f15\u3002\u4ee5 Python \u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u8c03\u7528 hash() \u51fd\u6570\u6765\u8ba1\u7b97\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u54c8\u5e0c\u503c\u3002

        • \u6574\u6570\u548c\u5e03\u5c14\u91cf\u7684\u54c8\u5e0c\u503c\u5c31\u662f\u5176\u672c\u8eab\u3002
        • \u6d6e\u70b9\u6570\u548c\u5b57\u7b26\u4e32\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\u8f83\u4e3a\u590d\u6742\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u8bf7\u81ea\u884c\u5b66\u4e60\u3002
        • \u5143\u7ec4\u7684\u54c8\u5e0c\u503c\u662f\u5bf9\u5176\u4e2d\u6bcf\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u54c8\u5e0c\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u54c8\u5e0c\u503c\u7ec4\u5408\u8d77\u6765\uff0c\u5f97\u5230\u5355\u4e00\u7684\u54c8\u5e0c\u503c\u3002
        • \u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u57fa\u4e8e\u5176\u5185\u5b58\u5730\u5740\u751f\u6210\u3002\u901a\u8fc7\u91cd\u5199\u5bf9\u8c61\u7684\u54c8\u5e0c\u65b9\u6cd5\uff0c\u53ef\u5b9e\u73b0\u57fa\u4e8e\u5185\u5bb9\u751f\u6210\u54c8\u5e0c\u503c\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u7684\u5185\u7f6e\u54c8\u5e0c\u503c\u8ba1\u7b97\u51fd\u6570\u7684\u5b9a\u4e49\u548c\u65b9\u6cd5\u4e0d\u540c\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig built_in_hash.py
        num = 3\nhash_num = hash(num)\n# \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nbol = True\nhash_bol = hash(bol)\n# \u5e03\u5c14\u91cf True \u7684\u54c8\u5e0c\u503c\u4e3a 1\ndec = 3.14159\nhash_dec = hash(dec)\n# \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 326484311674566659\nstr = \"Hello \u7b97\u6cd5\"\nhash_str = hash(str)\n# \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 4617003410720528961\ntup = (12836, \"\u5c0f\u54c8\")\nhash_tup = hash(tup)\n# \u5143\u7ec4 (12836, '\u5c0f\u54c8') \u7684\u54c8\u5e0c\u503c\u4e3a 1029005403108185979\nobj = ListNode(0)\nhash_obj = hash(obj)\n# \u8282\u70b9\u5bf9\u8c61 <ListNode object at 0x1058fd810> \u7684\u54c8\u5e0c\u503c\u4e3a 274267521\n
        built_in_hash.cpp
        int num = 3;\nsize_t hashNum = hash<int>()(num);\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nbool bol = true;\nsize_t hashBol = hash<bool>()(bol);\n// \u5e03\u5c14\u91cf 1 \u7684\u54c8\u5e0c\u503c\u4e3a 1\ndouble dec = 3.14159;\nsize_t hashDec = hash<double>()(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 4614256650576692846\nstring str = \"Hello \u7b97\u6cd5\";\nsize_t hashStr = hash<string>()(str);\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 15466937326284535026\n// \u5728 C++ \u4e2d\uff0c\u5185\u7f6e std:hash() \u4ec5\u63d0\u4f9b\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\n// \u6570\u7ec4\u3001\u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u8ba1\u7b97\u9700\u8981\u81ea\u884c\u5b9e\u73b0\n
        built_in_hash.java
        int num = 3;\nint hashNum = Integer.hashCode(num);\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3\nboolean bol = true;\nint hashBol = Boolean.hashCode(bol);\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\ndouble dec = 3.14159;\nint hashDec = Double.hashCode(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -727081396\nObject[] arr = { 12836, \"\u5c0f\u54c8\" };\nint hashTup = Arrays.hashCode(arr);\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 1151158\nListNode obj = new ListNode(0);\nint hashObj = obj.hashCode();\n// \u8282\u70b9\u5bf9\u8c61 utils.ListNode@7dc5e7b4 \u7684\u54c8\u5e0c\u503c\u4e3a 2110121908\n
        built_in_hash.cs
        int num = 3;\nint hashNum = num.GetHashCode();\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 3;\nbool bol = true;\nint hashBol = bol.GetHashCode();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1;\ndouble dec = 3.14159;\nint hashDec = dec.GetHashCode();\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729;\nstring str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.GetHashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -586107568;\nobject[] arr = [12836, \"\u5c0f\u54c8\"];\nint hashTup = arr.GetHashCode();\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 42931033;\nListNode obj = new(0);\nint hashObj = obj.GetHashCode();\n// \u8282\u70b9\u5bf9\u8c61 0 \u7684\u54c8\u5e0c\u503c\u4e3a 39053774;\n
        built_in_hash.go
        // Go \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.swift
        let num = 3\nlet hashNum = num.hashValue\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 9047044699613009734\nlet bol = true\nlet hashBol = bol.hashValue\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a -4431640247352757451\nlet dec = 3.14159\nlet hashDec = dec.hashValue\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -2465384235396674631\nlet str = \"Hello \u7b97\u6cd5\"\nlet hashStr = str.hashValue\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -7850626797806988787\nlet arr = [AnyHashable(12836), AnyHashable(\"\u5c0f\u54c8\")]\nlet hashTup = arr.hashValue\n// \u6570\u7ec4 [AnyHashable(12836), AnyHashable(\"\u5c0f\u54c8\")] \u7684\u54c8\u5e0c\u503c\u4e3a -2308633508154532996\nlet obj = ListNode(x: 0)\nlet hashObj = obj.hashValue\n// \u8282\u70b9\u5bf9\u8c61 utils.ListNode \u7684\u54c8\u5e0c\u503c\u4e3a -2434780518035996159\n
        built_in_hash.js
        // JavaScript \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.ts
        // TypeScript \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.dart
        int num = 3;\nint hashNum = num.hashCode;\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 34803\nbool bol = true;\nint hashBol = bol.hashCode;\n// \u5e03\u5c14\u503c true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\ndouble dec = 3.14159;\nint hashDec = dec.hashCode;\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2570631074981783\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode;\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 468167534\nList arr = [12836, \"\u5c0f\u54c8\"];\nint hashArr = arr.hashCode;\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 976512528\nListNode obj = new ListNode(0);\nint hashObj = obj.hashCode;\n// \u8282\u70b9\u5bf9\u8c61 Instance of 'ListNode' \u7684\u54c8\u5e0c\u503c\u4e3a 1033450432\n
        built_in_hash.rs
        use std::collections::hash_map::DefaultHasher;\nuse std::hash::{Hash, Hasher};\nlet num = 3;\nlet mut num_hasher = DefaultHasher::new();\nnum.hash(&mut num_hasher);\nlet hash_num = num_hasher.finish();\n// \u6574\u6570 3 \u7684\u54c8\u5e0c\u503c\u4e3a 568126464209439262\nlet bol = true;\nlet mut bol_hasher = DefaultHasher::new();\nbol.hash(&mut bol_hasher);\nlet hash_bol = bol_hasher.finish();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 4952851536318644461\nlet dec: f32 = 3.14159;\nlet mut dec_hasher = DefaultHasher::new();\ndec.to_bits().hash(&mut dec_hasher);\nlet hash_dec = dec_hasher.finish();\nprintln!(\"\u5c0f\u6570 {} \u7684\u54c8\u5e0c\u503c\u4e3a {}\", dec, hash_dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2566941990314602357\nlet str = \"Hello \u7b97\u6cd5\";\nlet mut str_hasher = DefaultHasher::new();\nstr.hash(&mut str_hasher);\nlet hash_str = str_hasher.finish();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 16092673739211250988\nlet arr = (&12836, &\"\u5c0f\u54c8\");\nlet mut tup_hasher = DefaultHasher::new();\narr.hash(&mut tup_hasher);\nlet hash_tup = tup_hasher.finish();\n// \u5143\u7ec4 (12836, \"\u5c0f\u54c8\") \u7684\u54c8\u5e0c\u503c\u4e3a 1885128010422702749\nlet node = ListNode::new(42);\nlet mut hasher = DefaultHasher::new();\nnode.borrow().val.hash(&mut hasher);\nlet hash = hasher.finish();\n// \u8282\u70b9\u5bf9\u8c61 RefCell { value: ListNode { val: 42, next: None } } \u7684\u54c8\u5e0c\u503c\u4e3a15387811073369036852\n
        built_in_hash.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e hash code \u51fd\u6570\n
        built_in_hash.zig
        \n

        \u5728\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u53ea\u6709\u4e0d\u53ef\u53d8\u5bf9\u8c61\u624d\u53ef\u4f5c\u4e3a\u54c8\u5e0c\u8868\u7684 key \u3002\u5047\u5982\u6211\u4eec\u5c06\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u4f5c\u4e3a key \uff0c\u5f53\u5217\u8868\u7684\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5b83\u7684\u54c8\u5e0c\u503c\u4e5f\u968f\u4e4b\u6539\u53d8\uff0c\u6211\u4eec\u5c31\u65e0\u6cd5\u5728\u54c8\u5e0c\u8868\u4e2d\u67e5\u8be2\u5230\u539f\u5148\u7684 value \u4e86\u3002

        \u867d\u7136\u81ea\u5b9a\u4e49\u5bf9\u8c61\uff08\u6bd4\u5982\u94fe\u8868\u8282\u70b9\uff09\u7684\u6210\u5458\u53d8\u91cf\u662f\u53ef\u53d8\u7684\uff0c\u4f46\u5b83\u662f\u53ef\u54c8\u5e0c\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u5bf9\u8c61\u7684\u54c8\u5e0c\u503c\u901a\u5e38\u662f\u57fa\u4e8e\u5185\u5b58\u5730\u5740\u751f\u6210\u7684\uff0c\u5373\u4f7f\u5bf9\u8c61\u7684\u5185\u5bb9\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u4f46\u5b83\u7684\u5185\u5b58\u5730\u5740\u4e0d\u53d8\uff0c\u54c8\u5e0c\u503c\u4ecd\u7136\u662f\u4e0d\u53d8\u7684\u3002

        \u7ec6\u5fc3\u7684\u4f60\u53ef\u80fd\u53d1\u73b0\u5728\u4e0d\u540c\u63a7\u5236\u53f0\u4e2d\u8fd0\u884c\u7a0b\u5e8f\u65f6\uff0c\u8f93\u51fa\u7684\u54c8\u5e0c\u503c\u662f\u4e0d\u540c\u7684\u3002\u8fd9\u662f\u56e0\u4e3a Python \u89e3\u91ca\u5668\u5728\u6bcf\u6b21\u542f\u52a8\u65f6\uff0c\u90fd\u4f1a\u4e3a\u5b57\u7b26\u4e32\u54c8\u5e0c\u51fd\u6570\u52a0\u5165\u4e00\u4e2a\u968f\u673a\u7684\u76d0\uff08Salt\uff09\u503c\u3002\u8fd9\u79cd\u505a\u6cd5\u53ef\u4ee5\u6709\u6548\u9632\u6b62 HashDoS \u653b\u51fb\uff0c\u63d0\u5347\u54c8\u5e0c\u7b97\u6cd5\u7684\u5b89\u5168\u6027\u3002

        "},{"location":"chapter_hashing/hash_collision/","title":"6.2 \u00a0 \u54c8\u5e0c\u51b2\u7a81","text":"

        \u4e0a\u4e00\u8282\u63d0\u5230\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u54c8\u5e0c\u51fd\u6570\u7684\u8f93\u5165\u7a7a\u95f4\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\uff0c\u56e0\u6b64\u7406\u8bba\u4e0a\u54c8\u5e0c\u51b2\u7a81\u662f\u4e0d\u53ef\u907f\u514d\u7684\u3002\u6bd4\u5982\uff0c\u8f93\u5165\u7a7a\u95f4\u4e3a\u5168\u4f53\u6574\u6570\uff0c\u8f93\u51fa\u7a7a\u95f4\u4e3a\u6570\u7ec4\u5bb9\u91cf\u5927\u5c0f\uff0c\u5219\u5fc5\u7136\u6709\u591a\u4e2a\u6574\u6570\u6620\u5c04\u81f3\u540c\u4e00\u6876\u7d22\u5f15\u3002

        \u54c8\u5e0c\u51b2\u7a81\u4f1a\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u9519\u8bef\uff0c\u4e25\u91cd\u5f71\u54cd\u54c8\u5e0c\u8868\u7684\u53ef\u7528\u6027\u3002\u4e3a\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u6bcf\u5f53\u9047\u5230\u54c8\u5e0c\u51b2\u7a81\u5c31\u8fdb\u884c\u54c8\u5e0c\u8868\u6269\u5bb9\uff0c\u76f4\u81f3\u51b2\u7a81\u6d88\u5931\u4e3a\u6b62\u3002\u6b64\u65b9\u6cd5\u7b80\u5355\u7c97\u66b4\u4e14\u6709\u6548\uff0c\u4f46\u6548\u7387\u592a\u4f4e\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u6269\u5bb9\u9700\u8981\u8fdb\u884c\u5927\u91cf\u7684\u6570\u636e\u642c\u8fd0\u4e0e\u54c8\u5e0c\u503c\u8ba1\u7b97\u3002\u4e3a\u4e86\u63d0\u5347\u6548\u7387\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u7b56\u7565\u3002

        1. \u6539\u826f\u54c8\u5e0c\u8868\u6570\u636e\u7ed3\u6784\uff0c\u4f7f\u5f97\u54c8\u5e0c\u8868\u53ef\u4ee5\u5728\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81\u65f6\u6b63\u5e38\u5de5\u4f5c\u3002
        2. \u4ec5\u5728\u5fc5\u8981\u65f6\uff0c\u5373\u5f53\u54c8\u5e0c\u51b2\u7a81\u6bd4\u8f83\u4e25\u91cd\u65f6\uff0c\u624d\u6267\u884c\u6269\u5bb9\u64cd\u4f5c\u3002

        \u54c8\u5e0c\u8868\u7684\u7ed3\u6784\u6539\u826f\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u201c\u94fe\u5f0f\u5730\u5740\u201d\u548c\u201c\u5f00\u653e\u5bfb\u5740\u201d\u3002

        "},{"location":"chapter_hashing/hash_collision/#621","title":"6.2.1 \u00a0 \u94fe\u5f0f\u5730\u5740","text":"

        \u5728\u539f\u59cb\u54c8\u5e0c\u8868\u4e2d\uff0c\u6bcf\u4e2a\u6876\u4ec5\u80fd\u5b58\u50a8\u4e00\u4e2a\u952e\u503c\u5bf9\u3002\u300c\u94fe\u5f0f\u5730\u5740 separate chaining\u300d\u5c06\u5355\u4e2a\u5143\u7d20\u8f6c\u6362\u4e3a\u94fe\u8868\uff0c\u5c06\u952e\u503c\u5bf9\u4f5c\u4e3a\u94fe\u8868\u8282\u70b9\uff0c\u5c06\u6240\u6709\u53d1\u751f\u51b2\u7a81\u7684\u952e\u503c\u5bf9\u90fd\u5b58\u50a8\u5728\u540c\u4e00\u94fe\u8868\u4e2d\u3002\u56fe 6-5 \u5c55\u793a\u4e86\u4e00\u4e2a\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\u7684\u4f8b\u5b50\u3002

        \u56fe 6-5 \u00a0 \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868

        \u57fa\u4e8e\u94fe\u5f0f\u5730\u5740\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\u7684\u64cd\u4f5c\u65b9\u6cd5\u53d1\u751f\u4e86\u4ee5\u4e0b\u53d8\u5316\u3002

        • \u67e5\u8be2\u5143\u7d20\uff1a\u8f93\u5165 key \uff0c\u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u5f97\u5230\u6876\u7d22\u5f15\uff0c\u5373\u53ef\u8bbf\u95ee\u94fe\u8868\u5934\u8282\u70b9\uff0c\u7136\u540e\u904d\u5386\u94fe\u8868\u5e76\u5bf9\u6bd4 key \u4ee5\u67e5\u627e\u76ee\u6807\u952e\u503c\u5bf9\u3002
        • \u6dfb\u52a0\u5143\u7d20\uff1a\u9996\u5148\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u8bbf\u95ee\u94fe\u8868\u5934\u8282\u70b9\uff0c\u7136\u540e\u5c06\u8282\u70b9\uff08\u952e\u503c\u5bf9\uff09\u6dfb\u52a0\u5230\u94fe\u8868\u4e2d\u3002
        • \u5220\u9664\u5143\u7d20\uff1a\u6839\u636e\u54c8\u5e0c\u51fd\u6570\u7684\u7ed3\u679c\u8bbf\u95ee\u94fe\u8868\u5934\u90e8\uff0c\u63a5\u7740\u904d\u5386\u94fe\u8868\u4ee5\u67e5\u627e\u76ee\u6807\u8282\u70b9\u5e76\u5c06\u5176\u5220\u9664\u3002

        \u94fe\u5f0f\u5730\u5740\u5b58\u5728\u4ee5\u4e0b\u5c40\u9650\u6027\u3002

        • \u5360\u7528\u7a7a\u95f4\u589e\u5927\uff0c\u94fe\u8868\u5305\u542b\u8282\u70b9\u6307\u9488\uff0c\u5b83\u76f8\u6bd4\u6570\u7ec4\u66f4\u52a0\u8017\u8d39\u5185\u5b58\u7a7a\u95f4\u3002
        • \u67e5\u8be2\u6548\u7387\u964d\u4f4e\uff0c\u56e0\u4e3a\u9700\u8981\u7ebf\u6027\u904d\u5386\u94fe\u8868\u6765\u67e5\u627e\u5bf9\u5e94\u5143\u7d20\u3002

        \u4ee5\u4e0b\u4ee3\u7801\u7ed9\u51fa\u4e86\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\u7684\u7b80\u5355\u5b9e\u73b0\uff0c\u9700\u8981\u6ce8\u610f\u4e24\u70b9\u3002

        • \u4f7f\u7528\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\u4ee3\u66ff\u94fe\u8868\uff0c\u4ece\u800c\u7b80\u5316\u4ee3\u7801\u3002\u5728\u8fd9\u79cd\u8bbe\u5b9a\u4e0b\uff0c\u54c8\u5e0c\u8868\uff08\u6570\u7ec4\uff09\u5305\u542b\u591a\u4e2a\u6876\uff0c\u6bcf\u4e2a\u6876\u90fd\u662f\u4e00\u4e2a\u5217\u8868\u3002
        • \u4ee5\u4e0b\u5b9e\u73b0\u5305\u542b\u54c8\u5e0c\u8868\u6269\u5bb9\u65b9\u6cd5\u3002\u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7 \\(\\frac{2}{3}\\) \u65f6\uff0c\u6211\u4eec\u5c06\u54c8\u5e0c\u8868\u6269\u5bb9\u81f3\u539f\u5148\u7684 \\(2\\) \u500d\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map_chaining.py
        class HashMapChaining:\n\"\"\"\u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\nself.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\nself.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nself.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\nself.buckets = [[] for _ in range(self.capacity)]  # \u6876\u6570\u7ec4\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nreturn key % self.capacity\ndef load_factor(self) -> float:\n\"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\nreturn self.size / self.capacity\ndef get(self, key: int) -> str | None:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket:\nif pair.key == key:\nreturn pair.val\n# \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nreturn None\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n# \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres:\nself.extend()\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket:\nif pair.key == key:\npair.val = val\nreturn\n# \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\npair = Pair(key, val)\nbucket.append(pair)\nself.size += 1\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\nindex = self.hash_func(key)\nbucket = self.buckets[index]\n# \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor pair in bucket:\nif pair.key == key:\nbucket.remove(pair)\nself.size -= 1\nbreak\ndef extend(self):\n\"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n# \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nbuckets = self.buckets\n# \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio\nself.buckets = [[] for _ in range(self.capacity)]\nself.size = 0\n# \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in buckets:\nfor pair in bucket:\nself.put(pair.key, pair.val)\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor bucket in self.buckets:\nres = []\nfor pair in bucket:\nres.append(str(pair.key) + \" -> \" + pair.val)\nprint(res)\n
        hash_map_chaining.cpp
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nprivate:\nint size;                       // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;                   // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres;               // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;                // \u6269\u5bb9\u500d\u6570\nvector<vector<Pair *>> buckets; // \u6876\u6570\u7ec4\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) {\nbuckets.resize(capacity);\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~HashMapChaining() {\nfor (auto &bucket : buckets) {\nfor (Pair *pair : bucket) {\n// \u91ca\u653e\u5185\u5b58\ndelete pair;\n}\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double)size / (double)capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\nint index = hashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair *pair : buckets[index]) {\nif (pair->key == key) {\nreturn pair->val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair *pair : buckets[index]) {\nif (pair->key == key) {\npair->val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nbuckets[index].push_back(new Pair(key, val));\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nauto &bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (int i = 0; i < bucket.size(); i++) {\nif (bucket[i]->key == key) {\nPair *tmp = bucket[i];\nbucket.erase(bucket.begin() + i); // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\ndelete tmp;                       // \u91ca\u653e\u5185\u5b58\nsize--;\nreturn;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nvector<vector<Pair *>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets.clear();\nbuckets.resize(capacity);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (auto &bucket : bucketsTmp) {\nfor (Pair *pair : bucket) {\nput(pair->key, pair->val);\n// \u91ca\u653e\u5185\u5b58\ndelete pair;\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (auto &bucket : buckets) {\ncout << \"[\";\nfor (Pair *pair : bucket) {\ncout << pair->key << \" -> \" << pair->val << \", \";\n}\ncout << \"]\\n\";\n}\n}\n};\n
        hash_map_chaining.java
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio; // \u6269\u5bb9\u500d\u6570\nList<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = new ArrayList<>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.add(new ArrayList<>());\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double) size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString get(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair pair : bucket) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair pair : bucket) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nPair pair = new Pair(key, val);\nbucket.add(pair);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets.get(index);\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (Pair pair : bucket) {\nif (pair.key == key) {\nbucket.remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new ArrayList<>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.add(new ArrayList<>());\n}\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (List<Pair> bucket : bucketsTmp) {\nfor (Pair pair : bucket) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (List<Pair> bucket : buckets) {\nList<String> res = new ArrayList<>();\nfor (Pair pair : bucket) {\nres.add(pair.key + \" -> \" + pair.val);\n}\nSystem.out.println(res);\n}\n}\n}\n
        hash_map_chaining.cs
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio; // \u6269\u5bb9\u500d\u6570\nList<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = new List<List<Pair>>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.Add([]);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble LoadFactor() {\nreturn (double)size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nforeach (Pair pair in buckets[index]) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (LoadFactor() > loadThres) {\nExtend();\n}\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nforeach (Pair pair in buckets[index]) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nbuckets[index].Add(new Pair(key, val));\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\nint index = HashFunc(key);\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nforeach (Pair pair in buckets[index].ToList()) {\nif (pair.key == key) {\nbuckets[index].Remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid Extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new List<List<Pair>>(capacity);\nfor (int i = 0; i < capacity; i++) {\nbuckets.Add([]);\n}\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nforeach (List<Pair> bucket in bucketsTmp) {\nforeach (Pair pair in bucket) {\nPut(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (List<Pair> bucket in buckets) {\nList<string> res = [];\nforeach (Pair pair in bucket) {\nres.Add(pair.key + \" -> \" + pair.val);\n}\nforeach (string kv in res) {\nConsole.WriteLine(kv);\n}\n}\n}\n}\n
        hash_map_chaining.go
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntype hashMapChaining struct {\nsize        int      // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity    int      // \u54c8\u5e0c\u8868\u5bb9\u91cf\nloadThres   float64  // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextendRatio int      // \u6269\u5bb9\u500d\u6570\nbuckets     [][]pair // \u6876\u6570\u7ec4\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapChaining() *hashMapChaining {\nbuckets := make([][]pair, 4)\nfor i := 0; i < 4; i++ {\nbuckets[i] = make([]pair, 0)\n}\nreturn &hashMapChaining{\nsize:        0,\ncapacity:    4,\nloadThres:   2.0 / 3.0,\nextendRatio: 2,\nbuckets:     buckets,\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapChaining) hashFunc(key int) int {\nreturn key % m.capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapChaining) loadFactor() float64 {\nreturn float64(m.size / m.capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapChaining) get(key int) string {\nidx := m.hashFunc(key)\nbucket := m.buckets[idx]\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor _, p := range bucket {\nif p.key == key {\nreturn p.val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\"\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (m *hashMapChaining) put(key int, val string) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif m.loadFactor() > m.loadThres {\nm.extend()\n}\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor _, p := range m.buckets[idx] {\nif p.key == key {\np.val = val\nreturn\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\np := pair{\nkey: key,\nval: val,\n}\nm.buckets[idx] = append(m.buckets[idx], p)\nm.size += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapChaining) remove(key int) {\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor i, p := range m.buckets[idx] {\nif p.key == key {\n// \u5207\u7247\u5220\u9664\nm.buckets[idx] = append(m.buckets[idx][:i], m.buckets[idx][i+1:]...)\nm.size -= 1\nbreak\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\ntmpBuckets := make([][]pair, len(m.buckets))\nfor i := 0; i < len(m.buckets); i++ {\ntmpBuckets[i] = make([]pair, len(m.buckets[i]))\ncopy(tmpBuckets[i], m.buckets[i])\n}\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nm.capacity *= m.extendRatio\nm.buckets = make([][]pair, m.capacity)\nfor i := 0; i < m.capacity; i++ {\nm.buckets[i] = make([]pair, 0)\n}\nm.size = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor _, bucket := range tmpBuckets {\nfor _, p := range bucket {\nm.put(p.key, p.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) print() {\nvar builder strings.Builder\nfor _, bucket := range m.buckets {\nbuilder.WriteString(\"[\")\nfor _, p := range bucket {\nbuilder.WriteString(strconv.Itoa(p.key) + \" -> \" + p.val + \" \")\n}\nbuilder.WriteString(\"]\")\nfmt.Println(builder.String())\nbuilder.Reset()\n}\n}\n
        hash_map_chaining.swift
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nvar size: Int // \u952e\u503c\u5bf9\u6570\u91cf\nvar capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\nvar loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nvar extendRatio: Int // \u6269\u5bb9\u500d\u6570\nvar buckets: [[Pair]] // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\nsize = 0\ncapacity = 4\nloadThres = 2.0 / 3.0\nextendRatio = 2\nbuckets = Array(repeating: [], count: capacity)\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc hashFunc(key: Int) -> Int {\nkey % capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc loadFactor() -> Double {\nDouble(size / capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket {\nif pair.key == key {\nreturn pair.val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de nil\nreturn nil\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif loadFactor() > loadThres {\nextend()\n}\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket {\nif pair.key == key {\npair.val = val\nreturn\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nlet pair = Pair(key: key, val: val)\nbuckets[index].append(pair)\nsize += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\nlet index = hashFunc(key: key)\nlet bucket = buckets[index]\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (pairIndex, pair) in bucket.enumerated() {\nif pair.key == key {\nbuckets[index].remove(at: pairIndex)\n}\n}\nsize -= 1\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet bucketsTmp = buckets\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio\nbuckets = Array(repeating: [], count: capacity)\nsize = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in bucketsTmp {\nfor pair in bucket {\nput(key: pair.key, val: pair.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor bucket in buckets {\nlet res = bucket.map { \"\\($0.key) -> \\($0.val)\" }\nSwift.print(res)\n}\n}\n}\n
        hash_map_chaining.js
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n#size; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio; // \u6269\u5bb9\u500d\u6570\n#buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0;\nthis.#capacity = 4;\nthis.#loadThres = 2.0 / 3.0;\nthis.#extendRatio = 2;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor() {\nreturn this.#size / this.#capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (const pair of bucket) {\nif (pair.key === key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key, val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (const pair of bucket) {\nif (pair.key === key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nconst pair = new Pair(key, val);\nbucket.push(pair);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key) {\nconst index = this.#hashFunc(key);\nlet bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (let i = 0; i < bucket.length; i++) {\nif (bucket[i].key === key) {\nbucket.splice(i, 1);\nthis.#size--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const bucket of bucketsTmp) {\nfor (const pair of bucket) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nfor (const bucket of this.#buckets) {\nlet res = [];\nfor (const pair of bucket) {\nres.push(pair.key + ' -> ' + pair.val);\n}\nconsole.log(res);\n}\n}\n}\n
        hash_map_chaining.ts
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n#size: number; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio: number; // \u6269\u5bb9\u500d\u6570\n#buckets: Pair[][]; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0;\nthis.#capacity = 4;\nthis.#loadThres = 2.0 / 3.0;\nthis.#extendRatio = 2;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key: number): number {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor(): number {\nreturn this.#size / this.#capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key: number): string | null {\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (const pair of bucket) {\nif (pair.key === key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key: number, val: string): void {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\nconst index = this.#hashFunc(key);\nconst bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (const pair of bucket) {\nif (pair.key === key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nconst pair = new Pair(key, val);\nbucket.push(pair);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key: number): void {\nconst index = this.#hashFunc(key);\nlet bucket = this.#buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (let i = 0; i < bucket.length; i++) {\nif (bucket[i].key === key) {\nbucket.splice(i, 1);\nthis.#size--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend(): void {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const bucket of bucketsTmp) {\nfor (const pair of bucket) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint(): void {\nfor (const bucket of this.#buckets) {\nlet res = [];\nfor (const pair of bucket) {\nres.push(pair.key + ' -> ' + pair.val);\n}\nconsole.log(res);\n}\n}\n}\n
        hash_map_chaining.dart
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\nlate int size; // \u952e\u503c\u5bf9\u6570\u91cf\nlate int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nlate double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nlate int extendRatio; // \u6269\u5bb9\u500d\u6570\nlate List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapChaining() {\nsize = 0;\ncapacity = 4;\nloadThres = 2.0 / 3.0;\nextendRatio = 2;\nbuckets = List.generate(capacity, (_) => []);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn size / capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor (Pair pair in bucket) {\nif (pair.key == key) {\nreturn pair.val;\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor (Pair pair in bucket) {\nif (pair.key == key) {\npair.val = val;\nreturn;\n}\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nPair pair = Pair(key, val);\nbucket.add(pair);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\nList<Pair> bucket = buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor (Pair pair in bucket) {\nif (pair.key == key) {\nbucket.remove(pair);\nsize--;\nbreak;\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<List<Pair>> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = List.generate(capacity, (_) => []);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (List<Pair> bucket in bucketsTmp) {\nfor (Pair pair in bucket) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (List<Pair> bucket in buckets) {\nList<String> res = [];\nfor (Pair pair in bucket) {\nres.add(\"${pair.key} -> ${pair.val}\");\n}\nprint(res);\n}\n}\n}\n
        hash_map_chaining.rs
        /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapChaining {\nsize: i32,\ncapacity: i32,\nload_thres: f32,\nextend_ratio: i32,\nbuckets: Vec<Vec<Pair>>,\n}\nimpl HashMapChaining {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new() -> Self {\nSelf {\nsize: 0,\ncapacity: 4,\nload_thres: 2.0 / 3.0,\nextend_ratio: 2,\nbuckets: vec![vec![]; 4],\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\nkey as usize % self.capacity as usize\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfn load_factor(&self) -> f32 {\nself.size as f32 / self.capacity as f32\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfn remove(&mut self, key: i32) -> Option<String> {\nlet index = self.hash_func(key);\nlet bucket = &mut self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nfor i in 0..bucket.len() {\nif bucket[i].key == key {\nlet pair = bucket.remove(i);\nself.size -= 1;\nreturn Some(pair.val);\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nNone\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfn extend(&mut self) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet buckets_tmp = std::mem::replace(&mut self.buckets, vec![]);\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio;\nself.buckets = vec![Vec::new(); self.capacity as usize];\nself.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor bucket in buckets_tmp {\nfor pair in bucket {\nself.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfn print(&self) {\nfor bucket in &self.buckets {\nlet mut res = Vec::new();\nfor pair in bucket {\nres.push(format!(\"{} -> {}\", pair.key, pair.val));\n}\nprintln!(\"{:?}\", res);\n}\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfn put(&mut self, key: i32, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres {\nself.extend();\n}\nlet index = self.hash_func(key);\nlet bucket = &mut self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nfor pair in bucket {\nif pair.key == key {\npair.val = val.clone();\nreturn;\n}\n}\nlet bucket = &mut self.buckets[index];\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\nlet pair = Pair {\nkey,\nval: val.clone(),\n};\nbucket.push(pair);\nself.size += 1;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfn get(&self, key: i32) -> Option<&str> {\nlet index = self.hash_func(key);\nlet bucket = &self.buckets[index];\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nfor pair in bucket {\nif pair.key == key {\nreturn Some(&pair.val);\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de None\nNone\n}\n}\n
        hash_map_chaining.c
        /* \u94fe\u8868\u8282\u70b9 */\ntypedef struct Node {\nPair *pair;\nstruct Node *next;\n} Node;\n/* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\nint size;         // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;  // \u6269\u5bb9\u500d\u6570\nNode **buckets;   // \u6876\u6570\u7ec4\n} HashMapChaining;\n/* \u6784\u9020\u51fd\u6570 */\nHashMapChaining *newHashMapChaining() {\nHashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));\nhashMap->size = 0;\nhashMap->capacity = 4;\nhashMap->loadThres = 2.0 / 3.0;\nhashMap->extendRatio = 2;\nhashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\nfor (int i = 0; i < hashMap->capacity; i++) {\nhashMap->buckets[i] = NULL;\n}\nreturn hashMap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapChaining(HashMapChaining *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nNode *cur = hashMap->buckets[i];\nwhile (cur) {\nNode *tmp = cur;\ncur = cur->next;\nfree(tmp->pair);\nfree(tmp);\n}\n}\nfree(hashMap->buckets);\nfree(hashMap);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapChaining *hashMap, int key) {\nreturn key % hashMap->capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapChaining *hashMap) {\nreturn (double)hashMap->size / (double)hashMap->capacity;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapChaining *hashMap, int key) {\nint index = hashFunc(hashMap, key);\n// \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \u5219\u8fd4\u56de\u5bf9\u5e94 val\nNode *cur = hashMap->buckets[index];\nwhile (cur) {\nif (cur->pair->key == key) {\nreturn cur->pair->val;\n}\ncur = cur->next;\n}\nreturn \"\"; // \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(HashMapChaining *hashMap, int key, const char *val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor(hashMap) > hashMap->loadThres) {\nextend(hashMap);\n}\nint index = hashFunc(hashMap, key);\n// \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nNode *cur = hashMap->buckets[index];\nwhile (cur) {\nif (cur->pair->key == key) {\nstrcpy(cur->pair->val, val); // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\nreturn;\n}\ncur = cur->next;\n}\n// \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nPair *newPair = (Pair *)malloc(sizeof(Pair));\nnewPair->key = key;\nstrcpy(newPair->val, val);\nNode *newNode = (Node *)malloc(sizeof(Node));\nnewNode->pair = newPair;\nnewNode->next = hashMap->buckets[index];\nhashMap->buckets[index] = newNode;\nhashMap->size++;\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapChaining *hashMap) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nint oldCapacity = hashMap->capacity;\nNode **oldBuckets = hashMap->buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nhashMap->capacity *= hashMap->extendRatio;\nhashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\nfor (int i = 0; i < hashMap->capacity; i++) {\nhashMap->buckets[i] = NULL;\n}\nhashMap->size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (int i = 0; i < oldCapacity; i++) {\nNode *cur = oldBuckets[i];\nwhile (cur) {\nput(hashMap, cur->pair->key, cur->pair->val);\nNode *temp = cur;\ncur = cur->next;\n// \u91ca\u653e\u5185\u5b58\nfree(temp->pair);\nfree(temp);\n}\n}\nfree(oldBuckets);\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapChaining *hashMap, int key) {\nint index = hashFunc(hashMap, key);\nNode *cur = hashMap->buckets[index];\nNode *pre = NULL;\nwhile (cur) {\nif (cur->pair->key == key) {\n// \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\nif (pre) {\npre->next = cur->next;\n} else {\nhashMap->buckets[index] = cur->next;\n}\n// \u91ca\u653e\u5185\u5b58\nfree(cur->pair);\nfree(cur);\nhashMap->size--;\nreturn;\n}\npre = cur;\ncur = cur->next;\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapChaining *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nNode *cur = hashMap->buckets[i];\nprintf(\"[\");\nwhile (cur) {\nprintf(\"%d -> %s, \", cur->pair->key, cur->pair->val);\ncur = cur->next;\n}\nprintf(\"]\\n\");\n}\n}\n
        hash_map_chaining.zig
        [class]{HashMapChaining}-[func]{}\n

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u94fe\u8868\u5f88\u957f\u65f6\uff0c\u67e5\u8be2\u6548\u7387 \\(O(n)\\) \u5f88\u5dee\u3002\u6b64\u65f6\u53ef\u4ee5\u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u201cAVL \u6811\u201d\u6216\u201c\u7ea2\u9ed1\u6811\u201d\uff0c\u4ece\u800c\u5c06\u67e5\u8be2\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(\\log n)\\) \u3002

        "},{"location":"chapter_hashing/hash_collision/#622","title":"6.2.2 \u00a0 \u5f00\u653e\u5bfb\u5740","text":"

        \u300c\u5f00\u653e\u5bfb\u5740 open addressing\u300d\u4e0d\u5f15\u5165\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\uff0c\u800c\u662f\u901a\u8fc7\u201c\u591a\u6b21\u63a2\u6d4b\u201d\u6765\u5904\u7406\u54c8\u5e0c\u51b2\u7a81\uff0c\u63a2\u6d4b\u65b9\u5f0f\u4e3b\u8981\u5305\u62ec\u7ebf\u6027\u63a2\u6d4b\u3001\u5e73\u65b9\u63a2\u6d4b\u3001\u591a\u6b21\u54c8\u5e0c\u7b49\u3002

        \u4e0b\u9762\u4ee5\u7ebf\u6027\u63a2\u6d4b\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\u7684\u5de5\u4f5c\u673a\u5236\u3002

        "},{"location":"chapter_hashing/hash_collision/#1","title":"1. \u00a0 \u7ebf\u6027\u63a2\u6d4b","text":"

        \u7ebf\u6027\u63a2\u6d4b\u91c7\u7528\u56fa\u5b9a\u6b65\u957f\u7684\u7ebf\u6027\u641c\u7d22\u6765\u8fdb\u884c\u63a2\u6d4b\uff0c\u5176\u64cd\u4f5c\u65b9\u6cd5\u4e0e\u666e\u901a\u54c8\u5e0c\u8868\u6709\u6240\u4e0d\u540c\u3002

        • \u63d2\u5165\u5143\u7d20\uff1a\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u82e5\u53d1\u73b0\u6876\u5185\u5df2\u6709\u5143\u7d20\uff0c\u5219\u4ece\u51b2\u7a81\u4f4d\u7f6e\u5411\u540e\u7ebf\u6027\u904d\u5386\uff08\u6b65\u957f\u901a\u5e38\u4e3a \\(1\\) \uff09\uff0c\u76f4\u81f3\u627e\u5230\u7a7a\u6876\uff0c\u5c06\u5143\u7d20\u63d2\u5165\u5176\u4e2d\u3002
        • \u67e5\u627e\u5143\u7d20\uff1a\u82e5\u53d1\u73b0\u54c8\u5e0c\u51b2\u7a81\uff0c\u5219\u4f7f\u7528\u76f8\u540c\u6b65\u957f\u5411\u540e\u7ebf\u6027\u904d\u5386\uff0c\u76f4\u5230\u627e\u5230\u5bf9\u5e94\u5143\u7d20\uff0c\u8fd4\u56de value \u5373\u53ef\uff1b\u5982\u679c\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u76ee\u6807\u5143\u7d20\u4e0d\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u8fd4\u56de \\(\\text{None}\\) \u3002

        \u56fe 6-6 \u5c55\u793a\u4e86\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u7684\u952e\u503c\u5bf9\u5206\u5e03\u3002\u6839\u636e\u6b64\u54c8\u5e0c\u51fd\u6570\uff0c\u6700\u540e\u4e24\u4f4d\u76f8\u540c\u7684 key \u90fd\u4f1a\u88ab\u6620\u5c04\u5230\u76f8\u540c\u7684\u6876\u3002\u800c\u901a\u8fc7\u7ebf\u6027\u63a2\u6d4b\uff0c\u5b83\u4eec\u88ab\u4f9d\u6b21\u5b58\u50a8\u5728\u8be5\u6876\u4ee5\u53ca\u4e4b\u4e0b\u7684\u6876\u4e2d\u3002

        \u56fe 6-6 \u00a0 \u5f00\u653e\u5bfb\u5740\u548c\u7ebf\u6027\u63a2\u6d4b

        \u7136\u800c\uff0c\u7ebf\u6027\u63a2\u6d4b\u5bb9\u6613\u4ea7\u751f\u201c\u805a\u96c6\u73b0\u8c61\u201d\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6570\u7ec4\u4e2d\u8fde\u7eed\u88ab\u5360\u7528\u7684\u4f4d\u7f6e\u8d8a\u957f\uff0c\u8fd9\u4e9b\u8fde\u7eed\u4f4d\u7f6e\u53d1\u751f\u54c8\u5e0c\u51b2\u7a81\u7684\u53ef\u80fd\u6027\u8d8a\u5927\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u4fc3\u4f7f\u8be5\u4f4d\u7f6e\u7684\u805a\u5806\u751f\u957f\uff0c\u5f62\u6210\u6076\u6027\u5faa\u73af\uff0c\u6700\u7ec8\u5bfc\u81f4\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u6548\u7387\u52a3\u5316\u3002

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\u4e2d\u76f4\u63a5\u5220\u9664\u5143\u7d20\u3002\u8fd9\u662f\u56e0\u4e3a\u5220\u9664\u5143\u7d20\u4f1a\u5728\u6570\u7ec4\u5185\u4ea7\u751f\u4e00\u4e2a\u7a7a\u6876 \\(\\text{None}\\) \uff0c\u800c\u5f53\u67e5\u8be2\u5143\u7d20\u65f6\uff0c\u7ebf\u6027\u63a2\u6d4b\u5230\u8be5\u7a7a\u6876\u5c31\u4f1a\u8fd4\u56de\uff0c\u56e0\u6b64\u5728\u8be5\u7a7a\u6876\u4e4b\u4e0b\u7684\u5143\u7d20\u90fd\u65e0\u6cd5\u518d\u88ab\u8bbf\u95ee\u5230\uff0c\u7a0b\u5e8f\u53ef\u80fd\u8bef\u5224\u8fd9\u4e9b\u5143\u7d20\u4e0d\u5b58\u5728\u3002

        \u56fe 6-7 \u00a0 \u5728\u5f00\u653e\u5bfb\u5740\u4e2d\u5220\u9664\u5143\u7d20\u5bfc\u81f4\u7684\u67e5\u8be2\u95ee\u9898

        \u4e3a\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u300c\u61d2\u5220\u9664 lazy deletion\u300d\u673a\u5236\uff1a\u5b83\u4e0d\u76f4\u63a5\u4ece\u54c8\u5e0c\u8868\u4e2d\u79fb\u9664\u5143\u7d20\uff0c\u800c\u662f\u5229\u7528\u4e00\u4e2a\u5e38\u91cf TOMBSTONE \u6765\u6807\u8bb0\u8fd9\u4e2a\u6876\u3002\u5728\u8be5\u673a\u5236\u4e0b\uff0c\\(\\text{None}\\) \u548c TOMBSTONE \u90fd\u4ee3\u8868\u7a7a\u6876\uff0c\u90fd\u53ef\u4ee5\u653e\u7f6e\u952e\u503c\u5bf9\u3002\u4f46\u4e0d\u540c\u7684\u662f\uff0c\u7ebf\u6027\u63a2\u6d4b\u5230 TOMBSTONE \u65f6\u5e94\u8be5\u7ee7\u7eed\u904d\u5386\uff0c\u56e0\u4e3a\u5176\u4e4b\u4e0b\u53ef\u80fd\u8fd8\u5b58\u5728\u952e\u503c\u5bf9\u3002

        \u7136\u800c\uff0c\u61d2\u5220\u9664\u53ef\u80fd\u4f1a\u52a0\u901f\u54c8\u5e0c\u8868\u7684\u6027\u80fd\u9000\u5316\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u6b21\u5220\u9664\u64cd\u4f5c\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5220\u9664\u6807\u8bb0\uff0c\u968f\u7740 TOMBSTONE \u7684\u589e\u52a0\uff0c\u641c\u7d22\u65f6\u95f4\u4e5f\u4f1a\u589e\u52a0\uff0c\u56e0\u4e3a\u7ebf\u6027\u63a2\u6d4b\u53ef\u80fd\u9700\u8981\u8df3\u8fc7\u591a\u4e2a TOMBSTONE \u624d\u80fd\u627e\u5230\u76ee\u6807\u5143\u7d20\u3002

        \u4e3a\u6b64\uff0c\u8003\u8651\u5728\u7ebf\u6027\u63a2\u6d4b\u4e2d\u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a TOMBSTONE \u7684\u7d22\u5f15\uff0c\u5e76\u5c06\u641c\u7d22\u5230\u7684\u76ee\u6807\u5143\u7d20\u4e0e\u8be5 TOMBSTONE \u4ea4\u6362\u4f4d\u7f6e\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u5f53\u6bcf\u6b21\u67e5\u8be2\u6216\u6dfb\u52a0\u5143\u7d20\u65f6\uff0c\u5143\u7d20\u4f1a\u88ab\u79fb\u52a8\u81f3\u8ddd\u79bb\u7406\u60f3\u4f4d\u7f6e\uff08\u63a2\u6d4b\u8d77\u59cb\u70b9\uff09\u66f4\u8fd1\u7684\u6876\uff0c\u4ece\u800c\u4f18\u5316\u67e5\u8be2\u6548\u7387\u3002

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5305\u542b\u61d2\u5220\u9664\u7684\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u3002\u4e3a\u4e86\u66f4\u52a0\u5145\u5206\u5730\u4f7f\u7528\u54c8\u5e0c\u8868\u7684\u7a7a\u95f4\uff0c\u6211\u4eec\u5c06\u54c8\u5e0c\u8868\u770b\u4f5c\u4e00\u4e2a\u201c\u73af\u5f62\u6570\u7ec4\u201d\uff0c\u5f53\u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u56de\u5230\u5934\u90e8\u7ee7\u7eed\u904d\u5386\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map_open_addressing.py
        class HashMapOpenAddressing:\n\"\"\"\u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\nself.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\nself.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nself.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\nself.buckets: list[Pair | None] = [None] * self.capacity  # \u6876\u6570\u7ec4\nself.TOMBSTONE = Pair(-1, \"-1\")  # \u5220\u9664\u6807\u8bb0\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nreturn key % self.capacity\ndef load_factor(self) -> float:\n\"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\nreturn self.size / self.capacity\ndef find_bucket(self, key: int) -> int:\n\"\"\"\u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\"\"\"\nindex = self.hash_func(key)\nfirst_tombstone = -1\n# \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile self.buckets[index] is not None:\n# \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif self.buckets[index].key == key:\n# \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif first_tombstone != -1:\nself.buckets[first_tombstone] = self.buckets[index]\nself.buckets[index] = self.TOMBSTONE\nreturn first_tombstone  # \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\nreturn index  # \u8fd4\u56de\u6876\u7d22\u5f15\n# \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif first_tombstone == -1 and self.buckets[index] is self.TOMBSTONE:\nfirst_tombstone = index\n# \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % self.capacity\n# \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn index if first_tombstone == -1 else first_tombstone\ndef get(self, key: int) -> str:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nreturn self.buckets[index].val\n# \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de None\nreturn None\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n# \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres:\nself.extend()\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nself.buckets[index].val = val\nreturn\n# \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nself.buckets[index] = Pair(key, val)\nself.size += 1\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n# \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nindex = self.find_bucket(key)\n# \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif self.buckets[index] not in [None, self.TOMBSTONE]:\nself.buckets[index] = self.TOMBSTONE\nself.size -= 1\ndef extend(self):\n\"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n# \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nbuckets_tmp = self.buckets\n# \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio\nself.buckets = [None] * self.capacity\nself.size = 0\n# \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in buckets_tmp:\nif pair not in [None, self.TOMBSTONE]:\nself.put(pair.key, pair.val)\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor pair in self.buckets:\nif pair is None:\nprint(\"None\")\nelif pair is self.TOMBSTONE:\nprint(\"TOMBSTONE\")\nelse:\nprint(pair.key, \"->\", pair.val)\n
        hash_map_open_addressing.cpp
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate:\nint size;                             // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity = 4;                     // \u54c8\u5e0c\u8868\u5bb9\u91cf\nconst double loadThres = 2.0 / 3.0;     // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nconst int extendRatio = 2;            // \u6269\u5bb9\u500d\u6570\nvector<Pair *> buckets;               // \u6876\u6570\u7ec4\nPair *TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapOpenAddressing() : size(0), buckets(capacity, nullptr) {\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~HashMapOpenAddressing() {\nfor (Pair *pair : buckets) {\nif (pair != nullptr && pair != TOMBSTONE) {\ndelete pair;\n}\n}\ndelete TOMBSTONE;\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn (double)size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != nullptr) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index]->key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\nreturn buckets[index]->val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\nbuckets[index]->val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\ndelete buckets[index];\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nvector<Pair *> bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = vector<Pair *>(capacity, nullptr);\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair *pair : bucketsTmp) {\nif (pair != nullptr && pair != TOMBSTONE) {\nput(pair->key, pair->val);\ndelete pair;\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (Pair *pair : buckets) {\nif (pair == nullptr) {\ncout << \"nullptr\" << endl;\n} else if (pair == TOMBSTONE) {\ncout << \"TOMBSTONE\" << endl;\n} else {\ncout << pair->key << \" -> \" << pair->val << endl;\n}\n}\n}\n};\n
        hash_map_open_addressing.java
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate int size; // \u952e\u503c\u5bf9\u6570\u91cf\nprivate int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nprivate final double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nprivate final int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nprivate Pair[] buckets; // \u6876\u6570\u7ec4\nprivate final Pair TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapOpenAddressing() {\nsize = 0;\nbuckets = new Pair[capacity];\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate int hashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nprivate double loadFactor() {\nreturn (double) size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nprivate int findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index].key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic String get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nreturn buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nprivate void extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair[] bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new Pair[capacity];\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair pair : bucketsTmp) {\nif (pair != null && pair != TOMBSTONE) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void print() {\nfor (Pair pair : buckets) {\nif (pair == null) {\nSystem.out.println(\"null\");\n} else if (pair == TOMBSTONE) {\nSystem.out.println(\"TOMBSTONE\");\n} else {\nSystem.out.println(pair.key + \" -> \" + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.cs
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nint size; // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nPair[] buckets; // \u6876\u6570\u7ec4\nPair TOMBSTONE = new(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\npublic HashMapOpenAddressing() {\nsize = 0;\nbuckets = new Pair[capacity];\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nreturn key % capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble LoadFactor() {\nreturn (double)size / capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint FindBucket(int key) {\nint index = HashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (buckets[index].key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nbuckets[firstTombstone] = buckets[index];\nbuckets[index] = TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nreturn buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (LoadFactor() > loadThres) {\nExtend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = new Pair(key, val);\nsize++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = FindBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (buckets[index] != null && buckets[index] != TOMBSTONE) {\nbuckets[index] = TOMBSTONE;\nsize--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid Extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair[] bucketsTmp = buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio;\nbuckets = new Pair[capacity];\nsize = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nforeach (Pair pair in bucketsTmp) {\nif (pair != null && pair != TOMBSTONE) {\nPut(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (Pair pair in buckets) {\nif (pair == null) {\nConsole.WriteLine(\"null\");\n} else if (pair == TOMBSTONE) {\nConsole.WriteLine(\"TOMBSTONE\");\n} else {\nConsole.WriteLine(pair.key + \" -> \" + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.go
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntype hashMapOpenAddressing struct {\nsize        int     // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity    int     // \u54c8\u5e0c\u8868\u5bb9\u91cf\nloadThres   float64 // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextendRatio int     // \u6269\u5bb9\u500d\u6570\nbuckets     []pair  // \u6876\u6570\u7ec4\nremoved     pair    // \u5220\u9664\u6807\u8bb0\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapOpenAddressing() *hashMapOpenAddressing {\nbuckets := make([]pair, 4)\nreturn &hashMapOpenAddressing{\nsize:        0,\ncapacity:    4,\nloadThres:   2.0 / 3.0,\nextendRatio: 2,\nbuckets:     buckets,\nremoved: pair{\nkey: -1,\nval: \"-1\",\n},\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapOpenAddressing) hashFunc(key int) int {\nreturn key % m.capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapOpenAddressing) loadFactor() float64 {\nreturn float64(m.size) / float64(m.capacity)\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) get(key int) string {\nidx := m.hashFunc(key)\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u8fd4\u56de null\nif m.buckets[j] == (pair{}) {\nreturn \"\"\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif m.buckets[j].key == key && m.buckets[j] != m.removed {\nreturn m.buckets[j].val\n}\n}\n// \u82e5\u672a\u627e\u5230 key \u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\"\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) put(key int, val string) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif m.loadFactor() > m.loadThres {\nm.extend()\n}\nidx := m.hashFunc(key)\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\u3001\u6216\u5e26\u6709\u5220\u9664\u6807\u8bb0\u7684\u6876\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u653e\u5165\u8be5\u6876\nif m.buckets[j] == (pair{}) || m.buckets[j] == m.removed {\nm.buckets[j] = pair{\nkey: key,\nval: val,\n}\nm.size += 1\nreturn\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val\nif m.buckets[j].key == key {\nm.buckets[j].val = val\n}\n}\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) remove(key int) {\nidx := m.hashFunc(key)\n// \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\nfor i := 0; i < m.capacity; i++ {\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nj := (idx + i) % m.capacity\n// \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif m.buckets[j] == (pair{}) {\nreturn\n}\n// \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u6807\u8bb0\u5220\u9664\u5e76\u8fd4\u56de\nif m.buckets[j].key == key {\nm.buckets[j] = m.removed\nm.size -= 1\n}\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\ntmpBuckets := make([]pair, len(m.buckets))\ncopy(tmpBuckets, m.buckets)\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nm.capacity *= m.extendRatio\nm.buckets = make([]pair, m.capacity)\nm.size = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor _, p := range tmpBuckets {\nif p != (pair{}) && p != m.removed {\nm.put(p.key, p.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) print() {\nfor _, p := range m.buckets {\nif p != (pair{}) {\nfmt.Println(strconv.Itoa(p.key) + \" -> \" + p.val)\n} else {\nfmt.Println(\"nil\")\n}\n}\n}\n
        hash_map_open_addressing.swift
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nvar size: Int // \u952e\u503c\u5bf9\u6570\u91cf\nvar capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\nvar loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nvar extendRatio: Int // \u6269\u5bb9\u500d\u6570\nvar buckets: [Pair?] // \u6876\u6570\u7ec4\nvar TOMBSTONE: Pair // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\ninit() {\nsize = 0\ncapacity = 4\nloadThres = 2.0 / 3.0\nextendRatio = 2\nbuckets = Array(repeating: nil, count: capacity)\nTOMBSTONE = Pair(key: -1, val: \"-1\")\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc hashFunc(key: Int) -> Int {\nkey % capacity\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc loadFactor() -> Double {\nDouble(size / capacity)\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nfunc findBucket(key: Int) -> Int {\nvar index = hashFunc(key: key)\nvar firstTombstone = -1\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile buckets[index] != nil {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif buckets[index]!.key == key {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif firstTombstone != -1 {\nbuckets[firstTombstone] = buckets[index]\nbuckets[index] = TOMBSTONE\nreturn firstTombstone // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif firstTombstone == -1 && buckets[index] == TOMBSTONE {\nfirstTombstone = index\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % capacity\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nreturn buckets[index]!.val\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn nil\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif loadFactor() > loadThres {\nextend()\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nbuckets[index]!.val = val\nreturn\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nbuckets[index] = Pair(key: key, val: val)\nsize += 1\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = findBucket(key: key)\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif buckets[index] != nil, buckets[index] != TOMBSTONE {\nbuckets[index] = TOMBSTONE\nsize -= 1\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet bucketsTmp = buckets\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\ncapacity *= extendRatio\nbuckets = Array(repeating: nil, count: capacity)\nsize = 0\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in bucketsTmp {\nif let pair, pair != TOMBSTONE {\nput(key: pair.key, val: pair.val)\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor pair in buckets {\nif pair == nil {\nSwift.print(\"null\")\n} else if pair == TOMBSTONE {\nSwift.print(\"TOMBSTONE\")\n} else {\nSwift.print(\"\\(pair!.key) -> \\(pair!.val)\")\n}\n}\n}\n}\n
        hash_map_open_addressing.js
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n#size; // \u952e\u503c\u5bf9\u6570\u91cf\n#capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n#loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n#extendRatio; // \u6269\u5bb9\u500d\u6570\n#buckets; // \u6876\u6570\u7ec4\n#TOMBSTONE; // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.#size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\nthis.#capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nthis.#loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nthis.#extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nthis.#buckets = Array(this.#capacity).fill(null); // \u6876\u6570\u7ec4\nthis.#TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % this.#capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\n#loadFactor() {\nreturn this.#size / this.#capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n#findBucket(key) {\nlet index = this.#hashFunc(key);\nlet firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (this.#buckets[index] !== null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (this.#buckets[index].key === key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone !== -1) {\nthis.#buckets[firstTombstone] = this.#buckets[index];\nthis.#buckets[index] = this.#TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (\nfirstTombstone === -1 &&\nthis.#buckets[index] === this.#TOMBSTONE\n) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % this.#capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone === -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nreturn this.#buckets[index].val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key, val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.#loadFactor() > this.#loadThres) {\nthis.#extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nthis.#buckets[index].val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nthis.#buckets[index] = new Pair(key, val);\nthis.#size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.#findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (\nthis.#buckets[index] !== null &&\nthis.#buckets[index] !== this.#TOMBSTONE\n) {\nthis.#buckets[index] = this.#TOMBSTONE;\nthis.#size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n#extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.#buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.#capacity *= this.#extendRatio;\nthis.#buckets = Array(this.#capacity).fill(null);\nthis.#size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const pair of bucketsTmp) {\nif (pair !== null && pair !== this.#TOMBSTONE) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nfor (const pair of this.#buckets) {\nif (pair === null) {\nconsole.log('null');\n} else if (pair === this.#TOMBSTONE) {\nconsole.log('TOMBSTONE');\n} else {\nconsole.log(pair.key + ' -> ' + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.ts
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nprivate size: number; // \u952e\u503c\u5bf9\u6570\u91cf\nprivate capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nprivate loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nprivate extendRatio: number; // \u6269\u5bb9\u500d\u6570\nprivate buckets: Array<Pair | null>; // \u6876\u6570\u7ec4\nprivate TOMBSTONE: Pair; // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor() {\nthis.size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\nthis.capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\nthis.loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nthis.extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nthis.buckets = Array(this.capacity).fill(null); // \u6876\u6570\u7ec4\nthis.TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate hashFunc(key: number): number {\nreturn key % this.capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nprivate loadFactor(): number {\nreturn this.size / this.capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nprivate findBucket(key: number): number {\nlet index = this.hashFunc(key);\nlet firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (this.buckets[index] !== null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (this.buckets[index]!.key === key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone !== -1) {\nthis.buckets[firstTombstone] = this.buckets[index];\nthis.buckets[index] = this.TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (\nfirstTombstone === -1 &&\nthis.buckets[index] === this.TOMBSTONE\n) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % this.capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone === -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key: number): string | null {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nreturn this.buckets[index]!.val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nput(key: number, val: string): void {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (this.loadFactor() > this.loadThres) {\nthis.extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nthis.buckets[index]!.val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nthis.buckets[index] = new Pair(key, val);\nthis.size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nremove(key: number): void {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nconst index = this.findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (\nthis.buckets[index] !== null &&\nthis.buckets[index] !== this.TOMBSTONE\n) {\nthis.buckets[index] = this.TOMBSTONE;\nthis.size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nprivate extend(): void {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nconst bucketsTmp = this.buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nthis.capacity *= this.extendRatio;\nthis.buckets = Array(this.capacity).fill(null);\nthis.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (const pair of bucketsTmp) {\nif (pair !== null && pair !== this.TOMBSTONE) {\nthis.put(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint(): void {\nfor (const pair of this.buckets) {\nif (pair === null) {\nconsole.log('null');\n} else if (pair === this.TOMBSTONE) {\nconsole.log('TOMBSTONE');\n} else {\nconsole.log(pair.key + ' -> ' + pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.dart
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\nlate int _size; // \u952e\u503c\u5bf9\u6570\u91cf\nint _capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble _loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint _extendRatio = 2; // \u6269\u5bb9\u500d\u6570\nlate List<Pair?> _buckets; // \u6876\u6570\u7ec4\nPair _TOMBSTONE = Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n/* \u6784\u9020\u65b9\u6cd5 */\nHashMapOpenAddressing() {\n_size = 0;\n_buckets = List.generate(_capacity, (index) => null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nreturn key % _capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor() {\nreturn _size / _capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(int key) {\nint index = hashFunc(key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (_buckets[index] != null) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (_buckets[index]!.key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\n_buckets[firstTombstone] = _buckets[index];\n_buckets[index] = _TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && _buckets[index] == _TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % _capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\nreturn _buckets[index]!.val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nreturn null;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor() > _loadThres) {\nextend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n_buckets[index]!.val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n_buckets[index] = new Pair(key, val);\n_size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n_buckets[index] = _TOMBSTONE;\n_size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend() {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nList<Pair?> bucketsTmp = _buckets;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n_capacity *= _extendRatio;\n_buckets = List.generate(_capacity, (index) => null);\n_size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (Pair? pair in bucketsTmp) {\nif (pair != null && pair != _TOMBSTONE) {\nput(pair.key, pair.val);\n}\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (Pair? pair in _buckets) {\nif (pair == null) {\nprint(\"null\");\n} else if (pair == _TOMBSTONE) {\nprint(\"TOMBSTONE\");\n} else {\nprint(\"${pair.key} -> ${pair.val}\");\n}\n}\n}\n}\n
        hash_map_open_addressing.rs
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapOpenAddressing {\nsize: usize,                    // \u952e\u503c\u5bf9\u6570\u91cf\ncapacity: usize,                // \u54c8\u5e0c\u8868\u5bb9\u91cf\nload_thres: f64,                // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nextend_ratio: usize,            // \u6269\u5bb9\u500d\u6570\nbuckets: Vec<Option<Pair>>,     // \u6876\u6570\u7ec4\nTOMBSTONE: Option<Pair>,        // \u5220\u9664\u6807\u8bb0\n}\nimpl HashMapOpenAddressing {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new() -> Self {\nSelf {\nsize: 0,\ncapacity: 4,\nload_thres: 2.0 / 3.0,\nextend_ratio: 2,\nbuckets: vec![None; 4],\nTOMBSTONE: Some(Pair {key: -1, val: \"-1\".to_string()}),\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\n(key % self.capacity as i32) as usize\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfn load_factor(&self) -> f64 {\nself.size as f64 / self.capacity as f64\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nfn find_bucket(&mut self, key: i32) -> usize {\nlet mut index = self.hash_func(key);\nlet mut first_tombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile self.buckets[index].is_some() {\n// \u82e5\u9047\u5230 key\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nif self.buckets[index].as_ref().unwrap().key == key {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u5efa\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif first_tombstone != -1 {\nself.buckets[first_tombstone as usize] = self.buckets[index].take();\nself.buckets[index] = self.TOMBSTONE.clone();\nreturn first_tombstone as usize;    // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index;   // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif first_tombstone == -1 && self.buckets[index] == self.TOMBSTONE {\nfirst_tombstone = index as i32;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % self.capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nif first_tombstone == -1 { index } else { first_tombstone as usize }\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfn get(&mut self, key: i32) -> Option<&str> {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nreturn self.buckets[index].as_ref().map(|pair| &pair.val as &str);\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\nNone\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfn put(&mut self, key: i32, val: String) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif self.load_factor() > self.load_thres {\nself.extend();\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nself.buckets[index].as_mut().unwrap().val = val;\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nself.buckets[index] = Some(Pair { key, val });\nself.size += 1;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfn remove(&mut self, key: i32) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nlet index = self.find_bucket(key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\nself.buckets[index] = self.TOMBSTONE.clone();\nself.size -= 1;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfn extend(&mut self) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nlet buckets_tmp = self.buckets.clone();\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nself.capacity *= self.extend_ratio;\nself.buckets = vec![None; self.capacity];\nself.size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor pair in buckets_tmp {\nif pair.is_none() || pair == self.TOMBSTONE {\ncontinue;\n}\nlet pair = pair.unwrap();\nself.put(pair.key, pair.val);\n}\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfn print(&self) {\nfor pair in &self.buckets {\nif pair.is_none() {\nprintln!(\"null\");\n} else if pair == &self.TOMBSTONE {\nprintln!(\"TOMBSTONE\");\n} else {\nlet pair = pair.as_ref().unwrap();\nprintln!(\"{} -> {}\", pair.key, pair.val);\n}\n}\n}\n}\n
        hash_map_open_addressing.c
        /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\nint size;         // \u952e\u503c\u5bf9\u6570\u91cf\nint capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\ndouble loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\nint extendRatio;  // \u6269\u5bb9\u500d\u6570\nPair **buckets;   // \u6876\u6570\u7ec4\nPair *TOMBSTONE;  // \u5220\u9664\u6807\u8bb0\n} HashMapOpenAddressing;\n/* \u6784\u9020\u51fd\u6570 */\nHashMapOpenAddressing *newHashMapOpenAddressing() {\nHashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));\nhashMap->size = 0;\nhashMap->capacity = 4;\nhashMap->loadThres = 2.0 / 3.0;\nhashMap->extendRatio = 2;\nhashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\nhashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));\nhashMap->TOMBSTONE->key = -1;\nhashMap->TOMBSTONE->val = \"-1\";\nreturn hashMap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nPair *pair = hashMap->buckets[i];\nif (pair != NULL && pair != hashMap->TOMBSTONE) {\nfree(pair->val);\nfree(pair);\n}\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapOpenAddressing *hashMap, int key) {\nreturn key % hashMap->capacity;\n}\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapOpenAddressing *hashMap) {\nreturn (double)hashMap->size / (double)hashMap->capacity;\n}\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(HashMapOpenAddressing *hashMap, int key) {\nint index = hashFunc(hashMap, key);\nint firstTombstone = -1;\n// \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\nwhile (hashMap->buckets[index] != NULL) {\n// \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u6876\u7d22\u5f15\nif (hashMap->buckets[index]->key == key) {\n// \u82e5\u4e4b\u524d\u9047\u5230\u4e86\u5220\u9664\u6807\u8bb0\uff0c\u5219\u5c06\u952e\u503c\u5bf9\u79fb\u52a8\u81f3\u8be5\u7d22\u5f15\nif (firstTombstone != -1) {\nhashMap->buckets[firstTombstone] = hashMap->buckets[index];\nhashMap->buckets[index] = hashMap->TOMBSTONE;\nreturn firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n}\nreturn index; // \u8fd4\u56de\u6876\u7d22\u5f15\n}\n// \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\nif (firstTombstone == -1 && hashMap->buckets[index] == hashMap->TOMBSTONE) {\nfirstTombstone = index;\n}\n// \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u8fd4\u56de\u5934\u90e8\nindex = (index + 1) % hashMap->capacity;\n}\n// \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\nreturn firstTombstone == -1 ? index : firstTombstone;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapOpenAddressing *hashMap, int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nreturn hashMap->buckets[index]->val;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\nreturn \"\";\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(HashMapOpenAddressing *hashMap, int key, char *val) {\n// \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\nif (loadFactor(hashMap) > hashMap->loadThres) {\nextend(hashMap);\n}\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nfree(hashMap->buckets[index]->val);\nhashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val + 1)));\nstrcpy(hashMap->buckets[index]->val, val);\nhashMap->buckets[index]->val[strlen(val)] = '\\0';\nreturn;\n}\n// \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\nPair *pair = (Pair *)malloc(sizeof(Pair));\npair->key = key;\npair->val = (char *)malloc(sizeof(strlen(val + 1)));\nstrcpy(pair->val, val);\npair->val[strlen(val)] = '\\0';\nhashMap->buckets[index] = pair;\nhashMap->size++;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapOpenAddressing *hashMap, int key) {\n// \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\nint index = findBucket(hashMap, key);\n// \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\nif (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\nPair *pair = hashMap->buckets[index];\nfree(pair->val);\nfree(pair);\nhashMap->buckets[index] = hashMap->TOMBSTONE;\nhashMap->size--;\n}\n}\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapOpenAddressing *hashMap) {\n// \u6682\u5b58\u539f\u54c8\u5e0c\u8868\nPair **bucketsTmp = hashMap->buckets;\nint oldCapacity = hashMap->capacity;\n// \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\nhashMap->capacity *= hashMap->extendRatio;\nhashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\nhashMap->size = 0;\n// \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\nfor (int i = 0; i < oldCapacity; i++) {\nPair *pair = bucketsTmp[i];\nif (pair != NULL && pair != hashMap->TOMBSTONE) {\nput(hashMap, pair->key, pair->val);\nfree(pair->val);\nfree(pair);\n}\n}\nfree(bucketsTmp);\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapOpenAddressing *hashMap) {\nfor (int i = 0; i < hashMap->capacity; i++) {\nPair *pair = hashMap->buckets[i];\nif (pair == NULL) {\nprintf(\"NULL\\n\");\n} else if (pair == hashMap->TOMBSTONE) {\nprintf(\"TOMBSTONE\\n\");\n} else {\nprintf(\"%d -> %s\\n\", pair->key, pair->val);\n}\n}\n}\n
        hash_map_open_addressing.zig
        [class]{HashMapOpenAddressing}-[func]{}\n
        "},{"location":"chapter_hashing/hash_collision/#2","title":"2. \u00a0 \u5e73\u65b9\u63a2\u6d4b","text":"

        \u5e73\u65b9\u63a2\u6d4b\u4e0e\u7ebf\u6027\u63a2\u6d4b\u7c7b\u4f3c\uff0c\u90fd\u662f\u5f00\u653e\u5bfb\u5740\u7684\u5e38\u89c1\u7b56\u7565\u4e4b\u4e00\u3002\u5f53\u53d1\u751f\u51b2\u7a81\u65f6\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e0d\u662f\u7b80\u5355\u5730\u8df3\u8fc7\u4e00\u4e2a\u56fa\u5b9a\u7684\u6b65\u6570\uff0c\u800c\u662f\u8df3\u8fc7\u201c\u63a2\u6d4b\u6b21\u6570\u7684\u5e73\u65b9\u201d\u7684\u6b65\u6570\uff0c\u5373 \\(1, 4, 9, \\dots\\) \u6b65\u3002

        \u5e73\u65b9\u63a2\u6d4b\u4e3b\u8981\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\u3002

        • \u5e73\u65b9\u63a2\u6d4b\u901a\u8fc7\u8df3\u8fc7\u5e73\u65b9\u7684\u8ddd\u79bb\uff0c\u8bd5\u56fe\u7f13\u89e3\u7ebf\u6027\u63a2\u6d4b\u7684\u805a\u96c6\u6548\u5e94\u3002
        • \u5e73\u65b9\u63a2\u6d4b\u4f1a\u8df3\u8fc7\u66f4\u5927\u7684\u8ddd\u79bb\u6765\u5bfb\u627e\u7a7a\u4f4d\u7f6e\uff0c\u6709\u52a9\u4e8e\u6570\u636e\u5206\u5e03\u5f97\u66f4\u52a0\u5747\u5300\u3002

        \u7136\u800c\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e5f\u5e76\u4e0d\u662f\u5b8c\u7f8e\u7684\u3002

        • \u4ecd\u7136\u5b58\u5728\u805a\u96c6\u73b0\u8c61\uff0c\u5373\u67d0\u4e9b\u4f4d\u7f6e\u6bd4\u5176\u4ed6\u4f4d\u7f6e\u66f4\u5bb9\u6613\u88ab\u5360\u7528\u3002
        • \u7531\u4e8e\u5e73\u65b9\u7684\u589e\u957f\uff0c\u5e73\u65b9\u63a2\u6d4b\u53ef\u80fd\u4e0d\u4f1a\u63a2\u6d4b\u6574\u4e2a\u54c8\u5e0c\u8868\uff0c\u8fd9\u610f\u5473\u7740\u5373\u4f7f\u54c8\u5e0c\u8868\u4e2d\u6709\u7a7a\u6876\uff0c\u5e73\u65b9\u63a2\u6d4b\u4e5f\u53ef\u80fd\u65e0\u6cd5\u8bbf\u95ee\u5230\u5b83\u3002
        "},{"location":"chapter_hashing/hash_collision/#3","title":"3. \u00a0 \u591a\u6b21\u54c8\u5e0c","text":"

        \u987e\u540d\u601d\u4e49\uff0c\u591a\u6b21\u54c8\u5e0c\u65b9\u6cd5\u4f7f\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570 \\(f_1(x)\\)\u3001\\(f_2(x)\\)\u3001\\(f_3(x)\\)\u3001\\(\\dots\\) \u8fdb\u884c\u63a2\u6d4b\u3002

        • \u63d2\u5165\u5143\u7d20\uff1a\u82e5\u54c8\u5e0c\u51fd\u6570 \\(f_1(x)\\) \u51fa\u73b0\u51b2\u7a81\uff0c\u5219\u5c1d\u8bd5 \\(f_2(x)\\) \uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u627e\u5230\u7a7a\u6876\u540e\u63d2\u5165\u5143\u7d20\u3002
        • \u67e5\u627e\u5143\u7d20\uff1a\u5728\u76f8\u540c\u7684\u54c8\u5e0c\u51fd\u6570\u987a\u5e8f\u4e0b\u8fdb\u884c\u67e5\u627e\uff0c\u76f4\u5230\u627e\u5230\u76ee\u6807\u5143\u7d20\u65f6\u8fd4\u56de\uff1b\u82e5\u9047\u5230\u7a7a\u6876\u6216\u5df2\u5c1d\u8bd5\u6240\u6709\u54c8\u5e0c\u51fd\u6570\uff0c\u8bf4\u660e\u54c8\u5e0c\u8868\u4e2d\u4e0d\u5b58\u5728\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(\\text{None}\\) \u3002

        \u4e0e\u7ebf\u6027\u63a2\u6d4b\u76f8\u6bd4\uff0c\u591a\u6b21\u54c8\u5e0c\u65b9\u6cd5\u4e0d\u6613\u4ea7\u751f\u805a\u96c6\uff0c\u4f46\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u4f1a\u5e26\u6765\u989d\u5916\u7684\u8ba1\u7b97\u91cf\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u5f00\u653e\u5bfb\u5740\uff08\u7ebf\u6027\u63a2\u6d4b\u3001\u5e73\u65b9\u63a2\u6d4b\u548c\u591a\u6b21\u54c8\u5e0c\uff09\u54c8\u5e0c\u8868\u90fd\u5b58\u5728\u201c\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u201d\u7684\u95ee\u9898\u3002

        "},{"location":"chapter_hashing/hash_collision/#623","title":"6.2.3 \u00a0 \u7f16\u7a0b\u8bed\u8a00\u7684\u9009\u62e9","text":"

        \u5404\u4e2a\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u7b56\u7565\uff0c\u4ee5\u4e0b\u4e3e\u51e0\u4e2a\u4f8b\u5b50\u3002

        • Python \u91c7\u7528\u5f00\u653e\u5bfb\u5740\u3002\u5b57\u5178 dict \u4f7f\u7528\u4f2a\u968f\u673a\u6570\u8fdb\u884c\u63a2\u6d4b\u3002
        • Java \u91c7\u7528\u94fe\u5f0f\u5730\u5740\u3002\u81ea JDK 1.8 \u4ee5\u6765\uff0c\u5f53 HashMap \u5185\u6570\u7ec4\u957f\u5ea6\u8fbe\u5230 64 \u4e14\u94fe\u8868\u957f\u5ea6\u8fbe\u5230 8 \u65f6\uff0c\u94fe\u8868\u4f1a\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u4ee5\u63d0\u5347\u67e5\u627e\u6027\u80fd\u3002
        • Go \u91c7\u7528\u94fe\u5f0f\u5730\u5740\u3002Go \u89c4\u5b9a\u6bcf\u4e2a\u6876\u6700\u591a\u5b58\u50a8 8 \u4e2a\u952e\u503c\u5bf9\uff0c\u8d85\u51fa\u5bb9\u91cf\u5219\u8fde\u63a5\u4e00\u4e2a\u6ea2\u51fa\u6876\u3002\u5f53\u6ea2\u51fa\u6876\u8fc7\u591a\u65f6\uff0c\u4f1a\u6267\u884c\u4e00\u6b21\u7279\u6b8a\u7684\u7b49\u91cf\u6269\u5bb9\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u6027\u80fd\u3002
        "},{"location":"chapter_hashing/hash_map/","title":"6.1 \u00a0 \u54c8\u5e0c\u8868","text":"

        \u300c\u54c8\u5e0c\u8868 hash table\u300d\uff0c\u53c8\u79f0\u300c\u6563\u5217\u8868\u300d\uff0c\u5176\u901a\u8fc7\u5efa\u7acb\u952e key \u4e0e\u503c value \u4e4b\u95f4\u7684\u6620\u5c04\uff0c\u5b9e\u73b0\u9ad8\u6548\u7684\u5143\u7d20\u67e5\u8be2\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u5411\u54c8\u5e0c\u8868\u8f93\u5165\u4e00\u4e2a\u952e key \uff0c\u5219\u53ef\u4ee5\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u83b7\u53d6\u5bf9\u5e94\u7684\u503c value \u3002

        \u5982\u56fe 6-1 \u6240\u793a\uff0c\u7ed9\u5b9a \\(n\\) \u4e2a\u5b66\u751f\uff0c\u6bcf\u4e2a\u5b66\u751f\u90fd\u6709\u201c\u59d3\u540d\u201d\u548c\u201c\u5b66\u53f7\u201d\u4e24\u9879\u6570\u636e\u3002\u5047\u5982\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u201c\u8f93\u5165\u4e00\u4e2a\u5b66\u53f7\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u59d3\u540d\u201d\u7684\u67e5\u8be2\u529f\u80fd\uff0c\u5219\u53ef\u4ee5\u91c7\u7528\u56fe 6-1 \u6240\u793a\u7684\u54c8\u5e0c\u8868\u6765\u5b9e\u73b0\u3002

        \u56fe 6-1 \u00a0 \u54c8\u5e0c\u8868\u7684\u62bd\u8c61\u8868\u793a

        \u9664\u54c8\u5e0c\u8868\u5916\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u67e5\u8be2\u529f\u80fd\uff0c\u5b83\u4eec\u7684\u6548\u7387\u5bf9\u6bd4\u5982\u8868 6-1 \u6240\u793a\u3002

        • \u6dfb\u52a0\u5143\u7d20\uff1a\u4ec5\u9700\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u6570\u7ec4\uff08\u94fe\u8868\uff09\u7684\u5c3e\u90e8\u5373\u53ef\uff0c\u4f7f\u7528 \\(O(1)\\) \u65f6\u95f4\u3002
        • \u67e5\u8be2\u5143\u7d20\uff1a\u7531\u4e8e\u6570\u7ec4\uff08\u94fe\u8868\uff09\u662f\u4e71\u5e8f\u7684\uff0c\u56e0\u6b64\u9700\u8981\u904d\u5386\u5176\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u5220\u9664\u5143\u7d20\uff1a\u9700\u8981\u5148\u67e5\u8be2\u5230\u5143\u7d20\uff0c\u518d\u4ece\u6570\u7ec4\uff08\u94fe\u8868\uff09\u4e2d\u5220\u9664\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002

        \u8868 6-1 \u00a0 \u5143\u7d20\u67e5\u8be2\u6548\u7387\u5bf9\u6bd4

        \u6570\u7ec4 \u94fe\u8868 \u54c8\u5e0c\u8868 \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(1)\\) \u6dfb\u52a0\u5143\u7d20 \\(O(1)\\) \\(O(1)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(1)\\)

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u5728\u54c8\u5e0c\u8868\u4e2d\u8fdb\u884c\u589e\u5220\u67e5\u6539\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662f \\(O(1)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002

        "},{"location":"chapter_hashing/hash_map/#611","title":"6.1.1 \u00a0 \u54c8\u5e0c\u8868\u5e38\u7528\u64cd\u4f5c","text":"

        \u54c8\u5e0c\u8868\u7684\u5e38\u89c1\u64cd\u4f5c\u5305\u62ec\uff1a\u521d\u59cb\u5316\u3001\u67e5\u8be2\u64cd\u4f5c\u3001\u6dfb\u52a0\u952e\u503c\u5bf9\u548c\u5220\u9664\u952e\u503c\u5bf9\u7b49\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map.py
        # \u521d\u59cb\u5316\u54c8\u5e0c\u8868\nhmap: dict = {}\n# \u6dfb\u52a0\u64cd\u4f5c\n# \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nhmap[12836] = \"\u5c0f\u54c8\"\nhmap[15937] = \"\u5c0f\u5570\"\nhmap[16750] = \"\u5c0f\u7b97\"\nhmap[13276] = \"\u5c0f\u6cd5\"\nhmap[10583] = \"\u5c0f\u9e2d\"\n# \u67e5\u8be2\u64cd\u4f5c\n# \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname: str = hmap[15937]\n# \u5220\u9664\u64cd\u4f5c\n# \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nhmap.pop(10583)\n
        hash_map.cpp
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nunordered_map<int, string> map;\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\";\nmap[15937] = \"\u5c0f\u5570\";\nmap[16750] = \"\u5c0f\u7b97\";\nmap[13276] = \"\u5c0f\u6cd5\";\nmap[10583] = \"\u5c0f\u9e2d\";\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.erase(10583);\n
        hash_map.java
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nMap<Integer, String> map = new HashMap<>();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.put(12836, \"\u5c0f\u54c8\");   map.put(15937, \"\u5c0f\u5570\");   map.put(16750, \"\u5c0f\u7b97\");   map.put(13276, \"\u5c0f\u6cd5\");\nmap.put(10583, \"\u5c0f\u9e2d\");\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map.get(15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.remove(10583);\n
        hash_map.cs
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nDictionary<int, string> map = new() {\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\n{ 12836, \"\u5c0f\u54c8\" },\n{ 15937, \"\u5c0f\u5570\" },\n{ 16750, \"\u5c0f\u7b97\" },\n{ 13276, \"\u5c0f\u6cd5\" },\n{ 10583, \"\u5c0f\u9e2d\" }\n};\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.Remove(10583);\n
        hash_map_test.go
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nhmap := make(map[int]string)\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nhmap[12836] = \"\u5c0f\u54c8\"\nhmap[15937] = \"\u5c0f\u5570\"\nhmap[16750] = \"\u5c0f\u7b97\"\nhmap[13276] = \"\u5c0f\u6cd5\"\nhmap[10583] = \"\u5c0f\u9e2d\"\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname := hmap[15937]\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\ndelete(hmap, 10583)\n
        hash_map.swift
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nvar map: [Int: String] = [:]\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\"\nmap[15937] = \"\u5c0f\u5570\"\nmap[16750] = \"\u5c0f\u7b97\"\nmap[13276] = \"\u5c0f\u6cd5\"\nmap[10583] = \"\u5c0f\u9e2d\"\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map[15937]!\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.removeValue(forKey: 10583)\n
        hash_map.js
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nconst map = new Map();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.set(12836, '\u5c0f\u54c8');\nmap.set(15937, '\u5c0f\u5570');\nmap.set(16750, '\u5c0f\u7b97');\nmap.set(13276, '\u5c0f\u6cd5');\nmap.set(10583, '\u5c0f\u9e2d');\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.delete(10583);\n
        hash_map.ts
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nconst map = new Map<number, string>();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.set(12836, '\u5c0f\u54c8');\nmap.set(15937, '\u5c0f\u5570');\nmap.set(16750, '\u5c0f\u7b97');\nmap.set(13276, '\u5c0f\u6cd5');\nmap.set(10583, '\u5c0f\u9e2d');\nconsole.info('\\n\u6dfb\u52a0\u5b8c\u6210\u540e\uff0c\u54c8\u5e0c\u8868\u4e3a\\nKey -> Value');\nconsole.info(map);\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\nconsole.info('\\n\u8f93\u5165\u5b66\u53f7 15937 \uff0c\u67e5\u8be2\u5230\u59d3\u540d ' + name);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.delete(10583);\nconsole.info('\\n\u5220\u9664 10583 \u540e\uff0c\u54c8\u5e0c\u8868\u4e3a\\nKey -> Value');\nconsole.info(map);\n
        hash_map.dart
        /* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nMap<int, String> map = {};\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap[12836] = \"\u5c0f\u54c8\";\nmap[15937] = \"\u5c0f\u5570\";\nmap[16750] = \"\u5c0f\u7b97\";\nmap[13276] = \"\u5c0f\u6cd5\";\nmap[10583] = \"\u5c0f\u9e2d\";\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map[15937];\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nmap.remove(10583);\n
        hash_map.rs
        use std::collections::HashMap;\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nlet mut map: HashMap<i32, String> = HashMap::new();\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.insert(12836, \"\u5c0f\u54c8\".to_string());\nmap.insert(15937, \"\u5c0f\u5570\".to_string());\nmap.insert(16750, \"\u5c0f\u7b97\".to_string());\nmap.insert(13279, \"\u5c0f\u6cd5\".to_string());\nmap.insert(10583, \"\u5c0f\u9e2d\".to_string());\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet _name: Option<&String> = map.get(&15937);\n/* \u5220\u9664\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u5220\u9664\u952e\u503c\u5bf9 (key, value)\nlet _removed_value: Option<String> = map.remove(&10583);\n
        hash_map.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u8868\n
        hash_map.zig
        \n

        \u54c8\u5e0c\u8868\u6709\u4e09\u79cd\u5e38\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff1a\u904d\u5386\u952e\u503c\u5bf9\u3001\u904d\u5386\u952e\u548c\u904d\u5386\u503c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig hash_map.py
        # \u904d\u5386\u54c8\u5e0c\u8868\n# \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor key, value in hmap.items():\nprint(key, \"->\", value)\n# \u5355\u72ec\u904d\u5386\u952e key\nfor key in hmap.keys():\nprint(key)\n# \u5355\u72ec\u904d\u5386\u503c value\nfor value in hmap.values():\nprint(value)\n
        hash_map.cpp
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (auto kv: map) {\ncout << kv.first << \" -> \" << kv.second << endl;\n}\n// \u4f7f\u7528\u8fed\u4ee3\u5668\u904d\u5386 key->value\nfor (auto iter = map.begin(); iter != map.end(); iter++) {\ncout << iter->first << \"->\" << iter->second << endl;\n}\n
        hash_map.java
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (Map.Entry <Integer, String> kv: map.entrySet()) {\nSystem.out.println(kv.getKey() + \" -> \" + kv.getValue());\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor (int key: map.keySet()) {\nSystem.out.println(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor (String val: map.values()) {\nSystem.out.println(val);\n}\n
        hash_map.cs
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nforeach (var kv in map) {\nConsole.WriteLine(kv.Key + \" -> \" + kv.Value);\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nforeach (int key in map.Keys) {\nConsole.WriteLine(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nforeach (string val in map.Values) {\nConsole.WriteLine(val);\n}\n
        hash_map_test.go
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor key, value := range hmap {\nfmt.Println(key, \"->\", value)\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor key := range hmap {\nfmt.Println(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor _, value := range hmap {\nfmt.Println(value)\n}\n
        hash_map.swift
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in map {\nprint(\"\\(key) -> \\(value)\")\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys {\nprint(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values {\nprint(value)\n}\n
        hash_map.js
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\nconsole.info('\\n\u904d\u5386\u952e\u503c\u5bf9 Key->Value');\nfor (const [k, v] of map.entries()) {\nconsole.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\nconsole.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\nconsole.info(v);\n}\n
        hash_map.ts
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\nconsole.info('\\n\u904d\u5386\u952e\u503c\u5bf9 Key->Value');\nfor (const [k, v] of map.entries()) {\nconsole.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\nconsole.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\nconsole.info(v);\n}\n
        hash_map.dart
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nmap.forEach((key, value) {\nprint('$key -> $value');\n});\n// \u5355\u72ec\u904d\u5386\u952e Key\nmap.keys.forEach((key) {\nprint(key);\n});\n// \u5355\u72ec\u904d\u5386\u503c Value\nmap.values.forEach((value) {\nprint(value);\n});\n
        hash_map.rs
        /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in &map {\nprintln!(\"{key} -> {value}\");\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys() {\nprintln!(\"{key}\"); }\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values() {\nprintln!(\"{value}\");\n}\n
        hash_map.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u8868\n
        hash_map.zig
        \n
        "},{"location":"chapter_hashing/hash_map/#612","title":"6.1.2 \u00a0 \u54c8\u5e0c\u8868\u7b80\u5355\u5b9e\u73b0","text":"

        \u6211\u4eec\u5148\u8003\u8651\u6700\u7b80\u5355\u7684\u60c5\u51b5\uff0c\u4ec5\u7528\u4e00\u4e2a\u6570\u7ec4\u6765\u5b9e\u73b0\u54c8\u5e0c\u8868\u3002\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u6211\u4eec\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u7a7a\u4f4d\u79f0\u4e3a\u300c\u6876 bucket\u300d\uff0c\u6bcf\u4e2a\u6876\u53ef\u5b58\u50a8\u4e00\u4e2a\u952e\u503c\u5bf9\u3002\u56e0\u6b64\uff0c\u67e5\u8be2\u64cd\u4f5c\u5c31\u662f\u627e\u5230 key \u5bf9\u5e94\u7684\u6876\uff0c\u5e76\u5728\u6876\u4e2d\u83b7\u53d6 value \u3002

        \u90a3\u4e48\uff0c\u5982\u4f55\u57fa\u4e8e key \u5b9a\u4f4d\u5bf9\u5e94\u7684\u6876\u5462\uff1f\u8fd9\u662f\u901a\u8fc7\u300c\u54c8\u5e0c\u51fd\u6570 hash function\u300d\u5b9e\u73b0\u7684\u3002\u54c8\u5e0c\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u4e00\u4e2a\u8f83\u5927\u7684\u8f93\u5165\u7a7a\u95f4\u6620\u5c04\u5230\u4e00\u4e2a\u8f83\u5c0f\u7684\u8f93\u51fa\u7a7a\u95f4\u3002\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u8f93\u5165\u7a7a\u95f4\u662f\u6240\u6709 key \uff0c\u8f93\u51fa\u7a7a\u95f4\u662f\u6240\u6709\u6876\uff08\u6570\u7ec4\u7d22\u5f15\uff09\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u8f93\u5165\u4e00\u4e2a key \uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u5f97\u5230\u8be5 key \u5bf9\u5e94\u7684\u952e\u503c\u5bf9\u5728\u6570\u7ec4\u4e2d\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002

        \u8f93\u5165\u4e00\u4e2a key \uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u8ba1\u7b97\u8fc7\u7a0b\u5206\u4e3a\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u901a\u8fc7\u67d0\u79cd\u54c8\u5e0c\u7b97\u6cd5 hash() \u8ba1\u7b97\u5f97\u5230\u54c8\u5e0c\u503c\u3002
        2. \u5c06\u54c8\u5e0c\u503c\u5bf9\u6876\u6570\u91cf\uff08\u6570\u7ec4\u957f\u5ea6\uff09capacity \u53d6\u6a21\uff0c\u4ece\u800c\u83b7\u53d6\u8be5 key \u5bf9\u5e94\u7684\u6570\u7ec4\u7d22\u5f15 index \u3002
        index = hash(key) % capacity\n

        \u968f\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5229\u7528 index \u5728\u54c8\u5e0c\u8868\u4e2d\u8bbf\u95ee\u5bf9\u5e94\u7684\u6876\uff0c\u4ece\u800c\u83b7\u53d6 value \u3002

        \u8bbe\u6570\u7ec4\u957f\u5ea6 capacity = 100\u3001\u54c8\u5e0c\u7b97\u6cd5 hash(key) = key \uff0c\u6613\u5f97\u54c8\u5e0c\u51fd\u6570\u4e3a key % 100 \u3002\u56fe 6-2 \u4ee5 key \u5b66\u53f7\u548c value \u59d3\u540d\u4e3a\u4f8b\uff0c\u5c55\u793a\u4e86\u54c8\u5e0c\u51fd\u6570\u7684\u5de5\u4f5c\u539f\u7406\u3002

        \u56fe 6-2 \u00a0 \u54c8\u5e0c\u51fd\u6570\u5de5\u4f5c\u539f\u7406

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u54c8\u5e0c\u8868\u3002\u5176\u4e2d\uff0c\u6211\u4eec\u5c06 key \u548c value \u5c01\u88c5\u6210\u4e00\u4e2a\u7c7b Pair \uff0c\u4ee5\u8868\u793a\u952e\u503c\u5bf9\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_hash_map.py
        class Pair:\n\"\"\"\u952e\u503c\u5bf9\"\"\"\ndef __init__(self, key: int, val: str):\nself.key = key\nself.val = val\nclass ArrayHashMap:\n\"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n# \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nself.buckets: list[Pair | None] = [None] * 100\ndef hash_func(self, key: int) -> int:\n\"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\nindex = key % 100\nreturn index\ndef get(self, key: int) -> str:\n\"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\nindex: int = self.hash_func(key)\npair: Pair = self.buckets[index]\nif pair is None:\nreturn None\nreturn pair.val\ndef put(self, key: int, val: str):\n\"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\npair = Pair(key, val)\nindex: int = self.hash_func(key)\nself.buckets[index] = pair\ndef remove(self, key: int):\n\"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\nindex: int = self.hash_func(key)\n# \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\nself.buckets[index] = None\ndef entry_set(self) -> list[Pair]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\"\"\"\nresult: list[Pair] = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair)\nreturn result\ndef key_set(self) -> list[int]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u952e\"\"\"\nresult = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair.key)\nreturn result\ndef value_set(self) -> list[str]:\n\"\"\"\u83b7\u53d6\u6240\u6709\u503c\"\"\"\nresult = []\nfor pair in self.buckets:\nif pair is not None:\nresult.append(pair.val)\nreturn result\ndef print(self):\n\"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\nfor pair in self.buckets:\nif pair is not None:\nprint(pair.key, \"->\", pair.val)\n
        array_hash_map.cpp
        /* \u952e\u503c\u5bf9 */\nstruct Pair {\npublic:\nint key;\nstring val;\nPair(int key, string val) {\nthis->key = key;\nthis->val = val;\n}\n};\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate:\nvector<Pair *> buckets;\npublic:\nArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = vector<Pair *>(100);\n}\n~ArrayHashMap() {\n// \u91ca\u653e\u5185\u5b58\nfor (const auto &bucket : buckets) {\ndelete bucket;\n}\nbuckets.clear();\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nstring get(int key) {\nint index = hashFunc(key);\nPair *pair = buckets[index];\nif (pair == nullptr)\nreturn \"\";\nreturn pair->val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, string val) {\nPair *pair = new Pair(key, val);\nint index = hashFunc(key);\nbuckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nint index = hashFunc(key);\n// \u91ca\u653e\u5185\u5b58\u5e76\u7f6e\u4e3a nullptr\ndelete buckets[index];\nbuckets[index] = nullptr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvector<Pair *> pairSet() {\nvector<Pair *> pairSet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\npairSet.push_back(pair);\n}\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvector<int> keySet() {\nvector<int> keySet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\nkeySet.push_back(pair->key);\n}\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvector<string> valueSet() {\nvector<string> valueSet;\nfor (Pair *pair : buckets) {\nif (pair != nullptr) {\nvalueSet.push_back(pair->val);\n}\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print() {\nfor (Pair *kv : pairSet()) {\ncout << kv->key << \" -> \" << kv->val << endl;\n}\n}\n};\n
        array_hash_map.java
        /* \u952e\u503c\u5bf9 */\nclass Pair {\npublic int key;\npublic String val;\npublic Pair(int key, String val) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate List<Pair> buckets;\npublic ArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = new ArrayList<>();\nfor (int i = 0; i < 100; i++) {\nbuckets.add(null);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate int hashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic String get(int key) {\nint index = hashFunc(key);\nPair pair = buckets.get(index);\nif (pair == null)\nreturn null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void put(int key, String val) {\nPair pair = new Pair(key, val);\nint index = hashFunc(key);\nbuckets.set(index, pair);\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void remove(int key) {\nint index = hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nbuckets.set(index, null);\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic List<Pair> pairSet() {\nList<Pair> pairSet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\npairSet.add(pair);\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic List<Integer> keySet() {\nList<Integer> keySet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\nkeySet.add(pair.key);\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic List<String> valueSet() {\nList<String> valueSet = new ArrayList<>();\nfor (Pair pair : buckets) {\nif (pair != null)\nvalueSet.add(pair.val);\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void print() {\nfor (Pair kv : pairSet()) {\nSystem.out.println(kv.key + \" -> \" + kv.val);\n}\n}\n}\n
        array_hash_map.cs
        /* \u952e\u503c\u5bf9 int->string */\nclass Pair(int key, string val) {\npublic int key = key;\npublic string val = val;\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nList<Pair?> buckets;\npublic ArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets = [];\nfor (int i = 0; i < 100; i++) {\nbuckets.Add(null);\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint HashFunc(int key) {\nint index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic string? Get(int key) {\nint index = HashFunc(key);\nPair? pair = buckets[index];\nif (pair == null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic void Put(int key, string val) {\nPair pair = new(key, val);\nint index = HashFunc(key);\nbuckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic void Remove(int key) {\nint index = HashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nbuckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic List<Pair> PairSet() {\nList<Pair> pairSet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\npairSet.Add(pair);\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic List<int> KeySet() {\nList<int> keySet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\nkeySet.Add(pair.key);\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic List<string> ValueSet() {\nList<string> valueSet = [];\nforeach (Pair? pair in buckets) {\nif (pair != null)\nvalueSet.Add(pair.val);\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic void Print() {\nforeach (Pair kv in PairSet()) {\nConsole.WriteLine(kv.key + \" -> \" + kv.val);\n}\n}\n}\n
        array_hash_map.go
        /* \u952e\u503c\u5bf9 */\ntype pair struct {\nkey int\nval string\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntype arrayHashMap struct {\nbuckets []*pair\n}\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nfunc newArrayHashMap() *arrayHashMap {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nbuckets := make([]*pair, 100)\nreturn &arrayHashMap{buckets: buckets}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (a *arrayHashMap) hashFunc(key int) int {\nindex := key % 100\nreturn index\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (a *arrayHashMap) get(key int) string {\nindex := a.hashFunc(key)\npair := a.buckets[index]\nif pair == nil {\nreturn \"Not Found\"\n}\nreturn pair.val\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (a *arrayHashMap) put(key int, val string) {\npair := &pair{key: key, val: val}\nindex := a.hashFunc(key)\na.buckets[index] = pair\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (a *arrayHashMap) remove(key int) {\nindex := a.hashFunc(key)\n// \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\na.buckets[index] = nil\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u5bf9 */\nfunc (a *arrayHashMap) pairSet() []*pair {\nvar pairs []*pair\nfor _, pair := range a.buckets {\nif pair != nil {\npairs = append(pairs, pair)\n}\n}\nreturn pairs\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc (a *arrayHashMap) keySet() []int {\nvar keys []int\nfor _, pair := range a.buckets {\nif pair != nil {\nkeys = append(keys, pair.key)\n}\n}\nreturn keys\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc (a *arrayHashMap) valueSet() []string {\nvar values []string\nfor _, pair := range a.buckets {\nif pair != nil {\nvalues = append(values, pair.val)\n}\n}\nreturn values\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (a *arrayHashMap) print() {\nfor _, pair := range a.buckets {\nif pair != nil {\nfmt.Println(pair.key, \"->\", pair.val)\n}\n}\n}\n
        array_hash_map.swift
        /* \u952e\u503c\u5bf9 */\nclass Pair: Equatable {\npublic var key: Int\npublic var val: String\npublic init(key: Int, val: String) {\nself.key = key\nself.val = val\n}\npublic static func == (lhs: Pair, rhs: Pair) -> Bool {\nlhs.key == rhs.key && lhs.val == rhs.val\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate var buckets: [Pair?] = []\ninit() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nfor _ in 0 ..< 100 {\nbuckets.append(nil)\n}\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate func hashFunc(key: Int) -> Int {\nlet index = key % 100\nreturn index\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc get(key: Int) -> String? {\nlet index = hashFunc(key: key)\nlet pair = buckets[index]\nreturn pair?.val\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc put(key: Int, val: String) {\nlet pair = Pair(key: key, val: val)\nlet index = hashFunc(key: key)\nbuckets[index] = pair\n}\n/* \u5220\u9664\u64cd\u4f5c */\nfunc remove(key: Int) {\nlet index = hashFunc(key: key)\n// \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\nbuckets[index] = nil\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nfunc pairSet() -> [Pair] {\nvar pairSet: [Pair] = []\nfor pair in buckets {\nif let pair = pair {\npairSet.append(pair)\n}\n}\nreturn pairSet\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc keySet() -> [Int] {\nvar keySet: [Int] = []\nfor pair in buckets {\nif let pair = pair {\nkeySet.append(pair.key)\n}\n}\nreturn keySet\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc valueSet() -> [String] {\nvar valueSet: [String] = []\nfor pair in buckets {\nif let pair = pair {\nvalueSet.append(pair.val)\n}\n}\nreturn valueSet\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc print() {\nfor pair in pairSet() {\nSwift.print(\"\\(pair.key) -> \\(pair.val)\")\n}\n}\n}\n
        array_hash_map.js
        /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\nconstructor(key, val) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n#buckets;\nconstructor() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nthis.#buckets = new Array(100).fill(null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\n#hashFunc(key) {\nreturn key % 100;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nget(key) {\nlet index = this.#hashFunc(key);\nlet pair = this.#buckets[index];\nif (pair === null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nset(key, val) {\nlet index = this.#hashFunc(key);\nthis.#buckets[index] = new Pair(key, val);\n}\n/* \u5220\u9664\u64cd\u4f5c */\ndelete(key) {\nlet index = this.#hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nthis.#buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nentries() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i]);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nkeys() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i].key);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvalues() {\nlet arr = [];\nfor (let i = 0; i < this.#buckets.length; i++) {\nif (this.#buckets[i]) {\narr.push(this.#buckets[i].val);\n}\n}\nreturn arr;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nprint() {\nlet pairSet = this.entries();\nfor (const pair of pairSet) {\nconsole.info(`${pair.key} -> ${pair.val}`);\n}\n}\n}\n
        array_hash_map.ts
        /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\npublic key: number;\npublic val: string;\nconstructor(key: number, val: string) {\nthis.key = key;\nthis.val = val;\n}\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nprivate readonly buckets: (Pair | null)[];\nconstructor() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nthis.buckets = new Array(100).fill(null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nprivate hashFunc(key: number): number {\nreturn key % 100;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npublic get(key: number): string | null {\nlet index = this.hashFunc(key);\nlet pair = this.buckets[index];\nif (pair === null) return null;\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npublic set(key: number, val: string) {\nlet index = this.hashFunc(key);\nthis.buckets[index] = new Pair(key, val);\n}\n/* \u5220\u9664\u64cd\u4f5c */\npublic delete(key: number) {\nlet index = this.hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nthis.buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npublic entries(): (Pair | null)[] {\nlet arr: (Pair | null)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i]);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npublic keys(): (number | undefined)[] {\nlet arr: (number | undefined)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i].key);\n}\n}\nreturn arr;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npublic values(): (string | undefined)[] {\nlet arr: (string | undefined)[] = [];\nfor (let i = 0; i < this.buckets.length; i++) {\nif (this.buckets[i]) {\narr.push(this.buckets[i].val);\n}\n}\nreturn arr;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npublic print() {\nlet pairSet = this.entries();\nfor (const pair of pairSet) {\nconsole.info(`${pair.key} -> ${pair.val}`);\n}\n}\n}\n
        array_hash_map.dart
        /* \u952e\u503c\u5bf9 */\nclass Pair {\nint key;\nString val;\nPair(this.key, this.val);\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\nlate List<Pair?> _buckets;\nArrayHashMap() {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n_buckets = List.filled(100, null);\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nint _hashFunc(int key) {\nfinal int index = key % 100;\nreturn index;\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\nString? get(int key) {\nfinal int index = _hashFunc(key);\nfinal Pair? pair = _buckets[index];\nif (pair == null) {\nreturn null;\n}\nreturn pair.val;\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(int key, String val) {\nfinal Pair pair = Pair(key, val);\nfinal int index = _hashFunc(key);\n_buckets[index] = pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid remove(int key) {\nfinal int index = _hashFunc(key);\n_buckets[index] = null;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nList<Pair> pairSet() {\nList<Pair> pairSet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\npairSet.add(pair);\n}\n}\nreturn pairSet;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nList<int> keySet() {\nList<int> keySet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\nkeySet.add(pair.key);\n}\n}\nreturn keySet;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nList<String> values() {\nList<String> valueSet = [];\nfor (final Pair? pair in _buckets) {\nif (pair != null) {\nvalueSet.add(pair.val);\n}\n}\nreturn valueSet;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid printHashMap() {\nfor (final Pair kv in pairSet()) {\nprint(\"${kv.key} -> ${kv.val}\");\n}\n}\n}\n
        array_hash_map.rs
        /* \u952e\u503c\u5bf9 */\n#[derive(Debug, Clone, PartialEq)]\npub struct Pair {\npub key: i32,\npub val: String,\n}\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\npub struct ArrayHashMap {\nbuckets: Vec<Option<Pair>>\n}\nimpl ArrayHashMap {\npub fn new() -> ArrayHashMap {\n// \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\nSelf { buckets: vec![None; 100] }\n}\n/* \u54c8\u5e0c\u51fd\u6570 */\nfn hash_func(&self, key: i32) -> usize {\nkey as usize % 100\n}\n/* \u67e5\u8be2\u64cd\u4f5c */\npub fn get(&self, key: i32) -> Option<&String> {\nlet index = self.hash_func(key);\nself.buckets[index].as_ref().map(|pair| &pair.val)\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\npub fn put(&mut self, key: i32, val: &str) {\nlet index = self.hash_func(key);\nself.buckets[index] = Some(Pair {\nkey,\nval: val.to_string(),\n});\n}\n/* \u5220\u9664\u64cd\u4f5c */\npub fn remove(&mut self, key: i32) {\nlet index = self.hash_func(key);\n// \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\nself.buckets[index] = None;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\npub fn entry_set(&self) -> Vec<&Pair> {\nself.buckets.iter().filter_map(|pair| pair.as_ref()).collect()\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\npub fn key_set(&self) -> Vec<&i32> {\nself.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.key)).collect()\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\npub fn value_set(&self) -> Vec<&String> {\nself.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.val)).collect()\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\npub fn print(&self) {\nfor pair in self.entry_set() {\nprintln!(\"{} -> {}\", pair.key, pair.val);\n}\n}\n}\n
        array_hash_map.c
        /* \u952e\u503c\u5bf9 int->string */\ntypedef struct {\nint key;\nchar *val;\n} Pair;\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntypedef struct {\nPair *buckets[HASHTABLE_CAPACITY];\n} ArrayHashMap;\n/* \u6784\u9020\u51fd\u6570 */\nArrayHashMap *newArrayHashMap() {\nArrayHashMap *hmap = malloc(sizeof(ArrayHashMap));\nreturn hmap;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayHashMap(ArrayHashMap *hmap) {\nfor (int i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nfree(hmap->buckets[i]->val);\nfree(hmap->buckets[i]);\n}\n}\nfree(hmap);\n}\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(ArrayHashMap *hmap, const int key, const char *val) {\nPair *Pair = malloc(sizeof(Pair));\nPair->key = key;\nPair->val = malloc(strlen(val) + 1);\nstrcpy(Pair->val, val);\nint index = hashFunc(key);\nhmap->buckets[index] = Pair;\n}\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(ArrayHashMap *hmap, const int key) {\nint index = hashFunc(key);\nfree(hmap->buckets[index]->val);\nfree(hmap->buckets[index]);\nhmap->buckets[index] = NULL;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvoid pairSet(ArrayHashMap *hmap, MapSet *set) {\nPair *entries;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nentries = malloc(sizeof(Pair) * total);\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nentries[index].key = hmap->buckets[i]->key;\nentries[index].val = malloc(strlen(hmap->buckets[i]->val) + 1);\nstrcpy(entries[index].val, hmap->buckets[i]->val);\nindex++;\n}\n}\nset->set = entries;\nset->len = total;\n}\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvoid keySet(ArrayHashMap *hmap, MapSet *set) {\nint *keys;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nkeys = malloc(total * sizeof(int));\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nkeys[index] = hmap->buckets[i]->key;\nindex++;\n}\n}\nset->set = keys;\nset->len = total;\n}\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvoid valueSet(ArrayHashMap *hmap, MapSet *set) {\nchar **vals;\nint i = 0, index = 0;\nint total = 0;\n/* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\ntotal++;\n}\n}\nvals = malloc(total * sizeof(char *));\nfor (i = 0; i < HASHTABLE_CAPACITY; i++) {\nif (hmap->buckets[i] != NULL) {\nvals[index] = hmap->buckets[i]->val;\nindex++;\n}\n}\nset->set = vals;\nset->len = total;\n}\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(ArrayHashMap *hmap) {\nint i;\nMapSet set;\npairSet(hmap, &set);\nPair *entries = (Pair *)set.set;\nfor (i = 0; i < set.len; i++) {\nprintf(\"%d -> %s\\n\", entries[i].key, entries[i].val);\n}\nfree(set.set);\n}\n
        array_hash_map.zig
        // \u952e\u503c\u5bf9\nconst Pair = struct {\nkey: usize = undefined,\nval: []const u8 = undefined,\npub fn init(key: usize, val: []const u8) Pair {\nreturn Pair {\n.key = key,\n.val = val,\n};\n}\n};\n// \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\nfn ArrayHashMap(comptime T: type) type {\nreturn struct {\nbucket: ?std.ArrayList(?T) = null,\nmem_allocator: std.mem.Allocator = undefined,\nconst Self = @This();\n// \u6784\u9020\u51fd\u6570\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nself.mem_allocator = allocator;\n// \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 100 \u7684\u6876\uff08\u6570\u7ec4\uff09\nself.bucket = std.ArrayList(?T).init(self.mem_allocator);\nvar i: i32 = 0;\nwhile (i < 100) : (i += 1) {\ntry self.bucket.?.append(null);\n}\n}\n// \u6790\u6784\u51fd\u6570\npub fn deinit(self: *Self) void {\nif (self.bucket != null) self.bucket.?.deinit();\n}\n// \u54c8\u5e0c\u51fd\u6570\nfn hashFunc(key: usize) usize {\nvar index = key % 100;\nreturn index;\n}\n// \u67e5\u8be2\u64cd\u4f5c\npub fn get(self: *Self, key: usize) []const u8 {\nvar index = hashFunc(key);\nvar pair = self.bucket.?.items[index];\nreturn pair.?.val;\n}\n// \u6dfb\u52a0\u64cd\u4f5c\npub fn put(self: *Self, key: usize, val: []const u8) !void {\nvar pair = Pair.init(key, val);\nvar index = hashFunc(key);\nself.bucket.?.items[index] = pair;\n}\n// \u5220\u9664\u64cd\u4f5c\npub fn remove(self: *Self, key: usize) !void {\nvar index = hashFunc(key);\n// \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\nself.bucket.?.items[index] = null;\n}       // \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\npub fn pairSet(self: *Self) !std.ArrayList(T) {\nvar entry_set = std.ArrayList(T).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry entry_set.append(item.?);\n}\nreturn entry_set;\n}  // \u83b7\u53d6\u6240\u6709\u952e\npub fn keySet(self: *Self) !std.ArrayList(usize) {\nvar key_set = std.ArrayList(usize).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry key_set.append(item.?.key);\n}\nreturn key_set;\n}  // \u83b7\u53d6\u6240\u6709\u503c\npub fn valueSet(self: *Self) !std.ArrayList([]const u8) {\nvar value_set = std.ArrayList([]const u8).init(self.mem_allocator);\nfor (self.bucket.?.items) |item| {\nif (item == null) continue;\ntry value_set.append(item.?.val);\n}\nreturn value_set;\n}\n// \u6253\u5370\u54c8\u5e0c\u8868\npub fn print(self: *Self) !void {\nvar entry_set = try self.pairSet();\ndefer entry_set.deinit();\nfor (entry_set.items) |item| {\nstd.debug.print(\"{} -> {s}\\n\", .{item.key, item.val});\n}\n}\n};\n}\n
        "},{"location":"chapter_hashing/hash_map/#613","title":"6.1.3 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u4e0e\u6269\u5bb9","text":"

        \u4ece\u672c\u8d28\u4e0a\u770b\uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u6240\u6709 key \u6784\u6210\u7684\u8f93\u5165\u7a7a\u95f4\u6620\u5c04\u5230\u6570\u7ec4\u6240\u6709\u7d22\u5f15\u6784\u6210\u7684\u8f93\u51fa\u7a7a\u95f4\uff0c\u800c\u8f93\u5165\u7a7a\u95f4\u5f80\u5f80\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\u3002\u56e0\u6b64\uff0c\u7406\u8bba\u4e0a\u4e00\u5b9a\u5b58\u5728\u201c\u591a\u4e2a\u8f93\u5165\u5bf9\u5e94\u76f8\u540c\u8f93\u51fa\u201d\u7684\u60c5\u51b5\u3002

        \u5bf9\u4e8e\u4e0a\u8ff0\u793a\u4f8b\u4e2d\u7684\u54c8\u5e0c\u51fd\u6570\uff0c\u5f53\u8f93\u5165\u7684 key \u540e\u4e24\u4f4d\u76f8\u540c\u65f6\uff0c\u54c8\u5e0c\u51fd\u6570\u7684\u8f93\u51fa\u7ed3\u679c\u4e5f\u76f8\u540c\u3002\u4f8b\u5982\uff0c\u67e5\u8be2\u5b66\u53f7\u4e3a 12836 \u548c 20336 \u7684\u4e24\u4e2a\u5b66\u751f\u65f6\uff0c\u6211\u4eec\u5f97\u5230\uff1a

        12836 % 100 = 36\n20336 % 100 = 36\n

        \u5982\u56fe 6-3 \u6240\u793a\uff0c\u4e24\u4e2a\u5b66\u53f7\u6307\u5411\u4e86\u540c\u4e00\u4e2a\u59d3\u540d\uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u5bf9\u7684\u3002\u6211\u4eec\u5c06\u8fd9\u79cd\u591a\u4e2a\u8f93\u5165\u5bf9\u5e94\u540c\u4e00\u8f93\u51fa\u7684\u60c5\u51b5\u79f0\u4e3a\u300c\u54c8\u5e0c\u51b2\u7a81 hash collision\u300d\u3002

        \u56fe 6-3 \u00a0 \u54c8\u5e0c\u51b2\u7a81\u793a\u4f8b

        \u5bb9\u6613\u60f3\u5230\uff0c\u54c8\u5e0c\u8868\u5bb9\u91cf \\(n\\) \u8d8a\u5927\uff0c\u591a\u4e2a key \u88ab\u5206\u914d\u5230\u540c\u4e00\u4e2a\u6876\u4e2d\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\uff0c\u51b2\u7a81\u5c31\u8d8a\u5c11\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6269\u5bb9\u54c8\u5e0c\u8868\u6765\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u3002

        \u5982\u56fe 6-4 \u6240\u793a\uff0c\u6269\u5bb9\u524d\u952e\u503c\u5bf9 (136, A) \u548c (236, D) \u53d1\u751f\u51b2\u7a81\uff0c\u6269\u5bb9\u540e\u51b2\u7a81\u6d88\u5931\u3002

        \u56fe 6-4 \u00a0 \u54c8\u5e0c\u8868\u6269\u5bb9

        \u7c7b\u4f3c\u4e8e\u6570\u7ec4\u6269\u5bb9\uff0c\u54c8\u5e0c\u8868\u6269\u5bb9\u9700\u5c06\u6240\u6709\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u8fc1\u79fb\u81f3\u65b0\u54c8\u5e0c\u8868\uff0c\u975e\u5e38\u8017\u65f6\uff1b\u5e76\u4e14\u7531\u4e8e\u54c8\u5e0c\u8868\u5bb9\u91cf capacity \u6539\u53d8\uff0c\u6211\u4eec\u9700\u8981\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u6765\u91cd\u65b0\u8ba1\u7b97\u6240\u6709\u952e\u503c\u5bf9\u7684\u5b58\u50a8\u4f4d\u7f6e\uff0c\u8fd9\u8fdb\u4e00\u6b65\u63d0\u9ad8\u4e86\u6269\u5bb9\u8fc7\u7a0b\u7684\u8ba1\u7b97\u5f00\u9500\u3002\u4e3a\u6b64\uff0c\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u9884\u7559\u8db3\u591f\u5927\u7684\u54c8\u5e0c\u8868\u5bb9\u91cf\uff0c\u9632\u6b62\u9891\u7e41\u6269\u5bb9\u3002

        \u300c\u8d1f\u8f7d\u56e0\u5b50 load factor\u300d\u662f\u54c8\u5e0c\u8868\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u5176\u5b9a\u4e49\u4e3a\u54c8\u5e0c\u8868\u7684\u5143\u7d20\u6570\u91cf\u9664\u4ee5\u6876\u6570\u91cf\uff0c\u7528\u4e8e\u8861\u91cf\u54c8\u5e0c\u51b2\u7a81\u7684\u4e25\u91cd\u7a0b\u5ea6\uff0c\u4e5f\u5e38\u4f5c\u4e3a\u54c8\u5e0c\u8868\u6269\u5bb9\u7684\u89e6\u53d1\u6761\u4ef6\u3002\u4f8b\u5982\u5728 Java \u4e2d\uff0c\u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7 \\(0.75\\) \u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c06\u54c8\u5e0c\u8868\u6269\u5bb9\u81f3\u539f\u5148\u7684 \\(2\\) \u500d\u3002

        "},{"location":"chapter_hashing/summary/","title":"6.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_hashing/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u8f93\u5165 key \uff0c\u54c8\u5e0c\u8868\u80fd\u591f\u5728 \\(O(1)\\) \u65f6\u95f4\u5185\u67e5\u8be2\u5230 value \uff0c\u6548\u7387\u975e\u5e38\u9ad8\u3002
        • \u5e38\u89c1\u7684\u54c8\u5e0c\u8868\u64cd\u4f5c\u5305\u62ec\u67e5\u8be2\u3001\u6dfb\u52a0\u952e\u503c\u5bf9\u3001\u5220\u9664\u952e\u503c\u5bf9\u548c\u904d\u5386\u54c8\u5e0c\u8868\u7b49\u3002
        • \u54c8\u5e0c\u51fd\u6570\u5c06 key \u6620\u5c04\u4e3a\u6570\u7ec4\u7d22\u5f15\uff0c\u4ece\u800c\u8bbf\u95ee\u5bf9\u5e94\u6876\u5e76\u83b7\u53d6 value \u3002
        • \u4e24\u4e2a\u4e0d\u540c\u7684 key \u53ef\u80fd\u5728\u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u540e\u5f97\u5230\u76f8\u540c\u7684\u6570\u7ec4\u7d22\u5f15\uff0c\u5bfc\u81f4\u67e5\u8be2\u7ed3\u679c\u51fa\u9519\uff0c\u8fd9\u79cd\u73b0\u8c61\u88ab\u79f0\u4e3a\u54c8\u5e0c\u51b2\u7a81\u3002
        • \u54c8\u5e0c\u8868\u5bb9\u91cf\u8d8a\u5927\uff0c\u54c8\u5e0c\u51b2\u7a81\u7684\u6982\u7387\u5c31\u8d8a\u4f4e\u3002\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7\u6269\u5bb9\u54c8\u5e0c\u8868\u6765\u7f13\u89e3\u54c8\u5e0c\u51b2\u7a81\u3002\u4e0e\u6570\u7ec4\u6269\u5bb9\u7c7b\u4f3c\uff0c\u54c8\u5e0c\u8868\u6269\u5bb9\u64cd\u4f5c\u7684\u5f00\u9500\u5f88\u5927\u3002
        • \u8d1f\u8f7d\u56e0\u5b50\u5b9a\u4e49\u4e3a\u54c8\u5e0c\u8868\u4e2d\u5143\u7d20\u6570\u91cf\u9664\u4ee5\u6876\u6570\u91cf\uff0c\u53cd\u6620\u4e86\u54c8\u5e0c\u51b2\u7a81\u7684\u4e25\u91cd\u7a0b\u5ea6\uff0c\u5e38\u7528\u4f5c\u89e6\u53d1\u54c8\u5e0c\u8868\u6269\u5bb9\u7684\u6761\u4ef6\u3002
        • \u94fe\u5f0f\u5730\u5740\u901a\u8fc7\u5c06\u5355\u4e2a\u5143\u7d20\u8f6c\u5316\u4e3a\u94fe\u8868\uff0c\u5c06\u6240\u6709\u51b2\u7a81\u5143\u7d20\u5b58\u50a8\u5728\u540c\u4e00\u4e2a\u94fe\u8868\u4e2d\u3002\u7136\u800c\uff0c\u94fe\u8868\u8fc7\u957f\u4f1a\u964d\u4f4e\u67e5\u8be2\u6548\u7387\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fdb\u4e00\u6b65\u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u7ea2\u9ed1\u6811\u6765\u63d0\u9ad8\u6548\u7387\u3002
        • \u5f00\u653e\u5bfb\u5740\u901a\u8fc7\u591a\u6b21\u63a2\u6d4b\u6765\u5904\u7406\u54c8\u5e0c\u51b2\u7a81\u3002\u7ebf\u6027\u63a2\u6d4b\u4f7f\u7528\u56fa\u5b9a\u6b65\u957f\uff0c\u7f3a\u70b9\u662f\u4e0d\u80fd\u5220\u9664\u5143\u7d20\uff0c\u4e14\u5bb9\u6613\u4ea7\u751f\u805a\u96c6\u3002\u591a\u6b21\u54c8\u5e0c\u4f7f\u7528\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u8fdb\u884c\u63a2\u6d4b\uff0c\u76f8\u8f83\u7ebf\u6027\u63a2\u6d4b\u66f4\u4e0d\u6613\u4ea7\u751f\u805a\u96c6\uff0c\u4f46\u591a\u4e2a\u54c8\u5e0c\u51fd\u6570\u589e\u52a0\u4e86\u8ba1\u7b97\u91cf\u3002
        • \u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u3002\u4f8b\u5982\uff0cJava \u7684 HashMap \u4f7f\u7528\u94fe\u5f0f\u5730\u5740\uff0c\u800c Python \u7684 Dict \u91c7\u7528\u5f00\u653e\u5bfb\u5740\u3002
        • \u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u54c8\u5e0c\u7b97\u6cd5\u5177\u6709\u786e\u5b9a\u6027\u3001\u9ad8\u6548\u7387\u548c\u5747\u5300\u5206\u5e03\u7684\u7279\u70b9\u3002\u5728\u5bc6\u7801\u5b66\u4e2d\uff0c\u54c8\u5e0c\u7b97\u6cd5\u8fd8\u5e94\u8be5\u5177\u5907\u6297\u78b0\u649e\u6027\u548c\u96ea\u5d29\u6548\u5e94\u3002
        • \u54c8\u5e0c\u7b97\u6cd5\u901a\u5e38\u91c7\u7528\u5927\u8d28\u6570\u4f5c\u4e3a\u6a21\u6570\uff0c\u4ee5\u6700\u5927\u5316\u5730\u4fdd\u8bc1\u54c8\u5e0c\u503c\u5747\u5300\u5206\u5e03\uff0c\u51cf\u5c11\u54c8\u5e0c\u51b2\u7a81\u3002
        • \u5e38\u89c1\u7684\u54c8\u5e0c\u7b97\u6cd5\u5305\u62ec MD5\u3001SHA-1\u3001SHA-2 \u548c SHA-3 \u7b49\u3002MD5 \u5e38\u7528\u4e8e\u6821\u9a8c\u6587\u4ef6\u5b8c\u6574\u6027\uff0cSHA-2 \u5e38\u7528\u4e8e\u5b89\u5168\u5e94\u7528\u4e0e\u534f\u8bae\u3002
        • \u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u4f1a\u4e3a\u6570\u636e\u7c7b\u578b\u63d0\u4f9b\u5185\u7f6e\u54c8\u5e0c\u7b97\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u54c8\u5e0c\u8868\u4e2d\u7684\u6876\u7d22\u5f15\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u4e0d\u53ef\u53d8\u5bf9\u8c61\u662f\u53ef\u54c8\u5e0c\u7684\u3002
        "},{"location":"chapter_hashing/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u4ec0\u4e48\u4e0d\u662f \\(O(n)\\) \uff1f

        \u5f53\u54c8\u5e0c\u51b2\u7a81\u6bd4\u8f83\u4e25\u91cd\u65f6\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u9000\u5316\u81f3 \\(O(n)\\) \u3002\u5f53\u54c8\u5e0c\u51fd\u6570\u8bbe\u8ba1\u5f97\u6bd4\u8f83\u597d\u3001\u5bb9\u91cf\u8bbe\u7f6e\u6bd4\u8f83\u5408\u7406\u3001\u51b2\u7a81\u6bd4\u8f83\u5e73\u5747\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002\u6211\u4eec\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u7684\u54c8\u5e0c\u8868\u65f6\uff0c\u901a\u5e38\u8ba4\u4e3a\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(1)\\) \u3002

        \u4e3a\u4ec0\u4e48\u4e0d\u4f7f\u7528\u54c8\u5e0c\u51fd\u6570 \\(f(x) = x\\) \u5462\uff1f\u8fd9\u6837\u5c31\u4e0d\u4f1a\u6709\u51b2\u7a81\u4e86

        \u5728 \\(f(x) = x\\) \u54c8\u5e0c\u51fd\u6570\u4e0b\uff0c\u6bcf\u4e2a\u5143\u7d20\u5bf9\u5e94\u552f\u4e00\u7684\u6876\u7d22\u5f15\uff0c\u8fd9\u4e0e\u6570\u7ec4\u7b49\u4ef7\u3002\u7136\u800c\uff0c\u8f93\u5165\u7a7a\u95f4\u901a\u5e38\u8fdc\u5927\u4e8e\u8f93\u51fa\u7a7a\u95f4\uff08\u6570\u7ec4\u957f\u5ea6\uff09\uff0c\u56e0\u6b64\u54c8\u5e0c\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u5f80\u5f80\u662f\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u54c8\u5e0c\u8868\u7684\u76ee\u6807\u662f\u5c06\u4e00\u4e2a\u8f83\u5927\u7684\u72b6\u6001\u7a7a\u95f4\u6620\u5c04\u5230\u4e00\u4e2a\u8f83\u5c0f\u7684\u7a7a\u95f4\uff0c\u5e76\u63d0\u4f9b \\(O(1)\\) \u7684\u67e5\u8be2\u6548\u7387\u3002

        \u54c8\u5e0c\u8868\u5e95\u5c42\u5b9e\u73b0\u662f\u6570\u7ec4\u3001\u94fe\u8868\u3001\u4e8c\u53c9\u6811\uff0c\u4f46\u4e3a\u4ec0\u4e48\u6548\u7387\u53ef\u4ee5\u6bd4\u5b83\u4eec\u66f4\u9ad8\u5462\uff1f

        \u9996\u5148\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u6548\u7387\u53d8\u9ad8\uff0c\u4f46\u7a7a\u95f4\u6548\u7387\u53d8\u4f4e\u4e86\u3002\u54c8\u5e0c\u8868\u6709\u76f8\u5f53\u4e00\u90e8\u5206\u5185\u5b58\u672a\u4f7f\u7528\u3002

        \u5176\u6b21\uff0c\u53ea\u662f\u5728\u7279\u5b9a\u4f7f\u7528\u573a\u666f\u4e0b\u65f6\u95f4\u6548\u7387\u53d8\u9ad8\u4e86\u3002\u5982\u679c\u4e00\u4e2a\u529f\u80fd\u80fd\u591f\u5728\u76f8\u540c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u4f7f\u7528\u6570\u7ec4\u6216\u94fe\u8868\u5b9e\u73b0\uff0c\u90a3\u4e48\u901a\u5e38\u6bd4\u54c8\u5e0c\u8868\u66f4\u5feb\u3002\u8fd9\u662f\u56e0\u4e3a\u54c8\u5e0c\u51fd\u6570\u8ba1\u7b97\u9700\u8981\u5f00\u9500\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u5e38\u6570\u9879\u66f4\u5927\u3002

        \u6700\u540e\uff0c\u54c8\u5e0c\u8868\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u80fd\u53d1\u751f\u52a3\u5316\u3002\u4f8b\u5982\u5728\u94fe\u5f0f\u5730\u5740\u4e2d\uff0c\u6211\u4eec\u91c7\u53d6\u5728\u94fe\u8868\u6216\u7ea2\u9ed1\u6811\u4e2d\u6267\u884c\u67e5\u627e\u64cd\u4f5c\uff0c\u4ecd\u7136\u6709\u9000\u5316\u81f3 \\(O(n)\\) \u65f6\u95f4\u7684\u98ce\u9669\u3002

        \u591a\u6b21\u54c8\u5e0c\u6709\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u7684\u7f3a\u9677\u5417\uff1f\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u7a7a\u95f4\u8fd8\u80fd\u518d\u6b21\u4f7f\u7528\u5417\uff1f

        \u591a\u6b21\u54c8\u5e0c\u662f\u5f00\u653e\u5bfb\u5740\u7684\u4e00\u79cd\uff0c\u5f00\u653e\u5bfb\u5740\u6cd5\u90fd\u6709\u4e0d\u80fd\u76f4\u63a5\u5220\u9664\u5143\u7d20\u7684\u7f3a\u9677\uff0c\u9700\u8981\u901a\u8fc7\u6807\u8bb0\u5220\u9664\u3002\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u7a7a\u95f4\u53ef\u4ee5\u518d\u6b21\u4f7f\u7528\u3002\u5f53\u5c06\u65b0\u5143\u7d20\u63d2\u5165\u54c8\u5e0c\u8868\uff0c\u5e76\u4e14\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u627e\u5230\u6807\u8bb0\u4e3a\u5df2\u5220\u9664\u7684\u4f4d\u7f6e\u65f6\uff0c\u8be5\u4f4d\u7f6e\u53ef\u4ee5\u88ab\u65b0\u5143\u7d20\u4f7f\u7528\u3002\u8fd9\u6837\u505a\u65e2\u80fd\u4fdd\u6301\u54c8\u5e0c\u8868\u7684\u63a2\u6d4b\u5e8f\u5217\u4e0d\u53d8\uff0c\u53c8\u80fd\u4fdd\u8bc1\u54c8\u5e0c\u8868\u7684\u7a7a\u95f4\u4f7f\u7528\u7387\u3002

        \u4e3a\u4ec0\u4e48\u5728\u7ebf\u6027\u63a2\u6d4b\u4e2d\uff0c\u67e5\u627e\u5143\u7d20\u7684\u65f6\u5019\u4f1a\u51fa\u73b0\u54c8\u5e0c\u51b2\u7a81\u5462\uff1f

        \u67e5\u627e\u7684\u65f6\u5019\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u627e\u5230\u5bf9\u5e94\u7684\u6876\u548c\u952e\u503c\u5bf9\uff0c\u53d1\u73b0 key \u4e0d\u5339\u914d\uff0c\u8fd9\u5c31\u4ee3\u8868\u6709\u54c8\u5e0c\u51b2\u7a81\u3002\u56e0\u6b64\uff0c\u7ebf\u6027\u63a2\u6d4b\u6cd5\u4f1a\u6839\u636e\u9884\u5148\u8bbe\u5b9a\u7684\u6b65\u957f\u4f9d\u6b21\u5411\u4e0b\u67e5\u627e\uff0c\u76f4\u81f3\u627e\u5230\u6b63\u786e\u7684\u952e\u503c\u5bf9\u6216\u65e0\u6cd5\u627e\u5230\u8df3\u51fa\u4e3a\u6b62\u3002

        \u4e3a\u4ec0\u4e48\u54c8\u5e0c\u8868\u6269\u5bb9\u80fd\u591f\u7f13\u89e3\u54c8\u5e0c\u51b2\u7a81\uff1f

        \u54c8\u5e0c\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u5f80\u5f80\u662f\u5bf9\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u53d6\u4f59\uff0c\u8ba9\u8f93\u51fa\u503c\u843d\u5728\u6570\u7ec4\u7d22\u5f15\u8303\u56f4\u5185\uff1b\u5728\u6269\u5bb9\u540e\uff0c\u6570\u7ec4\u957f\u5ea6 \\(n\\) \u53d1\u751f\u53d8\u5316\uff0c\u800c key \u5bf9\u5e94\u7684\u7d22\u5f15\u4e5f\u53ef\u80fd\u53d1\u751f\u53d8\u5316\u3002\u539f\u5148\u843d\u5728\u540c\u4e00\u4e2a\u6876\u7684\u591a\u4e2a key \uff0c\u5728\u6269\u5bb9\u540e\u53ef\u80fd\u4f1a\u88ab\u5206\u914d\u5230\u591a\u4e2a\u6876\u4e2d\uff0c\u4ece\u800c\u5b9e\u73b0\u54c8\u5e0c\u51b2\u7a81\u7684\u7f13\u89e3\u3002

        "},{"location":"chapter_heap/","title":"\u7b2c 8 \u7ae0 \u00a0 \u5806","text":"

        Abstract

        \u5806\u5c31\u50cf\u662f\u5c71\u5cb3\u5cf0\u5ce6\uff0c\u5c42\u53e0\u8d77\u4f0f\u3001\u5f62\u6001\u5404\u5f02\u3002

        \u5ea7\u5ea7\u5c71\u5cf0\u9ad8\u4f4e\u9519\u843d\uff0c\u800c\u6700\u9ad8\u7684\u5c71\u5cf0\u603b\u662f\u6700\u5148\u6620\u5165\u773c\u5e18\u3002

        "},{"location":"chapter_heap/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 8.1 \u00a0 \u5806
        • 8.2 \u00a0 \u5efa\u5806\u64cd\u4f5c
        • 8.3 \u00a0 Top-K \u95ee\u9898
        • 8.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_heap/build_heap/","title":"8.2 \u00a0 \u5efa\u5806\u64cd\u4f5c","text":"

        \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5e0c\u671b\u4f7f\u7528\u4e00\u4e2a\u5217\u8868\u7684\u6240\u6709\u5143\u7d20\u6765\u6784\u5efa\u4e00\u4e2a\u5806\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u88ab\u79f0\u4e3a\u201c\u5efa\u5806\u64cd\u4f5c\u201d\u3002

        "},{"location":"chapter_heap/build_heap/#821","title":"8.2.1 \u00a0 \u501f\u52a9\u5165\u5806\u64cd\u4f5c\u5b9e\u73b0","text":"

        \u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u5806\uff0c\u7136\u540e\u904d\u5386\u5217\u8868\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e2a\u5143\u7d20\u6267\u884c\u201c\u5165\u5806\u64cd\u4f5c\u201d\uff0c\u5373\u5148\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u5806\u7684\u5c3e\u90e8\uff0c\u518d\u5bf9\u8be5\u5143\u7d20\u6267\u884c\u201c\u4ece\u5e95\u81f3\u9876\u201d\u5806\u5316\u3002

        \u6bcf\u5f53\u4e00\u4e2a\u5143\u7d20\u5165\u5806\uff0c\u5806\u7684\u957f\u5ea6\u5c31\u52a0\u4e00\u3002\u7531\u4e8e\u8282\u70b9\u662f\u4ece\u9876\u5230\u5e95\u4f9d\u6b21\u88ab\u6dfb\u52a0\u8fdb\u4e8c\u53c9\u6811\u7684\uff0c\u56e0\u6b64\u5806\u662f\u201c\u81ea\u4e0a\u800c\u4e0b\u201d\u6784\u5efa\u7684\u3002

        \u8bbe\u5143\u7d20\u6570\u91cf\u4e3a \\(n\\) \uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u5165\u5806\u64cd\u4f5c\u4f7f\u7528 \\(O(\\log{n})\\) \u65f6\u95f4\uff0c\u56e0\u6b64\u8be5\u5efa\u5806\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        "},{"location":"chapter_heap/build_heap/#822","title":"8.2.2 \u00a0 \u901a\u8fc7\u904d\u5386\u5806\u5316\u5b9e\u73b0","text":"

        \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u79cd\u66f4\u4e3a\u9ad8\u6548\u7684\u5efa\u5806\u65b9\u6cd5\uff0c\u5171\u5206\u4e3a\u4e24\u6b65\u3002

        1. \u5c06\u5217\u8868\u6240\u6709\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u5230\u5806\u4e2d\uff0c\u6b64\u65f6\u5806\u7684\u6027\u8d28\u5c1a\u672a\u5f97\u5230\u6ee1\u8db3\u3002
        2. \u5012\u5e8f\u904d\u5386\u5806\uff08\u5373\u5c42\u5e8f\u904d\u5386\u7684\u5012\u5e8f\uff09\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e2a\u975e\u53f6\u8282\u70b9\u6267\u884c\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u3002

        \u6bcf\u5f53\u5806\u5316\u4e00\u4e2a\u8282\u70b9\u540e\uff0c\u4ee5\u8be5\u8282\u70b9\u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\u5c31\u5f62\u6210\u4e00\u4e2a\u5408\u6cd5\u7684\u5b50\u5806\u3002\u800c\u7531\u4e8e\u662f\u5012\u5e8f\u904d\u5386\uff0c\u56e0\u6b64\u5806\u662f\u201c\u81ea\u4e0b\u800c\u4e0a\u201d\u6784\u5efa\u7684\u3002

        \u4e4b\u6240\u4ee5\u9009\u62e9\u5012\u5e8f\u904d\u5386\uff0c\u662f\u56e0\u4e3a\u8fd9\u6837\u80fd\u591f\u4fdd\u8bc1\u5f53\u524d\u8282\u70b9\u4e4b\u4e0b\u7684\u5b50\u6811\u5df2\u7ecf\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\u8fd9\u6837\u5806\u5316\u5f53\u524d\u8282\u70b9\u624d\u662f\u6709\u6548\u7684\u3002

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u53f6\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5929\u7136\u5c31\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\u56e0\u6b64\u65e0\u987b\u5806\u5316\u3002\u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\uff0c\u6700\u540e\u4e00\u4e2a\u975e\u53f6\u8282\u70b9\u662f\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9\uff0c\u6211\u4eec\u4ece\u5b83\u5f00\u59cb\u5012\u5e8f\u904d\u5386\u5e76\u6267\u884c\u5806\u5316\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def __init__(self, nums: list[int]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806\"\"\"\n# \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nself.max_heap = nums\n# \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in range(self.parent(self.size() - 1), -1, -1):\nself.sift_down(i)\n
        my_heap.cpp
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(vector<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = nums;\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.java
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(List<Integer> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = new ArrayList<>(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.cs
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(IEnumerable<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = new List<int>(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nvar size = Parent(this.Size() - 1);\nfor (int i = size; i >= 0; i--) {\nSiftDown(i);\n}\n}\n
        my_heap.go
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u5207\u7247\u5efa\u5806 */\nfunc newMaxHeap(nums []any) *maxHeap {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nh := &maxHeap{data: nums}\nfor i := h.parent(len(h.data) - 1); i >= 0; i-- {\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nh.siftDown(i)\n}\nreturn h\n}\n
        my_heap.swift
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\ninit(nums: [Int]) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nmaxHeap = nums\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in stride(from: parent(i: size() - 1), through: 0, by: -1) {\nsiftDown(i: i)\n}\n}\n
        my_heap.js
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u5efa\u7acb\u7a7a\u5806\u6216\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nconstructor(nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nthis.#maxHeap = nums === undefined ? [] : [...nums];\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = this.#parent(this.size() - 1); i >= 0; i--) {\nthis.#siftDown(i);\n}\n}\n
        my_heap.ts
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u5efa\u7acb\u7a7a\u5806\u6216\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nconstructor(nums?: number[]) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nthis.maxHeap = nums === undefined ? [] : [...nums];\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = this.parent(this.size() - 1); i >= 0; i--) {\nthis.siftDown(i);\n}\n}\n
        my_heap.dart
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nMaxHeap(List<int> nums) {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\n_maxHeap = nums;\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = _parent(size() - 1); i >= 0; i--) {\nsiftDown(i);\n}\n}\n
        my_heap.rs
        /* \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806 */\nfn new(nums: Vec<i32>) -> Self {\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\nlet mut heap = MaxHeap { max_heap: nums };\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in (0..=Self::parent(heap.size() - 1)).rev() {\nheap.sift_down(i);\n}\nheap\n}\n
        my_heap.c
        /* \u6784\u9020\u51fd\u6570\uff0c\u6839\u636e\u5207\u7247\u5efa\u5806 */\nMaxHeap *newMaxHeap(int nums[], int size) {\n// \u6240\u6709\u5143\u7d20\u5165\u5806\nMaxHeap *maxHeap = (MaxHeap *)malloc(sizeof(MaxHeap));\nmaxHeap->size = size;\nmemcpy(maxHeap->data, nums, size * sizeof(int));\nfor (int i = parent(maxHeap, size - 1); i >= 0; i--) {\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nsiftDown(maxHeap, i);\n}\nreturn maxHeap;\n}\n
        my_heap.zig
        // \u6784\u9020\u65b9\u6cd5\uff0c\u6839\u636e\u8f93\u5165\u5217\u8868\u5efa\u5806\nfn init(self: *Self, allocator: std.mem.Allocator, nums: []const T) !void {\nif (self.max_heap != null) return;\nself.max_heap = std.ArrayList(T).init(allocator);\n// \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\ntry self.max_heap.?.appendSlice(nums);\n// \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nvar i: usize = parent(self.size() - 1) + 1;\nwhile (i > 0) : (i -= 1) {\ntry self.siftDown(i - 1);\n}\n}\n
        "},{"location":"chapter_heap/build_heap/#823","title":"8.2.3 \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"

        \u4e0b\u9762\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u63a8\u7b97\u7b2c\u4e8c\u79cd\u5efa\u5806\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002

        • \u5047\u8bbe\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \uff0c\u5219\u53f6\u8282\u70b9\u6570\u91cf\u4e3a \\((n + 1) / 2\\) \uff0c\u5176\u4e2d \\(/\\) \u4e3a\u5411\u4e0b\u6574\u9664\u3002\u56e0\u6b64\u9700\u8981\u5806\u5316\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\((n - 1) / 2\\) \u3002
        • \u5728\u4ece\u9876\u81f3\u5e95\u5806\u5316\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u6700\u591a\u5806\u5316\u5230\u53f6\u8282\u70b9\uff0c\u56e0\u6b64\u6700\u5927\u8fed\u4ee3\u6b21\u6570\u4e3a\u4e8c\u53c9\u6811\u9ad8\u5ea6 \\(\\log n\\) \u3002

        \u5c06\u4e0a\u8ff0\u4e24\u8005\u76f8\u4e58\uff0c\u53ef\u5f97\u5230\u5efa\u5806\u8fc7\u7a0b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u4f46\u8fd9\u4e2a\u4f30\u7b97\u7ed3\u679c\u5e76\u4e0d\u51c6\u786e\uff0c\u56e0\u4e3a\u6211\u4eec\u6ca1\u6709\u8003\u8651\u5230\u4e8c\u53c9\u6811\u5e95\u5c42\u8282\u70b9\u6570\u91cf\u8fdc\u591a\u4e8e\u9876\u5c42\u8282\u70b9\u7684\u6027\u8d28\u3002

        \u63a5\u4e0b\u6765\u6211\u4eec\u6765\u8fdb\u884c\u66f4\u4e3a\u51c6\u786e\u7684\u8ba1\u7b97\u3002\u4e3a\u4e86\u964d\u4f4e\u8ba1\u7b97\u96be\u5ea6\uff0c\u5047\u8bbe\u7ed9\u5b9a\u4e00\u4e2a\u8282\u70b9\u6570\u91cf\u4e3a \\(n\\) \u3001\u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u201c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u201d\uff0c\u8be5\u5047\u8bbe\u4e0d\u4f1a\u5f71\u54cd\u8ba1\u7b97\u7ed3\u679c\u7684\u6b63\u786e\u6027\u3002

        \u56fe 8-5 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u5404\u5c42\u8282\u70b9\u6570\u91cf

        \u5982\u56fe 8-5 \u6240\u793a\uff0c\u8282\u70b9\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u7684\u6700\u5927\u8fed\u4ee3\u6b21\u6570\u7b49\u4e8e\u8be5\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u800c\u8be5\u8ddd\u79bb\u6b63\u662f\u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u5404\u5c42\u7684\u201c\u8282\u70b9\u6570\u91cf \\(\\times\\) \u8282\u70b9\u9ad8\u5ea6\u201d\u6c42\u548c\uff0c\u5f97\u5230\u6240\u6709\u8282\u70b9\u7684\u5806\u5316\u8fed\u4ee3\u6b21\u6570\u7684\u603b\u548c\u3002

        \\[ T(h) = 2^0h + 2^1(h-1) + 2^2(h-2) + \\dots + 2^{(h-1)}\\times1 \\]

        \u5316\u7b80\u4e0a\u5f0f\u9700\u8981\u501f\u52a9\u4e2d\u5b66\u7684\u6570\u5217\u77e5\u8bc6\uff0c\u5148\u5bf9 \\(T(h)\\) \u4e58\u4ee5 \\(2\\) \uff0c\u5f97\u5230\uff1a

        \\[ \\begin{aligned} T(h) & = 2^0h + 2^1(h-1) + 2^2(h-2) + \\dots + 2^{h-1}\\times1 \\newline 2 T(h) & = 2^1h + 2^2(h-1) + 2^3(h-2) + \\dots + 2^{h}\\times1 \\newline \\end{aligned} \\]

        \u4f7f\u7528\u9519\u4f4d\u76f8\u51cf\u6cd5\uff0c\u7528\u4e0b\u5f0f \\(2 T(h)\\) \u51cf\u53bb\u4e0a\u5f0f \\(T(h)\\) \uff0c\u53ef\u5f97\uff1a

        \\[ 2T(h) - T(h) = T(h) = -2^0h + 2^1 + 2^2 + \\dots + 2^{h-1} + 2^h \\]

        \u89c2\u5bdf\u4e0a\u5f0f\uff0c\u53d1\u73b0 \\(T(h)\\) \u662f\u4e00\u4e2a\u7b49\u6bd4\u6570\u5217\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\u6c42\u548c\u516c\u5f0f\uff0c\u5f97\u5230\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\uff1a

        \\[ \\begin{aligned} T(h) & = 2 \\frac{1 - 2^h}{1 - 2} - h \\newline & = 2^{h+1} - h - 2 \\newline & = O(2^h) \\end{aligned} \\]

        \u8fdb\u4e00\u6b65\u5730\uff0c\u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u6570\u91cf\u4e3a \\(n = 2^{h+1} - 1\\) \uff0c\u6613\u5f97\u590d\u6742\u5ea6\u4e3a \\(O(2^h) = O(n)\\) \u3002\u4ee5\u4e0a\u63a8\u7b97\u8868\u660e\uff0c\u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002

        "},{"location":"chapter_heap/heap/","title":"8.1 \u00a0 \u5806","text":"

        \u300c\u5806 heap\u300d\u662f\u4e00\u79cd\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u4e3b\u8981\u53ef\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff0c\u5982\u56fe 8-1 \u6240\u793a\u3002

        • \u300c\u5927\u9876\u5806 max heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\geq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002
        • \u300c\u5c0f\u9876\u5806 min heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\leq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002

        \u56fe 8-1 \u00a0 \u5c0f\u9876\u5806\u4e0e\u5927\u9876\u5806

        \u5806\u4f5c\u4e3a\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u4e00\u4e2a\u7279\u4f8b\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u6700\u5e95\u5c42\u8282\u70b9\u9760\u5de6\u586b\u5145\uff0c\u5176\u4ed6\u5c42\u7684\u8282\u70b9\u90fd\u88ab\u586b\u6ee1\u3002
        • \u6211\u4eec\u5c06\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\u79f0\u4e3a\u201c\u5806\u9876\u201d\uff0c\u5c06\u5e95\u5c42\u6700\u9760\u53f3\u7684\u8282\u70b9\u79f0\u4e3a\u201c\u5806\u5e95\u201d\u3002
        • \u5bf9\u4e8e\u5927\u9876\u5806\uff08\u5c0f\u9876\u5806\uff09\uff0c\u5806\u9876\u5143\u7d20\uff08\u6839\u8282\u70b9\uff09\u7684\u503c\u5206\u522b\u662f\u6700\u5927\uff08\u6700\u5c0f\uff09\u7684\u3002
        "},{"location":"chapter_heap/heap/#811","title":"8.1.1 \u00a0 \u5806\u5e38\u7528\u64cd\u4f5c","text":"

        \u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684\u662f\u300c\u4f18\u5148\u961f\u5217 priority queue\u300d\uff0c\u8fd9\u662f\u4e00\u79cd\u62bd\u8c61\u6570\u636e\u7ed3\u6784\uff0c\u5b9a\u4e49\u4e3a\u5177\u6709\u4f18\u5148\u7ea7\u6392\u5e8f\u7684\u961f\u5217\u3002

        \u5b9e\u9645\u4e0a\uff0c\u5806\u901a\u5e38\u7528\u4e8e\u5b9e\u73b0\u4f18\u5148\u961f\u5217\uff0c\u5927\u9876\u5806\u76f8\u5f53\u4e8e\u5143\u7d20\u6309\u4ece\u5927\u5230\u5c0f\u7684\u987a\u5e8f\u51fa\u961f\u7684\u4f18\u5148\u961f\u5217\u3002\u4ece\u4f7f\u7528\u89d2\u5ea6\u6765\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u201c\u4f18\u5148\u961f\u5217\u201d\u548c\u201c\u5806\u201d\u770b\u4f5c\u7b49\u4ef7\u7684\u6570\u636e\u7ed3\u6784\u3002\u56e0\u6b64\uff0c\u672c\u4e66\u5bf9\u4e24\u8005\u4e0d\u505a\u7279\u522b\u533a\u5206\uff0c\u7edf\u4e00\u79f0\u4f5c\u201c\u5806\u201d\u3002

        \u5806\u7684\u5e38\u7528\u64cd\u4f5c\u89c1\u8868 8-1 \uff0c\u65b9\u6cd5\u540d\u9700\u8981\u6839\u636e\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002

        \u8868 8-1 \u00a0 \u5806\u7684\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u5806 \\(O(\\log n)\\) pop() \u5806\u9876\u5143\u7d20\u51fa\u5806 \\(O(\\log n)\\) peek() \u8bbf\u95ee\u5806\u9876\u5143\u7d20\uff08\u5927 / \u5c0f\u9876\u5806\u5206\u522b\u4e3a\u6700\u5927 / \u5c0f\u503c\uff09 \\(O(1)\\) size() \u83b7\u53d6\u5806\u7684\u5143\u7d20\u6570\u91cf \\(O(1)\\) isEmpty() \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a \\(O(1)\\)

        \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u63d0\u4f9b\u7684\u5806\u7c7b\uff08\u6216\u4f18\u5148\u961f\u5217\u7c7b\uff09\u3002

        \u7c7b\u4f3c\u4e8e\u6392\u5e8f\u7b97\u6cd5\u4e2d\u7684\u201c\u4ece\u5c0f\u5230\u5927\u6392\u5217\u201d\u548c\u201c\u4ece\u5927\u5230\u5c0f\u6392\u5217\u201d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e00\u4e2a flag \u6216\u4fee\u6539 Comparator \u5b9e\u73b0\u201c\u5c0f\u9876\u5806\u201d\u4e0e\u201c\u5927\u9876\u5806\u201d\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig heap.py
        # \u521d\u59cb\u5316\u5c0f\u9876\u5806\nmin_heap, flag = [], 1\n# \u521d\u59cb\u5316\u5927\u9876\u5806\nmax_heap, flag = [], -1\n# Python \u7684 heapq \u6a21\u5757\u9ed8\u8ba4\u5b9e\u73b0\u5c0f\u9876\u5806\n# \u8003\u8651\u5c06\u201c\u5143\u7d20\u53d6\u8d1f\u201d\u540e\u518d\u5165\u5806\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5c06\u5927\u5c0f\u5173\u7cfb\u98a0\u5012\uff0c\u4ece\u800c\u5b9e\u73b0\u5927\u9876\u5806\n# \u5728\u672c\u793a\u4f8b\u4e2d\uff0cflag = 1 \u65f6\u5bf9\u5e94\u5c0f\u9876\u5806\uff0cflag = -1 \u65f6\u5bf9\u5e94\u5927\u9876\u5806\n# \u5143\u7d20\u5165\u5806\nheapq.heappush(max_heap, flag * 1)\nheapq.heappush(max_heap, flag * 3)\nheapq.heappush(max_heap, flag * 2)\nheapq.heappush(max_heap, flag * 5)\nheapq.heappush(max_heap, flag * 4)\n# \u83b7\u53d6\u5806\u9876\u5143\u7d20\npeek: int = flag * max_heap[0] # 5\n# \u5806\u9876\u5143\u7d20\u51fa\u5806\n# \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nval = flag * heapq.heappop(max_heap) # 5\nval = flag * heapq.heappop(max_heap) # 4\nval = flag * heapq.heappop(max_heap) # 3\nval = flag * heapq.heappop(max_heap) # 2\nval = flag * heapq.heappop(max_heap) # 1\n# \u83b7\u53d6\u5806\u5927\u5c0f\nsize: int = len(max_heap)\n# \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = not max_heap\n# \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806\nmin_heap: list[int] = [1, 3, 2, 5, 4]\nheapq.heapify(min_heap)\n
        heap.cpp
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\npriority_queue<int, vector<int>, greater<int>> minHeap;\n// \u521d\u59cb\u5316\u5927\u9876\u5806\npriority_queue<int, vector<int>, less<int>> maxHeap;\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.push(1);\nmaxHeap.push(3);\nmaxHeap.push(2);\nmaxHeap.push(5);\nmaxHeap.push(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.top(); // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nmaxHeap.pop(); // 5\nmaxHeap.pop(); // 4\nmaxHeap.pop(); // 3\nmaxHeap.pop(); // 2\nmaxHeap.pop(); // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.empty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nvector<int> input{1, 3, 2, 5, 4};\npriority_queue<int, vector<int>, greater<int>> minHeap(input.begin(), input.end());\n
        heap.java
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nQueue<Integer> minHeap = new PriorityQueue<>();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\uff08\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4fee\u6539 Comparator \u5373\u53ef\uff09\nQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.offer(1);\nmaxHeap.offer(3);\nmaxHeap.offer(2);\nmaxHeap.offer(5);\nmaxHeap.offer(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.peek(); // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\npeek = maxHeap.poll(); // 5\npeek = maxHeap.poll(); // 4\npeek = maxHeap.poll(); // 3\npeek = maxHeap.poll(); // 2\npeek = maxHeap.poll(); // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = maxHeap.isEmpty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nminHeap = new PriorityQueue<>(Arrays.asList(1, 3, 2, 5, 4));\n
        heap.cs
        /* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nPriorityQueue<int, int> minHeap = new();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\uff08\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4fee\u6539 Comparator \u5373\u53ef\uff09\nPriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x));\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.Enqueue(1, 1);\nmaxHeap.Enqueue(3, 3);\nmaxHeap.Enqueue(2, 2);\nmaxHeap.Enqueue(5, 5);\nmaxHeap.Enqueue(4, 4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.Peek();//5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\npeek = maxHeap.Dequeue();  // 5\npeek = maxHeap.Dequeue();  // 4\npeek = maxHeap.Dequeue();  // 3\npeek = maxHeap.Dequeue();  // 2\npeek = maxHeap.Dequeue();  // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.Count;\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.Count == 0;\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nminHeap = new PriorityQueue<int, int>([(1, 1), (3, 3), (2, 2), (5, 5), (4, 4)]);\n
        heap.go
        // Go \u8bed\u8a00\u4e2d\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0 heap.Interface \u6765\u6784\u5efa\u6574\u6570\u5927\u9876\u5806\n// \u5b9e\u73b0 heap.Interface \u9700\u8981\u540c\u65f6\u5b9e\u73b0 sort.Interface\ntype intHeap []any\n// Push heap.Interface \u7684\u65b9\u6cd5\uff0c\u5b9e\u73b0\u63a8\u5165\u5143\u7d20\u5230\u5806\nfunc (h *intHeap) Push(x any) {\n// Push \u548c Pop \u4f7f\u7528 pointer receiver \u4f5c\u4e3a\u53c2\u6570\n// \u56e0\u4e3a\u5b83\u4eec\u4e0d\u4ec5\u4f1a\u5bf9\u5207\u7247\u7684\u5185\u5bb9\u8fdb\u884c\u8c03\u6574\uff0c\u8fd8\u4f1a\u4fee\u6539\u5207\u7247\u7684\u957f\u5ea6\u3002\n*h = append(*h, x.(int))\n}\n// Pop heap.Interface \u7684\u65b9\u6cd5\uff0c\u5b9e\u73b0\u5f39\u51fa\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Pop() any {\n// \u5f85\u51fa\u5806\u5143\u7d20\u5b58\u653e\u5728\u6700\u540e\nlast := (*h)[len(*h)-1]\n*h = (*h)[:len(*h)-1]\nreturn last\n}\n// Len sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Len() int {\nreturn len(*h)\n}\n// Less sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Less(i, j int) bool {\n// \u5982\u679c\u5b9e\u73b0\u5c0f\u9876\u5806\uff0c\u5219\u9700\u8981\u8c03\u6574\u4e3a\u5c0f\u4e8e\u53f7\nreturn (*h)[i].(int) > (*h)[j].(int)\n}\n// Swap sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Swap(i, j int) {\n(*h)[i], (*h)[j] = (*h)[j], (*h)[i]\n}\n// Top \u83b7\u53d6\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Top() any {\nreturn (*h)[0]\n}\n/* Driver Code */\nfunc TestHeap(t *testing.T) {\n/* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5927\u9876\u5806\nmaxHeap := &intHeap{}\nheap.Init(maxHeap)\n/* \u5143\u7d20\u5165\u5806 */\n// \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u6dfb\u52a0\u5143\u7d20\nheap.Push(maxHeap, 1)\nheap.Push(maxHeap, 3)\nheap.Push(maxHeap, 2)\nheap.Push(maxHeap, 4)\nheap.Push(maxHeap, 5)\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\ntop := maxHeap.Top()\nfmt.Printf(\"\u5806\u9876\u5143\u7d20\u4e3a %d\\n\", top)\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u79fb\u9664\u5143\u7d20\nheap.Pop(maxHeap) // 5\nheap.Pop(maxHeap) // 4\nheap.Pop(maxHeap) // 3\nheap.Pop(maxHeap) // 2\nheap.Pop(maxHeap) // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nsize := len(*maxHeap)\nfmt.Printf(\"\u5806\u5143\u7d20\u6570\u91cf\u4e3a %d\\n\", size)\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nisEmpty := len(*maxHeap) == 0\nfmt.Printf(\"\u5806\u662f\u5426\u4e3a\u7a7a %t\\n\", isEmpty)\n}\n
        heap.swift
        // Swift \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.js
        // JavaScript \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.ts
        // TypeScript \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.dart
        // Dart \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.rs
        use std::collections::BinaryHeap;\nuse std::cmp::Reverse;\n/* \u521d\u59cb\u5316\u5806 */\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nlet mut min_heap = BinaryHeap::<Reverse<i32>>::new();\n// \u521d\u59cb\u5316\u5927\u9876\u5806\nlet mut max_heap = BinaryHeap::new();\n/* \u5143\u7d20\u5165\u5806 */\nmax_heap.push(1);\nmax_heap.push(3);\nmax_heap.push(2);\nmax_heap.push(5);\nmax_heap.push(4);\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nlet peek = max_heap.peek().unwrap();  // 5\n/* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n// \u51fa\u5806\u5143\u7d20\u4f1a\u5f62\u6210\u4e00\u4e2a\u4ece\u5927\u5230\u5c0f\u7684\u5e8f\u5217\nlet peek = max_heap.pop().unwrap();   // 5\nlet peek = max_heap.pop().unwrap();   // 4\nlet peek = max_heap.pop().unwrap();   // 3\nlet peek = max_heap.pop().unwrap();   // 2\nlet peek = max_heap.pop().unwrap();   // 1\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nlet size = max_heap.len();\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = max_heap.is_empty();\n/* \u8f93\u5165\u5217\u8868\u5e76\u5efa\u5806 */\nlet min_heap = BinaryHeap::from(vec![Reverse(1), Reverse(3), Reverse(2), Reverse(5), Reverse(4)]);\n
        heap.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e Heap \u7c7b\n
        heap.zig
        \n
        "},{"location":"chapter_heap/heap/#812","title":"8.1.2 \u00a0 \u5806\u7684\u5b9e\u73b0","text":"

        \u4e0b\u6587\u5b9e\u73b0\u7684\u662f\u5927\u9876\u5806\u3002\u82e5\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u5c0f\u9876\u5806\uff0c\u53ea\u9700\u5c06\u6240\u6709\u5927\u5c0f\u903b\u8f91\u5224\u65ad\u53d6\u9006\uff08\u4f8b\u5982\uff0c\u5c06 \\(\\geq\\) \u66ff\u6362\u4e3a \\(\\leq\\) \uff09\u3002\u611f\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u3002

        "},{"location":"chapter_heap/heap/#1","title":"1. \u00a0 \u5806\u7684\u5b58\u50a8\u4e0e\u8868\u793a","text":"

        \u201c\u4e8c\u53c9\u6811\u201d\u7ae0\u8282\u8bb2\u8fc7\uff0c\u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u7528\u6570\u7ec4\u6765\u8868\u793a\u3002\u7531\u4e8e\u5806\u6b63\u662f\u4e00\u79cd\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u91c7\u7528\u6570\u7ec4\u6765\u5b58\u50a8\u5806\u3002

        \u5f53\u4f7f\u7528\u6570\u7ec4\u8868\u793a\u4e8c\u53c9\u6811\u65f6\uff0c\u5143\u7d20\u4ee3\u8868\u8282\u70b9\u503c\uff0c\u7d22\u5f15\u4ee3\u8868\u8282\u70b9\u5728\u4e8c\u53c9\u6811\u4e2d\u7684\u4f4d\u7f6e\u3002\u8282\u70b9\u6307\u9488\u901a\u8fc7\u7d22\u5f15\u6620\u5c04\u516c\u5f0f\u6765\u5b9e\u73b0\u3002

        \u5982\u56fe 8-2 \u6240\u793a\uff0c\u7ed9\u5b9a\u7d22\u5f15 \\(i\\) \uff0c\u5176\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 2\\) \uff0c\u7236\u8282\u70b9\u7d22\u5f15\u4e3a \\((i - 1) / 2\\)\uff08\u5411\u4e0b\u6574\u9664\uff09\u3002\u5f53\u7d22\u5f15\u8d8a\u754c\u65f6\uff0c\u8868\u793a\u7a7a\u8282\u70b9\u6216\u8282\u70b9\u4e0d\u5b58\u5728\u3002

        \u56fe 8-2 \u00a0 \u5806\u7684\u8868\u793a\u4e0e\u5b58\u50a8

        \u6211\u4eec\u53ef\u4ee5\u5c06\u7d22\u5f15\u6620\u5c04\u516c\u5f0f\u5c01\u88c5\u6210\u51fd\u6570\uff0c\u65b9\u4fbf\u540e\u7eed\u4f7f\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def left(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn 2 * i + 1\ndef right(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn 2 * i + 2\ndef parent(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15\"\"\"\nreturn (i - 1) // 2  # \u5411\u4e0b\u6574\u9664\n
        my_heap.cpp
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.java
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.cs
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint Left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint Right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint Parent(int i) {\nreturn (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.go
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) left(i int) int {\nreturn 2*i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) right(i int) int {\nreturn 2*i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfunc (h *maxHeap) parent(i int) int {\n// \u5411\u4e0b\u6574\u9664\nreturn (i - 1) / 2\n}\n
        my_heap.swift
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n2 * i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfunc parent(i: Int) -> Int {\n(i - 1) / 2 // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.js
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\n#left(i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\n#right(i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\n#parent(i) {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.ts
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nleft(i: number): number {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nright(i: number): number {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nparent(i: number): number {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.dart
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint _left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint _right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint _parent(int i) {\nreturn (i - 1) ~/ 2; // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.rs
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nfn left(i: usize) -> usize {\n2 * i + 1\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nfn right(i: usize) -> usize {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nfn parent(i: usize) -> usize {\n(i - 1) / 2 // \u5411\u4e0b\u6574\u9664\n}\n
        my_heap.c
        /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15 */\nint left(MaxHeap *maxHeap, int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15 */\nint right(MaxHeap *maxHeap, int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15 */\nint parent(MaxHeap *maxHeap, int i) {\nreturn (i - 1) / 2;\n}\n
        my_heap.zig
        // \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\nfn left(i: usize) usize {\nreturn 2 * i + 1;\n}\n// \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\nfn right(i: usize) usize {\nreturn 2 * i + 2;\n}\n// \u83b7\u53d6\u7236\u8282\u70b9\u7d22\u5f15\nfn parent(i: usize) usize {\n// return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\nreturn @divFloor(i - 1, 2);\n}\n
        "},{"location":"chapter_heap/heap/#2","title":"2. \u00a0 \u8bbf\u95ee\u5806\u9876\u5143\u7d20","text":"

        \u5806\u9876\u5143\u7d20\u5373\u4e3a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u4e5f\u5c31\u662f\u5217\u8868\u7684\u9996\u4e2a\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u5806\u9876\u5143\u7d20\"\"\"\nreturn self.max_heap[0]\n
        my_heap.cpp
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn maxHeap[0];\n}\n
        my_heap.java
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn maxHeap.get(0);\n}\n
        my_heap.cs
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint Peek() {\nreturn maxHeap[0];\n}\n
        my_heap.go
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc (h *maxHeap) peek() any {\nreturn h.data[0]\n}\n
        my_heap.swift
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nmaxHeap[0]\n}\n
        my_heap.js
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek() {\nreturn this.#maxHeap[0];\n}\n
        my_heap.ts
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek(): number {\nreturn this.maxHeap[0];\n}\n
        my_heap.dart
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\nreturn _maxHeap[0];\n}\n
        my_heap.rs
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<i32> {\nself.max_heap.first().copied()\n}\n
        my_heap.c
        /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek(MaxHeap *maxHeap) {\nreturn maxHeap->data[0];\n}\n
        my_heap.zig
        // \u8bbf\u95ee\u5806\u9876\u5143\u7d20\nfn peek(self: *Self) T {\nreturn self.max_heap.?.items[0];\n}  
        "},{"location":"chapter_heap/heap/#3","title":"3. \u00a0 \u5143\u7d20\u5165\u5806","text":"

        \u7ed9\u5b9a\u5143\u7d20 val \uff0c\u6211\u4eec\u9996\u5148\u5c06\u5176\u6dfb\u52a0\u5230\u5806\u5e95\u3002\u6dfb\u52a0\u4e4b\u540e\uff0c\u7531\u4e8e val \u53ef\u80fd\u5927\u4e8e\u5806\u4e2d\u5176\u4ed6\u5143\u7d20\uff0c\u5806\u7684\u6210\u7acb\u6761\u4ef6\u53ef\u80fd\u5df2\u88ab\u7834\u574f\uff0c\u56e0\u6b64\u9700\u8981\u4fee\u590d\u4ece\u63d2\u5165\u8282\u70b9\u5230\u6839\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u7684\u5404\u4e2a\u8282\u70b9\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u88ab\u79f0\u4e3a\u300c\u5806\u5316 heapify\u300d\u3002

        \u8003\u8651\u4ece\u5165\u5806\u8282\u70b9\u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u6267\u884c\u5806\u5316\u3002\u5982\u56fe 8-3 \u6240\u793a\uff0c\u6211\u4eec\u6bd4\u8f83\u63d2\u5165\u8282\u70b9\u4e0e\u5176\u7236\u8282\u70b9\u7684\u503c\uff0c\u5982\u679c\u63d2\u5165\u8282\u70b9\u66f4\u5927\uff0c\u5219\u5c06\u5b83\u4eec\u4ea4\u6362\u3002\u7136\u540e\u7ee7\u7eed\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u4ece\u5e95\u81f3\u9876\u4fee\u590d\u5806\u4e2d\u7684\u5404\u4e2a\u8282\u70b9\uff0c\u76f4\u81f3\u8d8a\u8fc7\u6839\u8282\u70b9\u6216\u9047\u5230\u65e0\u987b\u4ea4\u6362\u7684\u8282\u70b9\u65f6\u7ed3\u675f\u3002

        <1><2><3><4><5><6><7><8><9>

        \u56fe 8-3 \u00a0 \u5143\u7d20\u5165\u5806\u6b65\u9aa4

        \u8bbe\u8282\u70b9\u603b\u6570\u4e3a \\(n\\) \uff0c\u5219\u6811\u7684\u9ad8\u5ea6\u4e3a \\(O(\\log n)\\) \u3002\u7531\u6b64\u53ef\u77e5\uff0c\u5806\u5316\u64cd\u4f5c\u7684\u5faa\u73af\u8f6e\u6570\u6700\u591a\u4e3a \\(O(\\log n)\\) \uff0c\u5143\u7d20\u5165\u5806\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def push(self, val: int):\n\"\"\"\u5143\u7d20\u5165\u5806\"\"\"\n# \u6dfb\u52a0\u8282\u70b9\nself.max_heap.append(val)\n# \u4ece\u5e95\u81f3\u9876\u5806\u5316\nself.sift_up(self.size() - 1)\ndef sift_up(self, i: int):\n\"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\"\"\"\nwhile True:\n# \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\np = self.parent(i)\n# \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 or self.max_heap[i] <= self.max_heap[p]:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, p)\n# \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n
        my_heap.cpp
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.push_back(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap[i] <= maxHeap[p])\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap[i], maxHeap[p]);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.java
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap.get(i) <= maxHeap.get(p))\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.cs
        /* \u5143\u7d20\u5165\u5806 */\nvoid Push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.Add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nSiftUp(Size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid SiftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = Parent(i);\n// \u82e5\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap[i] <= maxHeap[p])\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nSwap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.go
        /* \u5143\u7d20\u5165\u5806 */\nfunc (h *maxHeap) push(val any) {\n// \u6dfb\u52a0\u8282\u70b9\nh.data = append(h.data, val)\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nh.siftUp(len(h.data) - 1)\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc (h *maxHeap) siftUp(i int) {\nfor true {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\np := h.parent(i)\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 || h.data[i].(int) <= h.data[p].(int) {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nh.swap(i, p)\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n}\n}\n
        my_heap.swift
        /* \u5143\u7d20\u5165\u5806 */\nfunc push(val: Int) {\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap.append(val)\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(i: size() - 1)\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc siftUp(i: Int) {\nvar i = i\nwhile true {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nlet p = parent(i: i)\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif p < 0 || maxHeap[i] <= maxHeap[p] {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i: i, j: p)\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p\n}\n}\n
        my_heap.js
        /* \u5143\u7d20\u5165\u5806 */\npush(val) {\n// \u6dfb\u52a0\u8282\u70b9\nthis.#maxHeap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nthis.#siftUp(this.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\n#siftUp(i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nconst p = this.#parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.#swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.ts
        /* \u5143\u7d20\u5165\u5806 */\npush(val: number): void {\n// \u6dfb\u52a0\u8282\u70b9\nthis.maxHeap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nthis.siftUp(this.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nsiftUp(i: number): void {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nconst p = this.parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || this.maxHeap[i] <= this.maxHeap[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.dart
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n// \u6dfb\u52a0\u8282\u70b9\n_maxHeap.add(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = _parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || _maxHeap[i] <= _maxHeap[p]) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n_swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.rs
        /* \u5143\u7d20\u5165\u5806 */\nfn push(&mut self, val: i32) {\n// \u6dfb\u52a0\u8282\u70b9\nself.max_heap.push(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nself.sift_up(self.size() - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfn sift_up(&mut self, mut i: usize) {\nloop {\n// \u8282\u70b9 i \u5df2\u7ecf\u662f\u5806\u9876\u8282\u70b9\u4e86\uff0c\u7ed3\u675f\u5806\u5316\nif i == 0 {\nbreak;\n}\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nlet p = Self::parent(i);\n// \u5f53\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif self.max_heap[i] <= self.max_heap[p] {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.c
        /* \u5143\u7d20\u5165\u5806 */\nvoid push(MaxHeap *maxHeap, int val) {\n// \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e0d\u5e94\u8be5\u6dfb\u52a0\u8fd9\u4e48\u591a\u8282\u70b9\nif (maxHeap->size == MAX_SIZE) {\nprintf(\"heap is full!\");\nreturn;\n}\n// \u6dfb\u52a0\u8282\u70b9\nmaxHeap->data[maxHeap->size] = val;\nmaxHeap->size++;\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\nsiftUp(maxHeap, maxHeap->size - 1);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(MaxHeap *maxHeap, int i) {\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nint p = parent(maxHeap, i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 || maxHeap->data[i] <= maxHeap->data[p]) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap, i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        my_heap.zig
        // \u5143\u7d20\u5165\u5806\nfn push(self: *Self, val: T) !void {\n// \u6dfb\u52a0\u8282\u70b9\ntry self.max_heap.?.append(val);\n// \u4ece\u5e95\u81f3\u9876\u5806\u5316\ntry self.siftUp(self.size() - 1);\n}  // \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\nfn siftUp(self: *Self, i_: usize) !void {\nvar i = i_;\nwhile (true) {\n// \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\nvar p = parent(i);\n// \u5f53\u201c\u8d8a\u8fc7\u6839\u8282\u70b9\u201d\u6216\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\nif (p < 0 or self.max_heap.?.items[i] <= self.max_heap.?.items[p]) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\ntry self.swap(i, p);\n// \u5faa\u73af\u5411\u4e0a\u5806\u5316\ni = p;\n}\n}\n
        "},{"location":"chapter_heap/heap/#4","title":"4. \u00a0 \u5806\u9876\u5143\u7d20\u51fa\u5806","text":"

        \u5806\u9876\u5143\u7d20\u662f\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9\uff0c\u5373\u5217\u8868\u9996\u5143\u7d20\u3002\u5982\u679c\u6211\u4eec\u76f4\u63a5\u4ece\u5217\u8868\u4e2d\u5220\u9664\u9996\u5143\u7d20\uff0c\u90a3\u4e48\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u7d22\u5f15\u90fd\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u8fd9\u5c06\u4f7f\u5f97\u540e\u7eed\u4f7f\u7528\u5806\u5316\u8fdb\u884c\u4fee\u590d\u53d8\u5f97\u56f0\u96be\u3002\u4e3a\u4e86\u5c3d\u91cf\u51cf\u5c11\u5143\u7d20\u7d22\u5f15\u7684\u53d8\u52a8\uff0c\u6211\u4eec\u91c7\u7528\u4ee5\u4e0b\u64cd\u4f5c\u6b65\u9aa4\u3002

        1. \u4ea4\u6362\u5806\u9876\u5143\u7d20\u4e0e\u5806\u5e95\u5143\u7d20\uff08\u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff09\u3002
        2. \u4ea4\u6362\u5b8c\u6210\u540e\uff0c\u5c06\u5806\u5e95\u4ece\u5217\u8868\u4e2d\u5220\u9664\uff08\u6ce8\u610f\uff0c\u7531\u4e8e\u5df2\u7ecf\u4ea4\u6362\uff0c\u56e0\u6b64\u5b9e\u9645\u4e0a\u5220\u9664\u7684\u662f\u539f\u6765\u7684\u5806\u9876\u5143\u7d20\uff09\u3002
        3. \u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u6267\u884c\u5806\u5316\u3002

        \u5982\u56fe 8-4 \u6240\u793a\uff0c\u201c\u4ece\u9876\u81f3\u5e95\u5806\u5316\u201d\u7684\u64cd\u4f5c\u65b9\u5411\u4e0e\u201c\u4ece\u5e95\u81f3\u9876\u5806\u5316\u201d\u76f8\u53cd\uff0c\u6211\u4eec\u5c06\u6839\u8282\u70b9\u7684\u503c\u4e0e\u5176\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u5c06\u6700\u5927\u7684\u5b50\u8282\u70b9\u4e0e\u6839\u8282\u70b9\u4ea4\u6362\u3002\u7136\u540e\u5faa\u73af\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u76f4\u5230\u8d8a\u8fc7\u53f6\u8282\u70b9\u6216\u9047\u5230\u65e0\u987b\u4ea4\u6362\u7684\u8282\u70b9\u65f6\u7ed3\u675f\u3002

        <1><2><3><4><5><6><7><8><9><10>

        \u56fe 8-4 \u00a0 \u5806\u9876\u5143\u7d20\u51fa\u5806\u6b65\u9aa4

        \u4e0e\u5143\u7d20\u5165\u5806\u64cd\u4f5c\u76f8\u4f3c\uff0c\u5806\u9876\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u4e3a \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig my_heap.py
        def pop(self) -> int:\n\"\"\"\u5143\u7d20\u51fa\u5806\"\"\"\n# \u5224\u7a7a\u5904\u7406\nif self.is_empty():\nraise IndexError(\"\u5806\u4e3a\u7a7a\")\n# \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nself.swap(0, self.size() - 1)\n# \u5220\u9664\u8282\u70b9\nval = self.max_heap.pop()\n# \u4ece\u9876\u81f3\u5e95\u5806\u5316\nself.sift_down(0)\n# \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\ndef sift_down(self, i: int):\n\"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\nwhile True:\n# \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl, r, ma = self.left(i), self.right(i), i\nif l < self.size() and self.max_heap[l] > self.max_heap[ma]:\nma = l\nif r < self.size() and self.max_heap[r] > self.max_heap[ma]:\nma = r\n# \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, ma)\n# \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n
        my_heap.cpp
        /* \u5143\u7d20\u51fa\u5806 */\nvoid pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty()) {\nthrow out_of_range(\"\u5806\u4e3a\u7a7a\");\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(maxHeap[0], maxHeap[size() - 1]);\n// \u5220\u9664\u8282\u70b9\nmaxHeap.pop_back();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = left(i), r = right(i), ma = i;\nif (l < size() && maxHeap[l] > maxHeap[ma])\nma = l;\nif (r < size() && maxHeap[r] > maxHeap[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\nswap(maxHeap[i], maxHeap[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.java
        /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(0, size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap.remove(size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = left(i), r = right(i), ma = i;\nif (l < size() && maxHeap.get(l) > maxHeap.get(ma))\nma = l;\nif (r < size() && maxHeap.get(r) > maxHeap.get(ma))\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.cs
        /* \u5143\u7d20\u51fa\u5806 */\nint Pop() {\n// \u5224\u7a7a\u5904\u7406\nif (IsEmpty())\nthrow new IndexOutOfRangeException();\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nSwap(0, Size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap.Last();\nmaxHeap.RemoveAt(Size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nSiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = Left(i), r = Right(i), ma = i;\nif (l < Size() && maxHeap[l] > maxHeap[ma])\nma = l;\nif (r < Size() && maxHeap[r] > maxHeap[ma])\nma = r;\n// \u82e5\u201c\u8282\u70b9 i \u6700\u5927\u201d\u6216\u201c\u8d8a\u8fc7\u53f6\u8282\u70b9\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nSwap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.go
        /* \u5143\u7d20\u51fa\u5806 */\nfunc (h *maxHeap) pop() any {\n// \u5224\u7a7a\u5904\u7406\nif h.isEmpty() {\nfmt.Println(\"error\")\nreturn nil\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nh.swap(0, h.size()-1)\n// \u5220\u9664\u8282\u70b9\nval := h.data[len(h.data)-1]\nh.data = h.data[:len(h.data)-1]\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nh.siftDown(0)\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc (h *maxHeap) siftDown(i int) {\nfor true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\nl, r, max := h.left(i), h.right(i), i\nif l < h.size() && h.data[l].(int) > h.data[max].(int) {\nmax = l\n}\nif r < h.size() && h.data[r].(int) > h.data[max].(int) {\nmax = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif max == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nh.swap(i, max)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = max\n}\n}\n
        my_heap.swift
        /* \u5143\u7d20\u51fa\u5806 */\nfunc pop() -> Int {\n// \u5224\u7a7a\u5904\u7406\nif isEmpty() {\nfatalError(\"\u5806\u4e3a\u7a7a\")\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(i: 0, j: size() - 1)\n// \u5220\u9664\u8282\u70b9\nlet val = maxHeap.remove(at: size() - 1)\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(i: 0)\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(i: Int) {\nvar i = i\nwhile true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = left(i: i)\nlet r = right(i: i)\nvar ma = i\nif l < size(), maxHeap[l] > maxHeap[ma] {\nma = l\n}\nif r < size(), maxHeap[r] > maxHeap[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(i: i, j: ma)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n
        my_heap.js
        /* \u5143\u7d20\u51fa\u5806 */\npop() {\n// \u5224\u7a7a\u5904\u7406\nif (this.isEmpty()) throw new Error('\u5806\u4e3a\u7a7a');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nthis.#swap(0, this.size() - 1);\n// \u5220\u9664\u8282\u70b9\nconst val = this.#maxHeap.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nthis.#siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\n#siftDown(i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nconst l = this.#left(i),\nr = this.#right(i);\nlet ma = i;\nif (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;\nif (r < this.size() && this.#maxHeap[r] > this.#maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.#swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.ts
        /* \u5143\u7d20\u51fa\u5806 */\npop(): number {\n// \u5224\u7a7a\u5904\u7406\nif (this.isEmpty()) throw new RangeError('Heap is empty.');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nthis.swap(0, this.size() - 1);\n// \u5220\u9664\u8282\u70b9\nconst val = this.maxHeap.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nthis.siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nsiftDown(i: number): void {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nconst l = this.left(i),\nr = this.right(i);\nlet ma = i;\nif (l < this.size() && this.maxHeap[l] > this.maxHeap[ma]) ma = l;\nif (r < this.size() && this.maxHeap[r] > this.maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nthis.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.dart
        /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty()) throw Exception('\u5806\u4e3a\u7a7a');\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n_swap(0, size() - 1);\n// \u5220\u9664\u8282\u70b9\nint val = _maxHeap.removeLast();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = _left(i);\nint r = _right(i);\nint ma = i;\nif (l < size() && _maxHeap[l] > _maxHeap[ma]) ma = l;\nif (r < size() && _maxHeap[r] > _maxHeap[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\n_swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.rs
        /* \u5143\u7d20\u51fa\u5806 */\nfn pop(&mut self) -> i32 {\n// \u5224\u7a7a\u5904\u7406\nif self.is_empty() {\npanic!(\"index out of bounds\");\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nself.swap(0, self.size() - 1);\n// \u5220\u9664\u8282\u70b9\nlet val = self.max_heap.remove(self.size() - 1);\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nself.sift_down(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nval\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(&mut self, mut i: usize) {\nloop {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet (l, r, mut ma) = (Self::left(i), Self::right(i), i);\nif l < self.size() && self.max_heap[l] > self.max_heap[ma] {\nma = l;\n}\nif r < self.size() && self.max_heap[r] > self.max_heap[ma] {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nself.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        my_heap.c
        /* \u5143\u7d20\u51fa\u5806 */\nint pop(MaxHeap *maxHeap) {\n// \u5224\u7a7a\u5904\u7406\nif (isEmpty(maxHeap)) {\nprintf(\"heap is empty!\");\nreturn INT_MAX;\n}\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(maxHeap, 0, size(maxHeap) - 1);\n// \u5220\u9664\u8282\u70b9\nint val = maxHeap->data[maxHeap->size - 1];\nmaxHeap->size--;\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\nsiftDown(maxHeap, 0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n}\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(MaxHeap *maxHeap, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\nint l = left(maxHeap, i);\nint r = right(maxHeap, i);\nint max = i;\nif (l < size(maxHeap) && maxHeap->data[l] > maxHeap->data[max]) {\nmax = l;\n}\nif (r < size(maxHeap) && maxHeap->data[r] > maxHeap->data[max]) {\nmax = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (max == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(maxHeap, i, max);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = max;\n}\n}\n
        my_heap.zig
        // \u5143\u7d20\u51fa\u5806\nfn pop(self: *Self) !T {\n// \u5224\u65ad\u5904\u7406\nif (self.isEmpty()) unreachable;\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\ntry self.swap(0, self.size() - 1);\n// \u5220\u9664\u8282\u70b9\nvar val = self.max_heap.?.pop();\n// \u4ece\u9876\u81f3\u5e95\u5806\u5316\ntry self.siftDown(0);\n// \u8fd4\u56de\u5806\u9876\u5143\u7d20\nreturn val;\n} // \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\nfn siftDown(self: *Self, i_: usize) !void {\nvar i = i_;\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nvar l = left(i);\nvar r = right(i);\nvar ma = i;\nif (l < self.size() and self.max_heap.?.items[l] > self.max_heap.?.items[ma]) ma = l;\nif (r < self.size() and self.max_heap.?.items[r] > self.max_heap.?.items[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\ntry self.swap(i, ma);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n
        "},{"location":"chapter_heap/heap/#813","title":"8.1.3 \u00a0 \u5806\u5e38\u89c1\u5e94\u7528","text":"
        • \u4f18\u5148\u961f\u5217\uff1a\u5806\u901a\u5e38\u4f5c\u4e3a\u5b9e\u73b0\u4f18\u5148\u961f\u5217\u7684\u9996\u9009\u6570\u636e\u7ed3\u6784\uff0c\u5176\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log n)\\) \uff0c\u800c\u5efa\u961f\u64cd\u4f5c\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u975e\u5e38\u9ad8\u6548\u3002
        • \u5806\u6392\u5e8f\uff1a\u7ed9\u5b9a\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u4eec\u5efa\u7acb\u4e00\u4e2a\u5806\uff0c\u7136\u540e\u4e0d\u65ad\u5730\u6267\u884c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\uff0c\u4ece\u800c\u5f97\u5230\u6709\u5e8f\u6570\u636e\u3002\u7136\u800c\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528\u4e00\u79cd\u66f4\u4f18\u96c5\u7684\u65b9\u5f0f\u5b9e\u73b0\u5806\u6392\u5e8f\uff0c\u8be6\u89c1\u201c\u5806\u6392\u5e8f\u201d\u7ae0\u8282\u3002
        • \u83b7\u53d6\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\uff1a\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5178\u7684\u7b97\u6cd5\u95ee\u9898\uff0c\u540c\u65f6\u4e5f\u662f\u4e00\u79cd\u5178\u578b\u5e94\u7528\uff0c\u4f8b\u5982\u9009\u62e9\u70ed\u5ea6\u524d 10 \u7684\u65b0\u95fb\u4f5c\u4e3a\u5fae\u535a\u70ed\u641c\uff0c\u9009\u53d6\u9500\u91cf\u524d 10 \u7684\u5546\u54c1\u7b49\u3002
        "},{"location":"chapter_heap/summary/","title":"8.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_heap/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u5806\u662f\u4e00\u68f5\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u6839\u636e\u6210\u7acb\u6761\u4ef6\u53ef\u5206\u4e3a\u5927\u9876\u5806\u548c\u5c0f\u9876\u5806\u3002\u5927\uff08\u5c0f\uff09\u9876\u5806\u7684\u5806\u9876\u5143\u7d20\u662f\u6700\u5927\uff08\u5c0f\uff09\u7684\u3002
        • \u4f18\u5148\u961f\u5217\u7684\u5b9a\u4e49\u662f\u5177\u6709\u51fa\u961f\u4f18\u5148\u7ea7\u7684\u961f\u5217\uff0c\u901a\u5e38\u4f7f\u7528\u5806\u6765\u5b9e\u73b0\u3002
        • \u5806\u7684\u5e38\u7528\u64cd\u4f5c\u53ca\u5176\u5bf9\u5e94\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5305\u62ec\uff1a\u5143\u7d20\u5165\u5806 \\(O(\\log n)\\)\u3001\u5806\u9876\u5143\u7d20\u51fa\u5806 \\(O(\\log n)\\) \u548c\u8bbf\u95ee\u5806\u9876\u5143\u7d20 \\(O(1)\\) \u7b49\u3002
        • \u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u7528\u6570\u7ec4\u8868\u793a\uff0c\u56e0\u6b64\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u6570\u7ec4\u6765\u5b58\u50a8\u5806\u3002
        • \u5806\u5316\u64cd\u4f5c\u7528\u4e8e\u7ef4\u62a4\u5806\u7684\u6027\u8d28\uff0c\u5728\u5165\u5806\u548c\u51fa\u5806\u64cd\u4f5c\u4e2d\u90fd\u4f1a\u7528\u5230\u3002
        • \u8f93\u5165 \\(n\\) \u4e2a\u5143\u7d20\u5e76\u5efa\u5806\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(n)\\) \uff0c\u975e\u5e38\u9ad8\u6548\u3002
        • Top-K \u662f\u4e00\u4e2a\u7ecf\u5178\u7b97\u6cd5\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u5806\u6570\u636e\u7ed3\u6784\u9ad8\u6548\u89e3\u51b3\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log k)\\) \u3002
        "},{"location":"chapter_heap/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6570\u636e\u7ed3\u6784\u7684\u201c\u5806\u201d\u4e0e\u5185\u5b58\u7ba1\u7406\u7684\u201c\u5806\u201d\u662f\u540c\u4e00\u4e2a\u6982\u5ff5\u5417\uff1f

        \u4e24\u8005\u4e0d\u662f\u540c\u4e00\u4e2a\u6982\u5ff5\uff0c\u53ea\u662f\u78b0\u5de7\u90fd\u53eb\u5806\u3002\u8ba1\u7b97\u673a\u7cfb\u7edf\u5185\u5b58\u4e2d\u7684\u5806\u662f\u52a8\u6001\u5185\u5b58\u5206\u914d\u7684\u4e00\u90e8\u5206\uff0c\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5b58\u50a8\u6570\u636e\u3002\u7a0b\u5e8f\u53ef\u4ee5\u8bf7\u6c42\u4e00\u5b9a\u91cf\u7684\u5806\u5185\u5b58\uff0c\u7528\u4e8e\u5b58\u50a8\u5982\u5bf9\u8c61\u548c\u6570\u7ec4\u7b49\u590d\u6742\u7ed3\u6784\u3002\u5f53\u8fd9\u4e9b\u6570\u636e\u4e0d\u518d\u9700\u8981\u65f6\uff0c\u7a0b\u5e8f\u9700\u8981\u91ca\u653e\u8fd9\u4e9b\u5185\u5b58\uff0c\u4ee5\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\u3002\u76f8\u8f83\u4e8e\u6808\u5185\u5b58\uff0c\u5806\u5185\u5b58\u7684\u7ba1\u7406\u548c\u4f7f\u7528\u9700\u8981\u66f4\u8c28\u614e\uff0c\u4f7f\u7528\u4e0d\u5f53\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u548c\u91ce\u6307\u9488\u7b49\u95ee\u9898\u3002

        "},{"location":"chapter_heap/top_k/","title":"8.3 \u00a0 Top-K \u95ee\u9898","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u65e0\u5e8f\u6570\u7ec4 nums \uff0c\u8bf7\u8fd4\u56de\u6570\u7ec4\u4e2d\u524d \\(k\\) \u5927\u7684\u5143\u7d20\u3002

        \u5bf9\u4e8e\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u5148\u4ecb\u7ecd\u4e24\u79cd\u601d\u8def\u6bd4\u8f83\u76f4\u63a5\u7684\u89e3\u6cd5\uff0c\u518d\u4ecb\u7ecd\u6548\u7387\u66f4\u9ad8\u7684\u5806\u89e3\u6cd5\u3002

        "},{"location":"chapter_heap/top_k/#831","title":"8.3.1 \u00a0 \u65b9\u6cd5\u4e00\uff1a\u904d\u5386\u9009\u62e9","text":"

        \u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u56fe 8-6 \u6240\u793a\u7684 \\(k\\) \u8f6e\u904d\u5386\uff0c\u5206\u522b\u5728\u6bcf\u8f6e\u4e2d\u63d0\u53d6\u7b2c \\(1\\)\u3001\\(2\\)\u3001\\(\\dots\\)\u3001\\(k\\) \u5927\u7684\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(nk)\\) \u3002

        \u6b64\u65b9\u6cd5\u53ea\u9002\u7528\u4e8e \\(k \\ll n\\) \u7684\u60c5\u51b5\uff0c\u56e0\u4e3a\u5f53 \\(k\\) \u4e0e \\(n\\) \u6bd4\u8f83\u63a5\u8fd1\u65f6\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411\u4e8e \\(O(n^2)\\) \uff0c\u975e\u5e38\u8017\u65f6\u3002

        \u56fe 8-6 \u00a0 \u904d\u5386\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        Tip

        \u5f53 \\(k = n\\) \u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5b8c\u6574\u7684\u6709\u5e8f\u5e8f\u5217\uff0c\u6b64\u65f6\u7b49\u4ef7\u4e8e\u201c\u9009\u62e9\u6392\u5e8f\u201d\u7b97\u6cd5\u3002

        "},{"location":"chapter_heap/top_k/#832","title":"8.3.2 \u00a0 \u65b9\u6cd5\u4e8c\uff1a\u6392\u5e8f","text":"

        \u5982\u56fe 8-7 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u5bf9\u6570\u7ec4 nums \u8fdb\u884c\u6392\u5e8f\uff0c\u518d\u8fd4\u56de\u6700\u53f3\u8fb9\u7684 \\(k\\) \u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002

        \u663e\u7136\uff0c\u8be5\u65b9\u6cd5\u201c\u8d85\u989d\u201d\u5b8c\u6210\u4efb\u52a1\u4e86\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u627e\u51fa\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\u5373\u53ef\uff0c\u800c\u4e0d\u9700\u8981\u6392\u5e8f\u5176\u4ed6\u5143\u7d20\u3002

        \u56fe 8-7 \u00a0 \u6392\u5e8f\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        "},{"location":"chapter_heap/top_k/#833","title":"8.3.3 \u00a0 \u65b9\u6cd5\u4e09\uff1a\u5806","text":"

        \u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u5806\u66f4\u52a0\u9ad8\u6548\u5730\u89e3\u51b3 Top-K \u95ee\u9898\uff0c\u6d41\u7a0b\u5982\u56fe 8-8 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316\u4e00\u4e2a\u5c0f\u9876\u5806\uff0c\u5176\u5806\u9876\u5143\u7d20\u6700\u5c0f\u3002
        2. \u5148\u5c06\u6570\u7ec4\u7684\u524d \\(k\\) \u4e2a\u5143\u7d20\u4f9d\u6b21\u5165\u5806\u3002
        3. \u4ece\u7b2c \\(k + 1\\) \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\uff0c\u5e76\u5c06\u5f53\u524d\u5143\u7d20\u5165\u5806\u3002
        4. \u904d\u5386\u5b8c\u6210\u540e\uff0c\u5806\u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u6700\u5927\u7684 \\(k\\) \u4e2a\u5143\u7d20\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 8-8 \u00a0 \u57fa\u4e8e\u5806\u5bfb\u627e\u6700\u5927\u7684 k \u4e2a\u5143\u7d20

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig top_k.py
        def top_k_heap(nums: list[int], k: int) -> list[int]:\n\"\"\"\u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20\"\"\"\n# \u521d\u59cb\u5316\u5c0f\u9876\u5806\nheap = []\n# \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor i in range(k):\nheapq.heappush(heap, nums[i])\n# \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i in range(k, len(nums)):\n# \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > heap[0]:\nheapq.heappop(heap)\nheapq.heappush(heap, nums[i])\nreturn heap\n
        top_k.cpp
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\npriority_queue<int, vector<int>, greater<int>> topKHeap(vector<int> &nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\npriority_queue<int, vector<int>, greater<int>> heap;\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.push(nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.size(); i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.top()) {\nheap.pop();\nheap.push(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.java
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nQueue<Integer> topKHeap(int[] nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nQueue<Integer> heap = new PriorityQueue<Integer>();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.offer(nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.peek()) {\nheap.poll();\nheap.offer(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.cs
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nPriorityQueue<int, int> TopKHeap(int[] nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nPriorityQueue<int, int> heap = new();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\nheap.Enqueue(nums[i], nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.Length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.Peek()) {\nheap.Dequeue();\nheap.Enqueue(nums[i], nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.go
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunc topKHeap(nums []int, k int) *minHeap {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\nh := &minHeap{}\nheap.Init(h)\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor i := 0; i < k; i++ {\nheap.Push(h, nums[i])\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i := k; i < len(nums); i++ {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > h.Top().(int) {\nheap.Pop(h)\nheap.Push(h, nums[i])\n}\n}\nreturn h\n}\n
        top_k.swift
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunc topKHeap(nums: [Int], k: Int) -> [Int] {\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5c0f\u9876\u5806\uff0c\u5e76\u5c06\u524d k \u4e2a\u5143\u7d20\u5efa\u5806\nvar heap = Heap(nums.prefix(k))\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor i in stride(from: k, to: nums.count, by: 1) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif nums[i] > heap.min()! {\n_ = heap.removeMin()\nheap.insert(nums[i])\n}\n}\nreturn heap.unordered\n}\n
        top_k.js
        /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap, val) {\n// \u5143\u7d20\u53d6\u53cd\nmaxHeap.push(-val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.pop();\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.peek();\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn maxHeap.getMaxHeap().map((num) => -num);\n}\n/* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunction topKHeap(nums, k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nconst maxHeap = new MaxHeap([]);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (let i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (let i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\n// \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\nreturn getMinHeap(maxHeap);\n}\n
        top_k.ts
        /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap: MaxHeap, val: number): void {\n// \u5143\u7d20\u53d6\u53cd\nmaxHeap.push(-val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap: MaxHeap): number {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.pop();\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap: MaxHeap): number {\n// \u5143\u7d20\u53d6\u53cd\nreturn -maxHeap.peek();\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap: MaxHeap): number[] {\n// \u5143\u7d20\u53d6\u53cd\nreturn maxHeap.getMaxHeap().map((num: number) => -num);\n}\n/* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfunction topKHeap(nums: number[], k: number): number[] {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nconst maxHeap = new MaxHeap([]);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (let i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (let i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\n// \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\nreturn getMinHeap(maxHeap);\n}\n
        top_k.dart
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nMinHeap topKHeap(List<int> nums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\uff0c\u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nMinHeap heap = MinHeap(nums.sublist(0, k));\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < nums.length; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > heap.peek()) {\nheap.pop();\nheap.push(nums[i]);\n}\n}\nreturn heap;\n}\n
        top_k.rs
        /* \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20 */\nfn top_k_heap(nums: Vec<i32>, k: usize) -> BinaryHeap<Reverse<i32>> {\n// BinaryHeap \u662f\u5927\u9876\u5806\uff0c\u4f7f\u7528 Reverse \u5c06\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u5b9e\u73b0\u5c0f\u9876\u5806\nlet mut heap = BinaryHeap::<Reverse<i32>>::new();\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor &num in nums.iter().take(k) {\nheap.push(Reverse(num));\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor &num in nums.iter().skip(k) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif num > heap.peek().unwrap().0 {\nheap.pop();\nheap.push(Reverse(num));\n}\n}\nheap\n}\n
        top_k.c
        /* \u5143\u7d20\u5165\u5806 */\nvoid pushMinHeap(MaxHeap *maxHeap, int val) {\n// \u5143\u7d20\u53d6\u53cd\npush(maxHeap, -val);\n}\n/* \u5143\u7d20\u51fa\u5806 */\nint popMinHeap(MaxHeap *maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -pop(maxHeap);\n}\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peekMinHeap(MaxHeap *maxHeap) {\n// \u5143\u7d20\u53d6\u53cd\nreturn -peek(maxHeap);\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nint *getMinHeap(MaxHeap *maxHeap) {\n// \u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\u5e76\u5b58\u5165 res \u6570\u7ec4\nint *res = (int *)malloc(maxHeap->size * sizeof(int));\nfor (int i = 0; i < maxHeap->size; i++) {\nres[i] = -maxHeap->data[i];\n}\nreturn res;\n}\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nint *getMinHeap(MaxHeap *maxHeap) {\n// \u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\u5e76\u5b58\u5165 res \u6570\u7ec4\nint *res = (int *)malloc(maxHeap->size * sizeof(int));\nfor (int i = 0; i < maxHeap->size; i++) {\nres[i] = -maxHeap->data[i];\n}\nreturn res;\n}\n// \u57fa\u4e8e\u5806\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684 k \u4e2a\u5143\u7d20\u7684\u51fd\u6570\nint *topKHeap(int *nums, int sizeNums, int k) {\n// \u521d\u59cb\u5316\u5c0f\u9876\u5806\n// \u8bf7\u6ce8\u610f\uff1a\u6211\u4eec\u5c06\u5806\u4e2d\u6240\u6709\u5143\u7d20\u53d6\u53cd\uff0c\u4ece\u800c\u7528\u5927\u9876\u5806\u6765\u6a21\u62df\u5c0f\u9876\u5806\nint *empty = (int *)malloc(0);\nMaxHeap *maxHeap = newMaxHeap(empty, 0);\n// \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\nfor (int i = 0; i < k; i++) {\npushMinHeap(maxHeap, nums[i]);\n}\n// \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\nfor (int i = k; i < sizeNums; i++) {\n// \u82e5\u5f53\u524d\u5143\u7d20\u5927\u4e8e\u5806\u9876\u5143\u7d20\uff0c\u5219\u5c06\u5806\u9876\u5143\u7d20\u51fa\u5806\u3001\u5f53\u524d\u5143\u7d20\u5165\u5806\nif (nums[i] > peekMinHeap(maxHeap)) {\npopMinHeap(maxHeap);\npushMinHeap(maxHeap, nums[i]);\n}\n}\nint *res = getMinHeap(maxHeap);\n// \u91ca\u653e\u5185\u5b58\ndelMaxHeap(maxHeap);\nreturn res;\n}\n
        top_k.zig
        [class]{}-[func]{topKHeap}\n

        \u603b\u5171\u6267\u884c\u4e86 \\(n\\) \u8f6e\u5165\u5806\u548c\u51fa\u5806\uff0c\u5806\u7684\u6700\u5927\u957f\u5ea6\u4e3a \\(k\\) \uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log k)\\) \u3002\u8be5\u65b9\u6cd5\u7684\u6548\u7387\u5f88\u9ad8\uff0c\u5f53 \\(k\\) \u8f83\u5c0f\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411 \\(O(n)\\) \uff1b\u5f53 \\(k\\) \u8f83\u5927\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 \\(O(n \\log n)\\) \u3002

        \u53e6\u5916\uff0c\u8be5\u65b9\u6cd5\u9002\u7528\u4e8e\u52a8\u6001\u6570\u636e\u6d41\u7684\u4f7f\u7528\u573a\u666f\u3002\u5728\u4e0d\u65ad\u52a0\u5165\u6570\u636e\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u6301\u7eed\u7ef4\u62a4\u5806\u5185\u7684\u5143\u7d20\uff0c\u4ece\u800c\u5b9e\u73b0\u6700\u5927 \\(k\\) \u4e2a\u5143\u7d20\u7684\u52a8\u6001\u66f4\u65b0\u3002

        "},{"location":"chapter_introduction/","title":"\u7b2c 1 \u7ae0 \u00a0 \u521d\u8bc6\u7b97\u6cd5","text":"

        Abstract

        \u4e00\u4f4d\u5c11\u5973\u7fe9\u7fe9\u8d77\u821e\uff0c\u4e0e\u6570\u636e\u4ea4\u7ec7\u5728\u4e00\u8d77\uff0c\u88d9\u6446\u4e0a\u98d8\u626c\u7740\u7b97\u6cd5\u7684\u65cb\u5f8b\u3002

        \u5979\u9080\u8bf7\u4f60\u5171\u821e\uff0c\u8bf7\u7d27\u8ddf\u5979\u7684\u6b65\u4f10\uff0c\u8e0f\u5165\u5145\u6ee1\u903b\u8f91\u4e0e\u7f8e\u611f\u7684\u7b97\u6cd5\u4e16\u754c\u3002

        "},{"location":"chapter_introduction/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 1.1 \u00a0 \u7b97\u6cd5\u65e0\u5904\u4e0d\u5728
        • 1.2 \u00a0 \u7b97\u6cd5\u662f\u4ec0\u4e48
        • 1.3 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_introduction/algorithms_are_everywhere/","title":"1.1 \u00a0 \u7b97\u6cd5\u65e0\u5904\u4e0d\u5728","text":"

        \u5f53\u6211\u4eec\u542c\u5230\u201c\u7b97\u6cd5\u201d\u8fd9\u4e2a\u8bcd\u65f6\uff0c\u5f88\u81ea\u7136\u5730\u4f1a\u60f3\u5230\u6570\u5b66\u3002\u7136\u800c\u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7b97\u6cd5\u5e76\u4e0d\u6d89\u53ca\u590d\u6742\u6570\u5b66\uff0c\u800c\u662f\u66f4\u591a\u5730\u4f9d\u8d56\u57fa\u672c\u903b\u8f91\uff0c\u8fd9\u4e9b\u903b\u8f91\u5728\u6211\u4eec\u7684\u65e5\u5e38\u751f\u6d3b\u4e2d\u5904\u5904\u53ef\u89c1\u3002

        \u5728\u6b63\u5f0f\u63a2\u8ba8\u7b97\u6cd5\u4e4b\u524d\uff0c\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u4e8b\u5b9e\u503c\u5f97\u5206\u4eab\uff1a\u4f60\u5df2\u7ecf\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u5b66\u4f1a\u4e86\u8bb8\u591a\u7b97\u6cd5\uff0c\u5e76\u4e60\u60ef\u5c06\u5b83\u4eec\u5e94\u7528\u5230\u65e5\u5e38\u751f\u6d3b\u4e2d\u4e86\u3002\u4e0b\u9762\u6211\u5c06\u4e3e\u51e0\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\u6765\u8bc1\u5b9e\u8fd9\u4e00\u70b9\u3002

        \u4f8b\u4e00\uff1a\u67e5\u9605\u5b57\u5178\u3002\u5728\u5b57\u5178\u91cc\uff0c\u6bcf\u4e2a\u6c49\u5b57\u90fd\u5bf9\u5e94\u4e00\u4e2a\u62fc\u97f3\uff0c\u800c\u5b57\u5178\u662f\u6309\u7167\u62fc\u97f3\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u7684\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u67e5\u627e\u4e00\u4e2a\u62fc\u97f3\u9996\u5b57\u6bcd\u4e3a \\(r\\) \u7684\u5b57\uff0c\u901a\u5e38\u4f1a\u6309\u7167\u56fe 1-1 \u6240\u793a\u7684\u65b9\u5f0f\u5b9e\u73b0\u3002

        1. \u7ffb\u5f00\u5b57\u5178\u7ea6\u4e00\u534a\u7684\u9875\u6570\uff0c\u67e5\u770b\u8be5\u9875\u7684\u9996\u5b57\u6bcd\u662f\u4ec0\u4e48\uff0c\u5047\u8bbe\u9996\u5b57\u6bcd\u4e3a \\(m\\) \u3002
        2. \u7531\u4e8e\u5728\u62fc\u97f3\u5b57\u6bcd\u8868\u4e2d \\(r\\) \u4f4d\u4e8e \\(m\\) \u4e4b\u540e\uff0c\u6240\u4ee5\u6392\u9664\u5b57\u5178\u524d\u534a\u90e8\u5206\uff0c\u67e5\u627e\u8303\u56f4\u7f29\u5c0f\u5230\u540e\u534a\u90e8\u5206\u3002
        3. \u4e0d\u65ad\u91cd\u590d\u6b65\u9aa4 1. \u548c \u6b65\u9aa4 2. \uff0c\u76f4\u81f3\u627e\u5230\u62fc\u97f3\u9996\u5b57\u6bcd\u4e3a \\(r\\) \u7684\u9875\u7801\u4e3a\u6b62\u3002
        <1><2><3><4><5>

        \u56fe 1-1 \u00a0 \u67e5\u5b57\u5178\u6b65\u9aa4

        \u67e5\u5b57\u5178\u8fd9\u4e2a\u5c0f\u5b66\u751f\u5fc5\u5907\u6280\u80fd\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u8457\u540d\u7684\u201c\u4e8c\u5206\u67e5\u627e\u201d\u7b97\u6cd5\u3002\u4ece\u6570\u636e\u7ed3\u6784\u7684\u89d2\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u5b57\u5178\u89c6\u4e3a\u4e00\u4e2a\u5df2\u6392\u5e8f\u7684\u201c\u6570\u7ec4\u201d\uff1b\u4ece\u7b97\u6cd5\u7684\u89d2\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u67e5\u5b57\u5178\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u770b\u4f5c\u201c\u4e8c\u5206\u67e5\u627e\u201d\u3002

        \u4f8b\u4e8c\uff1a\u6574\u7406\u6251\u514b\u3002\u6211\u4eec\u5728\u6253\u724c\u65f6\uff0c\u6bcf\u5c40\u90fd\u9700\u8981\u6574\u7406\u624b\u4e2d\u7684\u6251\u514b\u724c\uff0c\u4f7f\u5176\u4ece\u5c0f\u5230\u5927\u6392\u5217\uff0c\u5b9e\u73b0\u6d41\u7a0b\u5982\u56fe 1-2 \u6240\u793a\u3002

        1. \u5c06\u6251\u514b\u724c\u5212\u5206\u4e3a\u201c\u6709\u5e8f\u201d\u548c\u201c\u65e0\u5e8f\u201d\u4e24\u90e8\u5206\uff0c\u5e76\u5047\u8bbe\u521d\u59cb\u72b6\u6001\u4e0b\u6700\u5de6 1 \u5f20\u6251\u514b\u724c\u5df2\u7ecf\u6709\u5e8f\u3002
        2. \u5728\u65e0\u5e8f\u90e8\u5206\u62bd\u51fa\u4e00\u5f20\u6251\u514b\u724c\uff0c\u63d2\u5165\u81f3\u6709\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\uff1b\u5b8c\u6210\u540e\u6700\u5de6 2 \u5f20\u6251\u514b\u5df2\u7ecf\u6709\u5e8f\u3002
        3. \u4e0d\u65ad\u5faa\u73af\u6b65\u9aa4 2. \uff0c\u6bcf\u4e00\u8f6e\u5c06\u4e00\u5f20\u6251\u514b\u724c\u4ece\u65e0\u5e8f\u90e8\u5206\u63d2\u5165\u81f3\u6709\u5e8f\u90e8\u5206\uff0c\u76f4\u81f3\u6240\u6709\u6251\u514b\u724c\u90fd\u6709\u5e8f\u3002

        \u56fe 1-2 \u00a0 \u6251\u514b\u6392\u5e8f\u6b65\u9aa4

        \u4e0a\u8ff0\u6574\u7406\u6251\u514b\u724c\u7684\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u201c\u63d2\u5165\u6392\u5e8f\u201d\u7b97\u6cd5\uff0c\u5b83\u5728\u5904\u7406\u5c0f\u578b\u6570\u636e\u96c6\u65f6\u975e\u5e38\u9ad8\u6548\u3002\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\u7684\u6392\u5e8f\u5e93\u51fd\u6570\u4e2d\u90fd\u6709\u63d2\u5165\u6392\u5e8f\u7684\u8eab\u5f71\u3002

        \u4f8b\u4e09\uff1a\u8d27\u5e01\u627e\u96f6\u3002\u5047\u8bbe\u6211\u4eec\u5728\u8d85\u5e02\u8d2d\u4e70\u4e86 \\(69\\) \u5143\u7684\u5546\u54c1\uff0c\u7ed9\u4e86\u6536\u94f6\u5458 \\(100\\) \u5143\uff0c\u5219\u6536\u94f6\u5458\u9700\u8981\u627e\u6211\u4eec \\(31\\) \u5143\u3002\u4ed6\u4f1a\u5f88\u81ea\u7136\u5730\u5b8c\u6210\u5982\u56fe 1-3 \u6240\u793a\u7684\u601d\u8003\u3002

        1. \u53ef\u9009\u9879\u662f\u6bd4 \\(31\\) \u5143\u9762\u503c\u66f4\u5c0f\u7684\u8d27\u5e01\uff0c\u5305\u62ec \\(1\\) \u5143\u3001\\(5\\) \u5143\u3001\\(10\\) \u5143\u3001\\(20\\) \u5143\u3002
        2. \u4ece\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(20\\) \u5143\uff0c\u5269\u4f59 \\(31 - 20 = 11\\) \u5143\u3002
        3. \u4ece\u5269\u4f59\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(10\\) \u5143\uff0c\u5269\u4f59 \\(11 - 10 = 1\\) \u5143\u3002
        4. \u4ece\u5269\u4f59\u53ef\u9009\u9879\u4e2d\u62ff\u51fa\u6700\u5927\u7684 \\(1\\) \u5143\uff0c\u5269\u4f59 \\(1 - 1 = 0\\) \u5143\u3002
        5. \u5b8c\u6210\u627e\u96f6\uff0c\u65b9\u6848\u4e3a \\(20 + 10 + 1 = 31\\) \u5143\u3002

        \u56fe 1-3 \u00a0 \u8d27\u5e01\u627e\u96f6\u8fc7\u7a0b

        \u5728\u4ee5\u4e0a\u6b65\u9aa4\u4e2d\uff0c\u6211\u4eec\u6bcf\u4e00\u6b65\u90fd\u91c7\u53d6\u5f53\u524d\u770b\u6765\u6700\u597d\u7684\u9009\u62e9\uff08\u5c3d\u53ef\u80fd\u7528\u5927\u9762\u989d\u7684\u8d27\u5e01\uff09\uff0c\u6700\u7ec8\u5f97\u5230\u4e86\u53ef\u884c\u7684\u627e\u96f6\u65b9\u6848\u3002\u4ece\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u89d2\u5ea6\u770b\uff0c\u8fd9\u79cd\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u201c\u8d2a\u5fc3\u201d\u7b97\u6cd5\u3002

        \u5c0f\u5230\u70f9\u996a\u4e00\u9053\u83dc\uff0c\u5927\u5230\u661f\u9645\u822a\u884c\uff0c\u51e0\u4e4e\u6240\u6709\u95ee\u9898\u7684\u89e3\u51b3\u90fd\u79bb\u4e0d\u5f00\u7b97\u6cd5\u3002\u8ba1\u7b97\u673a\u7684\u51fa\u73b0\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u901a\u8fc7\u7f16\u7a0b\u5c06\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u540c\u65f6\u7f16\u5199\u4ee3\u7801\u8c03\u7528 CPU \u548c GPU \u6267\u884c\u7b97\u6cd5\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6211\u4eec\u5c31\u80fd\u628a\u751f\u6d3b\u4e2d\u7684\u95ee\u9898\u8f6c\u79fb\u5230\u8ba1\u7b97\u673a\u4e0a\uff0c\u4ee5\u66f4\u9ad8\u6548\u7684\u65b9\u5f0f\u89e3\u51b3\u5404\u79cd\u590d\u6742\u95ee\u9898\u3002

        Tip

        \u5982\u679c\u4f60\u5bf9\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u3001\u6570\u7ec4\u548c\u4e8c\u5206\u67e5\u627e\u7b49\u6982\u5ff5\u4ecd\u611f\u5230\u4e00\u77e5\u534a\u89e3\uff0c\u8bf7\u7ee7\u7eed\u5f80\u4e0b\u9605\u8bfb\uff0c\u672c\u4e66\u5c06\u5f15\u5bfc\u4f60\u8fc8\u5165\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u77e5\u8bc6\u6bbf\u5802\u3002

        "},{"location":"chapter_introduction/summary/","title":"1.3 \u00a0 \u5c0f\u7ed3","text":"
        • \u7b97\u6cd5\u5728\u65e5\u5e38\u751f\u6d3b\u4e2d\u65e0\u5904\u4e0d\u5728\uff0c\u5e76\u4e0d\u662f\u9065\u4e0d\u53ef\u53ca\u7684\u9ad8\u6df1\u77e5\u8bc6\u3002\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u5df2\u7ecf\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u5b66\u4f1a\u4e86\u8bb8\u591a\u7b97\u6cd5\uff0c\u7528\u4ee5\u89e3\u51b3\u751f\u6d3b\u4e2d\u7684\u5927\u5c0f\u95ee\u9898\u3002
        • \u67e5\u9605\u5b57\u5178\u7684\u539f\u7406\u4e0e\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u76f8\u4e00\u81f4\u3002\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u4f53\u73b0\u4e86\u5206\u800c\u6cbb\u4e4b\u7684\u91cd\u8981\u7b97\u6cd5\u601d\u60f3\u3002
        • \u6574\u7406\u6251\u514b\u7684\u8fc7\u7a0b\u4e0e\u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\u975e\u5e38\u7c7b\u4f3c\u3002\u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\u9002\u5408\u6392\u5e8f\u5c0f\u578b\u6570\u636e\u96c6\u3002
        • \u8d27\u5e01\u627e\u96f6\u7684\u6b65\u9aa4\u672c\u8d28\u4e0a\u662f\u8d2a\u5fc3\u7b97\u6cd5\uff0c\u6bcf\u4e00\u6b65\u90fd\u91c7\u53d6\u5f53\u524d\u770b\u6765\u6700\u597d\u7684\u9009\u62e9\u3002
        • \u7b97\u6cd5\u662f\u5728\u6709\u9650\u65f6\u95f4\u5185\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u4e00\u7ec4\u6307\u4ee4\u6216\u64cd\u4f5c\u6b65\u9aa4\uff0c\u800c\u6570\u636e\u7ed3\u6784\u662f\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u548c\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\u3002
        • \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7d27\u5bc6\u76f8\u8fde\u3002\u6570\u636e\u7ed3\u6784\u662f\u7b97\u6cd5\u7684\u57fa\u77f3\uff0c\u800c\u7b97\u6cd5\u662f\u6570\u636e\u7ed3\u6784\u53d1\u6325\u4f5c\u7528\u7684\u821e\u53f0\u3002
        • \u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7c7b\u6bd4\u4e3a\u62fc\u88c5\u79ef\u6728\uff0c\u79ef\u6728\u4ee3\u8868\u6570\u636e\uff0c\u79ef\u6728\u7684\u5f62\u72b6\u548c\u8fde\u63a5\u65b9\u5f0f\u7b49\u4ee3\u8868\u6570\u636e\u7ed3\u6784\uff0c\u62fc\u88c5\u79ef\u6728\u7684\u6b65\u9aa4\u5219\u5bf9\u5e94\u7b97\u6cd5\u3002
        "},{"location":"chapter_introduction/what_is_dsa/","title":"1.2 \u00a0 \u7b97\u6cd5\u662f\u4ec0\u4e48","text":""},{"location":"chapter_introduction/what_is_dsa/#121","title":"1.2.1 \u00a0 \u7b97\u6cd5\u5b9a\u4e49","text":"

        \u300c\u7b97\u6cd5 algorithm\u300d\u662f\u5728\u6709\u9650\u65f6\u95f4\u5185\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u4e00\u7ec4\u6307\u4ee4\u6216\u64cd\u4f5c\u6b65\u9aa4\uff0c\u5b83\u5177\u6709\u4ee5\u4e0b\u7279\u6027\u3002

        • \u95ee\u9898\u662f\u660e\u786e\u7684\uff0c\u5305\u542b\u6e05\u6670\u7684\u8f93\u5165\u548c\u8f93\u51fa\u5b9a\u4e49\u3002
        • \u5177\u6709\u53ef\u884c\u6027\uff0c\u80fd\u591f\u5728\u6709\u9650\u6b65\u9aa4\u3001\u65f6\u95f4\u548c\u5185\u5b58\u7a7a\u95f4\u4e0b\u5b8c\u6210\u3002
        • \u5404\u6b65\u9aa4\u90fd\u6709\u786e\u5b9a\u7684\u542b\u4e49\uff0c\u5728\u76f8\u540c\u7684\u8f93\u5165\u548c\u8fd0\u884c\u6761\u4ef6\u4e0b\uff0c\u8f93\u51fa\u59cb\u7ec8\u76f8\u540c\u3002
        "},{"location":"chapter_introduction/what_is_dsa/#122","title":"1.2.2 \u00a0 \u6570\u636e\u7ed3\u6784\u5b9a\u4e49","text":"

        \u300c\u6570\u636e\u7ed3\u6784 data structure\u300d\u662f\u8ba1\u7b97\u673a\u4e2d\u7ec4\u7ec7\u548c\u5b58\u50a8\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u5177\u6709\u4ee5\u4e0b\u8bbe\u8ba1\u76ee\u6807\u3002

        • \u7a7a\u95f4\u5360\u7528\u5c3d\u91cf\u5c11\uff0c\u4ee5\u8282\u7701\u8ba1\u7b97\u673a\u5185\u5b58\u3002
        • \u6570\u636e\u64cd\u4f5c\u5c3d\u53ef\u80fd\u5feb\u901f\uff0c\u6db5\u76d6\u6570\u636e\u8bbf\u95ee\u3001\u6dfb\u52a0\u3001\u5220\u9664\u3001\u66f4\u65b0\u7b49\u3002
        • \u63d0\u4f9b\u7b80\u6d01\u7684\u6570\u636e\u8868\u793a\u548c\u903b\u8f91\u4fe1\u606f\uff0c\u4ee5\u4fbf\u7b97\u6cd5\u9ad8\u6548\u8fd0\u884c\u3002

        \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1\u662f\u4e00\u4e2a\u5145\u6ee1\u6743\u8861\u7684\u8fc7\u7a0b\u3002\u5982\u679c\u60f3\u5728\u67d0\u65b9\u9762\u53d6\u5f97\u63d0\u5347\uff0c\u5f80\u5f80\u9700\u8981\u5728\u53e6\u4e00\u65b9\u9762\u4f5c\u51fa\u59a5\u534f\u3002\u4e0b\u9762\u4e3e\u4e24\u4e2a\u4f8b\u5b50\u3002

        • \u94fe\u8868\u76f8\u8f83\u4e8e\u6570\u7ec4\uff0c\u5728\u6570\u636e\u6dfb\u52a0\u548c\u5220\u9664\u64cd\u4f5c\u4e0a\u66f4\u52a0\u4fbf\u6377\uff0c\u4f46\u727a\u7272\u4e86\u6570\u636e\u8bbf\u95ee\u901f\u5ea6\u3002
        • \u56fe\u76f8\u8f83\u4e8e\u94fe\u8868\uff0c\u63d0\u4f9b\u4e86\u66f4\u4e30\u5bcc\u7684\u903b\u8f91\u4fe1\u606f\uff0c\u4f46\u9700\u8981\u5360\u7528\u66f4\u5927\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        "},{"location":"chapter_introduction/what_is_dsa/#123","title":"1.2.3 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5173\u7cfb","text":"

        \u5982\u56fe 1-4 \u6240\u793a\uff0c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u9ad8\u5ea6\u76f8\u5173\u3001\u7d27\u5bc6\u7ed3\u5408\uff0c\u5177\u4f53\u8868\u73b0\u5728\u4ee5\u4e0b\u4e09\u4e2a\u65b9\u9762\u3002

        • \u6570\u636e\u7ed3\u6784\u662f\u7b97\u6cd5\u7684\u57fa\u77f3\u3002\u6570\u636e\u7ed3\u6784\u4e3a\u7b97\u6cd5\u63d0\u4f9b\u4e86\u7ed3\u6784\u5316\u5b58\u50a8\u7684\u6570\u636e\uff0c\u4ee5\u53ca\u64cd\u4f5c\u6570\u636e\u7684\u65b9\u6cd5\u3002
        • \u7b97\u6cd5\u662f\u6570\u636e\u7ed3\u6784\u53d1\u6325\u4f5c\u7528\u7684\u821e\u53f0\u3002\u6570\u636e\u7ed3\u6784\u672c\u8eab\u4ec5\u5b58\u50a8\u6570\u636e\u4fe1\u606f\uff0c\u7ed3\u5408\u7b97\u6cd5\u624d\u80fd\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u3002
        • \u7b97\u6cd5\u901a\u5e38\u53ef\u4ee5\u57fa\u4e8e\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\uff0c\u4f46\u6267\u884c\u6548\u7387\u53ef\u80fd\u76f8\u5dee\u5f88\u5927\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u662f\u5173\u952e\u3002

        \u56fe 1-4 \u00a0 \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u5173\u7cfb

        \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u72b9\u5982\u56fe 1-5 \u6240\u793a\u7684\u62fc\u88c5\u79ef\u6728\u3002\u4e00\u5957\u79ef\u6728\uff0c\u9664\u4e86\u5305\u542b\u8bb8\u591a\u96f6\u4ef6\u4e4b\u5916\uff0c\u8fd8\u9644\u6709\u8be6\u7ec6\u7684\u7ec4\u88c5\u8bf4\u660e\u4e66\u3002\u6211\u4eec\u6309\u7167\u8bf4\u660e\u4e66\u4e00\u6b65\u6b65\u64cd\u4f5c\uff0c\u5c31\u80fd\u7ec4\u88c5\u51fa\u7cbe\u7f8e\u7684\u79ef\u6728\u6a21\u578b\u3002

        \u56fe 1-5 \u00a0 \u62fc\u88c5\u79ef\u6728

        \u4e24\u8005\u7684\u8be6\u7ec6\u5bf9\u5e94\u5173\u7cfb\u5982\u8868 1-1 \u6240\u793a\u3002

        \u8868 1-1 \u00a0 \u5c06\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7c7b\u6bd4\u4e3a\u62fc\u88c5\u79ef\u6728

        \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5 \u62fc\u88c5\u79ef\u6728 \u8f93\u5165\u6570\u636e \u672a\u62fc\u88c5\u7684\u79ef\u6728 \u6570\u636e\u7ed3\u6784 \u79ef\u6728\u7ec4\u7ec7\u5f62\u5f0f\uff0c\u5305\u62ec\u5f62\u72b6\u3001\u5927\u5c0f\u3001\u8fde\u63a5\u65b9\u5f0f\u7b49 \u7b97\u6cd5 \u628a\u79ef\u6728\u62fc\u6210\u76ee\u6807\u5f62\u6001\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u6b65\u9aa4 \u8f93\u51fa\u6570\u636e \u79ef\u6728\u6a21\u578b

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u662f\u72ec\u7acb\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u3002\u6b63\u56e0\u5982\u6b64\uff0c\u672c\u4e66\u5f97\u4ee5\u63d0\u4f9b\u57fa\u4e8e\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u5b9e\u73b0\u3002

        \u7ea6\u5b9a\u4fd7\u6210\u7684\u7b80\u79f0

        \u5728\u5b9e\u9645\u8ba8\u8bba\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u201c\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u201d\u7b80\u79f0\u4e3a\u201c\u7b97\u6cd5\u201d\u3002\u6bd4\u5982\u4f17\u6240\u5468\u77e5\u7684 LeetCode \u7b97\u6cd5\u9898\u76ee\uff0c\u5b9e\u9645\u4e0a\u540c\u65f6\u8003\u67e5\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u4e24\u65b9\u9762\u7684\u77e5\u8bc6\u3002

        "},{"location":"chapter_preface/","title":"\u7b2c 0 \u7ae0 \u00a0 \u524d\u8a00","text":"

        Abstract

        \u7b97\u6cd5\u72b9\u5982\u7f8e\u5999\u7684\u4ea4\u54cd\u4e50\uff0c\u6bcf\u4e00\u884c\u4ee3\u7801\u90fd\u50cf\u97f5\u5f8b\u822c\u6d41\u6dcc\u3002

        \u613f\u8fd9\u672c\u4e66\u5728\u4f60\u7684\u8111\u6d77\u4e2d\u8f7b\u8f7b\u54cd\u8d77\uff0c\u7559\u4e0b\u72ec\u7279\u800c\u6df1\u523b\u7684\u65cb\u5f8b\u3002

        "},{"location":"chapter_preface/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 0.1 \u00a0 \u5173\u4e8e\u672c\u4e66
        • 0.2 \u00a0 \u5982\u4f55\u4f7f\u7528\u672c\u4e66
        • 0.3 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_preface/about_the_book/","title":"0.1 \u00a0 \u5173\u4e8e\u672c\u4e66","text":"

        \u672c\u9879\u76ee\u65e8\u5728\u521b\u5efa\u4e00\u672c\u5f00\u6e90\u3001\u514d\u8d39\u3001\u65b0\u624b\u53cb\u597d\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5165\u95e8\u6559\u7a0b\u3002

        • \u5168\u4e66\u91c7\u7528\u52a8\u753b\u56fe\u89e3\uff0c\u7ed3\u6784\u5316\u5730\u8bb2\u89e3\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u77e5\u8bc6\uff0c\u5185\u5bb9\u6e05\u6670\u6613\u61c2\u3001\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1\u3002
        • \u7b97\u6cd5\u6e90\u4ee3\u7801\u7686\u53ef\u4e00\u952e\u8fd0\u884c\uff0c\u652f\u6301 Python\u3001C++\u3001Java\u3001C#\u3001Go\u3001Swift\u3001JavaScript\u3001TypeScript\u3001Dart\u3001Rust\u3001C\u3001Zig \u7b49\u8bed\u8a00\u3002
        • \u9f13\u52b1\u8bfb\u8005\u5728\u7ae0\u8282\u8ba8\u8bba\u533a\u4e92\u5e2e\u4e92\u52a9\u3001\u5171\u540c\u8fdb\u6b65\uff0c\u63d0\u95ee\u4e0e\u8bc4\u8bba\u901a\u5e38\u53ef\u5728\u4e24\u65e5\u5185\u5f97\u5230\u56de\u590d\u3002
        "},{"location":"chapter_preface/about_the_book/#011","title":"0.1.1 \u00a0 \u8bfb\u8005\u5bf9\u8c61","text":"

        \u82e5\u4f60\u662f\u7b97\u6cd5\u521d\u5b66\u8005\uff0c\u4ece\u672a\u63a5\u89e6\u8fc7\u7b97\u6cd5\uff0c\u6216\u8005\u5df2\u7ecf\u6709\u4e00\u4e9b\u5237\u9898\u7ecf\u9a8c\uff0c\u5bf9\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6709\u6a21\u7cca\u7684\u8ba4\u8bc6\uff0c\u5728\u4f1a\u4e0e\u4e0d\u4f1a\u4e4b\u95f4\u53cd\u590d\u6a2a\u8df3\uff0c\u90a3\u4e48\u672c\u4e66\u6b63\u662f\u4e3a\u4f60\u91cf\u8eab\u5b9a\u5236\u7684\uff01

        \u5982\u679c\u4f60\u5df2\u7ecf\u79ef\u7d2f\u4e00\u5b9a\u5237\u9898\u91cf\uff0c\u719f\u6089\u5927\u90e8\u5206\u9898\u578b\uff0c\u90a3\u4e48\u672c\u4e66\u53ef\u52a9\u4f60\u56de\u987e\u4e0e\u68b3\u7406\u7b97\u6cd5\u77e5\u8bc6\u4f53\u7cfb\uff0c\u4ed3\u5e93\u6e90\u4ee3\u7801\u53ef\u4ee5\u5f53\u4f5c\u201c\u5237\u9898\u5de5\u5177\u5e93\u201d\u6216\u201c\u7b97\u6cd5\u5b57\u5178\u201d\u6765\u4f7f\u7528\u3002

        \u82e5\u4f60\u662f\u7b97\u6cd5\u5927\u795e\uff0c\u6211\u4eec\u671f\u5f85\u6536\u5230\u4f60\u7684\u5b9d\u8d35\u5efa\u8bae\uff0c\u6216\u8005\u4e00\u8d77\u53c2\u4e0e\u521b\u4f5c\u3002

        \u524d\u7f6e\u6761\u4ef6

        \u4f60\u9700\u8981\u81f3\u5c11\u5177\u5907\u4efb\u4e00\u8bed\u8a00\u7684\u7f16\u7a0b\u57fa\u7840\uff0c\u80fd\u591f\u9605\u8bfb\u548c\u7f16\u5199\u7b80\u5355\u4ee3\u7801\u3002

        "},{"location":"chapter_preface/about_the_book/#012","title":"0.1.2 \u00a0 \u5185\u5bb9\u7ed3\u6784","text":"

        \u672c\u4e66\u7684\u4e3b\u8981\u5185\u5bb9\u5982\u56fe 0-1 \u6240\u793a\u3002

        • \u590d\u6742\u5ea6\u5206\u6790\uff1a\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u7684\u8bc4\u4ef7\u7ef4\u5ea6\u4e0e\u65b9\u6cd5\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u63a8\u7b97\u65b9\u6cd5\u3001\u5e38\u89c1\u7c7b\u578b\u3001\u793a\u4f8b\u7b49\u3002
        • \u6570\u636e\u7ed3\u6784\uff1a\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u6570\u636e\u7ed3\u6784\u7684\u5206\u7c7b\u65b9\u6cd5\u3002\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6808\u3001\u961f\u5217\u3001\u54c8\u5e0c\u8868\u3001\u6811\u3001\u5806\u3001\u56fe\u7b49\u6570\u636e\u7ed3\u6784\u7684\u5b9a\u4e49\u3001\u4f18\u7f3a\u70b9\u3001\u5e38\u7528\u64cd\u4f5c\u3001\u5e38\u89c1\u7c7b\u578b\u3001\u5178\u578b\u5e94\u7528\u3001\u5b9e\u73b0\u65b9\u6cd5\u7b49\u3002
        • \u7b97\u6cd5\uff1a\u641c\u7d22\u3001\u6392\u5e8f\u3001\u5206\u6cbb\u3001\u56de\u6eaf\u3001\u52a8\u6001\u89c4\u5212\u3001\u8d2a\u5fc3\u7b49\u7b97\u6cd5\u7684\u5b9a\u4e49\u3001\u4f18\u7f3a\u70b9\u3001\u6548\u7387\u3001\u5e94\u7528\u573a\u666f\u3001\u89e3\u9898\u6b65\u9aa4\u548c\u793a\u4f8b\u95ee\u9898\u7b49\u3002

        \u56fe 0-1 \u00a0 \u672c\u4e66\u4e3b\u8981\u5185\u5bb9

        "},{"location":"chapter_preface/about_the_book/#013","title":"0.1.3 \u00a0 \u81f4\u8c22","text":"

        \u5728\u672c\u4e66\u7684\u521b\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u5f97\u5230\u4e86\u8bb8\u591a\u4eba\u7684\u5e2e\u52a9\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a

        • \u611f\u8c22\u6211\u5728\u516c\u53f8\u7684\u5bfc\u5e08\u674e\u6c50\u535a\u58eb\uff0c\u5728\u4e00\u6b21\u7545\u8c08\u4e2d\u4f60\u9f13\u52b1\u6211\u201c\u5feb\u884c\u52a8\u8d77\u6765\u201d\uff0c\u575a\u5b9a\u4e86\u6211\u5199\u8fd9\u672c\u4e66\u7684\u51b3\u5fc3\uff1b
        • \u611f\u8c22\u6211\u7684\u5973\u670b\u53cb\u6ce1\u6ce1\u4f5c\u4e3a\u672c\u4e66\u7684\u9996\u4f4d\u8bfb\u8005\uff0c\u4ece\u7b97\u6cd5\u5c0f\u767d\u7684\u89d2\u5ea6\u63d0\u51fa\u8bb8\u591a\u5b9d\u8d35\u5efa\u8bae\uff0c\u4f7f\u5f97\u672c\u4e66\u66f4\u9002\u5408\u65b0\u624b\u9605\u8bfb\uff1b
        • \u611f\u8c22\u817e\u5b9d\u3001\u7426\u5b9d\u3001\u98de\u5b9d\u4e3a\u672c\u4e66\u8d77\u4e86\u4e00\u4e2a\u5bcc\u6709\u521b\u610f\u7684\u540d\u5b57\uff0c\u5524\u8d77\u5927\u5bb6\u5199\u4e0b\u7b2c\u4e00\u884c\u4ee3\u7801 \"Hello World!\" \u7684\u7f8e\u597d\u56de\u5fc6\uff1b
        • \u611f\u8c22\u6821\u94e8\u5728\u77e5\u8bc6\u4ea7\u6743\u65b9\u9762\u63d0\u4f9b\u7684\u4e13\u4e1a\u5e2e\u52a9\uff0c\u8fd9\u5bf9\u672c\u5f00\u6e90\u4e66\u7684\u53d1\u5c55\u8d77\u5230\u4e86\u91cd\u8981\u7684\u4f5c\u7528\uff1b
        • \u611f\u8c22\u82cf\u6f7c\u4e3a\u672c\u4e66\u8bbe\u8ba1\u4e86\u7cbe\u7f8e\u7684\u5c01\u9762\u548c logo \uff0c\u5e76\u5728\u6211\u7684\u5f3a\u8feb\u75c7\u4e0b\u591a\u6b21\u8010\u5fc3\u4fee\u6539\uff1b
        • \u611f\u8c22 @squidfunk \u63d0\u4f9b\u7684\u5199\u4f5c\u6392\u7248\u5efa\u8bae\uff0c\u4ee5\u53ca\u4ed6\u5f00\u53d1\u7684\u5f00\u6e90\u6587\u6863\u4e3b\u9898 Material-for-MkDocs \u3002

        \u5728\u5199\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u9605\u8bfb\u4e86\u8bb8\u591a\u5173\u4e8e\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u6559\u6750\u548c\u6587\u7ae0\u3002\u8fd9\u4e9b\u4f5c\u54c1\u4e3a\u672c\u4e66\u63d0\u4f9b\u4e86\u4f18\u79c0\u7684\u8303\u672c\uff0c\u786e\u4fdd\u4e86\u672c\u4e66\u5185\u5bb9\u7684\u51c6\u786e\u6027\u4e0e\u54c1\u8d28\u3002\u5728\u6b64\u611f\u8c22\u6240\u6709\u8001\u5e08\u548c\u524d\u8f88\u4eec\u7684\u6770\u51fa\u8d21\u732e\uff01

        \u672c\u4e66\u5021\u5bfc\u624b\u8111\u5e76\u7528\u7684\u5b66\u4e60\u65b9\u5f0f\uff0c\u5728\u8fd9\u4e00\u70b9\u4e0a\u6df1\u53d7\u300a\u52a8\u624b\u5b66\u6df1\u5ea6\u5b66\u4e60\u300b\u7684\u542f\u53d1\u3002\u5728\u6b64\u5411\u5404\u4f4d\u8bfb\u8005\u5f3a\u70c8\u63a8\u8350\u8fd9\u672c\u4f18\u79c0\u7684\u8457\u4f5c\u3002

        \u8877\u5fc3\u611f\u8c22\u6211\u7684\u7236\u6bcd\uff0c\u6b63\u662f\u4f60\u4eec\u4e00\u76f4\u4ee5\u6765\u7684\u652f\u6301\u4e0e\u9f13\u52b1\uff0c\u8ba9\u6211\u6709\u673a\u4f1a\u505a\u8fd9\u4ef6\u5bcc\u6709\u8da3\u5473\u7684\u4e8b\u3002

        "},{"location":"chapter_preface/suggestions/","title":"0.2 \u00a0 \u5982\u4f55\u4f7f\u7528\u672c\u4e66","text":"

        Tip

        \u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u7684\u9605\u8bfb\u4f53\u9a8c\uff0c\u5efa\u8bae\u4f60\u901a\u8bfb\u672c\u8282\u5185\u5bb9\u3002

        "},{"location":"chapter_preface/suggestions/#021","title":"0.2.1 \u00a0 \u884c\u6587\u98ce\u683c\u7ea6\u5b9a","text":"
        • \u6807\u9898\u540e\u6807\u6ce8 * \u7684\u662f\u9009\u8bfb\u7ae0\u8282\uff0c\u5185\u5bb9\u76f8\u5bf9\u56f0\u96be\u3002\u5982\u679c\u4f60\u7684\u65f6\u95f4\u6709\u9650\uff0c\u53ef\u4ee5\u5148\u8df3\u8fc7\u3002
        • \u91cd\u8981\u4e13\u6709\u540d\u8bcd\u53ca\u5176\u82f1\u6587\u7ffb\u8bd1\u4f1a\u7528 \u300c \u300d \u62ec\u53f7\u6807\u6ce8\uff0c\u4f8b\u5982 \u300c\u6570\u7ec4 array\u300d \u3002\u5efa\u8bae\u8bb0\u4f4f\u5b83\u4eec\uff0c\u4ee5\u4fbf\u9605\u8bfb\u6587\u732e\u3002
        • \u4e13\u6709\u540d\u8bcd\u548c\u6709\u7279\u6307\u542b\u4e49\u7684\u8bcd\u53e5\u4f1a\u4f7f\u7528 \u201c\u5f15\u53f7\u201d \u6807\u6ce8\uff0c\u4ee5\u907f\u514d\u6b67\u4e49\u3002
        • \u91cd\u8981\u540d\u8bcd\u3001\u91cd\u70b9\u5185\u5bb9\u548c\u603b\u7ed3\u6027\u8bed\u53e5\u4f1a\u88ab \u52a0\u7c97 \uff0c\u8fd9\u7c7b\u6587\u5b57\u503c\u5f97\u7279\u522b\u5173\u6ce8\u3002
        • \u5f53\u6d89\u53ca\u7f16\u7a0b\u8bed\u8a00\u4e4b\u95f4\u4e0d\u4e00\u81f4\u7684\u540d\u8bcd\u65f6\uff0c\u672c\u4e66\u5747\u4ee5 Python \u4e3a\u51c6\uff0c\u4f8b\u5982\u4f7f\u7528 \\(\\text{None}\\) \u6765\u8868\u793a\u201c\u7a7a\u201d\u3002
        • \u672c\u4e66\u90e8\u5206\u653e\u5f03\u4e86\u7f16\u7a0b\u8bed\u8a00\u7684\u6ce8\u91ca\u89c4\u8303\uff0c\u4ee5\u6362\u53d6\u66f4\u52a0\u7d27\u51d1\u7684\u5185\u5bb9\u6392\u7248\u3002\u6ce8\u91ca\u4e3b\u8981\u5206\u4e3a\u4e09\u79cd\u7c7b\u578b\uff1a\u6807\u9898\u6ce8\u91ca\u3001\u5185\u5bb9\u6ce8\u91ca\u3001\u591a\u884c\u6ce8\u91ca\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        \"\"\"\u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49\"\"\"\n# \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\"\"\"\n\u591a\u884c\n\u6ce8\u91ca\n\"\"\"\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        /* \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49 */\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n/**\n * \u591a\u884c\n * \u6ce8\u91ca\n */\n
        // \u6807\u9898\u6ce8\u91ca\uff0c\u7528\u4e8e\u6807\u6ce8\u51fd\u6570\u3001\u7c7b\u3001\u6d4b\u8bd5\u6837\u4f8b\u7b49\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n// \u591a\u884c\n// \u6ce8\u91ca\n
        "},{"location":"chapter_preface/suggestions/#022","title":"0.2.2 \u00a0 \u5728\u52a8\u753b\u56fe\u89e3\u4e2d\u9ad8\u6548\u5b66\u4e60","text":"

        \u76f8\u8f83\u4e8e\u6587\u5b57\uff0c\u89c6\u9891\u548c\u56fe\u7247\u5177\u6709\u66f4\u9ad8\u7684\u4fe1\u606f\u5bc6\u5ea6\u548c\u7ed3\u6784\u5316\u7a0b\u5ea6\uff0c\u66f4\u6613\u4e8e\u7406\u89e3\u3002\u5728\u672c\u4e66\u4e2d\uff0c\u91cd\u70b9\u548c\u96be\u70b9\u77e5\u8bc6\u5c06\u4e3b\u8981\u901a\u8fc7\u52a8\u753b\u548c\u56fe\u89e3\u5f62\u5f0f\u5c55\u793a\uff0c\u800c\u6587\u5b57\u5219\u4f5c\u4e3a\u52a8\u753b\u548c\u56fe\u7247\u7684\u89e3\u91ca\u4e0e\u8865\u5145\u3002

        \u5982\u679c\u4f60\u5728\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u53d1\u73b0\u67d0\u6bb5\u5185\u5bb9\u63d0\u4f9b\u4e86\u5982\u56fe 0-2 \u6240\u793a\u7684\u52a8\u753b\u6216\u56fe\u89e3\uff0c\u8bf7\u4ee5\u56fe\u4e3a\u4e3b\u3001\u4ee5\u6587\u5b57\u4e3a\u8f85\uff0c\u7efc\u5408\u4e24\u8005\u6765\u7406\u89e3\u5185\u5bb9\u3002

        \u56fe 0-2 \u00a0 \u52a8\u753b\u56fe\u89e3\u793a\u4f8b

        "},{"location":"chapter_preface/suggestions/#023","title":"0.2.3 \u00a0 \u5728\u4ee3\u7801\u5b9e\u8df5\u4e2d\u52a0\u6df1\u7406\u89e3","text":"

        \u672c\u4e66\u7684\u914d\u5957\u4ee3\u7801\u6258\u7ba1\u5728 GitHub \u4ed3\u5e93\u3002\u5982\u56fe 0-3 \u6240\u793a\uff0c\u6e90\u4ee3\u7801\u9644\u6709\u6d4b\u8bd5\u6837\u4f8b\uff0c\u53ef\u4e00\u952e\u8fd0\u884c\u3002

        \u5982\u679c\u65f6\u95f4\u5141\u8bb8\uff0c\u5efa\u8bae\u4f60\u53c2\u7167\u4ee3\u7801\u81ea\u884c\u6572\u4e00\u904d\u3002\u5982\u679c\u5b66\u4e60\u65f6\u95f4\u6709\u9650\uff0c\u8bf7\u81f3\u5c11\u901a\u8bfb\u5e76\u8fd0\u884c\u6240\u6709\u4ee3\u7801\u3002

        \u4e0e\u9605\u8bfb\u4ee3\u7801\u76f8\u6bd4\uff0c\u7f16\u5199\u4ee3\u7801\u7684\u8fc7\u7a0b\u5f80\u5f80\u80fd\u5e26\u6765\u66f4\u591a\u6536\u83b7\u3002\u52a8\u624b\u5b66\uff0c\u624d\u662f\u771f\u7684\u5b66\u3002

        \u56fe 0-3 \u00a0 \u8fd0\u884c\u4ee3\u7801\u793a\u4f8b

        \u8fd0\u884c\u4ee3\u7801\u7684\u524d\u7f6e\u5de5\u4f5c\u4e3b\u8981\u5206\u4e3a\u4e09\u6b65\u3002

        \u7b2c\u4e00\u6b65\uff1a\u5b89\u88c5\u672c\u5730\u7f16\u7a0b\u73af\u5883\u3002\u8bf7\u53c2\u7167\u9644\u5f55\u6240\u793a\u7684\u6559\u7a0b\u8fdb\u884c\u5b89\u88c5\uff0c\u5982\u679c\u5df2\u5b89\u88c5\uff0c\u5219\u53ef\u8df3\u8fc7\u6b64\u6b65\u9aa4\u3002

        \u7b2c\u4e8c\u6b65\uff1a\u514b\u9686\u6216\u4e0b\u8f7d\u4ee3\u7801\u4ed3\u5e93\u3002\u524d\u5f80 GitHub \u4ed3\u5e93\u3002

        \u5982\u679c\u5df2\u7ecf\u5b89\u88c5 Git \uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u514b\u9686\u672c\u4ed3\u5e93\uff1a

        git clone https://github.com/krahets/hello-algo.git\n

        \u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728\u56fe 0-4 \u6240\u793a\u7684\u4f4d\u7f6e\uff0c\u70b9\u51fb\u201cDownload ZIP\u201d\u6309\u94ae\u76f4\u63a5\u4e0b\u8f7d\u4ee3\u7801\u538b\u7f29\u5305\uff0c\u7136\u540e\u5728\u672c\u5730\u89e3\u538b\u5373\u53ef\u3002

        \u56fe 0-4 \u00a0 \u514b\u9686\u4ed3\u5e93\u4e0e\u4e0b\u8f7d\u4ee3\u7801

        \u7b2c\u4e09\u6b65\uff1a\u8fd0\u884c\u6e90\u4ee3\u7801\u3002\u5982\u56fe 0-5 \u6240\u793a\uff0c\u5bf9\u4e8e\u9876\u90e8\u6807\u6709\u6587\u4ef6\u540d\u79f0\u7684\u4ee3\u7801\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u4ed3\u5e93\u7684 codes \u6587\u4ef6\u5939\u5185\u627e\u5230\u5bf9\u5e94\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\u3002\u6e90\u4ee3\u7801\u6587\u4ef6\u53ef\u4e00\u952e\u8fd0\u884c\uff0c\u5c06\u5e2e\u52a9\u4f60\u8282\u7701\u4e0d\u5fc5\u8981\u7684\u8c03\u8bd5\u65f6\u95f4\uff0c\u8ba9\u4f60\u80fd\u591f\u4e13\u6ce8\u4e8e\u5b66\u4e60\u5185\u5bb9\u3002

        \u56fe 0-5 \u00a0 \u4ee3\u7801\u5757\u4e0e\u5bf9\u5e94\u7684\u6e90\u4ee3\u7801\u6587\u4ef6

        "},{"location":"chapter_preface/suggestions/#024","title":"0.2.4 \u00a0 \u5728\u63d0\u95ee\u8ba8\u8bba\u4e2d\u5171\u540c\u6210\u957f","text":"

        \u5728\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u8bf7\u4e0d\u8981\u8f7b\u6613\u8df3\u8fc7\u90a3\u4e9b\u6ca1\u5b66\u660e\u767d\u7684\u77e5\u8bc6\u70b9\u3002\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u63d0\u51fa\u4f60\u7684\u95ee\u9898\uff0c\u6211\u548c\u5c0f\u4f19\u4f34\u4eec\u5c06\u7aed\u8bda\u4e3a\u4f60\u89e3\u7b54\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u53ef\u5728\u4e24\u5929\u5185\u56de\u590d\u3002

        \u5982\u56fe 0-6 \u6240\u793a\uff0c\u6bcf\u4e2a\u7ae0\u8282\u7684\u5e95\u90e8\u90fd\u914d\u6709\u8bc4\u8bba\u533a\u3002\u5e0c\u671b\u4f60\u80fd\u591a\u5173\u6ce8\u8bc4\u8bba\u533a\u7684\u5185\u5bb9\u3002\u4e00\u65b9\u9762\uff0c\u4f60\u53ef\u4ee5\u4e86\u89e3\u5927\u5bb6\u9047\u5230\u7684\u95ee\u9898\uff0c\u4ece\u800c\u67e5\u6f0f\u8865\u7f3a\uff0c\u6fc0\u53d1\u66f4\u6df1\u5165\u7684\u601d\u8003\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u671f\u5f85\u4f60\u80fd\u6177\u6168\u5730\u56de\u7b54\u5176\u4ed6\u5c0f\u4f19\u4f34\u7684\u95ee\u9898\uff0c\u5206\u4eab\u4f60\u7684\u89c1\u89e3\uff0c\u5e2e\u52a9\u4ed6\u4eba\u8fdb\u6b65\u3002

        \u56fe 0-6 \u00a0 \u8bc4\u8bba\u533a\u793a\u4f8b

        "},{"location":"chapter_preface/suggestions/#025","title":"0.2.5 \u00a0 \u7b97\u6cd5\u5b66\u4e60\u8def\u7ebf","text":"

        \u4ece\u603b\u4f53\u4e0a\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b66\u4e60\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u7684\u8fc7\u7a0b\u5212\u5206\u4e3a\u4e09\u4e2a\u9636\u6bb5\u3002

        1. \u9636\u6bb5\u4e00\uff1a\u7b97\u6cd5\u5165\u95e8\u3002\u6211\u4eec\u9700\u8981\u719f\u6089\u5404\u79cd\u6570\u636e\u7ed3\u6784\u7684\u7279\u70b9\u548c\u7528\u6cd5\uff0c\u5b66\u4e60\u4e0d\u540c\u7b97\u6cd5\u7684\u539f\u7406\u3001\u6d41\u7a0b\u3001\u7528\u9014\u548c\u6548\u7387\u7b49\u65b9\u9762\u7684\u5185\u5bb9\u3002
        2. \u9636\u6bb5\u4e8c\uff1a\u5237\u7b97\u6cd5\u9898\u3002\u5efa\u8bae\u4ece\u70ed\u95e8\u9898\u76ee\u5f00\u5237\uff0c\u5982\u201c\u5251\u6307 Offer\u201d\u548c\u201cLeetCode Hot 100\u201d\uff0c\u5148\u79ef\u7d2f\u81f3\u5c11 100 \u9053\u9898\u76ee\uff0c\u719f\u6089\u4e3b\u6d41\u7684\u7b97\u6cd5\u95ee\u9898\u3002\u521d\u6b21\u5237\u9898\u65f6\uff0c\u201c\u77e5\u8bc6\u9057\u5fd8\u201d\u53ef\u80fd\u662f\u4e00\u4e2a\u6311\u6218\uff0c\u4f46\u8bf7\u653e\u5fc3\uff0c\u8fd9\u662f\u5f88\u6b63\u5e38\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u201c\u827e\u5bbe\u6d69\u65af\u9057\u5fd8\u66f2\u7ebf\u201d\u6765\u590d\u4e60\u9898\u76ee\uff0c\u901a\u5e38\u5728\u8fdb\u884c 3\uff5e5 \u8f6e\u7684\u91cd\u590d\u540e\uff0c\u5c31\u80fd\u5c06\u5176\u7262\u8bb0\u5728\u5fc3\u3002
        3. \u9636\u6bb5\u4e09\uff1a\u642d\u5efa\u77e5\u8bc6\u4f53\u7cfb\u3002\u5728\u5b66\u4e60\u65b9\u9762\uff0c\u6211\u4eec\u53ef\u4ee5\u9605\u8bfb\u7b97\u6cd5\u4e13\u680f\u6587\u7ae0\u3001\u89e3\u9898\u6846\u67b6\u548c\u7b97\u6cd5\u6559\u6750\uff0c\u4ee5\u4e0d\u65ad\u4e30\u5bcc\u77e5\u8bc6\u4f53\u7cfb\u3002\u5728\u5237\u9898\u65b9\u9762\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u91c7\u7528\u8fdb\u9636\u5237\u9898\u7b56\u7565\uff0c\u5982\u6309\u4e13\u9898\u5206\u7c7b\u3001\u4e00\u9898\u591a\u89e3\u3001\u4e00\u89e3\u591a\u9898\u7b49\uff0c\u76f8\u5173\u7684\u5237\u9898\u5fc3\u5f97\u53ef\u4ee5\u5728\u5404\u4e2a\u793e\u533a\u627e\u5230\u3002

        \u5982\u56fe 0-7 \u6240\u793a\uff0c\u672c\u4e66\u5185\u5bb9\u4e3b\u8981\u6db5\u76d6\u201c\u9636\u6bb5\u4e00\u201d\uff0c\u65e8\u5728\u5e2e\u52a9\u4f60\u66f4\u9ad8\u6548\u5730\u5c55\u5f00\u9636\u6bb5\u4e8c\u548c\u9636\u6bb5\u4e09\u7684\u5b66\u4e60\u3002

        \u56fe 0-7 \u00a0 \u7b97\u6cd5\u5b66\u4e60\u8def\u7ebf

        "},{"location":"chapter_preface/summary/","title":"0.3 \u00a0 \u5c0f\u7ed3","text":"
        • \u672c\u4e66\u7684\u4e3b\u8981\u53d7\u4f17\u662f\u7b97\u6cd5\u521d\u5b66\u8005\u3002\u5982\u679c\u5df2\u6709\u4e00\u5b9a\u57fa\u7840\uff0c\u672c\u4e66\u80fd\u5e2e\u52a9\u4f60\u7cfb\u7edf\u56de\u987e\u7b97\u6cd5\u77e5\u8bc6\uff0c\u4e66\u4e2d\u6e90\u4ee3\u7801\u4e5f\u53ef\u4f5c\u4e3a\u201c\u5237\u9898\u5de5\u5177\u5e93\u201d\u4f7f\u7528\u3002
        • \u4e66\u4e2d\u5185\u5bb9\u4e3b\u8981\u5305\u62ec\u590d\u6742\u5ea6\u5206\u6790\u3001\u6570\u636e\u7ed3\u6784\u3001\u7b97\u6cd5\u4e09\u90e8\u5206\uff0c\u6db5\u76d6\u4e86\u8be5\u9886\u57df\u7684\u5927\u90e8\u5206\u4e3b\u9898\u3002
        • \u5bf9\u4e8e\u7b97\u6cd5\u65b0\u624b\uff0c\u5728\u521d\u5b66\u9636\u6bb5\u9605\u8bfb\u4e00\u672c\u5165\u95e8\u4e66\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u4ee5\u5c11\u8d70\u8bb8\u591a\u5f2f\u8def\u3002
        • \u4e66\u4e2d\u7684\u52a8\u753b\u548c\u56fe\u89e3\u901a\u5e38\u7528\u4e8e\u4ecb\u7ecd\u91cd\u70b9\u548c\u96be\u70b9\u77e5\u8bc6\u3002\u9605\u8bfb\u672c\u4e66\u65f6\uff0c\u5e94\u7ed9\u4e88\u8fd9\u4e9b\u5185\u5bb9\u66f4\u591a\u5173\u6ce8\u3002
        • \u5b9e\u8df5\u4e43\u5b66\u4e60\u7f16\u7a0b\u4e4b\u6700\u4f73\u9014\u5f84\u3002\u5f3a\u70c8\u5efa\u8bae\u8fd0\u884c\u6e90\u4ee3\u7801\u5e76\u4eb2\u81ea\u6572\u4ee3\u7801\u3002
        • \u672c\u4e66\u7f51\u9875\u7248\u7684\u6bcf\u4e2a\u7ae0\u8282\u90fd\u8bbe\u6709\u8ba8\u8bba\u533a\uff0c\u6b22\u8fce\u968f\u65f6\u5206\u4eab\u4f60\u7684\u7591\u60d1\u4e0e\u89c1\u89e3\u3002
        "},{"location":"chapter_reference/","title":"\u53c2\u8003\u6587\u732e","text":"

        [1] Thomas H. Cormen, et al. Introduction to Algorithms (3rd Edition).

        [2] Aditya Bhargava. Grokking Algorithms: An Illustrated Guide for Programmers and Other Curious People (1st Edition).

        [3] \u4e25\u851a\u654f. \u6570\u636e\u7ed3\u6784\uff08C \u8bed\u8a00\u7248\uff09.

        [4] \u9093\u4fca\u8f89. \u6570\u636e\u7ed3\u6784\uff08C++ \u8bed\u8a00\u7248\uff0c\u7b2c\u4e09\u7248\uff09.

        [5] \u9a6c\u514b \u827e\u4f26 \u7ef4\u65af\u8457\uff0c\u9648\u8d8a\u8bd1. \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5206\u6790\uff1aJava\u8bed\u8a00\u63cf\u8ff0\uff08\u7b2c\u4e09\u7248\uff09.

        [6] \u7a0b\u6770. \u5927\u8bdd\u6570\u636e\u7ed3\u6784.

        [7] \u738b\u4e89. \u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u4e4b\u7f8e.

        [8] Gayle Laakmann McDowell. Cracking the Coding Interview: 189 Programming Questions and Solutions (6th Edition).

        [9] Aston Zhang, et al. Dive into Deep Learning.

        "},{"location":"chapter_searching/","title":"\u7b2c 10 \u7ae0 \u00a0 \u641c\u7d22","text":"

        Abstract

        \u641c\u7d22\u662f\u4e00\u573a\u672a\u77e5\u7684\u5192\u9669\uff0c\u6211\u4eec\u6216\u8bb8\u9700\u8981\u8d70\u904d\u795e\u79d8\u7a7a\u95f4\u7684\u6bcf\u4e2a\u89d2\u843d\uff0c\u53c8\u6216\u8bb8\u53ef\u4ee5\u5feb\u901f\u9501\u5b9a\u76ee\u6807\u3002

        \u5728\u8fd9\u573a\u5bfb\u89c5\u4e4b\u65c5\u4e2d\uff0c\u6bcf\u4e00\u6b21\u63a2\u7d22\u90fd\u53ef\u80fd\u5f97\u5230\u4e00\u4e2a\u672a\u66fe\u6599\u60f3\u7684\u7b54\u6848\u3002

        "},{"location":"chapter_searching/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 10.1 \u00a0 \u4e8c\u5206\u67e5\u627e
        • 10.2 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9
        • 10.3 \u00a0 \u4e8c\u5206\u67e5\u627e\u8fb9\u754c
        • 10.4 \u00a0 \u54c8\u5e0c\u4f18\u5316\u7b56\u7565
        • 10.5 \u00a0 \u91cd\u8bc6\u641c\u7d22\u7b97\u6cd5
        • 10.6 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_searching/binary_search/","title":"10.1 \u00a0 \u4e8c\u5206\u67e5\u627e","text":"

        \u300c\u4e8c\u5206\u67e5\u627e binary search\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u9ad8\u6548\u641c\u7d22\u7b97\u6cd5\u3002\u5b83\u5229\u7528\u6570\u636e\u7684\u6709\u5e8f\u6027\uff0c\u6bcf\u8f6e\u7f29\u5c0f\u4e00\u534a\u641c\u7d22\u8303\u56f4\uff0c\u76f4\u81f3\u627e\u5230\u76ee\u6807\u5143\u7d20\u6216\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u4e3a\u6b62\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5143\u7d20\u6309\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u6392\u5217\u4e14\u4e0d\u91cd\u590d\u3002\u8bf7\u67e5\u627e\u5e76\u8fd4\u56de\u5143\u7d20 target \u5728\u8be5\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u3002\u82e5\u6570\u7ec4\u4e0d\u5305\u542b\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002\u793a\u4f8b\u5982\u56fe 10-1 \u6240\u793a\u3002

        \u56fe 10-1 \u00a0 \u4e8c\u5206\u67e5\u627e\u793a\u4f8b\u6570\u636e

        \u5982\u56fe 10-2 \u6240\u793a\uff0c\u6211\u4eec\u5148\u521d\u59cb\u5316\u6307\u9488 \\(i = 0\\) \u548c \\(j = n - 1\\) \uff0c\u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u548c\u5c3e\u5143\u7d20\uff0c\u4ee3\u8868\u641c\u7d22\u533a\u95f4 \\([0, n - 1]\\) \u3002\u8bf7\u6ce8\u610f\uff0c\u4e2d\u62ec\u53f7\u8868\u793a\u95ed\u533a\u95f4\uff0c\u5176\u5305\u542b\u8fb9\u754c\u503c\u672c\u8eab\u3002

        \u63a5\u4e0b\u6765\uff0c\u5faa\u73af\u6267\u884c\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 \\(m = \\lfloor {(i + j) / 2} \\rfloor\\) \uff0c\u5176\u4e2d \\(\\lfloor \\: \\rfloor\\) \u8868\u793a\u5411\u4e0b\u53d6\u6574\u64cd\u4f5c\u3002
        2. \u5224\u65ad nums[m] \u548c target \u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5206\u4e3a\u4ee5\u4e0b\u4e09\u79cd\u60c5\u51b5\u3002
          1. \u5f53 nums[m] < target \u65f6\uff0c\u8bf4\u660e target \u5728\u533a\u95f4 \\([m + 1, j]\\) \u4e2d\uff0c\u56e0\u6b64\u6267\u884c \\(i = m + 1\\) \u3002
          2. \u5f53 nums[m] > target \u65f6\uff0c\u8bf4\u660e target \u5728\u533a\u95f4 \\([i, m - 1]\\) \u4e2d\uff0c\u56e0\u6b64\u6267\u884c \\(j = m - 1\\) \u3002
          3. \u5f53 nums[m] = target \u65f6\uff0c\u8bf4\u660e\u627e\u5230 target \uff0c\u56e0\u6b64\u8fd4\u56de\u7d22\u5f15 \\(m\\) \u3002

        \u82e5\u6570\u7ec4\u4e0d\u5305\u542b\u76ee\u6807\u5143\u7d20\uff0c\u641c\u7d22\u533a\u95f4\u6700\u7ec8\u4f1a\u7f29\u5c0f\u4e3a\u7a7a\u3002\u6b64\u65f6\u8fd4\u56de \\(-1\\) \u3002

        <1><2><3><4><5><6><7>

        \u56fe 10-2 \u00a0 \u4e8c\u5206\u67e5\u627e\u6d41\u7a0b

        \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e \\(i\\) \u548c \\(j\\) \u90fd\u662f int \u7c7b\u578b\uff0c\u56e0\u6b64 \\(i + j\\) \u53ef\u80fd\u4f1a\u8d85\u51fa int \u7c7b\u578b\u7684\u53d6\u503c\u8303\u56f4\u3002\u4e3a\u4e86\u907f\u514d\u5927\u6570\u8d8a\u754c\uff0c\u6211\u4eec\u901a\u5e38\u91c7\u7528\u516c\u5f0f \\(m = \\lfloor {i + (j - i) / 2} \\rfloor\\) \u6765\u8ba1\u7b97\u4e2d\u70b9\u3002

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search.py
        def binary_search(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09\"\"\"\n# \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\ni, j = 0, len(nums) - 1\n# \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j:\n# \u7406\u8bba\u4e0a Python \u7684\u6570\u5b57\u53ef\u4ee5\u65e0\u9650\u5927\uff08\u53d6\u51b3\u4e8e\u5185\u5b58\u5927\u5c0f\uff09\uff0c\u65e0\u987b\u8003\u8651\u5927\u6570\u8d8a\u754c\u95ee\u9898\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nreturn m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn -1  # \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n
        binary_search.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(vector<int> &nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.size() - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.java
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(int[] nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.cs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint BinarySearch(int[] nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.Length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.go
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunc binarySearch(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\ni, j := 0, len(nums)-1\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nfor i <= j {\nm := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.swift
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nvar i = 0\nvar j = nums.count - 1\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.js
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunction binarySearch(nums, target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet i = 0,\nj = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\nconst m = parseInt(i + (j - i) / 2);\nif (nums[m] < target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse return m; // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.ts
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfunction binarySearch(nums: number[], target: number): number {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet i = 0,\nj = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = Math.floor(i + (j - i) / 2);\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\nreturn -1; // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n}\n
        binary_search.dart
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(List<int> nums, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = nums.length - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.rs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nlet mut i = 0;\nlet mut j = nums.len() as i32 - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile i <= j {\nlet m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}                       }\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.c
        /* \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09 */\nint binarySearch(int *nums, int len, int target) {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nint i = 0, j = len - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.zig
        // \u4e8c\u5206\u67e5\u627e\uff08\u53cc\u95ed\u533a\u95f4\uff09\nfn binarySearch(comptime T: type, nums: std.ArrayList(T), target: T) T {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1] \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20\nvar i: usize = 0;\nvar j: usize = nums.items.len - 1;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i > j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nvar m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1;\n} else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1;\n} else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn @intCast(m);\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n

        \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(\\log n)\\) \uff1a\u5728\u4e8c\u5206\u5faa\u73af\u4e2d\uff0c\u533a\u95f4\u6bcf\u8f6e\u7f29\u5c0f\u4e00\u534a\uff0c\u5faa\u73af\u6b21\u6570\u4e3a \\(\\log_2 n\\) \u3002

        \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\) \uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7a7a\u95f4\u3002

        "},{"location":"chapter_searching/binary_search/#1011","title":"10.1.1 \u00a0 \u533a\u95f4\u8868\u793a\u65b9\u6cd5","text":"

        \u9664\u4e86\u4e0a\u8ff0\u53cc\u95ed\u533a\u95f4\u5916\uff0c\u5e38\u89c1\u7684\u533a\u95f4\u8868\u793a\u8fd8\u6709\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u533a\u95f4\uff0c\u5b9a\u4e49\u4e3a \\([0, n)\\) \uff0c\u5373\u5de6\u8fb9\u754c\u5305\u542b\u81ea\u8eab\uff0c\u53f3\u8fb9\u754c\u4e0d\u5305\u542b\u81ea\u8eab\u3002\u5728\u8be5\u8868\u793a\u4e0b\uff0c\u533a\u95f4 \\([i, j]\\) \u5728 \\(i = j\\) \u65f6\u4e3a\u7a7a\u3002

        \u6211\u4eec\u53ef\u4ee5\u57fa\u4e8e\u8be5\u8868\u793a\u5b9e\u73b0\u5177\u6709\u76f8\u540c\u529f\u80fd\u7684\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search.py
        def binary_search_lcro(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09\"\"\"\n# \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\ni, j = 0, len(nums)\n# \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\nelif nums[m] > target:\nj = m  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nelse:\nreturn m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn -1  # \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n
        binary_search.cpp
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(vector<int> &nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.size();\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.java
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(int[] nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.cs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint BinarySearchLCRO(int[] nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.Length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.go
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunc binarySearchLCRO(nums []int, target int) int {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\ni, j := 0, len(nums)\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nfor i < j {\nm := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.swift
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunc binarySearchLCRO(nums: [Int], target: Int) -> Int {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nvar i = 0\nvar j = nums.count\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1\n} else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m\n} else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1\n}\n
        binary_search.js
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunction binarySearchLCRO(nums, target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet i = 0,\nj = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\nconst m = parseInt(i + (j - i) / 2);\nif (nums[m] < target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target)\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nelse return m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.ts
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfunction binarySearchLCRO(nums: number[], target: number): number {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet i = 0,\nj = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nconst m = Math.floor(i + (j - i) / 2);\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\nreturn -1; // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n}\n
        binary_search.dart
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(List<int> nums, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = nums.length;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums[m] > target) {\n// \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {\n// \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.rs
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nfn binary_search_lcro(nums: &[i32], target: i32) -> i32 {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nlet mut i = 0;\nlet mut j = nums.len() as i32;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile i < j {\nlet m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m - 1;\n} else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}                       }\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.c
        /* \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09 */\nint binarySearchLCRO(int *nums, int len, int target) {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nint i = 0, j = len;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i < j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\nelse if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\nelse // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn m;\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n
        binary_search.zig
        // \u4e8c\u5206\u67e5\u627e\uff08\u5de6\u95ed\u53f3\u5f00\u533a\u95f4\uff09\nfn binarySearchLCRO(comptime T: type, nums: std.ArrayList(T), target: T) T {\n// \u521d\u59cb\u5316\u5de6\u95ed\u53f3\u5f00\u533a\u95f4 [0, n) \uff0c\u5373 i, j \u5206\u522b\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u3001\u5c3e\u5143\u7d20+1\nvar i: usize = 0;\nvar j: usize = nums.items.len;\n// \u5faa\u73af\uff0c\u5f53\u641c\u7d22\u533a\u95f4\u4e3a\u7a7a\u65f6\u8df3\u51fa\uff08\u5f53 i = j \u65f6\u4e3a\u7a7a\uff09\nwhile (i <= j) {\nvar m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\ni = m + 1;\n} else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\nj = m;\n} else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\nreturn @intCast(m);\n}\n}\n// \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\nreturn -1;\n}\n

        \u5982\u56fe 10-3 \u6240\u793a\uff0c\u5728\u4e24\u79cd\u533a\u95f4\u8868\u793a\u4e0b\uff0c\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u7684\u521d\u59cb\u5316\u3001\u5faa\u73af\u6761\u4ef6\u548c\u7f29\u5c0f\u533a\u95f4\u64cd\u4f5c\u7686\u6709\u6240\u4e0d\u540c\u3002

        \u7531\u4e8e\u201c\u53cc\u95ed\u533a\u95f4\u201d\u8868\u793a\u4e2d\u7684\u5de6\u53f3\u8fb9\u754c\u90fd\u88ab\u5b9a\u4e49\u4e3a\u95ed\u533a\u95f4\uff0c\u56e0\u6b64\u901a\u8fc7\u6307\u9488 \\(i\\) \u548c\u6307\u9488 \\(j\\) \u7f29\u5c0f\u533a\u95f4\u7684\u64cd\u4f5c\u4e5f\u662f\u5bf9\u79f0\u7684\u3002\u8fd9\u6837\u66f4\u4e0d\u5bb9\u6613\u51fa\u9519\uff0c\u56e0\u6b64\u4e00\u822c\u5efa\u8bae\u91c7\u7528\u201c\u53cc\u95ed\u533a\u95f4\u201d\u7684\u5199\u6cd5\u3002

        \u56fe 10-3 \u00a0 \u4e24\u79cd\u533a\u95f4\u5b9a\u4e49

        "},{"location":"chapter_searching/binary_search/#1012","title":"10.1.2 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u4e8c\u5206\u67e5\u627e\u5728\u65f6\u95f4\u548c\u7a7a\u95f4\u65b9\u9762\u90fd\u6709\u8f83\u597d\u7684\u6027\u80fd\u3002

        • \u4e8c\u5206\u67e5\u627e\u7684\u65f6\u95f4\u6548\u7387\u9ad8\u3002\u5728\u5927\u6570\u636e\u91cf\u4e0b\uff0c\u5bf9\u6570\u9636\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5177\u6709\u663e\u8457\u4f18\u52bf\u3002\u4f8b\u5982\uff0c\u5f53\u6570\u636e\u5927\u5c0f \\(n = 2^{20}\\) \u65f6\uff0c\u7ebf\u6027\u67e5\u627e\u9700\u8981 \\(2^{20} = 1048576\\) \u8f6e\u5faa\u73af\uff0c\u800c\u4e8c\u5206\u67e5\u627e\u4ec5\u9700 \\(\\log_2 2^{20} = 20\\) \u8f6e\u5faa\u73af\u3002
        • \u4e8c\u5206\u67e5\u627e\u65e0\u987b\u989d\u5916\u7a7a\u95f4\u3002\u76f8\u8f83\u4e8e\u9700\u8981\u501f\u52a9\u989d\u5916\u7a7a\u95f4\u7684\u641c\u7d22\u7b97\u6cd5\uff08\u4f8b\u5982\u54c8\u5e0c\u67e5\u627e\uff09\uff0c\u4e8c\u5206\u67e5\u627e\u66f4\u52a0\u8282\u7701\u7a7a\u95f4\u3002

        \u7136\u800c\uff0c\u4e8c\u5206\u67e5\u627e\u5e76\u975e\u9002\u7528\u4e8e\u6240\u6709\u60c5\u51b5\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u4e8c\u5206\u67e5\u627e\u4ec5\u9002\u7528\u4e8e\u6709\u5e8f\u6570\u636e\u3002\u82e5\u8f93\u5165\u6570\u636e\u65e0\u5e8f\uff0c\u4e3a\u4e86\u4f7f\u7528\u4e8c\u5206\u67e5\u627e\u800c\u4e13\u95e8\u8fdb\u884c\u6392\u5e8f\uff0c\u5f97\u4e0d\u507f\u5931\u3002\u56e0\u4e3a\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u901a\u5e38\u4e3a \\(O(n \\log n)\\) \uff0c\u6bd4\u7ebf\u6027\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u90fd\u66f4\u9ad8\u3002\u5bf9\u4e8e\u9891\u7e41\u63d2\u5165\u5143\u7d20\u7684\u573a\u666f\uff0c\u4e3a\u4fdd\u6301\u6570\u7ec4\u6709\u5e8f\u6027\uff0c\u9700\u8981\u5c06\u5143\u7d20\u63d2\u5165\u5230\u7279\u5b9a\u4f4d\u7f6e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u4e5f\u662f\u975e\u5e38\u6602\u8d35\u7684\u3002
        • \u4e8c\u5206\u67e5\u627e\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u3002\u4e8c\u5206\u67e5\u627e\u9700\u8981\u8df3\u8dc3\u5f0f\uff08\u975e\u8fde\u7eed\u5730\uff09\u8bbf\u95ee\u5143\u7d20\uff0c\u800c\u5728\u94fe\u8868\u4e2d\u6267\u884c\u8df3\u8dc3\u5f0f\u8bbf\u95ee\u7684\u6548\u7387\u8f83\u4f4e\uff0c\u56e0\u6b64\u4e0d\u9002\u5408\u5e94\u7528\u5728\u94fe\u8868\u6216\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u5c0f\u6570\u636e\u91cf\u4e0b\uff0c\u7ebf\u6027\u67e5\u627e\u6027\u80fd\u66f4\u4f73\u3002\u5728\u7ebf\u6027\u67e5\u627e\u4e2d\uff0c\u6bcf\u8f6e\u53ea\u9700 1 \u6b21\u5224\u65ad\u64cd\u4f5c\uff1b\u800c\u5728\u4e8c\u5206\u67e5\u627e\u4e2d\uff0c\u9700\u8981 1 \u6b21\u52a0\u6cd5\u30011 \u6b21\u9664\u6cd5\u30011 ~ 3 \u6b21\u5224\u65ad\u64cd\u4f5c\u30011 \u6b21\u52a0\u6cd5\uff08\u51cf\u6cd5\uff09\uff0c\u5171 4 ~ 6 \u4e2a\u5355\u5143\u64cd\u4f5c\uff1b\u56e0\u6b64\uff0c\u5f53\u6570\u636e\u91cf \\(n\\) \u8f83\u5c0f\u65f6\uff0c\u7ebf\u6027\u67e5\u627e\u53cd\u800c\u6bd4\u4e8c\u5206\u67e5\u627e\u66f4\u5feb\u3002
        "},{"location":"chapter_searching/binary_search_edge/","title":"10.3 \u00a0 \u4e8c\u5206\u67e5\u627e\u8fb9\u754c","text":""},{"location":"chapter_searching/binary_search_edge/#1031","title":"10.3.1 \u00a0 \u67e5\u627e\u5de6\u8fb9\u754c","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002\u8bf7\u8fd4\u56de\u6570\u7ec4\u4e2d\u6700\u5de6\u4e00\u4e2a\u5143\u7d20 target \u7684\u7d22\u5f15\u3002\u82e5\u6570\u7ec4\u4e2d\u4e0d\u5305\u542b\u8be5\u5143\u7d20\uff0c\u5219\u8fd4\u56de \\(-1\\) \u3002

        \u56de\u5fc6\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\u7684\u65b9\u6cd5\uff0c\u641c\u7d22\u5b8c\u6210\u540e \\(i\\) \u6307\u5411\u6700\u5de6\u4e00\u4e2a target \uff0c\u56e0\u6b64\u67e5\u627e\u63d2\u5165\u70b9\u672c\u8d28\u4e0a\u662f\u5728\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target \u7684\u7d22\u5f15\u3002

        \u8003\u8651\u901a\u8fc7\u67e5\u627e\u63d2\u5165\u70b9\u7684\u51fd\u6570\u5b9e\u73b0\u67e5\u627e\u5de6\u8fb9\u754c\u3002\u8bf7\u6ce8\u610f\uff0c\u6570\u7ec4\u4e2d\u53ef\u80fd\u4e0d\u5305\u542b target \uff0c\u8fd9\u79cd\u60c5\u51b5\u53ef\u80fd\u5bfc\u81f4\u4ee5\u4e0b\u4e24\u79cd\u7ed3\u679c\u3002

        • \u63d2\u5165\u70b9\u7684\u7d22\u5f15 \\(i\\) \u8d8a\u754c\u3002
        • \u5143\u7d20 nums[i] \u4e0e target \u4e0d\u76f8\u7b49\u3002

        \u5f53\u9047\u5230\u4ee5\u4e0a\u4e24\u79cd\u60c5\u51b5\u65f6\uff0c\u76f4\u63a5\u8fd4\u56de \\(-1\\) \u5373\u53ef\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_edge.py
        def binary_search_left_edge(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target\"\"\"\n# \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\ni = binary_search_insertion(nums, target)\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == len(nums) or nums[i] != target:\nreturn -1\n# \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n
        binary_search_edge.cpp
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(vector<int> &nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.size() || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.java
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(int[] nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binary_search_insertion.binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.cs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint BinarySearchLeftEdge(int[] nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binary_search_insertion.BinarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.Length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.go
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunc binarySearchLeftEdge(nums []int, target int) int {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\ni := binarySearchInsertion(nums, target)\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == len(nums) || nums[i] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n}\n
        binary_search_edge.swift
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunc binarySearchLeftEdge(nums: [Int], target: Int) -> Int {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nlet i = binarySearchInsertion(nums: nums, target: target)\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == nums.count || nums[i] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i\n}\n
        binary_search_edge.js
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunction binarySearchLeftEdge(nums, target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nconst i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i === nums.length || nums[i] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.ts
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfunction binarySearchLeftEdge(nums: Array<number>, target: number): number {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nconst i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i === nums.length || nums[i] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.dart
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(List<int> nums, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == nums.length || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.rs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nfn binary_search_left_edge(nums: &[i32], target: i32) -> i32 {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nlet i = binary_search_insertion(nums, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif i == nums.len() as i32 || nums[i as usize] != target {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\ni\n}\n
        binary_search_edge.c
        /* \u4e8c\u5206\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target */\nint binarySearchLeftEdge(int *nums, int numSize, int target) {\n// \u7b49\u4ef7\u4e8e\u67e5\u627e target \u7684\u63d2\u5165\u70b9\nint i = binarySearchInsertion(nums, numSize, target);\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (i == numSize || nums[i] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\nreturn i;\n}\n
        binary_search_edge.zig
        [class]{}-[func]{binarySearchLeftEdge}\n
        "},{"location":"chapter_searching/binary_search_edge/#1032","title":"10.3.2 \u00a0 \u67e5\u627e\u53f3\u8fb9\u754c","text":"

        \u90a3\u4e48\u5982\u4f55\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \u5462\uff1f\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u4fee\u6539\u4ee3\u7801\uff0c\u66ff\u6362\u5728 nums[m] == target \u60c5\u51b5\u4e0b\u7684\u6307\u9488\u6536\u7f29\u64cd\u4f5c\u3002\u4ee3\u7801\u5728\u6b64\u7701\u7565\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u3002

        \u4e0b\u9762\u6211\u4eec\u4ecb\u7ecd\u4e24\u79cd\u66f4\u52a0\u53d6\u5de7\u7684\u65b9\u6cd5\u3002

        "},{"location":"chapter_searching/binary_search_edge/#1","title":"1. \u00a0 \u590d\u7528\u67e5\u627e\u5de6\u8fb9\u754c","text":"

        \u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u67e5\u627e\u6700\u5de6\u5143\u7d20\u7684\u51fd\u6570\u6765\u67e5\u627e\u6700\u53f3\u5143\u7d20\uff0c\u5177\u4f53\u65b9\u6cd5\u4e3a\uff1a\u5c06\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\u3002

        \u5982\u56fe 10-7 \u6240\u793a\uff0c\u67e5\u627e\u5b8c\u6210\u540e\uff0c\u6307\u9488 \\(i\\) \u6307\u5411\u6700\u5de6\u4e00\u4e2a target + 1\uff08\u5982\u679c\u5b58\u5728\uff09\uff0c\u800c \\(j\\) \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0c\u56e0\u6b64\u8fd4\u56de \\(j\\) \u5373\u53ef\u3002

        \u56fe 10-7 \u00a0 \u5c06\u67e5\u627e\u53f3\u8fb9\u754c\u8f6c\u5316\u4e3a\u67e5\u627e\u5de6\u8fb9\u754c

        \u8bf7\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u63d2\u5165\u70b9\u662f \\(i\\) \uff0c\u56e0\u6b64\u9700\u8981\u5c06\u5176\u51cf \\(1\\) \uff0c\u4ece\u800c\u83b7\u5f97 \\(j\\) \uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_edge.py
        def binary_search_right_edge(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target\"\"\"\n# \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\ni = binary_search_insertion(nums, target + 1)\n# j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nj = i - 1\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 or nums[j] != target:\nreturn -1\n# \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n
        binary_search_edge.cpp
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(vector<int> &nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.java
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(int[] nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binary_search_insertion.binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.cs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint BinarySearchRightEdge(int[] nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binary_search_insertion.BinarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.go
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunc binarySearchRightEdge(nums []int, target int) int {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\ni := binarySearchInsertion(nums, target+1)\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nj := i - 1\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n}\n
        binary_search_edge.swift
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunc binarySearchRightEdge(nums: [Int], target: Int) -> Int {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nlet i = binarySearchInsertion(nums: nums, target: target + 1)\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nlet j = i - 1\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j] != target {\nreturn -1\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j\n}\n
        binary_search_edge.js
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunction binarySearchRightEdge(nums, target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nconst i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nconst j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j === -1 || nums[j] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.ts
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfunction binarySearchRightEdge(nums: Array<number>, target: number): number {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nconst i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nconst j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j === -1 || nums[j] !== target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.dart
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(List<int> nums, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.rs
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nfn binary_search_right_edge(nums: &[i32], target: i32) -> i32 {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nlet i = binary_search_insertion(nums, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nlet j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif j == -1 || nums[j as usize] != target {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nj\n}\n
        binary_search_edge.c
        /* \u4e8c\u5206\u67e5\u627e\u6700\u53f3\u4e00\u4e2a target */\nint binarySearchRightEdge(int *nums, int numSize, int target) {\n// \u8f6c\u5316\u4e3a\u67e5\u627e\u6700\u5de6\u4e00\u4e2a target + 1\nint i = binarySearchInsertion(nums, numSize, target + 1);\n// j \u6307\u5411\u6700\u53f3\u4e00\u4e2a target \uff0ci \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\nint j = i - 1;\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\nif (j == -1 || nums[j] != target) {\nreturn -1;\n}\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\nreturn j;\n}\n
        binary_search_edge.zig
        [class]{}-[func]{binarySearchRightEdge}\n
        "},{"location":"chapter_searching/binary_search_edge/#2","title":"2. \u00a0 \u8f6c\u5316\u4e3a\u67e5\u627e\u5143\u7d20","text":"

        \u6211\u4eec\u77e5\u9053\uff0c\u5f53\u6570\u7ec4\u4e0d\u5305\u542b target \u65f6\uff0c\u6700\u7ec8 \\(i\\) \u548c \\(j\\) \u4f1a\u5206\u522b\u6307\u5411\u9996\u4e2a\u5927\u4e8e\u3001\u5c0f\u4e8e target \u7684\u5143\u7d20\u3002

        \u56e0\u6b64\uff0c\u5982\u56fe 10-8 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728\u7684\u5143\u7d20\uff0c\u7528\u4e8e\u67e5\u627e\u5de6\u53f3\u8fb9\u754c\u3002

        • \u67e5\u627e\u6700\u5de6\u4e00\u4e2a target \uff1a\u53ef\u4ee5\u8f6c\u5316\u4e3a\u67e5\u627e target - 0.5 \uff0c\u5e76\u8fd4\u56de\u6307\u9488 \\(i\\) \u3002
        • \u67e5\u627e\u6700\u53f3\u4e00\u4e2a target \uff1a\u53ef\u4ee5\u8f6c\u5316\u4e3a\u67e5\u627e target + 0.5 \uff0c\u5e76\u8fd4\u56de\u6307\u9488 \\(j\\) \u3002

        \u56fe 10-8 \u00a0 \u5c06\u67e5\u627e\u8fb9\u754c\u8f6c\u5316\u4e3a\u67e5\u627e\u5143\u7d20

        \u4ee3\u7801\u5728\u6b64\u7701\u7565\uff0c\u4ee5\u4e0b\u4e24\u70b9\u503c\u5f97\u6ce8\u610f\u3002

        • \u7ed9\u5b9a\u6570\u7ec4\u4e0d\u5305\u542b\u5c0f\u6570\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u65e0\u987b\u5173\u5fc3\u5982\u4f55\u5904\u7406\u76f8\u7b49\u7684\u60c5\u51b5\u3002
        • \u56e0\u4e3a\u8be5\u65b9\u6cd5\u5f15\u5165\u4e86\u5c0f\u6570\uff0c\u6240\u4ee5\u9700\u8981\u5c06\u51fd\u6570\u4e2d\u7684\u53d8\u91cf target \u6539\u4e3a\u6d6e\u70b9\u6570\u7c7b\u578b\u3002
        "},{"location":"chapter_searching/binary_search_insertion/","title":"10.2 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9","text":"

        \u4e8c\u5206\u67e5\u627e\u4e0d\u4ec5\u53ef\u7528\u4e8e\u641c\u7d22\u76ee\u6807\u5143\u7d20\uff0c\u8fd8\u53ef\u7528\u4e8e\u89e3\u51b3\u8bb8\u591a\u53d8\u79cd\u95ee\u9898\uff0c\u6bd4\u5982\u641c\u7d22\u76ee\u6807\u5143\u7d20\u7684\u63d2\u5165\u4f4d\u7f6e\u3002

        "},{"location":"chapter_searching/binary_search_insertion/#1021","title":"10.2.1 \u00a0 \u65e0\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6709\u5e8f\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u5143\u7d20 target \uff0c\u6570\u7ec4\u4e0d\u5b58\u5728\u91cd\u590d\u5143\u7d20\u3002\u73b0\u5c06 target \u63d2\u5165\u6570\u7ec4 nums \u4e2d\uff0c\u5e76\u4fdd\u6301\u5176\u6709\u5e8f\u6027\u3002\u82e5\u6570\u7ec4\u4e2d\u5df2\u5b58\u5728\u5143\u7d20 target \uff0c\u5219\u63d2\u5165\u5230\u5176\u5de6\u65b9\u3002\u8bf7\u8fd4\u56de\u63d2\u5165\u540e target \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15\u3002

        \u56fe 10-4 \u00a0 \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\u793a\u4f8b\u6570\u636e

        \u5982\u679c\u60f3\u590d\u7528\u4e0a\u4e00\u8282\u7684\u4e8c\u5206\u67e5\u627e\u4ee3\u7801\uff0c\u5219\u9700\u8981\u56de\u7b54\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\u3002

        \u95ee\u9898\u4e00\uff1a\u5f53\u6570\u7ec4\u4e2d\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u70b9\u7684\u7d22\u5f15\u662f\u5426\u662f\u8be5\u5143\u7d20\u7684\u7d22\u5f15\uff1f

        \u9898\u76ee\u8981\u6c42\u5c06 target \u63d2\u5165\u5230\u76f8\u7b49\u5143\u7d20\u7684\u5de6\u8fb9\uff0c\u8fd9\u610f\u5473\u7740\u65b0\u63d2\u5165\u7684 target \u66ff\u6362\u4e86\u539f\u6765 target \u7684\u4f4d\u7f6e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6570\u7ec4\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u70b9\u7684\u7d22\u5f15\u5c31\u662f\u8be5 target \u7684\u7d22\u5f15\u3002

        \u95ee\u9898\u4e8c\uff1a\u5f53\u6570\u7ec4\u4e2d\u4e0d\u5b58\u5728 target \u65f6\uff0c\u63d2\u5165\u70b9\u662f\u54ea\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff1f

        \u8fdb\u4e00\u6b65\u601d\u8003\u4e8c\u5206\u67e5\u627e\u8fc7\u7a0b\uff1a\u5f53 nums[m] < target \u65f6 \\(i\\) \u79fb\u52a8\uff0c\u8fd9\u610f\u5473\u7740\u6307\u9488 \\(i\\) \u5728\u5411\u5927\u4e8e\u7b49\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002\u540c\u7406\uff0c\u6307\u9488 \\(j\\) \u59cb\u7ec8\u5728\u5411\u5c0f\u4e8e\u7b49\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002

        \u56e0\u6b64\u4e8c\u5206\u7ed3\u675f\u65f6\u4e00\u5b9a\u6709\uff1a\\(i\\) \u6307\u5411\u9996\u4e2a\u5927\u4e8e target \u7684\u5143\u7d20\uff0c\\(j\\) \u6307\u5411\u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u3002\u6613\u5f97\u5f53\u6570\u7ec4\u4e0d\u5305\u542b target \u65f6\uff0c\u63d2\u5165\u7d22\u5f15\u4e3a \\(i\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_insertion.py
        def binary_search_insertion_simple(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09\"\"\"\ni, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nreturn m  # \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n# \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n
        binary_search_insertion.cpp
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(vector<int> &nums, int target) {\nint i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.java
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(int[] nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.cs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint BinarySearchInsertionSimple(int[] nums, int target) {\nint i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.go
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertionSimple(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\ni, j := 0, len(nums)-1\nfor i <= j {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm := i + (j-i)/2\nif nums[m] < target {\n// target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target {\n// target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else {\n// \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\nreturn m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.swift
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertionSimple(nums: [Int], target: Int) -> Int {\nvar i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target {\ni = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m] > target {\nj = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.js
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(nums, target) {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.ts
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(\nnums: Array<number>,\ntarget: number\n): number {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.dart
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(List<int> nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.rs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\npub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 {\nlet (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {\ni = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m as usize] > target {\nj = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1;  // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\ni\n}\n
        binary_search_insertion.c
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertionSimple(int *nums, int numSize, int target) {\nint i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nreturn m; // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n}\n}\n// \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.zig
        [class]{}-[func]{binarySearchInsertionSimple}\n
        "},{"location":"chapter_searching/binary_search_insertion/#1022","title":"10.2.2 \u00a0 \u5b58\u5728\u91cd\u590d\u5143\u7d20\u7684\u60c5\u51b5","text":"

        Question

        \u5728\u4e0a\u4e00\u9898\u7684\u57fa\u7840\u4e0a\uff0c\u89c4\u5b9a\u6570\u7ec4\u53ef\u80fd\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u5176\u4f59\u4e0d\u53d8\u3002

        \u5047\u8bbe\u6570\u7ec4\u4e2d\u5b58\u5728\u591a\u4e2a target \uff0c\u5219\u666e\u901a\u4e8c\u5206\u67e5\u627e\u53ea\u80fd\u8fd4\u56de\u5176\u4e2d\u4e00\u4e2a target \u7684\u7d22\u5f15\uff0c\u800c\u65e0\u6cd5\u786e\u5b9a\u8be5\u5143\u7d20\u7684\u5de6\u8fb9\u548c\u53f3\u8fb9\u8fd8\u6709\u591a\u5c11 target\u3002

        \u9898\u76ee\u8981\u6c42\u5c06\u76ee\u6807\u5143\u7d20\u63d2\u5165\u5230\u6700\u5de6\u8fb9\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5de6\u4e00\u4e2a target \u7684\u7d22\u5f15\u3002\u521d\u6b65\u8003\u8651\u901a\u8fc7\u56fe 10-5 \u6240\u793a\u7684\u6b65\u9aa4\u5b9e\u73b0\u3002

        1. \u6267\u884c\u4e8c\u5206\u67e5\u627e\uff0c\u5f97\u5230\u4efb\u610f\u4e00\u4e2a target \u7684\u7d22\u5f15\uff0c\u8bb0\u4e3a \\(k\\) \u3002
        2. \u4ece\u7d22\u5f15 \\(k\\) \u5f00\u59cb\uff0c\u5411\u5de6\u8fdb\u884c\u7ebf\u6027\u904d\u5386\uff0c\u5f53\u627e\u5230\u6700\u5de6\u8fb9\u7684 target \u65f6\u8fd4\u56de\u3002

        \u56fe 10-5 \u00a0 \u7ebf\u6027\u67e5\u627e\u91cd\u590d\u5143\u7d20\u7684\u63d2\u5165\u70b9

        \u6b64\u65b9\u6cd5\u867d\u7136\u53ef\u7528\uff0c\u4f46\u5176\u5305\u542b\u7ebf\u6027\u67e5\u627e\uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5f53\u6570\u7ec4\u4e2d\u5b58\u5728\u5f88\u591a\u91cd\u590d\u7684 target \u65f6\uff0c\u8be5\u65b9\u6cd5\u6548\u7387\u5f88\u4f4e\u3002

        \u73b0\u8003\u8651\u62d3\u5c55\u4e8c\u5206\u67e5\u627e\u4ee3\u7801\u3002\u5982\u56fe 10-6 \u6240\u793a\uff0c\u6574\u4f53\u6d41\u7a0b\u4fdd\u6301\u4e0d\u53d8\uff0c\u6bcf\u8f6e\u5148\u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 \\(m\\) \uff0c\u518d\u5224\u65ad target \u548c nums[m] \u7684\u5927\u5c0f\u5173\u7cfb\uff0c\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u3002

        • \u5f53 nums[m] < target \u6216 nums[m] > target \u65f6\uff0c\u8bf4\u660e\u8fd8\u6ca1\u6709\u627e\u5230 target \uff0c\u56e0\u6b64\u91c7\u7528\u666e\u901a\u4e8c\u5206\u67e5\u627e\u7684\u7f29\u5c0f\u533a\u95f4\u64cd\u4f5c\uff0c\u4ece\u800c\u4f7f\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5411 target \u9760\u8fd1\u3002
        • \u5f53 nums[m] == target \u65f6\uff0c\u8bf4\u660e\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 \\([i, m - 1]\\) \u4e2d\uff0c\u56e0\u6b64\u91c7\u7528 \\(j = m - 1\\) \u6765\u7f29\u5c0f\u533a\u95f4\uff0c\u4ece\u800c\u4f7f\u6307\u9488 \\(j\\) \u5411\u5c0f\u4e8e target \u7684\u5143\u7d20\u9760\u8fd1\u3002

        \u5faa\u73af\u5b8c\u6210\u540e\uff0c\\(i\\) \u6307\u5411\u6700\u5de6\u8fb9\u7684 target \uff0c\\(j\\) \u6307\u5411\u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\uff0c\u56e0\u6b64\u7d22\u5f15 \\(i\\) \u5c31\u662f\u63d2\u5165\u70b9\u3002

        <1><2><3><4><5><6><7><8>

        \u56fe 10-6 \u00a0 \u4e8c\u5206\u67e5\u627e\u91cd\u590d\u5143\u7d20\u7684\u63d2\u5165\u70b9\u7684\u6b65\u9aa4

        \u89c2\u5bdf\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5224\u65ad\u5206\u652f nums[m] > target \u548c nums[m] == target \u7684\u64cd\u4f5c\u76f8\u540c\uff0c\u56e0\u6b64\u4e24\u8005\u53ef\u4ee5\u5408\u5e76\u3002

        \u5373\u4fbf\u5982\u6b64\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u5c06\u5224\u65ad\u6761\u4ef6\u4fdd\u6301\u5c55\u5f00\uff0c\u56e0\u4e3a\u5176\u903b\u8f91\u66f4\u52a0\u6e05\u6670\u3001\u53ef\u8bfb\u6027\u66f4\u597d\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_insertion.py
        def binary_search_insertion(nums: list[int], target: int) -> int:\n\"\"\"\u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09\"\"\"\ni, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j:\nm = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target:\ni = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\nelif nums[m] > target:\nj = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nelse:\nj = m - 1  # \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n# \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n
        binary_search_insertion.cpp
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(vector<int> &nums, int target) {\nint i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.java
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(int[] nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.cs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint BinarySearchInsertion(int[] nums, int target) {\nint i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.go
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertion(nums []int, target int) int {\n// \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\ni, j := 0, len(nums)-1\nfor i <= j {\n// \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nm := i + (j-i)/2\nif nums[m] < target {\n// target \u5728\u533a\u95f4 [m+1, j] \u4e2d\ni = m + 1\n} else if nums[m] > target {\n// target \u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n} else {\n// \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\nj = m - 1\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.swift
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunc binarySearchInsertion(nums: [Int], target: Int) -> Int {\nvar i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m] < target {\ni = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m] > target {\nj = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1 // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i\n}\n
        binary_search_insertion.js
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertion(nums, target) {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.ts
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertion(nums: Array<number>, target: number): number {\nlet i = 0,\nj = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nconst m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.dart
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(List<int> nums, int target) {\nint i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.rs
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\npub fn binary_search_insertion(nums: &[i32], target: i32) -> i32 {\nlet (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile i <= j {\nlet m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif nums[m as usize] < target {\ni = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if nums[m as usize] > target {\nj = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1;  // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\ni\n}\n
        binary_search_insertion.c
        /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u5b58\u5728\u91cd\u590d\u5143\u7d20\uff09 */\nint binarySearchInsertion(int *nums, int numSize, int target) {\nint i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\nwhile (i <= j) {\nint m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\nif (nums[m] < target) {\ni = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n} else if (nums[m] > target) {\nj = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n} else {\nj = m - 1; // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n}\n}\n// \u8fd4\u56de\u63d2\u5165\u70b9 i\nreturn i;\n}\n
        binary_search_insertion.zig
        [class]{}-[func]{binarySearchInsertion}\n

        Tip

        \u672c\u8282\u7684\u4ee3\u7801\u90fd\u662f\u201c\u53cc\u95ed\u533a\u95f4\u201d\u5199\u6cd5\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u201c\u5de6\u95ed\u53f3\u5f00\u201d\u5199\u6cd5\u3002

        \u603b\u7684\u6765\u770b\uff0c\u4e8c\u5206\u67e5\u627e\u65e0\u975e\u5c31\u662f\u7ed9\u6307\u9488 \\(i\\) \u548c \\(j\\) \u5206\u522b\u8bbe\u5b9a\u641c\u7d22\u76ee\u6807\uff0c\u76ee\u6807\u53ef\u80fd\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u5143\u7d20\uff08\u4f8b\u5982 target \uff09\uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u4e2a\u5143\u7d20\u8303\u56f4\uff08\u4f8b\u5982\u5c0f\u4e8e target \u7684\u5143\u7d20\uff09\u3002

        \u5728\u4e0d\u65ad\u7684\u5faa\u73af\u4e8c\u5206\u4e2d\uff0c\u6307\u9488 \\(i\\) \u548c \\(j\\) \u90fd\u9010\u6e10\u903c\u8fd1\u9884\u5148\u8bbe\u5b9a\u7684\u76ee\u6807\u3002\u6700\u7ec8\uff0c\u5b83\u4eec\u6216\u662f\u6210\u529f\u627e\u5230\u7b54\u6848\uff0c\u6216\u662f\u8d8a\u8fc7\u8fb9\u754c\u540e\u505c\u6b62\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/","title":"10.4 \u00a0 \u54c8\u5e0c\u4f18\u5316\u7b56\u7565","text":"

        \u5728\u7b97\u6cd5\u9898\u4e2d\uff0c\u6211\u4eec\u5e38\u901a\u8fc7\u5c06\u7ebf\u6027\u67e5\u627e\u66ff\u6362\u4e3a\u54c8\u5e0c\u67e5\u627e\u6765\u964d\u4f4e\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6211\u4eec\u501f\u52a9\u4e00\u4e2a\u7b97\u6cd5\u9898\u6765\u52a0\u6df1\u7406\u89e3\u3002

        Question

        \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums \u548c\u4e00\u4e2a\u76ee\u6807\u5143\u7d20 target \uff0c\u8bf7\u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u201c\u548c\u201d\u4e3a target \u7684\u4e24\u4e2a\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u6570\u7ec4\u7d22\u5f15\u3002\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u89e3\u5373\u53ef\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/#1041","title":"10.4.1 \u00a0 \u7ebf\u6027\u67e5\u627e\uff1a\u4ee5\u65f6\u95f4\u6362\u7a7a\u95f4","text":"

        \u8003\u8651\u76f4\u63a5\u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408\u3002\u5982\u56fe 10-9 \u6240\u793a\uff0c\u6211\u4eec\u5f00\u542f\u4e00\u4e2a\u4e24\u5c42\u5faa\u73af\uff0c\u5728\u6bcf\u8f6e\u4e2d\u5224\u65ad\u4e24\u4e2a\u6574\u6570\u7684\u548c\u662f\u5426\u4e3a target \uff0c\u82e5\u662f\uff0c\u5219\u8fd4\u56de\u5b83\u4eec\u7684\u7d22\u5f15\u3002

        \u56fe 10-9 \u00a0 \u7ebf\u6027\u67e5\u627e\u6c42\u89e3\u4e24\u6570\u4e4b\u548c

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig two_sum.py
        def two_sum_brute_force(nums: list[int], target: int) -> list[int]:\n\"\"\"\u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\"\"\"\n# \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in range(len(nums) - 1):\nfor j in range(i + 1, len(nums)):\nif nums[i] + nums[j] == target:\nreturn [i, j]\nreturn []\n
        two_sum.cpp
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nvector<int> twoSumBruteForce(vector<int> &nums, int target) {\nint size = nums.size();\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn {i, j};\n}\n}\nreturn {};\n}\n
        two_sum.java
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] twoSumBruteForce(int[] nums, int target) {\nint size = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn new int[] { i, j };\n}\n}\nreturn new int[0];\n}\n
        two_sum.cs
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] TwoSumBruteForce(int[] nums, int target) {\nint size = nums.Length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (int i = 0; i < size - 1; i++) {\nfor (int j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target)\nreturn [i, j];\n}\n}\nreturn [];\n}\n
        two_sum.go
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums []int, target int) []int {\nsize := len(nums)\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i := 0; i < size-1; i++ {\nfor j := i + 1; i < size; j++ {\nif nums[i]+nums[j] == target {\nreturn []int{i, j}\n}\n}\n}\nreturn nil\n}\n
        two_sum.swift
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums: [Int], target: Int) -> [Int] {\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in nums.indices.dropLast() {\nfor j in nums.indices.dropFirst(i + 1) {\nif nums[i] + nums[j] == target {\nreturn [i, j]\n}\n}\n}\nreturn [0]\n}\n
        two_sum.js
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums, target) {\nconst n = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (let i = 0; i < n; i++) {\nfor (let j = i + 1; j < n; j++) {\nif (nums[i] + nums[j] === target) {\nreturn [i, j];\n}\n}\n}\nreturn [];\n}\n
        two_sum.ts
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums: number[], target: number): number[] {\nconst n = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (let i = 0; i < n; i++) {\nfor (let j = i + 1; j < n; j++) {\nif (nums[i] + nums[j] === target) {\nreturn [i, j];\n}\n}\n}\nreturn [];\n}\n
        two_sum.dart
        /* \u65b9\u6cd5\u4e00\uff1a \u66b4\u529b\u679a\u4e3e */\nList<int> twoSumBruteForce(List<int> nums, int target) {\nint size = nums.length;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor (var i = 0; i < size - 1; i++) {\nfor (var j = i + 1; j < size; j++) {\nif (nums[i] + nums[j] == target) return [i, j];\n}\n}\nreturn [0];\n}\n
        two_sum.rs
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\npub fn two_sum_brute_force(nums: &Vec<i32>, target: i32) -> Option<Vec<i32>> {\nlet size = nums.len();\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nfor i in 0..size - 1 {\nfor j in i + 1..size {\nif nums[i] + nums[j] == target {\nreturn Some(vec![i as i32, j as i32]);\n}\n}\n}\nNone\n}\n
        two_sum.c
        /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {\nfor (int i = 0; i < numsSize; ++i) {\nfor (int j = i + 1; j < numsSize; ++j) {\nif (nums[i] + nums[j] == target) {\nint *res = malloc(sizeof(int) * 2);\nres[0] = i, res[1] = j;\n*returnSize = 2;\nreturn res;\n}\n}\n}\n*returnSize = 0;\nreturn NULL;\n}\n
        two_sum.zig
        // \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\nfn twoSumBruteForce(nums: []i32, target: i32) ?[2]i32 {\nvar size: usize = nums.len;\nvar i: usize = 0;\n// \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\nwhile (i < size - 1) : (i += 1) {\nvar j = i + 1;\nwhile (j < size) : (j += 1) {\nif (nums[i] + nums[j] == target) {\nreturn [_]i32{@intCast(i), @intCast(j)};\n}\n}\n}\nreturn null;\n}\n

        \u6b64\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \uff0c\u5728\u5927\u6570\u636e\u91cf\u4e0b\u975e\u5e38\u8017\u65f6\u3002

        "},{"location":"chapter_searching/replace_linear_by_hashing/#1042","title":"10.4.2 \u00a0 \u54c8\u5e0c\u67e5\u627e\uff1a\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4","text":"

        \u8003\u8651\u501f\u52a9\u4e00\u4e2a\u54c8\u5e0c\u8868\uff0c\u952e\u503c\u5bf9\u5206\u522b\u4e3a\u6570\u7ec4\u5143\u7d20\u548c\u5143\u7d20\u7d22\u5f15\u3002\u5faa\u73af\u904d\u5386\u6570\u7ec4\uff0c\u6bcf\u8f6e\u6267\u884c\u56fe 10-10 \u6240\u793a\u7684\u6b65\u9aa4\u3002

        1. \u5224\u65ad\u6570\u5b57 target - nums[i] \u662f\u5426\u5728\u54c8\u5e0c\u8868\u4e2d\uff0c\u82e5\u662f\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u8fd9\u4e24\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u3002
        2. \u5c06\u952e\u503c\u5bf9 nums[i] \u548c\u7d22\u5f15 i \u6dfb\u52a0\u8fdb\u54c8\u5e0c\u8868\u3002
        <1><2><3>

        \u56fe 10-10 \u00a0 \u8f85\u52a9\u54c8\u5e0c\u8868\u6c42\u89e3\u4e24\u6570\u4e4b\u548c

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff0c\u4ec5\u9700\u5355\u5c42\u5faa\u73af\u5373\u53ef\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig two_sum.py
        def two_sum_hash_table(nums: list[int], target: int) -> list[int]:\n\"\"\"\u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\"\"\"\n# \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndic = {}\n# \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor i in range(len(nums)):\nif target - nums[i] in dic:\nreturn [dic[target - nums[i]], i]\ndic[nums[i]] = i\nreturn []\n
        two_sum.cpp
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nvector<int> twoSumHashTable(vector<int> &nums, int target) {\nint size = nums.size();\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nunordered_map<int, int> dic;\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.find(target - nums[i]) != dic.end()) {\nreturn {dic[target - nums[i]], i};\n}\ndic.emplace(nums[i], i);\n}\nreturn {};\n}\n
        two_sum.java
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] twoSumHashTable(int[] nums, int target) {\nint size = nums.length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nMap<Integer, Integer> dic = new HashMap<>();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.containsKey(target - nums[i])) {\nreturn new int[] { dic.get(target - nums[i]), i };\n}\ndic.put(nums[i], i);\n}\nreturn new int[0];\n}\n
        two_sum.cs
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] TwoSumHashTable(int[] nums, int target) {\nint size = nums.Length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nDictionary<int, int> dic = [];\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (int i = 0; i < size; i++) {\nif (dic.ContainsKey(target - nums[i])) {\nreturn [dic[target - nums[i]], i];\n}\ndic.Add(nums[i], i);\n}\nreturn [];\n}\n
        two_sum.go
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunc twoSumHashTable(nums []int, target int) []int {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nhashTable := map[int]int{}\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor idx, val := range nums {\nif preIdx, ok := hashTable[target-val]; ok {\nreturn []int{preIdx, idx}\n}\nhashTable[val] = idx\n}\nreturn nil\n}\n
        two_sum.swift
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunc twoSumHashTable(nums: [Int], target: Int) -> [Int] {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nvar dic: [Int: Int] = [:]\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor i in nums.indices {\nif let j = dic[target - nums[i]] {\nreturn [j, i]\n}\ndic[nums[i]] = i\n}\nreturn [0]\n}\n
        two_sum.js
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunction twoSumHashTable(nums, target) {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet m = {};\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (let i = 0; i < nums.length; i++) {\nif (m[target - nums[i]] !== undefined) {\nreturn [m[target - nums[i]], i];\n} else {\nm[nums[i]] = i;\n}\n}\nreturn [];\n}\n
        two_sum.ts
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nfunction twoSumHashTable(nums: number[], target: number): number[] {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet m: Map<number, number> = new Map();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (let i = 0; i < nums.length; i++) {\nlet index = m.get(target - nums[i]);\nif (index !== undefined) {\nreturn [index, i];\n} else {\nm.set(nums[i], i);\n}\n}\nreturn [];\n}\n
        two_sum.dart
        /* \u65b9\u6cd5\u4e8c\uff1a \u8f85\u52a9\u54c8\u5e0c\u8868 */\nList<int> twoSumHashTable(List<int> nums, int target) {\nint size = nums.length;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nMap<int, int> dic = HashMap();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (var i = 0; i < size; i++) {\nif (dic.containsKey(target - nums[i])) {\nreturn [dic[target - nums[i]]!, i];\n}\ndic.putIfAbsent(nums[i], () => i);\n}\nreturn [0];\n}\n
        two_sum.rs
        /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\npub fn two_sum_hash_table(nums: &Vec<i32>, target: i32) -> Option<Vec<i32>> {\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nlet mut dic = HashMap::new();\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nfor (i, num) in nums.iter().enumerate() {\nmatch dic.get(&(target - num)) {\nSome(v) => return Some(vec![*v as i32, i as i32]),\nNone => dic.insert(num, i as i32)\n};\n}\nNone\n}\n
        two_sum.c
        /* \u54c8\u5e0c\u8868 */\ntypedef struct {\nint key;\nint val;\nUT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n/* \u54c8\u5e0c\u8868\u67e5\u8be2 */\nHashTable *find(HashTable *h, int key) {\nHashTable *tmp;\nHASH_FIND_INT(h, &key, tmp);\nreturn tmp;\n}\n/* \u54c8\u5e0c\u8868\u5143\u7d20\u63d2\u5165 */\nvoid insert(HashTable *h, int key, int val) {\nHashTable *t = find(h, key);\nif (t == NULL) {\nHashTable *tmp = malloc(sizeof(HashTable));\ntmp->key = key, tmp->val = val;\nHASH_ADD_INT(h, key, tmp);\n} else {\nt->val = val;\n}\n}\n/* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint *twoSumHashTable(int *nums, int numsSize, int target, int *returnSize) {\nHashTable *hashtable = NULL;\nfor (int i = 0; i < numsSize; i++) {\nHashTable *t = find(hashtable, target - nums[i]);\nif (t != NULL) {\nint *res = malloc(sizeof(int) * 2);\nres[0] = t->val, res[1] = i;\n*returnSize = 2;\nreturn res;\n}\ninsert(hashtable, nums[i], i);\n}\n*returnSize = 0;\nreturn NULL;\n}\n
        two_sum.zig
        // \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\nfn twoSumHashTable(nums: []i32, target: i32) !?[2]i32 {\nvar size: usize = nums.len;\n// \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nvar dic = std.AutoHashMap(i32, i32).init(std.heap.page_allocator);\ndefer dic.deinit();\nvar i: usize = 0;\n// \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nwhile (i < size) : (i += 1) {\nif (dic.contains(target - nums[i])) {\nreturn [_]i32{dic.get(target - nums[i]).?, @intCast(i)};\n}\ntry dic.put(nums[i], @intCast(i));\n}\nreturn null;\n}\n

        \u6b64\u65b9\u6cd5\u901a\u8fc7\u54c8\u5e0c\u67e5\u627e\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n^2)\\) \u964d\u81f3 \\(O(n)\\) \uff0c\u5927\u5e45\u63d0\u5347\u8fd0\u884c\u6548\u7387\u3002

        \u7531\u4e8e\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u989d\u5916\u7684\u54c8\u5e0c\u8868\uff0c\u56e0\u6b64\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u8be5\u65b9\u6cd5\u7684\u6574\u4f53\u65f6\u7a7a\u6548\u7387\u66f4\u4e3a\u5747\u8861\uff0c\u56e0\u6b64\u5b83\u662f\u672c\u9898\u7684\u6700\u4f18\u89e3\u6cd5\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/","title":"10.5 \u00a0 \u91cd\u8bc6\u641c\u7d22\u7b97\u6cd5","text":"

        \u300c\u641c\u7d22\u7b97\u6cd5 searching algorithm\u300d\u7528\u4e8e\u5728\u6570\u636e\u7ed3\u6784\uff08\u4f8b\u5982\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6811\u6216\u56fe\uff09\u4e2d\u641c\u7d22\u4e00\u4e2a\u6216\u4e00\u7ec4\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u3002

        \u641c\u7d22\u7b97\u6cd5\u53ef\u6839\u636e\u5b9e\u73b0\u601d\u8def\u5206\u4e3a\u4ee5\u4e0b\u4e24\u7c7b\u3002

        • \u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u6765\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\uff0c\u4f8b\u5982\u6570\u7ec4\u3001\u94fe\u8868\u3001\u6811\u548c\u56fe\u7684\u904d\u5386\u7b49\u3002
        • \u5229\u7528\u6570\u636e\u7ec4\u7ec7\u7ed3\u6784\u6216\u6570\u636e\u5305\u542b\u7684\u5148\u9a8c\u4fe1\u606f\uff0c\u5b9e\u73b0\u9ad8\u6548\u5143\u7d20\u67e5\u627e\uff0c\u4f8b\u5982\u4e8c\u5206\u67e5\u627e\u3001\u54c8\u5e0c\u67e5\u627e\u548c\u4e8c\u53c9\u641c\u7d22\u6811\u67e5\u627e\u7b49\u3002

        \u4e0d\u96be\u53d1\u73b0\uff0c\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u90fd\u5df2\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u8fc7\uff0c\u56e0\u6b64\u641c\u7d22\u7b97\u6cd5\u5bf9\u4e8e\u6211\u4eec\u6765\u8bf4\u5e76\u4e0d\u964c\u751f\u3002\u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4ece\u66f4\u52a0\u7cfb\u7edf\u7684\u89c6\u89d2\u5207\u5165\uff0c\u91cd\u65b0\u5ba1\u89c6\u641c\u7d22\u7b97\u6cd5\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1051","title":"10.5.1 \u00a0 \u66b4\u529b\u641c\u7d22","text":"

        \u66b4\u529b\u641c\u7d22\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u7684\u6bcf\u4e2a\u5143\u7d20\u6765\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        • \u201c\u7ebf\u6027\u641c\u7d22\u201d\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u94fe\u8868\u7b49\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002\u5b83\u4ece\u6570\u636e\u7ed3\u6784\u7684\u4e00\u7aef\u5f00\u59cb\uff0c\u9010\u4e2a\u8bbf\u95ee\u5143\u7d20\uff0c\u76f4\u5230\u627e\u5230\u76ee\u6807\u5143\u7d20\u6216\u5230\u8fbe\u53e6\u4e00\u7aef\u4ecd\u6ca1\u6709\u627e\u5230\u76ee\u6807\u5143\u7d20\u4e3a\u6b62\u3002
        • \u201c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u548c\u201c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u201d\u662f\u56fe\u548c\u6811\u7684\u4e24\u79cd\u904d\u5386\u7b56\u7565\u3002\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u4ece\u521d\u59cb\u8282\u70b9\u5f00\u59cb\u9010\u5c42\u641c\u7d22\uff0c\u7531\u8fd1\u53ca\u8fdc\u5730\u8bbf\u95ee\u5404\u4e2a\u8282\u70b9\u3002\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u4ece\u521d\u59cb\u8282\u70b9\u5f00\u59cb\uff0c\u6cbf\u7740\u4e00\u6761\u8def\u5f84\u8d70\u5230\u5934\uff0c\u518d\u56de\u6eaf\u5e76\u5c1d\u8bd5\u5176\u4ed6\u8def\u5f84\uff0c\u76f4\u5230\u904d\u5386\u5b8c\u6574\u4e2a\u6570\u636e\u7ed3\u6784\u3002

        \u66b4\u529b\u641c\u7d22\u7684\u4f18\u70b9\u662f\u7b80\u5355\u4e14\u901a\u7528\u6027\u597d\uff0c\u65e0\u987b\u5bf9\u6570\u636e\u505a\u9884\u5904\u7406\u548c\u501f\u52a9\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\u3002

        \u7136\u800c\uff0c\u6b64\u7c7b\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u5176\u4e2d \\(n\\) \u4e3a\u5143\u7d20\u6570\u91cf\uff0c\u56e0\u6b64\u5728\u6570\u636e\u91cf\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\u6027\u80fd\u8f83\u5dee\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1052","title":"10.5.2 \u00a0 \u81ea\u9002\u5e94\u641c\u7d22","text":"

        \u81ea\u9002\u5e94\u641c\u7d22\u5229\u7528\u6570\u636e\u7684\u7279\u6709\u5c5e\u6027\uff08\u4f8b\u5982\u6709\u5e8f\u6027\uff09\u6765\u4f18\u5316\u641c\u7d22\u8fc7\u7a0b\uff0c\u4ece\u800c\u66f4\u9ad8\u6548\u5730\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        • \u201c\u4e8c\u5206\u67e5\u627e\u201d\u5229\u7528\u6570\u636e\u7684\u6709\u5e8f\u6027\u5b9e\u73b0\u9ad8\u6548\u67e5\u627e\uff0c\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u3002
        • \u201c\u54c8\u5e0c\u67e5\u627e\u201d\u5229\u7528\u54c8\u5e0c\u8868\u5c06\u641c\u7d22\u6570\u636e\u548c\u76ee\u6807\u6570\u636e\u5efa\u7acb\u4e3a\u952e\u503c\u5bf9\u6620\u5c04\uff0c\u4ece\u800c\u5b9e\u73b0\u67e5\u8be2\u64cd\u4f5c\u3002
        • \u201c\u6811\u67e5\u627e\u201d\u5728\u7279\u5b9a\u7684\u6811\u7ed3\u6784\uff08\u4f8b\u5982\u4e8c\u53c9\u641c\u7d22\u6811\uff09\u4e2d\uff0c\u57fa\u4e8e\u6bd4\u8f83\u8282\u70b9\u503c\u6765\u5feb\u901f\u6392\u9664\u8282\u70b9\uff0c\u4ece\u800c\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002

        \u6b64\u7c7b\u7b97\u6cd5\u7684\u4f18\u70b9\u662f\u6548\u7387\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \u3002

        \u7136\u800c\uff0c\u4f7f\u7528\u8fd9\u4e9b\u7b97\u6cd5\u5f80\u5f80\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u4f8b\u5982\uff0c\u4e8c\u5206\u67e5\u627e\u9700\u8981\u9884\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u54c8\u5e0c\u67e5\u627e\u548c\u6811\u67e5\u627e\u90fd\u9700\u8981\u501f\u52a9\u989d\u5916\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7ef4\u62a4\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u4e5f\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u5f00\u9500\u3002

        Tip

        \u81ea\u9002\u5e94\u641c\u7d22\u7b97\u6cd5\u5e38\u88ab\u79f0\u4e3a\u67e5\u627e\u7b97\u6cd5\uff0c\u4e3b\u8981\u7528\u4e8e\u5728\u7279\u5b9a\u6570\u636e\u7ed3\u6784\u4e2d\u5feb\u901f\u68c0\u7d22\u76ee\u6807\u5143\u7d20\u3002

        "},{"location":"chapter_searching/searching_algorithm_revisited/#1053","title":"10.5.3 \u00a0 \u641c\u7d22\u65b9\u6cd5\u9009\u53d6","text":"

        \u7ed9\u5b9a\u5927\u5c0f\u4e3a \\(n\\) \u7684\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7ebf\u6027\u641c\u7d22\u3001\u4e8c\u5206\u67e5\u627e\u3001\u6811\u67e5\u627e\u3001\u54c8\u5e0c\u67e5\u627e\u7b49\u591a\u79cd\u65b9\u6cd5\u4ece\u4e2d\u641c\u7d22\u76ee\u6807\u5143\u7d20\u3002\u5404\u4e2a\u65b9\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u5982\u56fe 10-11 \u6240\u793a\u3002

        \u56fe 10-11 \u00a0 \u591a\u79cd\u641c\u7d22\u7b56\u7565

        \u4e0a\u8ff0\u51e0\u79cd\u65b9\u6cd5\u7684\u64cd\u4f5c\u6548\u7387\u4e0e\u7279\u6027\u5982\u8868 10-1 \u6240\u793a\u3002

        \u8868 10-1 \u00a0 \u67e5\u627e\u7b97\u6cd5\u6548\u7387\u5bf9\u6bd4

        \u7ebf\u6027\u641c\u7d22 \u4e8c\u5206\u67e5\u627e \u6811\u67e5\u627e \u54c8\u5e0c\u67e5\u627e \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u63d2\u5165\u5143\u7d20 \\(O(1)\\) \\(O(n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(n)\\) \\(O(\\log n)\\) \\(O(1)\\) \u989d\u5916\u7a7a\u95f4 \\(O(1)\\) \\(O(1)\\) \\(O(n)\\) \\(O(n)\\) \u6570\u636e\u9884\u5904\u7406 / \u6392\u5e8f \\(O(n \\log n)\\) \u5efa\u6811 \\(O(n \\log n)\\) \u5efa\u54c8\u5e0c\u8868 \\(O(n)\\) \u6570\u636e\u662f\u5426\u6709\u5e8f \u65e0\u5e8f \u6709\u5e8f \u6709\u5e8f \u65e0\u5e8f

        \u641c\u7d22\u7b97\u6cd5\u7684\u9009\u62e9\u8fd8\u53d6\u51b3\u4e8e\u6570\u636e\u4f53\u91cf\u3001\u641c\u7d22\u6027\u80fd\u8981\u6c42\u3001\u6570\u636e\u67e5\u8be2\u4e0e\u66f4\u65b0\u9891\u7387\u7b49\u3002

        \u7ebf\u6027\u641c\u7d22

        • \u901a\u7528\u6027\u8f83\u597d\uff0c\u65e0\u987b\u4efb\u4f55\u6570\u636e\u9884\u5904\u7406\u64cd\u4f5c\u3002\u5047\u5982\u6211\u4eec\u4ec5\u9700\u67e5\u8be2\u4e00\u6b21\u6570\u636e\uff0c\u90a3\u4e48\u5176\u4ed6\u4e09\u79cd\u65b9\u6cd5\u7684\u6570\u636e\u9884\u5904\u7406\u7684\u65f6\u95f4\u6bd4\u7ebf\u6027\u641c\u7d22\u7684\u65f6\u95f4\u8fd8\u8981\u66f4\u957f\u3002
        • \u9002\u7528\u4e8e\u4f53\u91cf\u8f83\u5c0f\u7684\u6570\u636e\uff0c\u6b64\u60c5\u51b5\u4e0b\u65f6\u95f4\u590d\u6742\u5ea6\u5bf9\u6548\u7387\u5f71\u54cd\u8f83\u5c0f\u3002
        • \u9002\u7528\u4e8e\u6570\u636e\u66f4\u65b0\u9891\u7387\u8f83\u9ad8\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u8be5\u65b9\u6cd5\u4e0d\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u4efb\u4f55\u989d\u5916\u7ef4\u62a4\u3002

        \u4e8c\u5206\u67e5\u627e

        • \u9002\u7528\u4e8e\u5927\u6570\u636e\u91cf\u7684\u60c5\u51b5\uff0c\u6548\u7387\u8868\u73b0\u7a33\u5b9a\uff0c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \u3002
        • \u6570\u636e\u91cf\u4e0d\u80fd\u8fc7\u5927\uff0c\u56e0\u4e3a\u5b58\u50a8\u6570\u7ec4\u9700\u8981\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u3002
        • \u4e0d\u9002\u7528\u4e8e\u9ad8\u9891\u589e\u5220\u6570\u636e\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u7ef4\u62a4\u6709\u5e8f\u6570\u7ec4\u7684\u5f00\u9500\u8f83\u5927\u3002

        \u54c8\u5e0c\u67e5\u627e

        • \u9002\u5408\u5bf9\u67e5\u8be2\u6027\u80fd\u8981\u6c42\u5f88\u9ad8\u7684\u573a\u666f\uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\) \u3002
        • \u4e0d\u9002\u5408\u9700\u8981\u6709\u5e8f\u6570\u636e\u6216\u8303\u56f4\u67e5\u627e\u7684\u573a\u666f\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u65e0\u6cd5\u7ef4\u62a4\u6570\u636e\u7684\u6709\u5e8f\u6027\u3002
        • \u5bf9\u54c8\u5e0c\u51fd\u6570\u548c\u54c8\u5e0c\u51b2\u7a81\u5904\u7406\u7b56\u7565\u7684\u4f9d\u8d56\u6027\u8f83\u9ad8\uff0c\u5177\u6709\u8f83\u5927\u7684\u6027\u80fd\u52a3\u5316\u98ce\u9669\u3002
        • \u4e0d\u9002\u5408\u6570\u636e\u91cf\u8fc7\u5927\u7684\u60c5\u51b5\uff0c\u56e0\u4e3a\u54c8\u5e0c\u8868\u9700\u8981\u989d\u5916\u7a7a\u95f4\u6765\u6700\u5927\u7a0b\u5ea6\u5730\u51cf\u5c11\u51b2\u7a81\uff0c\u4ece\u800c\u63d0\u4f9b\u826f\u597d\u7684\u67e5\u8be2\u6027\u80fd\u3002

        \u6811\u67e5\u627e

        • \u9002\u7528\u4e8e\u6d77\u91cf\u6570\u636e\uff0c\u56e0\u4e3a\u6811\u8282\u70b9\u5728\u5185\u5b58\u4e2d\u662f\u5206\u6563\u5b58\u50a8\u7684\u3002
        • \u9002\u5408\u9700\u8981\u7ef4\u62a4\u6709\u5e8f\u6570\u636e\u6216\u8303\u56f4\u67e5\u627e\u7684\u573a\u666f\u3002
        • \u5728\u6301\u7eed\u589e\u5220\u8282\u70b9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u80fd\u4ea7\u751f\u503e\u659c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n)\\) \u3002
        • \u82e5\u4f7f\u7528 AVL \u6811\u6216\u7ea2\u9ed1\u6811\uff0c\u5219\u5404\u9879\u64cd\u4f5c\u53ef\u5728 \\(O(\\log n)\\) \u6548\u7387\u4e0b\u7a33\u5b9a\u8fd0\u884c\uff0c\u4f46\u7ef4\u62a4\u6811\u5e73\u8861\u7684\u64cd\u4f5c\u4f1a\u589e\u52a0\u989d\u5916\u5f00\u9500\u3002
        "},{"location":"chapter_searching/summary/","title":"10.6 \u00a0 \u5c0f\u7ed3","text":"
        • \u4e8c\u5206\u67e5\u627e\u4f9d\u8d56\u6570\u636e\u7684\u6709\u5e8f\u6027\uff0c\u901a\u8fc7\u5faa\u73af\u9010\u6b65\u7f29\u51cf\u4e00\u534a\u641c\u7d22\u533a\u95f4\u6765\u8fdb\u884c\u67e5\u627e\u3002\u5b83\u8981\u6c42\u8f93\u5165\u6570\u636e\u6709\u5e8f\uff0c\u4e14\u4ec5\u9002\u7528\u4e8e\u6570\u7ec4\u6216\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u3002
        • \u66b4\u529b\u641c\u7d22\u901a\u8fc7\u904d\u5386\u6570\u636e\u7ed3\u6784\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u7ebf\u6027\u641c\u7d22\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u94fe\u8868\uff0c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u548c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u9002\u7528\u4e8e\u56fe\u548c\u6811\u3002\u6b64\u7c7b\u7b97\u6cd5\u901a\u7528\u6027\u597d\uff0c\u65e0\u987b\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\uff0c\u4f46\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u8f83\u9ad8\u3002
        • \u54c8\u5e0c\u67e5\u627e\u3001\u6811\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u5c5e\u4e8e\u9ad8\u6548\u641c\u7d22\u65b9\u6cd5\uff0c\u53ef\u5728\u7279\u5b9a\u6570\u636e\u7ed3\u6784\u4e2d\u5feb\u901f\u5b9a\u4f4d\u76ee\u6807\u5143\u7d20\u3002\u6b64\u7c7b\u7b97\u6cd5\u6548\u7387\u9ad8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe \\(O(\\log n)\\) \u751a\u81f3 \\(O(1)\\) \uff0c\u4f46\u901a\u5e38\u9700\u8981\u501f\u52a9\u989d\u5916\u6570\u636e\u7ed3\u6784\u3002
        • \u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u6570\u636e\u4f53\u91cf\u3001\u641c\u7d22\u6027\u80fd\u8981\u6c42\u3001\u6570\u636e\u67e5\u8be2\u548c\u66f4\u65b0\u9891\u7387\u7b49\u56e0\u7d20\u8fdb\u884c\u5177\u4f53\u5206\u6790\uff0c\u4ece\u800c\u9009\u62e9\u5408\u9002\u7684\u641c\u7d22\u65b9\u6cd5\u3002
        • \u7ebf\u6027\u641c\u7d22\u9002\u7528\u4e8e\u5c0f\u578b\u6216\u9891\u7e41\u66f4\u65b0\u7684\u6570\u636e\uff1b\u4e8c\u5206\u67e5\u627e\u9002\u7528\u4e8e\u5927\u578b\u3001\u6392\u5e8f\u7684\u6570\u636e\uff1b\u54c8\u5e0c\u67e5\u627e\u9002\u7528\u4e8e\u5bf9\u67e5\u8be2\u6548\u7387\u8981\u6c42\u8f83\u9ad8\u4e14\u65e0\u987b\u8303\u56f4\u67e5\u8be2\u7684\u6570\u636e\uff1b\u6811\u67e5\u627e\u9002\u7528\u4e8e\u9700\u8981\u7ef4\u62a4\u987a\u5e8f\u548c\u652f\u6301\u8303\u56f4\u67e5\u8be2\u7684\u5927\u578b\u52a8\u6001\u6570\u636e\u3002
        • \u7528\u54c8\u5e0c\u67e5\u627e\u66ff\u6362\u7ebf\u6027\u67e5\u627e\u662f\u4e00\u79cd\u5e38\u7528\u7684\u4f18\u5316\u8fd0\u884c\u65f6\u95f4\u7684\u7b56\u7565\uff0c\u53ef\u5c06\u65f6\u95f4\u590d\u6742\u5ea6\u4ece \\(O(n)\\) \u964d\u81f3 \\(O(1)\\) \u3002
        "},{"location":"chapter_sorting/","title":"\u7b2c 11 \u7ae0 \u00a0 \u6392\u5e8f","text":"

        Abstract

        \u6392\u5e8f\u72b9\u5982\u4e00\u628a\u5c06\u6df7\u4e71\u53d8\u4e3a\u79e9\u5e8f\u7684\u9b54\u6cd5\u94a5\u5319\uff0c\u4f7f\u6211\u4eec\u80fd\u4ee5\u66f4\u9ad8\u6548\u7684\u65b9\u5f0f\u7406\u89e3\u4e0e\u5904\u7406\u6570\u636e\u3002

        \u65e0\u8bba\u662f\u7b80\u5355\u7684\u5347\u5e8f\uff0c\u8fd8\u662f\u590d\u6742\u7684\u5206\u7c7b\u6392\u5217\uff0c\u6392\u5e8f\u90fd\u5411\u6211\u4eec\u5c55\u793a\u4e86\u6570\u636e\u7684\u548c\u8c10\u7f8e\u611f\u3002

        "},{"location":"chapter_sorting/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 11.1 \u00a0 \u6392\u5e8f\u7b97\u6cd5
        • 11.2 \u00a0 \u9009\u62e9\u6392\u5e8f
        • 11.3 \u00a0 \u5192\u6ce1\u6392\u5e8f
        • 11.4 \u00a0 \u63d2\u5165\u6392\u5e8f
        • 11.5 \u00a0 \u5feb\u901f\u6392\u5e8f
        • 11.6 \u00a0 \u5f52\u5e76\u6392\u5e8f
        • 11.7 \u00a0 \u5806\u6392\u5e8f
        • 11.8 \u00a0 \u6876\u6392\u5e8f
        • 11.9 \u00a0 \u8ba1\u6570\u6392\u5e8f
        • 11.10 \u00a0 \u57fa\u6570\u6392\u5e8f
        • 11.11 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_sorting/bubble_sort/","title":"11.3 \u00a0 \u5192\u6ce1\u6392\u5e8f","text":"

        \u300c\u5192\u6ce1\u6392\u5e8f bubble sort\u300d\u901a\u8fc7\u8fde\u7eed\u5730\u6bd4\u8f83\u4e0e\u4ea4\u6362\u76f8\u90bb\u5143\u7d20\u5b9e\u73b0\u6392\u5e8f\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u50cf\u6c14\u6ce1\u4ece\u5e95\u90e8\u5347\u5230\u9876\u90e8\u4e00\u6837\uff0c\u56e0\u6b64\u5f97\u540d\u5192\u6ce1\u6392\u5e8f\u3002

        \u5982\u56fe 11-4 \u6240\u793a\uff0c\u5192\u6ce1\u8fc7\u7a0b\u53ef\u4ee5\u5229\u7528\u5143\u7d20\u4ea4\u6362\u64cd\u4f5c\u6765\u6a21\u62df\uff1a\u4ece\u6570\u7ec4\u6700\u5de6\u7aef\u5f00\u59cb\u5411\u53f3\u904d\u5386\uff0c\u4f9d\u6b21\u6bd4\u8f83\u76f8\u90bb\u5143\u7d20\u5927\u5c0f\uff0c\u5982\u679c\u201c\u5de6\u5143\u7d20 > \u53f3\u5143\u7d20\u201d\u5c31\u4ea4\u6362\u4e8c\u8005\u3002\u904d\u5386\u5b8c\u6210\u540e\uff0c\u6700\u5927\u7684\u5143\u7d20\u4f1a\u88ab\u79fb\u52a8\u5230\u6570\u7ec4\u7684\u6700\u53f3\u7aef\u3002

        <1><2><3><4><5><6><7>

        \u56fe 11-4 \u00a0 \u5229\u7528\u5143\u7d20\u4ea4\u6362\u64cd\u4f5c\u6a21\u62df\u5192\u6ce1

        "},{"location":"chapter_sorting/bubble_sort/#1131","title":"11.3.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u6b65\u9aa4\u5982\u56fe 11-5 \u6240\u793a\u3002

        1. \u9996\u5148\uff0c\u5bf9 \\(n\\) \u4e2a\u5143\u7d20\u6267\u884c\u201c\u5192\u6ce1\u201d\uff0c\u5c06\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\uff0c
        2. \u63a5\u4e0b\u6765\uff0c\u5bf9\u5269\u4f59 \\(n - 1\\) \u4e2a\u5143\u7d20\u6267\u884c\u201c\u5192\u6ce1\u201d\uff0c\u5c06\u7b2c\u4e8c\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\u3002
        3. \u4ee5\u6b64\u7c7b\u63a8\uff0c\u7ecf\u8fc7 \\(n - 1\\) \u8f6e\u201c\u5192\u6ce1\u201d\u540e\uff0c\u524d \\(n - 1\\) \u5927\u7684\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u81f3\u6b63\u786e\u4f4d\u7f6e\u3002
        4. \u4ec5\u5269\u7684\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u662f\u6700\u5c0f\u5143\u7d20\uff0c\u65e0\u987b\u6392\u5e8f\uff0c\u56e0\u6b64\u6570\u7ec4\u6392\u5e8f\u5b8c\u6210\u3002

        \u56fe 11-5 \u00a0 \u5192\u6ce1\u6392\u5e8f\u6d41\u7a0b

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bubble_sort.py
        def bubble_sort(nums: list[int]):\n\"\"\"\u5192\u6ce1\u6392\u5e8f\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(n - 1, 0, -1):\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j + 1] = nums[j + 1], nums[j]\n
        bubble_sort.cpp
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n// \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\nswap(nums[j], nums[j + 1]);\n}\n}\n}\n}\n
        bubble_sort.java
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.cs
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid BubbleSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\n}\n}\n}\n}\n
        bubble_sort.go
        /* \u5192\u6ce1\u6392\u5e8f */\nfunc bubbleSort(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j+1] = nums[j+1], nums[j]\n}\n}\n}\n}\n
        bubble_sort.swift
        /* \u5192\u6ce1\u6392\u5e8f */\nfunc bubbleSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in stride(from: 0, to: i, by: 1) {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\n}\n}\n}\n}\n
        bubble_sort.js
        /* \u5192\u6ce1\u6392\u5e8f */\nfunction bubbleSort(nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.ts
        /* \u5192\u6ce1\u6392\u5e8f */\nfunction bubbleSort(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.dart
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.rs
        /* \u5192\u6ce1\u6392\u5e8f */\nfn bubble_sort(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        bubble_sort.c
        /* \u5192\u6ce1\u6392\u5e8f */\nvoid bubbleSort(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = 0; i < size - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < size - 1 - i; j++) {\nif (nums[j] > nums[j + 1]) {\nint temp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = temp;\n}\n}\n}\n}\n
        bubble_sort.zig
        // \u5192\u6ce1\u6392\u5e8f\nfn bubbleSort(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: usize = nums.len - 1;\nwhile (i > 0) : (i -= 1) {\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\n}\n}\n}\n}\n
        "},{"location":"chapter_sorting/bubble_sort/#1132","title":"11.3.2 \u00a0 \u6548\u7387\u4f18\u5316","text":"

        \u6211\u4eec\u53d1\u73b0\uff0c\u5982\u679c\u67d0\u8f6e\u201c\u5192\u6ce1\u201d\u4e2d\u6ca1\u6709\u6267\u884c\u4efb\u4f55\u4ea4\u6362\u64cd\u4f5c\uff0c\u8bf4\u660e\u6570\u7ec4\u5df2\u7ecf\u5b8c\u6210\u6392\u5e8f\uff0c\u53ef\u76f4\u63a5\u8fd4\u56de\u7ed3\u679c\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u589e\u52a0\u4e00\u4e2a\u6807\u5fd7\u4f4d flag \u6765\u76d1\u6d4b\u8fd9\u79cd\u60c5\u51b5\uff0c\u4e00\u65e6\u51fa\u73b0\u5c31\u7acb\u5373\u8fd4\u56de\u3002

        \u7ecf\u8fc7\u4f18\u5316\uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4ecd\u4e3a \\(O(n^2)\\) \uff1b\u4f46\u5f53\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u6709\u5e8f\u65f6\uff0c\u53ef\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bubble_sort.py
        def bubble_sort_with_flag(nums: list[int]):\n\"\"\"\u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in range(n - 1, 0, -1):\nflag = False  # \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n# \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j in range(i):\nif nums[j] > nums[j + 1]:\n# \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j + 1] = nums[j + 1], nums[j]\nflag = True  # \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\nif not flag:\nbreak  # \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n
        bubble_sort.cpp
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.size() - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n// \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\nswap(nums[j], nums[j + 1]);\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag)\nbreak; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.java
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09 */\nvoid bubbleSortWithFlag(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\nboolean flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag)\nbreak; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.cs
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid BubbleSortWithFlag(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.Length - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);\nflag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break;     // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.go
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunc bubbleSortWithFlag(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := len(nums) - 1; i > 0; i-- {\nflag := false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor j := 0; j < i; j++ {\nif nums[j] > nums[j+1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nnums[j], nums[j+1] = nums[j+1], nums[j]\nflag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif flag == false { // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\nbreak\n}\n}\n}\n
        bubble_sort.swift
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunc bubbleSortWithFlag(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\nvar flag = false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\nfor j in stride(from: 0, to: i, by: 1) {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j]\nnums[j] = nums[j + 1]\nnums[j + 1] = tmp\nflag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif !flag { // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\nbreak\n}\n}\n}\n
        bubble_sort.js
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunction bubbleSortWithFlag(nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\nlet flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.ts
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nfunction bubbleSortWithFlag(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (let i = nums.length - 1; i > 0; i--) {\nlet flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (let j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.dart
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = nums.length - 1; i > 0; i--) {\nbool flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < i; j++) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nint tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif (!flag) break; // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.rs
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09 */\nfn bubble_sort_with_flag(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i in (1..nums.len()).rev() {\nlet mut flag = false; // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nfor j in 0..i {\nif nums[j] > nums[j + 1] {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nlet tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n}\n}\nif !flag {break};  // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        bubble_sort.c
        /* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*/\nvoid bubbleSortWithFlag(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor (int i = 0; i < size - 1; i++) {\nbool flag = false;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\nfor (int j = 0; j < size - 1 - i; j++) {\nif (nums[j] > nums[j + 1]) {\nint temp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = temp;\nflag = true;\n}\n}\nif (!flag)\nbreak;\n}\n}\n
        bubble_sort.zig
        // \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09\nfn bubbleSortWithFlag(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nvar i: usize = nums.len - 1;\nwhile (i > 0) : (i -= 1) {\nvar flag = false;   // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\nvar j: usize = 0;\n// \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef \nwhile (j < i) : (j += 1) {\nif (nums[j] > nums[j + 1]) {\n// \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\nvar tmp = nums[j];\nnums[j] = nums[j + 1];\nnums[j + 1] = tmp;\nflag = true;\n}\n}\nif (!flag) break;   // \u6b64\u8f6e\u5192\u6ce1\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n}\n}\n
        "},{"location":"chapter_sorting/bubble_sort/#1133","title":"11.3.3 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5404\u8f6e\u201c\u5192\u6ce1\u201d\u904d\u5386\u7684\u6570\u7ec4\u957f\u5ea6\u4f9d\u6b21\u4e3a \\(n - 1\\)\u3001\\(n - 2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u603b\u548c\u4e3a \\((n - 1) n / 2\\) \u3002\u5728\u5f15\u5165 flag \u4f18\u5316\u540e\uff0c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe\u5230 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u7531\u4e8e\u5728\u201c\u5192\u6ce1\u201d\u4e2d\u9047\u5230\u76f8\u7b49\u5143\u7d20\u4e0d\u4ea4\u6362\u3002
        "},{"location":"chapter_sorting/bucket_sort/","title":"11.8 \u00a0 \u6876\u6392\u5e8f","text":"

        \u524d\u8ff0\u51e0\u79cd\u6392\u5e8f\u7b97\u6cd5\u90fd\u5c5e\u4e8e\u201c\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u7b97\u6cd5\u201d\uff0c\u5b83\u4eec\u901a\u8fc7\u6bd4\u8f83\u5143\u7d20\u95f4\u7684\u5927\u5c0f\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u6b64\u7c7b\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u65e0\u6cd5\u8d85\u8d8a \\(O(n \\log n)\\) \u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u51e0\u79cd\u201c\u975e\u6bd4\u8f83\u6392\u5e8f\u7b97\u6cd5\u201d\uff0c\u5b83\u4eec\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u8fbe\u5230\u7ebf\u6027\u9636\u3002

        \u300c\u6876\u6392\u5e8f bucket sort\u300d\u662f\u5206\u6cbb\u7b56\u7565\u7684\u4e00\u4e2a\u5178\u578b\u5e94\u7528\u3002\u5b83\u901a\u8fc7\u8bbe\u7f6e\u4e00\u4e9b\u5177\u6709\u5927\u5c0f\u987a\u5e8f\u7684\u6876\uff0c\u6bcf\u4e2a\u6876\u5bf9\u5e94\u4e00\u4e2a\u6570\u636e\u8303\u56f4\uff0c\u5c06\u6570\u636e\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff1b\u7136\u540e\uff0c\u5728\u6bcf\u4e2a\u6876\u5185\u90e8\u5206\u522b\u6267\u884c\u6392\u5e8f\uff1b\u6700\u7ec8\u6309\u7167\u6876\u7684\u987a\u5e8f\u5c06\u6240\u6709\u6570\u636e\u5408\u5e76\u3002

        "},{"location":"chapter_sorting/bucket_sort/#1181","title":"11.8.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8003\u8651\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u662f\u8303\u56f4 \\([0, 1)\\) \u5185\u7684\u6d6e\u70b9\u6570\u3002\u6876\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-13 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316 \\(k\\) \u4e2a\u6876\uff0c\u5c06 \\(n\\) \u4e2a\u5143\u7d20\u5206\u914d\u5230 \\(k\\) \u4e2a\u6876\u4e2d\u3002
        2. \u5bf9\u6bcf\u4e2a\u6876\u5206\u522b\u6267\u884c\u6392\u5e8f\uff08\u8fd9\u91cc\u91c7\u7528\u7f16\u7a0b\u8bed\u8a00\u7684\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff09\u3002
        3. \u6309\u7167\u6876\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u5408\u5e76\u7ed3\u679c\u3002

        \u56fe 11-13 \u00a0 \u6876\u6392\u5e8f\u7b97\u6cd5\u6d41\u7a0b

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig bucket_sort.py
        def bucket_sort(nums: list[float]):\n\"\"\"\u6876\u6392\u5e8f\"\"\"\n# \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nk = len(nums) // 2\nbuckets = [[] for _ in range(k)]\n# 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor num in nums:\n# \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\ni = int(num * k)\n# \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].append(num)\n# 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor bucket in buckets:\n# \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort()\n# 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\ni = 0\nfor bucket in buckets:\nfor num in bucket:\nnums[i] = num\ni += 1\n
        bucket_sort.cpp
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(vector<float> &nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.size() / 2;\nvector<vector<float>> buckets(k);\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (float num : nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = num * k;\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\nbuckets[i].push_back(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (vector<float> &bucket : buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nsort(bucket.begin(), bucket.end());\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (vector<float> &bucket : buckets) {\nfor (float num : bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.java
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(float[] nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.length / 2;\nList<List<Float>> buckets = new ArrayList<>();\nfor (int i = 0; i < k; i++) {\nbuckets.add(new ArrayList<>());\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (float num : nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (int) (num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets.get(i).add(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (List<Float> bucket : buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nCollections.sort(bucket);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (List<Float> bucket : buckets) {\nfor (float num : bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.cs
        /* \u6876\u6392\u5e8f */\nvoid BucketSort(float[] nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.Length / 2;\nList<List<float>> buckets = [];\nfor (int i = 0; i < k; i++) {\nbuckets.Add([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nforeach (float num in nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (int)(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].Add(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nforeach (List<float> bucket in buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.Sort();\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint j = 0;\nforeach (List<float> bucket in buckets) {\nforeach (float num in bucket) {\nnums[j++] = num;\n}\n}\n}\n
        bucket_sort.go
        /* \u6876\u6392\u5e8f */\nfunc bucketSort(nums []float64) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nk := len(nums) / 2\nbuckets := make([][]float64, k)\nfor i := 0; i < k; i++ {\nbuckets[i] = make([]float64, 0)\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor _, num := range nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\ni := int(num * float64(k))\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i] = append(buckets[i], num)\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor i := 0; i < k; i++ {\n// \u4f7f\u7528\u5185\u7f6e\u5207\u7247\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nsort.Float64s(buckets[i])\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\ni := 0\nfor _, bucket := range buckets {\nfor _, num := range bucket {\nnums[i] = num\ni++\n}\n}\n}\n
        bucket_sort.swift
        /* \u6876\u6392\u5e8f */\nfunc bucketSort(nums: inout [Double]) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nlet k = nums.count / 2\nvar buckets = (0 ..< k).map { _ in [Double]() }\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor num in nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nlet i = Int(num * Double(k))\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].append(num)\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor i in buckets.indices {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbuckets[i].sort()\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nvar i = nums.startIndex\nfor bucket in buckets {\nfor num in bucket {\nnums[i] = num\nnums.formIndex(after: &i)\n}\n}\n}\n
        bucket_sort.js
        /* \u6876\u6392\u5e8f */\nfunction bucketSort(nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nconst k = nums.length / 2;\nconst buckets = [];\nfor (let i = 0; i < k; i++) {\nbuckets.push([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (const num of nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nconst i = Math.floor(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (const bucket of buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort((a, b) => a - b);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet i = 0;\nfor (const bucket of buckets) {\nfor (const num of bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.ts
        /* \u6876\u6392\u5e8f */\nfunction bucketSort(nums: number[]): void {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nconst k = nums.length / 2;\nconst buckets: number[][] = [];\nfor (let i = 0; i < k; i++) {\nbuckets.push([]);\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (const num of nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nconst i = Math.floor(num * k);\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (const bucket of buckets) {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort((a, b) => a - b);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet i = 0;\nfor (const bucket of buckets) {\nfor (const num of bucket) {\nnums[i++] = num;\n}\n}\n}\n
        bucket_sort.dart
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(List<double> nums) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = nums.length ~/ 2;\nList<List<double>> buckets = List.generate(k, (index) => []);\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (double _num in nums) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 _num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint i = (_num * k).toInt();\n// \u5c06 _num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\nbuckets[i].add(_num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (List<double> bucket in buckets) {\nbucket.sort();\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nint i = 0;\nfor (List<double> bucket in buckets) {\nfor (double _num in bucket) {\nnums[i++] = _num;\n}\n}\n}\n
        bucket_sort.rs
        /* \u6876\u6392\u5e8f */\nfn bucket_sort(nums: &mut [f64]) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nlet k = nums.len() / 2;\nlet mut buckets = vec![vec![]; k];\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor &mut num in &mut *nums {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nlet i = (num * k as f64) as usize;\n// \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\nbuckets[i].push(num);\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor bucket in &mut buckets {\n// \u4f7f\u7528\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u66ff\u6362\u6210\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\nbucket.sort_by(|a, b| a.partial_cmp(b).unwrap());\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nlet mut i = 0;\nfor bucket in &mut buckets {\nfor &mut num in bucket {\nnums[i] = num;\ni += 1;\n}\n}\n}\n
        bucket_sort.c
        /* \u6876\u6392\u5e8f */\nvoid bucketSort(float nums[], int size) {\n// \u521d\u59cb\u5316 k = n/2 \u4e2a\u6876\uff0c\u9884\u671f\u5411\u6bcf\u4e2a\u6876\u5206\u914d 2 \u4e2a\u5143\u7d20\nint k = size / 2;\nfloat **buckets = calloc(k, sizeof(float *));\nfor (int i = 0; i < k; i++) {\n// \u6bcf\u4e2a\u6876\u6700\u591a\u53ef\u4ee5\u5206\u914d k \u4e2a\u5143\u7d20\nbuckets[i] = calloc(ARRAY_SIZE, sizeof(float));\n}\n// 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\nfor (int i = 0; i < size; i++) {\n// \u8f93\u5165\u6570\u636e\u8303\u56f4\u4e3a [0, 1)\uff0c\u4f7f\u7528 num * k \u6620\u5c04\u5230\u7d22\u5f15\u8303\u56f4 [0, k-1]\nint bucket_idx = nums[i] * k;\nint j = 0;\n// \u5982\u679c\u6876\u4e2d\u6709\u6570\u636e\u4e14\u6570\u636e\u5c0f\u4e8e\u5f53\u524d\u503c nums[i], \u8981\u5c06\u5176\u653e\u5230\u5f53\u524d\u6876\u7684\u540e\u9762\uff0c\u76f8\u5f53\u4e8e cpp \u4e2d\u7684 push_back\nwhile (buckets[bucket_idx][j] > 0 && buckets[bucket_idx][j] < nums[i]) {\nj++;\n}\nfloat temp = nums[i];\nwhile (j < ARRAY_SIZE && buckets[bucket_idx][j] > 0) {\nswap(&temp, &buckets[bucket_idx][j]);\nj++;\n}\nbuckets[bucket_idx][j] = temp;\n}\n// 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\nfor (int i = 0; i < k; i++) {\nqsort(buckets[i], ARRAY_SIZE, sizeof(float), compare_float);\n}\n// 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\nfor (int i = 0, j = 0; j < k; j++) {\nfor (int l = 0; l < ARRAY_SIZE; l++) {\nif (buckets[j][l] > 0) {\nnums[i++] = buckets[j][l];\n}\n}\n}\n// \u91ca\u653e\u4e0a\u8ff0\u5206\u914d\u7684\u5185\u5b58\nfor (int i = 0; i < k; i++) {\nfree(buckets[i]);\n}\nfree(buckets);\n}\n
        bucket_sort.zig
        [class]{}-[func]{bucketSort}\n
        "},{"location":"chapter_sorting/bucket_sort/#1182","title":"11.8.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"

        \u6876\u6392\u5e8f\u9002\u7528\u4e8e\u5904\u7406\u4f53\u91cf\u5f88\u5927\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u6570\u636e\u5305\u542b 100 \u4e07\u4e2a\u5143\u7d20\uff0c\u7531\u4e8e\u7a7a\u95f4\u9650\u5236\uff0c\u7cfb\u7edf\u5185\u5b58\u65e0\u6cd5\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u6570\u636e\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u5206\u6210 1000 \u4e2a\u6876\uff0c\u7136\u540e\u5206\u522b\u5bf9\u6bcf\u4e2a\u6876\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u540e\u5c06\u7ed3\u679c\u5408\u5e76\u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n + k)\\) \uff1a\u5047\u8bbe\u5143\u7d20\u5728\u5404\u4e2a\u6876\u5185\u5e73\u5747\u5206\u5e03\uff0c\u90a3\u4e48\u6bcf\u4e2a\u6876\u5185\u7684\u5143\u7d20\u6570\u91cf\u4e3a \\(\\frac{n}{k}\\) \u3002\u5047\u8bbe\u6392\u5e8f\u5355\u4e2a\u6876\u4f7f\u7528 \\(O(\\frac{n}{k} \\log\\frac{n}{k})\\) \u65f6\u95f4\uff0c\u5219\u6392\u5e8f\u6240\u6709\u6876\u4f7f\u7528 \\(O(n \\log\\frac{n}{k})\\) \u65f6\u95f4\u3002\u5f53\u6876\u6570\u91cf \\(k\\) \u6bd4\u8f83\u5927\u65f6\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5219\u8d8b\u5411\u4e8e \\(O(n)\\) \u3002\u5408\u5e76\u7ed3\u679c\u65f6\u9700\u8981\u904d\u5386\u6240\u6709\u6876\u548c\u5143\u7d20\uff0c\u82b1\u8d39 \\(O(n + k)\\) \u65f6\u95f4\u3002
        • \u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u6570\u636e\u88ab\u5206\u914d\u5230\u4e00\u4e2a\u6876\u4e2d\uff0c\u4e14\u6392\u5e8f\u8be5\u6876\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + k)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u9700\u8981\u501f\u52a9 \\(k\\) \u4e2a\u6876\u548c\u603b\u5171 \\(n\\) \u4e2a\u5143\u7d20\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u6876\u6392\u5e8f\u662f\u5426\u7a33\u5b9a\u53d6\u51b3\u4e8e\u6392\u5e8f\u6876\u5185\u5143\u7d20\u7684\u7b97\u6cd5\u662f\u5426\u7a33\u5b9a\u3002
        "},{"location":"chapter_sorting/bucket_sort/#1183","title":"11.8.3 \u00a0 \u5982\u4f55\u5b9e\u73b0\u5e73\u5747\u5206\u914d","text":"

        \u6876\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7406\u8bba\u4e0a\u53ef\u4ee5\u8fbe\u5230 \\(O(n)\\) \uff0c\u5173\u952e\u5728\u4e8e\u5c06\u5143\u7d20\u5747\u5300\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\uff0c\u56e0\u4e3a\u5b9e\u9645\u6570\u636e\u5f80\u5f80\u4e0d\u662f\u5747\u5300\u5206\u5e03\u7684\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u60f3\u8981\u5c06\u6dd8\u5b9d\u4e0a\u7684\u6240\u6709\u5546\u54c1\u6309\u4ef7\u683c\u8303\u56f4\u5e73\u5747\u5206\u914d\u5230 10 \u4e2a\u6876\u4e2d\uff0c\u4f46\u5546\u54c1\u4ef7\u683c\u5206\u5e03\u4e0d\u5747\uff0c\u4f4e\u4e8e 100 \u5143\u7684\u975e\u5e38\u591a\uff0c\u9ad8\u4e8e 1000 \u5143\u7684\u975e\u5e38\u5c11\u3002\u82e5\u5c06\u4ef7\u683c\u533a\u95f4\u5e73\u5747\u5212\u5206\u4e3a 10 \u4e2a\uff0c\u5404\u4e2a\u6876\u4e2d\u7684\u5546\u54c1\u6570\u91cf\u5dee\u8ddd\u4f1a\u975e\u5e38\u5927\u3002

        \u4e3a\u5b9e\u73b0\u5e73\u5747\u5206\u914d\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u8bbe\u5b9a\u4e00\u6761\u5927\u81f4\u7684\u5206\u754c\u7ebf\uff0c\u5c06\u6570\u636e\u7c97\u7565\u5730\u5206\u5230 3 \u4e2a\u6876\u4e2d\u3002\u5206\u914d\u5b8c\u6bd5\u540e\uff0c\u518d\u5c06\u5546\u54c1\u8f83\u591a\u7684\u6876\u7ee7\u7eed\u5212\u5206\u4e3a 3 \u4e2a\u6876\uff0c\u76f4\u81f3\u6240\u6709\u6876\u4e2d\u7684\u5143\u7d20\u6570\u91cf\u5927\u81f4\u76f8\u7b49\u3002

        \u5982\u56fe 11-14 \u6240\u793a\uff0c\u8fd9\u79cd\u65b9\u6cd5\u672c\u8d28\u4e0a\u662f\u521b\u5efa\u4e00\u68f5\u9012\u5f52\u6811\uff0c\u76ee\u6807\u662f\u8ba9\u53f6\u8282\u70b9\u7684\u503c\u5c3d\u53ef\u80fd\u5e73\u5747\u3002\u5f53\u7136\uff0c\u4e0d\u4e00\u5b9a\u8981\u6bcf\u8f6e\u5c06\u6570\u636e\u5212\u5206\u4e3a 3 \u4e2a\u6876\uff0c\u5177\u4f53\u5212\u5206\u65b9\u5f0f\u53ef\u6839\u636e\u6570\u636e\u7279\u70b9\u7075\u6d3b\u9009\u62e9\u3002

        \u56fe 11-14 \u00a0 \u9012\u5f52\u5212\u5206\u6876

        \u5982\u679c\u6211\u4eec\u63d0\u524d\u77e5\u9053\u5546\u54c1\u4ef7\u683c\u7684\u6982\u7387\u5206\u5e03\uff0c\u5219\u53ef\u4ee5\u6839\u636e\u6570\u636e\u6982\u7387\u5206\u5e03\u8bbe\u7f6e\u6bcf\u4e2a\u6876\u7684\u4ef7\u683c\u5206\u754c\u7ebf\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6570\u636e\u5206\u5e03\u5e76\u4e0d\u4e00\u5b9a\u9700\u8981\u7279\u610f\u7edf\u8ba1\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u6570\u636e\u7279\u70b9\u91c7\u7528\u67d0\u79cd\u6982\u7387\u6a21\u578b\u8fdb\u884c\u8fd1\u4f3c\u3002

        \u5982\u56fe 11-15 \u6240\u793a\uff0c\u6211\u4eec\u5047\u8bbe\u5546\u54c1\u4ef7\u683c\u670d\u4ece\u6b63\u6001\u5206\u5e03\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5408\u7406\u5730\u8bbe\u5b9a\u4ef7\u683c\u533a\u95f4\uff0c\u4ece\u800c\u5c06\u5546\u54c1\u5e73\u5747\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\u3002

        \u56fe 11-15 \u00a0 \u6839\u636e\u6982\u7387\u5206\u5e03\u5212\u5206\u6876

        "},{"location":"chapter_sorting/counting_sort/","title":"11.9 \u00a0 \u8ba1\u6570\u6392\u5e8f","text":"

        \u300c\u8ba1\u6570\u6392\u5e8f counting sort\u300d\u901a\u8fc7\u7edf\u8ba1\u5143\u7d20\u6570\u91cf\u6765\u5b9e\u73b0\u6392\u5e8f\uff0c\u901a\u5e38\u5e94\u7528\u4e8e\u6574\u6570\u6570\u7ec4\u3002

        "},{"location":"chapter_sorting/counting_sort/#1191","title":"11.9.1 \u00a0 \u7b80\u5355\u5b9e\u73b0","text":"

        \u5148\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u3002\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4 nums \uff0c\u5176\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u201c\u975e\u8d1f\u6574\u6570\u201d\uff0c\u8ba1\u6570\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-16 \u6240\u793a\u3002

        1. \u904d\u5386\u6570\u7ec4\uff0c\u627e\u51fa\u5176\u4e2d\u7684\u6700\u5927\u6570\u5b57\uff0c\u8bb0\u4e3a \\(m\\) \uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a \\(m + 1\\) \u7684\u8f85\u52a9\u6570\u7ec4 counter \u3002
        2. \u501f\u52a9 counter \u7edf\u8ba1 nums \u4e2d\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u5176\u4e2d counter[num] \u5bf9\u5e94\u6570\u5b57 num \u7684\u51fa\u73b0\u6b21\u6570\u3002\u7edf\u8ba1\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u904d\u5386 nums\uff08\u8bbe\u5f53\u524d\u6570\u5b57\u4e3a num\uff09\uff0c\u6bcf\u8f6e\u5c06 counter[num] \u589e\u52a0 \\(1\\) \u5373\u53ef\u3002
        3. \u7531\u4e8e counter \u7684\u5404\u4e2a\u7d22\u5f15\u5929\u7136\u6709\u5e8f\uff0c\u56e0\u6b64\u76f8\u5f53\u4e8e\u6240\u6709\u6570\u5b57\u5df2\u7ecf\u6392\u5e8f\u597d\u4e86\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u904d\u5386 counter \uff0c\u6839\u636e\u5404\u6570\u5b57\u51fa\u73b0\u6b21\u6570\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u586b\u5165 nums \u5373\u53ef\u3002

        \u56fe 11-16 \u00a0 \u8ba1\u6570\u6392\u5e8f\u6d41\u7a0b

        \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig counting_sort.py
        def counting_sort_naive(nums: list[int]):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\"\"\"\n# \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\n# 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm = 0\nfor num in nums:\nm = max(m, num)\n# 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n# counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter = [0] * (m + 1)\nfor num in nums:\ncounter[num] += 1\n# 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\ni = 0\nfor num in range(m + 1):\nfor _ in range(counter[num]):\nnums[i] = num\ni += 1\n
        counting_sort.cpp
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(vector<int> &nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvector<int> counter(m + 1, 0);\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.java
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.cs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid CountingSortNaive(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nforeach (int num in nums) {\nm = Math.Max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nforeach (int num in nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.go
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunc countingSortNaive(nums []int) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm := 0\nfor _, num := range nums {\nif num > m {\nm = num\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter := make([]int, m+1)\nfor _, num := range nums {\ncounter[num]++\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nfor i, num := 0, 0; num < m+1; num++ {\nfor j := 0; j < counter[num]; j++ {\nnums[i] = num\ni++\n}\n}\n}\n
        counting_sort.swift
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunc countingSortNaive(nums: inout [Int]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = nums.max()!\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvar counter = Array(repeating: 0, count: m + 1)\nfor num in nums {\ncounter[num] += 1\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nvar i = 0\nfor num in stride(from: 0, to: m + 1, by: 1) {\nfor _ in stride(from: 0, to: counter[num], by: 1) {\nnums[i] = num\ni += 1\n}\n}\n}\n
        counting_sort.js
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunction countingSortNaive(nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter = new Array(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet i = 0;\nfor (let num = 0; num < m + 1; num++) {\nfor (let j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.ts
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfunction countingSortNaive(nums: number[]): void {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter: number[] = new Array<number>(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet i = 0;\nfor (let num = 0; num < m + 1; num++) {\nfor (let j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n}\n
        counting_sort.dart
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(List<int> nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int _num in nums) {\nm = max(m, _num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[_num] \u4ee3\u8868 _num \u7684\u51fa\u73b0\u6b21\u6570\nList<int> counter = List.filled(m + 1, 0);\nfor (int _num in nums) {\ncounter[_num]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int _num = 0; _num < m + 1; _num++) {\nfor (int j = 0; j < counter[_num]; j++, i++) {\nnums[i] = _num;\n}\n}\n}\n
        counting_sort.rs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nfn counting_sort_naive(nums: &mut [i32]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = *nums.into_iter().max().unwrap();\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nlet mut counter = vec![0; m as usize + 1];\nfor &num in &*nums {\ncounter[num as usize] += 1;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nlet mut i = 0;\nfor num in 0..m + 1 {\nfor _ in 0..counter[num as usize] {\nnums[i] = num;\ni += 1;\n}\n}\n}\n
        counting_sort.c
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u7b80\u5355\u5b9e\u73b0\uff0c\u65e0\u6cd5\u7528\u4e8e\u6392\u5e8f\u5bf9\u8c61\nvoid countingSortNaive(int nums[], int size) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int i = 0; i < size; i++) {\nif (nums[i] > m) {\nm = nums[i];\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint *counter = calloc(m, sizeof(int));\nfor (int i = 0; i < size; i++) {\ncounter[nums[i]]++;\n}\n// 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\nint i = 0;\nfor (int num = 0; num < m + 1; num++) {\nfor (int j = 0; j < counter[num]; j++, i++) {\nnums[i] = num;\n}\n}\n// 4. \u91ca\u653e\u5185\u5b58\nfree(counter);\n}\n
        counting_sort.zig
        [class]{}-[func]{countingSortNaive}\n

        \u8ba1\u6570\u6392\u5e8f\u4e0e\u6876\u6392\u5e8f\u7684\u8054\u7cfb

        \u4ece\u6876\u6392\u5e8f\u7684\u89d2\u5ea6\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8ba1\u6570\u6392\u5e8f\u4e2d\u7684\u8ba1\u6570\u6570\u7ec4 counter \u7684\u6bcf\u4e2a\u7d22\u5f15\u89c6\u4e3a\u4e00\u4e2a\u6876\uff0c\u5c06\u7edf\u8ba1\u6570\u91cf\u7684\u8fc7\u7a0b\u770b\u4f5c\u5c06\u5404\u4e2a\u5143\u7d20\u5206\u914d\u5230\u5bf9\u5e94\u7684\u6876\u4e2d\u3002\u672c\u8d28\u4e0a\uff0c\u8ba1\u6570\u6392\u5e8f\u662f\u6876\u6392\u5e8f\u5728\u6574\u578b\u6570\u636e\u4e0b\u7684\u4e00\u4e2a\u7279\u4f8b\u3002

        "},{"location":"chapter_sorting/counting_sort/#1192","title":"11.9.2 \u00a0 \u5b8c\u6574\u5b9e\u73b0","text":"

        \u7ec6\u5fc3\u7684\u8bfb\u8005\u53ef\u80fd\u53d1\u73b0\u4e86\uff0c\u5982\u679c\u8f93\u5165\u6570\u636e\u662f\u5bf9\u8c61\uff0c\u4e0a\u8ff0\u6b65\u9aa4 3. \u5c31\u5931\u6548\u4e86\u3002\u5047\u8bbe\u8f93\u5165\u6570\u636e\u662f\u5546\u54c1\u5bf9\u8c61\uff0c\u6211\u4eec\u60f3\u6309\u7167\u5546\u54c1\u4ef7\u683c\uff08\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff09\u5bf9\u5546\u54c1\u8fdb\u884c\u6392\u5e8f\uff0c\u800c\u4e0a\u8ff0\u7b97\u6cd5\u53ea\u80fd\u7ed9\u51fa\u4ef7\u683c\u7684\u6392\u5e8f\u7ed3\u679c\u3002

        \u90a3\u4e48\u5982\u4f55\u624d\u80fd\u5f97\u5230\u539f\u6570\u636e\u7684\u6392\u5e8f\u7ed3\u679c\u5462\uff1f\u6211\u4eec\u9996\u5148\u8ba1\u7b97 counter \u7684\u201c\u524d\u7f00\u548c\u201d\u3002\u987e\u540d\u601d\u4e49\uff0c\u7d22\u5f15 i \u5904\u7684\u524d\u7f00\u548c prefix[i] \u7b49\u4e8e\u6570\u7ec4\u524d i \u4e2a\u5143\u7d20\u4e4b\u548c\uff1a

        \\[ \\text{prefix}[i] = \\sum_{j=0}^i \\text{counter[j]} \\]

        \u524d\u7f00\u548c\u5177\u6709\u660e\u786e\u7684\u610f\u4e49\uff0cprefix[num] - 1 \u4ee3\u8868\u5143\u7d20 num \u5728\u7ed3\u679c\u6570\u7ec4 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\u3002\u8fd9\u4e2a\u4fe1\u606f\u975e\u5e38\u5173\u952e\uff0c\u56e0\u4e3a\u5b83\u544a\u8bc9\u6211\u4eec\u5404\u4e2a\u5143\u7d20\u5e94\u8be5\u51fa\u73b0\u5728\u7ed3\u679c\u6570\u7ec4\u7684\u54ea\u4e2a\u4f4d\u7f6e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5012\u5e8f\u904d\u5386\u539f\u6570\u7ec4 nums \u7684\u6bcf\u4e2a\u5143\u7d20 num \uff0c\u5728\u6bcf\u8f6e\u8fed\u4ee3\u4e2d\u6267\u884c\u4ee5\u4e0b\u4e24\u6b65\u3002

        1. \u5c06 num \u586b\u5165\u6570\u7ec4 res \u7684\u7d22\u5f15 prefix[num] - 1 \u5904\u3002
        2. \u4ee4\u524d\u7f00\u548c prefix[num] \u51cf\u5c0f \\(1\\) \uff0c\u4ece\u800c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\u3002

        \u904d\u5386\u5b8c\u6210\u540e\uff0c\u6570\u7ec4 res \u4e2d\u5c31\u662f\u6392\u5e8f\u597d\u7684\u7ed3\u679c\uff0c\u6700\u540e\u4f7f\u7528 res \u8986\u76d6\u539f\u6570\u7ec4 nums \u5373\u53ef\u3002\u56fe 11-17 \u5c55\u793a\u4e86\u5b8c\u6574\u7684\u8ba1\u6570\u6392\u5e8f\u6d41\u7a0b\u3002

        <1><2><3><4><5><6><7><8>

        \u56fe 11-17 \u00a0 \u8ba1\u6570\u6392\u5e8f\u6b65\u9aa4

        \u8ba1\u6570\u6392\u5e8f\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig counting_sort.py
        def counting_sort(nums: list[int]):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\"\"\"\n# \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\n# 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm = max(nums)\n# 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n# counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter = [0] * (m + 1)\nfor num in nums:\ncounter[num] += 1\n# 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n# \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in range(m):\ncounter[i + 1] += counter[i]\n# 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n# \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nn = len(nums)\nres = [0] * n\nfor i in range(n - 1, -1, -1):\nnum = nums[i]\nres[counter[num] - 1] = num  # \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num] -= 1  # \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n# \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in range(n):\nnums[i] = res[i]\n
        counting_sort.cpp
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(vector<int> &nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvector<int> counter(m + 1, 0);\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.size();\nvector<int> res(n);\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--;              // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nnums = res;\n}\n
        counting_sort.java
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int num : nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nfor (int num : nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.length;\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.cs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid CountingSort(int[] nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nforeach (int num in nums) {\nm = Math.Max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint[] counter = new int[m + 1];\nforeach (int num in nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.Length;\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.go
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunc countingSort(nums []int) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nm := 0\nfor _, num := range nums {\nif num > m {\nm = num\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\ncounter := make([]int, m+1)\nfor _, num := range nums {\ncounter[num]++\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i := 0; i < m; i++ {\ncounter[i+1] += counter[i]\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nn := len(nums)\nres := make([]int, n)\nfor i := n - 1; i >= 0; i-- {\nnum := nums[i]\n// \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\nres[counter[num]-1] = num\n// \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\ncounter[num]--\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\ncopy(nums, res)\n}\n
        counting_sort.swift
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunc countingSort(nums: inout [Int]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = nums.max()!\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nvar counter = Array(repeating: 0, count: m + 1)\nfor num in nums {\ncounter[num] += 1\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in stride(from: 0, to: m, by: 1) {\ncounter[i + 1] += counter[i]\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nvar res = Array(repeating: 0, count: nums.count)\nfor i in stride(from: nums.count - 1, through: 0, by: -1) {\nlet num = nums[i]\nres[counter[num] - 1] = num // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num] -= 1 // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in stride(from: 0, to: nums.count, by: 1) {\nnums[i] = res[i]\n}\n}\n
        counting_sort.js
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunction countingSort(nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter = new Array(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (let i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nconst n = nums.length;\nconst res = new Array(n);\nfor (let i = n - 1; i >= 0; i--) {\nconst num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.ts
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfunction countingSort(nums: number[]): void {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = 0;\nfor (const num of nums) {\nm = Math.max(m, num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nconst counter: number[] = new Array<number>(m + 1).fill(0);\nfor (const num of nums) {\ncounter[num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (let i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nconst n = nums.length;\nconst res: number[] = new Array<number>(n);\nfor (let i = n - 1; i >= 0; i--) {\nconst num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n
        counting_sort.dart
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(List<int> nums) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int _num in nums) {\nm = max(m, _num);\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[_num] \u4ee3\u8868 _num \u7684\u51fa\u73b0\u6b21\u6570\nList<int> counter = List.filled(m + 1, 0);\nfor (int _num in nums) {\ncounter[_num]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[_num]-1 \u662f _num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint n = nums.length;\nList<int> res = List.filled(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint _num = nums[i];\nres[counter[_num] - 1] = _num; // \u5c06 _num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[_num]--; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e _num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nnums.setAll(0, res);\n}\n
        counting_sort.rs
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nfn counting_sort(nums: &mut [i32]) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nlet m = *nums.into_iter().max().unwrap();\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nlet mut counter = vec![0; m as usize + 1];\nfor &num in &*nums {\ncounter[num as usize] += 1;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor i in 0..m as usize {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nlet n = nums.len();\nlet mut res = vec![0; n];\nfor i in (0..n).rev() {\nlet num = nums[i];\nres[counter[num as usize] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num as usize] -= 1; // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in 0..n {\nnums[i] = res[i];\n}\n}\n
        counting_sort.c
        /* \u8ba1\u6570\u6392\u5e8f */\n// \u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u6392\u5e8f\u5bf9\u8c61\uff0c\u5e76\u4e14\u662f\u7a33\u5b9a\u6392\u5e8f\nvoid countingSort(int nums[], int size) {\n// 1. \u7edf\u8ba1\u6570\u7ec4\u6700\u5927\u5143\u7d20 m\nint m = 0;\nfor (int i = 0; i < size; i++) {\nif (nums[i] > m) {\nm = nums[i];\n}\n}\n// 2. \u7edf\u8ba1\u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n// counter[num] \u4ee3\u8868 num \u7684\u51fa\u73b0\u6b21\u6570\nint *counter = calloc(m, sizeof(int));\nfor (int i = 0; i < size; i++) {\ncounter[nums[i]]++;\n}\n// 3. \u6c42 counter \u7684\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u6b21\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u5c3e\u7d22\u5f15\u201d\n// \u5373 counter[num]-1 \u662f num \u5728 res \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\nfor (int i = 0; i < m; i++) {\ncounter[i + 1] += counter[i];\n}\n// 4. \u5012\u5e8f\u904d\u5386 nums \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u7ed3\u679c\u6570\u7ec4 res\n// \u521d\u59cb\u5316\u6570\u7ec4 res \u7528\u4e8e\u8bb0\u5f55\u7ed3\u679c\nint *res = malloc(sizeof(int) * size);\nfor (int i = size - 1; i >= 0; i--) {\nint num = nums[i];\nres[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\ncounter[num]--;              // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n}\n// \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\nmemcpy(nums, res, size * sizeof(int));\n// 5. \u91ca\u653e\u5185\u5b58\nfree(counter);\n}\n
        counting_sort.zig
        [class]{}-[func]{countingSort}\n
        "},{"location":"chapter_sorting/counting_sort/#1193","title":"11.9.3 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n + m)\\) \uff1a\u6d89\u53ca\u904d\u5386 nums \u548c\u904d\u5386 counter \uff0c\u90fd\u4f7f\u7528\u7ebf\u6027\u65f6\u95f4\u3002\u4e00\u822c\u60c5\u51b5\u4e0b \\(n \\gg m\\) \uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u4e8e \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + m)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u501f\u52a9\u4e86\u957f\u5ea6\u5206\u522b\u4e3a \\(n\\) \u548c \\(m\\) \u7684\u6570\u7ec4 res \u548c counter \u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u7531\u4e8e\u5411 res \u4e2d\u586b\u5145\u5143\u7d20\u7684\u987a\u5e8f\u662f\u201c\u4ece\u53f3\u5411\u5de6\u201d\u7684\uff0c\u56e0\u6b64\u5012\u5e8f\u904d\u5386 nums \u53ef\u4ee5\u907f\u514d\u6539\u53d8\u76f8\u7b49\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u7a33\u5b9a\u6392\u5e8f\u3002\u5b9e\u9645\u4e0a\uff0c\u6b63\u5e8f\u904d\u5386 nums \u4e5f\u53ef\u4ee5\u5f97\u5230\u6b63\u786e\u7684\u6392\u5e8f\u7ed3\u679c\uff0c\u4f46\u7ed3\u679c\u662f\u975e\u7a33\u5b9a\u7684\u3002
        "},{"location":"chapter_sorting/counting_sort/#1194","title":"11.9.4 \u00a0 \u5c40\u9650\u6027","text":"

        \u770b\u5230\u8fd9\u91cc\uff0c\u4f60\u4e5f\u8bb8\u4f1a\u89c9\u5f97\u8ba1\u6570\u6392\u5e8f\u975e\u5e38\u5de7\u5999\uff0c\u4ec5\u901a\u8fc7\u7edf\u8ba1\u6570\u91cf\u5c31\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u6392\u5e8f\u3002\u7136\u800c\uff0c\u4f7f\u7528\u8ba1\u6570\u6392\u5e8f\u7684\u524d\u7f6e\u6761\u4ef6\u76f8\u5bf9\u8f83\u4e3a\u4e25\u683c\u3002

        \u8ba1\u6570\u6392\u5e8f\u53ea\u9002\u7528\u4e8e\u975e\u8d1f\u6574\u6570\u3002\u82e5\u60f3\u5c06\u5176\u7528\u4e8e\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\uff0c\u9700\u8981\u786e\u4fdd\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u8f6c\u6362\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u5e76\u4e14\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u4e0d\u80fd\u6539\u53d8\u5404\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u5bf9\u5927\u5c0f\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u5305\u542b\u8d1f\u6570\u7684\u6574\u6570\u6570\u7ec4\uff0c\u53ef\u4ee5\u5148\u7ed9\u6240\u6709\u6570\u5b57\u52a0\u4e0a\u4e00\u4e2a\u5e38\u6570\uff0c\u5c06\u5168\u90e8\u6570\u5b57\u8f6c\u5316\u4e3a\u6b63\u6570\uff0c\u6392\u5e8f\u5b8c\u6210\u540e\u518d\u8f6c\u6362\u56de\u53bb\u3002

        \u8ba1\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u636e\u91cf\u5927\u4f46\u6570\u636e\u8303\u56f4\u8f83\u5c0f\u7684\u60c5\u51b5\u3002\u6bd4\u5982\uff0c\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d \\(m\\) \u4e0d\u80fd\u592a\u5927\uff0c\u5426\u5219\u4f1a\u5360\u7528\u8fc7\u591a\u7a7a\u95f4\u3002\u800c\u5f53 \\(n \\ll m\\) \u65f6\uff0c\u8ba1\u6570\u6392\u5e8f\u4f7f\u7528 \\(O(m)\\) \u65f6\u95f4\uff0c\u53ef\u80fd\u6bd4 \\(O(n \\log n)\\) \u7684\u6392\u5e8f\u7b97\u6cd5\u8fd8\u8981\u6162\u3002

        "},{"location":"chapter_sorting/heap_sort/","title":"11.7 \u00a0 \u5806\u6392\u5e8f","text":"

        Tip

        \u9605\u8bfb\u672c\u8282\u524d\uff0c\u8bf7\u786e\u4fdd\u5df2\u5b66\u5b8c\u201c\u5806\u201c\u7ae0\u8282\u3002

        \u300c\u5806\u6392\u5e8f heap sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5806\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\u7684\u9ad8\u6548\u6392\u5e8f\u7b97\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u5df2\u7ecf\u5b66\u8fc7\u7684\u201c\u5efa\u5806\u64cd\u4f5c\u201d\u548c\u201c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u201d\u5b9e\u73b0\u5806\u6392\u5e8f\u3002

        1. \u8f93\u5165\u6570\u7ec4\u5e76\u5efa\u7acb\u5c0f\u9876\u5806\uff0c\u6b64\u65f6\u6700\u5c0f\u5143\u7d20\u4f4d\u4e8e\u5806\u9876\u3002
        2. \u4e0d\u65ad\u6267\u884c\u51fa\u5806\u64cd\u4f5c\uff0c\u4f9d\u6b21\u8bb0\u5f55\u51fa\u5806\u5143\u7d20\uff0c\u5373\u53ef\u5f97\u5230\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u7684\u5e8f\u5217\u3002

        \u4ee5\u4e0a\u65b9\u6cd5\u867d\u7136\u53ef\u884c\uff0c\u4f46\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u989d\u5916\u6570\u7ec4\u6765\u4fdd\u5b58\u5f39\u51fa\u7684\u5143\u7d20\uff0c\u6bd4\u8f83\u6d6a\u8d39\u7a7a\u95f4\u3002\u5728\u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528\u4e00\u79cd\u66f4\u52a0\u4f18\u96c5\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002

        "},{"location":"chapter_sorting/heap_sort/#1171","title":"11.7.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u5806\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-12 \u6240\u793a\u3002

        1. \u8f93\u5165\u6570\u7ec4\u5e76\u5efa\u7acb\u5927\u9876\u5806\u3002\u5b8c\u6210\u540e\uff0c\u6700\u5927\u5143\u7d20\u4f4d\u4e8e\u5806\u9876\u3002
        2. \u5c06\u5806\u9876\u5143\u7d20\uff08\u7b2c\u4e00\u4e2a\u5143\u7d20\uff09\u4e0e\u5806\u5e95\u5143\u7d20\uff08\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff09\u4ea4\u6362\u3002\u5b8c\u6210\u4ea4\u6362\u540e\uff0c\u5806\u7684\u957f\u5ea6\u51cf \\(1\\) \uff0c\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u52a0 \\(1\\) \u3002
        3. \u4ece\u5806\u9876\u5143\u7d20\u5f00\u59cb\uff0c\u4ece\u9876\u5230\u5e95\u6267\u884c\u5806\u5316\u64cd\u4f5c\uff08Sift Down\uff09\u3002\u5b8c\u6210\u5806\u5316\u540e\uff0c\u5806\u7684\u6027\u8d28\u5f97\u5230\u4fee\u590d\u3002
        4. \u5faa\u73af\u6267\u884c\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\u3002\u5faa\u73af \\(n - 1\\) \u8f6e\u540e\uff0c\u5373\u53ef\u5b8c\u6210\u6570\u7ec4\u6392\u5e8f\u3002

        Tip

        \u5b9e\u9645\u4e0a\uff0c\u5143\u7d20\u51fa\u5806\u64cd\u4f5c\u4e2d\u4e5f\u5305\u542b\u7b2c 2. \u6b65\u548c\u7b2c 3. \u6b65\uff0c\u53ea\u662f\u591a\u4e86\u4e00\u4e2a\u5f39\u51fa\u5143\u7d20\u7684\u6b65\u9aa4\u3002

        <1><2><3><4><5><6><7><8><9><10><11><12>

        \u56fe 11-12 \u00a0 \u5806\u6392\u5e8f\u6b65\u9aa4

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e0e\u201c\u5806\u201d\u7ae0\u8282\u76f8\u540c\u7684\u4ece\u9876\u81f3\u5e95\u5806\u5316 sift_down() \u51fd\u6570\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u5806\u7684\u957f\u5ea6\u4f1a\u968f\u7740\u63d0\u53d6\u6700\u5927\u5143\u7d20\u800c\u51cf\u5c0f\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u7ed9 sift_down() \u51fd\u6570\u6dfb\u52a0\u4e00\u4e2a\u957f\u5ea6\u53c2\u6570 \\(n\\) \uff0c\u7528\u4e8e\u6307\u5b9a\u5806\u7684\u5f53\u524d\u6709\u6548\u957f\u5ea6\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig heap_sort.py
        def sift_down(nums: list[int], n: int, i: int):\n\"\"\"\u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\nwhile True:\n# \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl = 2 * i + 1\nr = 2 * i + 2\nma = i\nif l < n and nums[l] > nums[ma]:\nma = l\nif r < n and nums[r] > nums[ma]:\nma = r\n# \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i:\nbreak\n# \u4ea4\u6362\u4e24\u8282\u70b9\nnums[i], nums[ma] = nums[ma], nums[i]\n# \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\ndef heap_sort(nums: list[int]):\n\"\"\"\u5806\u6392\u5e8f\"\"\"\n# \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in range(len(nums) // 2 - 1, -1, -1):\nsift_down(nums, len(nums), i)\n# \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in range(len(nums) - 1, 0, -1):\n# \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nnums[0], nums[i] = nums[i], nums[0]\n# \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsift_down(nums, i, 0)\n
        heap_sort.cpp
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(vector<int> &nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nswap(nums[i], nums[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(vector<int> &nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.size() / 2 - 1; i >= 0; --i) {\nsiftDown(nums, nums.size(), i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.size() - 1; i > 0; --i) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nswap(nums[0], nums[i]);\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.java
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int[] nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(int[] nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.length / 2 - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.cs
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int[] nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i)\nbreak;\n// \u4ea4\u6362\u4e24\u8282\u70b9\n(nums[ma], nums[i]) = (nums[i], nums[ma]);\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid HeapSort(int[] nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.Length / 2 - 1; i >= 0; i--) {\nSiftDown(nums, nums.Length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.Length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n(nums[i], nums[0]) = (nums[0], nums[i]);\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nSiftDown(nums, i, 0);\n}\n}\n
        heap_sort.go
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(nums *[]int, n, i int) {\nfor true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nl := 2*i + 1\nr := 2*i + 2\nma := i\nif l < n && (*nums)[l] > (*nums)[ma] {\nma = l\n}\nif r < n && (*nums)[r] > (*nums)[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n(*nums)[i], (*nums)[ma] = (*nums)[ma], (*nums)[i]\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n/* \u5806\u6392\u5e8f */\nfunc heapSort(nums *[]int) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i := len(*nums)/2 - 1; i >= 0; i-- {\nsiftDown(nums, len(*nums), i)\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i := len(*nums) - 1; i > 0; i-- {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n(*nums)[0], (*nums)[i] = (*nums)[i], (*nums)[0]\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0)\n}\n}\n
        heap_sort.swift
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(nums: inout [Int], n: Int, i: Int) {\nvar i = i\nwhile true {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1\nlet r = 2 * i + 2\nvar ma = i\nif l < n, nums[l] > nums[ma] {\nma = l\n}\nif r < n, nums[r] > nums[ma] {\nma = r\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nnums.swapAt(i, ma)\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma\n}\n}\n/* \u5806\u6392\u5e8f */\nfunc heapSort(nums: inout [Int]) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in stride(from: nums.count / 2 - 1, through: 0, by: -1) {\nsiftDown(nums: &nums, n: nums.count, i: i)\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in stride(from: nums.count - 1, to: 0, by: -1) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nnums.swapAt(0, i)\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums: &nums, n: i, i: 0)\n}\n}\n
        heap_sort.js
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunction siftDown(nums, n, i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet ma = i;\nif (l < n && nums[l] > nums[ma]) {\nma = l;\n}\nif (r < n && nums[r] > nums[ma]) {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n[nums[i], nums[ma]] = [nums[ma], nums[i]];\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfunction heapSort(nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n[nums[0], nums[i]] = [nums[i], nums[0]];\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.ts
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunction siftDown(nums: number[], n: number, i: number): void {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet ma = i;\nif (l < n && nums[l] > nums[ma]) {\nma = l;\n}\nif (r < n && nums[r] > nums[ma]) {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma === i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\n[nums[i], nums[ma]] = [nums[ma], nums[i]];\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfunction heapSort(nums: number[]): void {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (let i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\n[nums[0], nums[i]] = [nums[i], nums[0]];\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.dart
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(List<int> nums, int n, int i) {\nwhile (true) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma]) ma = l;\nif (r < n && nums[r] > nums[ma]) ma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) break;\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(List<int> nums) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = nums.length ~/ 2 - 1; i >= 0; i--) {\nsiftDown(nums, nums.length, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = nums.length - 1; i > 0; i--) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.rs
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(nums: &mut [i32], n: usize, mut i: usize) {\nloop {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nlet l = 2 * i + 1;\nlet r = 2 * i + 2;\nlet mut ma = i;\nif l < n && nums[l] > nums[ma] {\nma = l;\n}\nif r < n && nums[r] > nums[ma] {\nma = r;\n}\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif ma == i {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nlet temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nfn heap_sort(nums: &mut [i32]) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor i in (0..=nums.len() / 2 - 1).rev() {\nsift_down(nums, nums.len(), i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor i in (1..=nums.len() - 1).rev() {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nlet tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsift_down(nums, i, 0);\n}\n}\n
        heap_sort.c
        /* \u5806\u7684\u957f\u5ea6\u4e3a n \uff0c\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int nums[], int n, int i) {\nwhile (1) {\n// \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\nint l = 2 * i + 1;\nint r = 2 * i + 2;\nint ma = i;\nif (l < n && nums[l] > nums[ma])\nma = l;\nif (r < n && nums[r] > nums[ma])\nma = r;\n// \u82e5\u8282\u70b9 i \u6700\u5927\u6216\u7d22\u5f15 l, r \u8d8a\u754c\uff0c\u5219\u65e0\u987b\u7ee7\u7eed\u5806\u5316\uff0c\u8df3\u51fa\nif (ma == i) {\nbreak;\n}\n// \u4ea4\u6362\u4e24\u8282\u70b9\nint temp = nums[i];\nnums[i] = nums[ma];\nnums[ma] = temp;\n// \u5faa\u73af\u5411\u4e0b\u5806\u5316\ni = ma;\n}\n}\n/* \u5806\u6392\u5e8f */\nvoid heapSort(int nums[], int n) {\n// \u5efa\u5806\u64cd\u4f5c\uff1a\u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\nfor (int i = n / 2 - 1; i >= 0; --i) {\nsiftDown(nums, n, i);\n}\n// \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\nfor (int i = n - 1; i > 0; --i) {\n// \u4ea4\u6362\u6839\u8282\u70b9\u4e0e\u6700\u53f3\u53f6\u8282\u70b9\uff08\u4ea4\u6362\u9996\u5143\u7d20\u4e0e\u5c3e\u5143\u7d20\uff09\nint tmp = nums[0];\nnums[0] = nums[i];\nnums[i] = tmp;\n// \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\nsiftDown(nums, i, 0);\n}\n}\n
        heap_sort.zig
        [class]{}-[func]{siftDown}\n[class]{}-[func]{heapSort}\n
        "},{"location":"chapter_sorting/heap_sort/#1172","title":"11.7.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5efa\u5806\u64cd\u4f5c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002\u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(\\log n)\\) \uff0c\u5171\u5faa\u73af \\(n - 1\\) \u8f6e\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u51e0\u4e2a\u6307\u9488\u53d8\u91cf\u4f7f\u7528 \\(O(1)\\) \u7a7a\u95f4\u3002\u5143\u7d20\u4ea4\u6362\u548c\u5806\u5316\u64cd\u4f5c\u90fd\u662f\u5728\u539f\u6570\u7ec4\u4e0a\u8fdb\u884c\u7684\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u4ea4\u6362\u5806\u9876\u5143\u7d20\u548c\u5806\u5e95\u5143\u7d20\u65f6\uff0c\u76f8\u7b49\u5143\u7d20\u7684\u76f8\u5bf9\u4f4d\u7f6e\u53ef\u80fd\u53d1\u751f\u53d8\u5316\u3002
        "},{"location":"chapter_sorting/insertion_sort/","title":"11.4 \u00a0 \u63d2\u5165\u6392\u5e8f","text":"

        \u300c\u63d2\u5165\u6392\u5e8f insertion sort\u300d\u662f\u4e00\u79cd\u7b80\u5355\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5b83\u7684\u5de5\u4f5c\u539f\u7406\u4e0e\u624b\u52a8\u6574\u7406\u4e00\u526f\u724c\u7684\u8fc7\u7a0b\u975e\u5e38\u76f8\u4f3c\u3002

        \u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u5728\u672a\u6392\u5e8f\u533a\u95f4\u9009\u62e9\u4e00\u4e2a\u57fa\u51c6\u5143\u7d20\uff0c\u5c06\u8be5\u5143\u7d20\u4e0e\u5176\u5de6\u4fa7\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u5143\u7d20\u9010\u4e00\u6bd4\u8f83\u5927\u5c0f\uff0c\u5e76\u5c06\u8be5\u5143\u7d20\u63d2\u5165\u5230\u6b63\u786e\u7684\u4f4d\u7f6e\u3002

        \u56fe 11-6 \u5c55\u793a\u4e86\u6570\u7ec4\u63d2\u5165\u5143\u7d20\u7684\u64cd\u4f5c\u6d41\u7a0b\u3002\u8bbe\u57fa\u51c6\u5143\u7d20\u4e3a base \uff0c\u6211\u4eec\u9700\u8981\u5c06\u4ece\u76ee\u6807\u7d22\u5f15\u5230 base \u4e4b\u95f4\u7684\u6240\u6709\u5143\u7d20\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\uff0c\u7136\u540e\u5c06 base \u8d4b\u503c\u7ed9\u76ee\u6807\u7d22\u5f15\u3002

        \u56fe 11-6 \u00a0 \u5355\u6b21\u63d2\u5165\u64cd\u4f5c

        "},{"location":"chapter_sorting/insertion_sort/#1141","title":"11.4.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u63d2\u5165\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-7 \u6240\u793a\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6570\u7ec4\u7684\u7b2c 1 \u4e2a\u5143\u7d20\u5df2\u5b8c\u6210\u6392\u5e8f\u3002
        2. \u9009\u53d6\u6570\u7ec4\u7684\u7b2c 2 \u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6570\u7ec4\u7684\u524d 2 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        3. \u9009\u53d6\u7b2c 3 \u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6570\u7ec4\u7684\u524d 3 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        4. \u4ee5\u6b64\u7c7b\u63a8\uff0c\u5728\u6700\u540e\u4e00\u8f6e\u4e2d\uff0c\u9009\u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a base \uff0c\u5c06\u5176\u63d2\u5165\u5230\u6b63\u786e\u4f4d\u7f6e\u540e\uff0c\u6240\u6709\u5143\u7d20\u5747\u5df2\u6392\u5e8f\u3002

        \u56fe 11-7 \u00a0 \u63d2\u5165\u6392\u5e8f\u6d41\u7a0b

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig insertion_sort.py
        def insertion_sort(nums: list[int]):\n\"\"\"\u63d2\u5165\u6392\u5e8f\"\"\"\n# \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u533a\u95f4\u4e3a [0, i-1]\nfor i in range(1, len(nums)):\nbase = nums[i]\nj = i - 1\n# \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u533a\u95f4 [0, i-1] \u4e2d\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0 and nums[j] > base:\nnums[j + 1] = nums[j]  # \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1\nnums[j + 1] = base  # \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n
        insertion_sort.cpp
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(vector<int> &nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.size(); i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.java
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.length; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base;        // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.cs
        /* \u63d2\u5165\u6392\u5e8f */\nvoid InsertionSort(int[] nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.Length; i++) {\nint bas = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > bas) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = bas;         // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.go
        /* \u63d2\u5165\u6392\u5e8f */\nfunc insertionSort(nums []int) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\nfor i := 1; i < len(nums); i++ {\nbase := nums[i]\nj := i - 1\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nfor j >= 0 && nums[j] > base {\nnums[j+1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--\n}\nnums[j+1] = base // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.swift
        /* \u63d2\u5165\u6392\u5e8f */\nfunc insertionSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor i in stride(from: 1, to: nums.count, by: 1) {\nlet base = nums[i]\nvar j = i - 1\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0, nums[j] > base {\nnums[j + 1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1\n}\nnums[j + 1] = base // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.js
        /* \u63d2\u5165\u6392\u5e8f */\nfunction insertionSort(nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (let i = 1; i < nums.length; i++) {\nlet base = nums[i],\nj = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.ts
        /* \u63d2\u5165\u6392\u5e8f */\nfunction insertionSort(nums: number[]): void {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (let i = 1; i < nums.length; i++) {\nconst base = nums[i];\nlet j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.dart
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(List<int> nums) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < nums.length; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\nnums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj--;\n}\nnums[j + 1] = base; // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.rs
        /* \u63d2\u5165\u6392\u5e8f */\nfn insertion_sort(nums: &mut [i32]) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor i in 1..nums.len() {\nlet (base, mut j) = (nums[i],  (i - 1) as i32);\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile j >= 0 && nums[j as usize] > base {\nnums[(j + 1) as usize] = nums[j as usize]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nj -= 1;\n}\nnums[(j + 1) as usize] = base;  // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        insertion_sort.c
        /* \u63d2\u5165\u6392\u5e8f */\nvoid insertionSort(int nums[], int size) {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nfor (int i = 1; i < size; i++) {\nint base = nums[i], j = i - 1;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 0 && nums[j] > base) {\n// \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\nnums[j + 1] = nums[j];\nj--;\n}\n// \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\nnums[j + 1] = base;\n}\n}\n
        insertion_sort.zig
        // \u63d2\u5165\u6392\u5e8f\nfn insertionSort(nums: []i32) void {\n// \u5916\u5faa\u73af\uff1a\u5df2\u6392\u5e8f\u5143\u7d20\u6570\u91cf\u4e3a 1, 2, ..., n\nvar i: usize = 1;\nwhile (i < nums.len) : (i += 1) {\nvar base = nums[i];\nvar j: usize = i;\n// \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\nwhile (j >= 1 and nums[j - 1] > base) : (j -= 1) {\nnums[j] = nums[j - 1];  // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n}\nnums[j] = base;             // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n}\n}\n
        "},{"location":"chapter_sorting/insertion_sort/#1142","title":"11.4.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n^2)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u63d2\u5165\u64cd\u4f5c\u5206\u522b\u9700\u8981\u5faa\u73af \\(n - 1\\)\u3001\\(n-2\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \u6b21\uff0c\u6c42\u548c\u5f97\u5230 \\((n - 1) n / 2\\) \uff0c\u56e0\u6b64\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002\u5728\u9047\u5230\u6709\u5e8f\u6570\u636e\u65f6\uff0c\u63d2\u5165\u64cd\u4f5c\u4f1a\u63d0\u524d\u7ec8\u6b62\u3002\u5f53\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u6709\u5e8f\u65f6\uff0c\u63d2\u5165\u6392\u5e8f\u8fbe\u5230\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u63d2\u5165\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u4f1a\u5c06\u5143\u7d20\u63d2\u5165\u5230\u76f8\u7b49\u5143\u7d20\u7684\u53f3\u4fa7\uff0c\u4e0d\u4f1a\u6539\u53d8\u5b83\u4eec\u7684\u987a\u5e8f\u3002
        "},{"location":"chapter_sorting/insertion_sort/#1143","title":"11.4.3 \u00a0 \u63d2\u5165\u6392\u5e8f\u4f18\u52bf","text":"

        \u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u800c\u6211\u4eec\u5373\u5c06\u5b66\u4e60\u7684\u5feb\u901f\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u5c3d\u7ba1\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u66f4\u9ad8\uff0c\u4f46\u5728\u6570\u636e\u91cf\u8f83\u5c0f\u7684\u60c5\u51b5\u4e0b\uff0c\u63d2\u5165\u6392\u5e8f\u901a\u5e38\u66f4\u5feb\u3002

        \u8fd9\u4e2a\u7ed3\u8bba\u4e0e\u7ebf\u6027\u67e5\u627e\u548c\u4e8c\u5206\u67e5\u627e\u7684\u9002\u7528\u60c5\u51b5\u7684\u7ed3\u8bba\u7c7b\u4f3c\u3002\u5feb\u901f\u6392\u5e8f\u8fd9\u7c7b \\(O(n \\log n)\\) \u7684\u7b97\u6cd5\u5c5e\u4e8e\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5f80\u5f80\u5305\u542b\u66f4\u591a\u5355\u5143\u8ba1\u7b97\u64cd\u4f5c\u3002\u800c\u5728\u6570\u636e\u91cf\u8f83\u5c0f\u65f6\uff0c\\(n^2\\) \u548c \\(n \\log n\\) \u7684\u6570\u503c\u6bd4\u8f83\u63a5\u8fd1\uff0c\u590d\u6742\u5ea6\u4e0d\u5360\u4e3b\u5bfc\u5730\u4f4d\uff1b\u6bcf\u8f6e\u4e2d\u7684\u5355\u5143\u64cd\u4f5c\u6570\u91cf\u8d77\u5230\u51b3\u5b9a\u6027\u4f5c\u7528\u3002

        \u5b9e\u9645\u4e0a\uff0c\u8bb8\u591a\u7f16\u7a0b\u8bed\u8a00\uff08\u4f8b\u5982 Java\uff09\u7684\u5185\u7f6e\u6392\u5e8f\u51fd\u6570\u91c7\u7528\u4e86\u63d2\u5165\u6392\u5e8f\uff0c\u5927\u81f4\u601d\u8def\u4e3a\uff1a\u5bf9\u4e8e\u957f\u6570\u7ec4\uff0c\u91c7\u7528\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u4f8b\u5982\u5feb\u901f\u6392\u5e8f\uff1b\u5bf9\u4e8e\u77ed\u6570\u7ec4\uff0c\u76f4\u63a5\u4f7f\u7528\u63d2\u5165\u6392\u5e8f\u3002

        \u867d\u7136\u5192\u6ce1\u6392\u5e8f\u3001\u9009\u62e9\u6392\u5e8f\u548c\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \uff0c\u4f46\u5728\u5b9e\u9645\u60c5\u51b5\u4e2d\uff0c\u63d2\u5165\u6392\u5e8f\u7684\u4f7f\u7528\u9891\u7387\u663e\u8457\u9ad8\u4e8e\u5192\u6ce1\u6392\u5e8f\u548c\u9009\u62e9\u6392\u5e8f\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u5192\u6ce1\u6392\u5e8f\u57fa\u4e8e\u5143\u7d20\u4ea4\u6362\u5b9e\u73b0\uff0c\u9700\u8981\u501f\u52a9\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf\uff0c\u5171\u6d89\u53ca 3 \u4e2a\u5355\u5143\u64cd\u4f5c\uff1b\u63d2\u5165\u6392\u5e8f\u57fa\u4e8e\u5143\u7d20\u8d4b\u503c\u5b9e\u73b0\uff0c\u4ec5\u9700 1 \u4e2a\u5355\u5143\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u5192\u6ce1\u6392\u5e8f\u7684\u8ba1\u7b97\u5f00\u9500\u901a\u5e38\u6bd4\u63d2\u5165\u6392\u5e8f\u66f4\u9ad8\u3002
        • \u9009\u62e9\u6392\u5e8f\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(n^2)\\) \u3002\u5982\u679c\u7ed9\u5b9a\u4e00\u7ec4\u90e8\u5206\u6709\u5e8f\u7684\u6570\u636e\uff0c\u63d2\u5165\u6392\u5e8f\u901a\u5e38\u6bd4\u9009\u62e9\u6392\u5e8f\u6548\u7387\u66f4\u9ad8\u3002
        • \u9009\u62e9\u6392\u5e8f\u4e0d\u7a33\u5b9a\uff0c\u65e0\u6cd5\u5e94\u7528\u4e8e\u591a\u7ea7\u6392\u5e8f\u3002
        "},{"location":"chapter_sorting/merge_sort/","title":"11.6 \u00a0 \u5f52\u5e76\u6392\u5e8f","text":"

        \u300c\u5f52\u5e76\u6392\u5e8f merge sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5305\u542b\u56fe 11-10 \u6240\u793a\u7684\u201c\u5212\u5206\u201d\u548c\u201c\u5408\u5e76\u201d\u9636\u6bb5\u3002

        1. \u5212\u5206\u9636\u6bb5\uff1a\u901a\u8fc7\u9012\u5f52\u4e0d\u65ad\u5730\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5904\u5206\u5f00\uff0c\u5c06\u957f\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u8f6c\u6362\u4e3a\u77ed\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u3002
        2. \u5408\u5e76\u9636\u6bb5\uff1a\u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u5212\u5206\uff0c\u5f00\u59cb\u5408\u5e76\uff0c\u6301\u7eed\u5730\u5c06\u5de6\u53f3\u4e24\u4e2a\u8f83\u77ed\u7684\u6709\u5e8f\u6570\u7ec4\u5408\u5e76\u4e3a\u4e00\u4e2a\u8f83\u957f\u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u76f4\u81f3\u7ed3\u675f\u3002

        \u56fe 11-10 \u00a0 \u5f52\u5e76\u6392\u5e8f\u7684\u5212\u5206\u4e0e\u5408\u5e76\u9636\u6bb5

        "},{"location":"chapter_sorting/merge_sort/#1161","title":"11.6.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u5982\u56fe 11-11 \u6240\u793a\uff0c\u201c\u5212\u5206\u9636\u6bb5\u201d\u4ece\u9876\u81f3\u5e95\u9012\u5f52\u5730\u5c06\u6570\u7ec4\u4ece\u4e2d\u70b9\u5207\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\u3002

        1. \u8ba1\u7b97\u6570\u7ec4\u4e2d\u70b9 mid \uff0c\u9012\u5f52\u5212\u5206\u5de6\u5b50\u6570\u7ec4\uff08\u533a\u95f4 [left, mid] \uff09\u548c\u53f3\u5b50\u6570\u7ec4\uff08\u533a\u95f4 [mid + 1, right] \uff09\u3002
        2. \u9012\u5f52\u6267\u884c\u6b65\u9aa4 1. \uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u533a\u95f4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u3002

        \u201c\u5408\u5e76\u9636\u6bb5\u201d\u4ece\u5e95\u81f3\u9876\u5730\u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u5408\u5e76\u4e3a\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ece\u957f\u5ea6\u4e3a 1 \u7684\u5b50\u6570\u7ec4\u5f00\u59cb\u5408\u5e76\uff0c\u5408\u5e76\u9636\u6bb5\u4e2d\u7684\u6bcf\u4e2a\u5b50\u6570\u7ec4\u90fd\u662f\u6709\u5e8f\u7684\u3002

        <1><2><3><4><5><6><7><8><9><10>

        \u56fe 11-11 \u00a0 \u5f52\u5e76\u6392\u5e8f\u6b65\u9aa4

        \u89c2\u5bdf\u53d1\u73b0\uff0c\u5f52\u5e76\u6392\u5e8f\u4e0e\u4e8c\u53c9\u6811\u540e\u5e8f\u904d\u5386\u7684\u9012\u5f52\u987a\u5e8f\u662f\u4e00\u81f4\u7684\u3002

        • \u540e\u5e8f\u904d\u5386\uff1a\u5148\u9012\u5f52\u5de6\u5b50\u6811\uff0c\u518d\u9012\u5f52\u53f3\u5b50\u6811\uff0c\u6700\u540e\u5904\u7406\u6839\u8282\u70b9\u3002
        • \u5f52\u5e76\u6392\u5e8f\uff1a\u5148\u9012\u5f52\u5de6\u5b50\u6570\u7ec4\uff0c\u518d\u9012\u5f52\u53f3\u5b50\u6570\u7ec4\uff0c\u6700\u540e\u5904\u7406\u5408\u5e76\u3002

        \u5f52\u5e76\u6392\u5e8f\u7684\u5b9e\u73b0\u5982\u4ee5\u4e0b\u4ee3\u7801\u6240\u793a\u3002\u8bf7\u6ce8\u610f\uff0cnums \u7684\u5f85\u5408\u5e76\u533a\u95f4\u4e3a [left, right] \uff0c\u800c tmp \u7684\u5bf9\u5e94\u533a\u95f4\u4e3a [0, right - left] \u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig merge_sort.py
        def merge(nums: list[int], left: int, mid: int, right: int):\n\"\"\"\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\"\"\"\n# \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n# \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\ntmp = [0] * (right - left + 1)\n# \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\ni, j, k = left, mid + 1, 0\n# \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid and j <= right:\nif nums[i] <= nums[j]:\ntmp[k] = nums[i]\ni += 1\nelse:\ntmp[k] = nums[j]\nj += 1\nk += 1\n# \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid:\ntmp[k] = nums[i]\ni += 1\nk += 1\nwhile j <= right:\ntmp[k] = nums[j]\nj += 1\nk += 1\n# \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in range(0, len(tmp)):\nnums[left + k] = tmp[k]\ndef merge_sort(nums: list[int], left: int, right: int):\n\"\"\"\u5f52\u5e76\u6392\u5e8f\"\"\"\n# \u7ec8\u6b62\u6761\u4ef6\nif left >= right:\nreturn  # \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n# \u5212\u5206\u9636\u6bb5\nmid = (left + right) // 2  # \u8ba1\u7b97\u4e2d\u70b9\nmerge_sort(nums, left, mid)  # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmerge_sort(nums, mid + 1, right)  # \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n# \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right)\n
        merge_sort.cpp
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(vector<int> &nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nvector<int> tmp(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.size(); k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(vector<int> &nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.java
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(int[] nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint[] tmp = new int[right - left + 1];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int[] nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2; // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.cs
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid Merge(int[] nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint[] tmp = new int[right - left + 1];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.Length; ++k) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid MergeSort(int[] nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return;       // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nMergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nMergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nMerge(nums, left, mid, right);\n}\n
        merge_sort.go
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunc merge(nums []int, left, mid, right int) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\ntmp := make([]int, right-left+1)\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\ni, j, k := left, mid+1, 0\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nfor i <= mid && j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[i]\ni++\n} else {\ntmp[k] = nums[j]\nj++\n}\nk++\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nfor i <= mid {\ntmp[k] = nums[i]\ni++\nk++\n}\nfor j <= right {\ntmp[k] = nums[j]\nj++\nk++\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k := 0; k < len(tmp); k++ {\nnums[left+k] = tmp[k]\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums []int, left, right int) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right {\nreturn\n}\n// \u5212\u5206\u9636\u6bb5\nmid := (left + right) / 2\nmergeSort(nums, left, mid)\nmergeSort(nums, mid+1, right)\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right)\n}\n
        merge_sort.swift
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunc merge(nums: inout [Int], left: Int, mid: Int, right: Int) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nvar tmp = Array(repeating: 0, count: right - left + 1)\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nvar i = left, j = mid + 1, k = 0\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid, j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[i]\ni += 1\nk += 1\n} else {\ntmp[k] = nums[j]\nj += 1\nk += 1\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid {\ntmp[k] = nums[i]\ni += 1\nk += 1\n}\nwhile j <= right {\ntmp[k] = nums[j]\nj += 1\nk += 1\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in tmp.indices {\nnums[left + k] = tmp[k]\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums: inout [Int], left: Int, right: Int) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right { // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nreturn\n}\n// \u5212\u5206\u9636\u6bb5\nlet mid = (left + right) / 2 // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums: &nums, left: left, right: mid) // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums: &nums, left: mid + 1, right: right) // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums: &nums, left: left, mid: mid, right: right)\n}\n
        merge_sort.js
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunction merge(nums, left, mid, right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nconst tmp = new Array(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet i = left,\nj = mid + 1,\nk = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums, left, right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.ts
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfunction merge(nums: number[], left: number, mid: number, right: number): void {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nconst tmp = new Array(right - left + 1);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet i = left,\nj = mid + 1,\nk = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums: number[], left: number, right: number): void {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.dart
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(List<int> nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nList<int> tmp = List.filled(right - left + 1, 0);\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j])\ntmp[k++] = nums[i++];\nelse\ntmp[k++] = nums[j++];\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmp.length; k++) {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(List<int> nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.rs
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nfn merge(nums: &mut [i32], left: usize, mid: usize, right: usize) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nlet tmp_size = right - left + 1;\nlet mut tmp = vec![0; tmp_size];\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nlet (mut i, mut j, mut k) = (left, mid + 1, 0);\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid && j <= right {\nif nums[i] <= nums[j] {\ntmp[k] = nums[j];\ni += 1;\n} else {\ntmp[k] = nums[j];\nj += 1;\n}\nk += 1;\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile i <= mid {\ntmp[k] = nums[i];\nk += 1;\ni += 1;\n}\nwhile j <= right {\ntmp[k] = nums[j];\nk += 1;\nj += 1;\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor k in 0..tmp_size {\nnums[left + k] = tmp[k];\n}\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nfn merge_sort(nums: &mut [i32], left: usize, right: usize) {\n// \u7ec8\u6b62\u6761\u4ef6\nif left >= right { return; }             // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nlet mid = (left + right) / 2;     // \u8ba1\u7b97\u4e2d\u70b9\nmerge_sort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmerge_sort(nums, mid + 1, right);  // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.c
        /* \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4 */\nvoid merge(int *nums, int left, int mid, int right) {\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid+1, right]\n// \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\nint tmpSize = right - left + 1;\nint *tmp = (int *)malloc(tmpSize * sizeof(int));\n// \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\nint i = left, j = mid + 1, k = 0;\n// \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid && j <= right) {\nif (nums[i] <= nums[j]) {\ntmp[k++] = nums[i++];\n} else {\ntmp[k++] = nums[j++];\n}\n}\n// \u5c06\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u5269\u4f59\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\nwhile (i <= mid) {\ntmp[k++] = nums[i++];\n}\nwhile (j <= right) {\ntmp[k++] = nums[j++];\n}\n// \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\nfor (k = 0; k < tmpSize; ++k) {\nnums[left + k] = tmp[k];\n}\n// \u91ca\u653e\u5185\u5b58\nfree(tmp);\n}\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int *nums, int left, int right) {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right)\nreturn; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nint mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\nmergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\nmergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\nmerge(nums, left, mid, right);\n}\n
        merge_sort.zig
        // \u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\n// \u5de6\u5b50\u6570\u7ec4\u533a\u95f4 [left, mid]\n// \u53f3\u5b50\u6570\u7ec4\u533a\u95f4 [mid + 1, right]\nfn merge(nums: []i32, left: usize, mid: usize, right: usize) !void {\n// \u521d\u59cb\u5316\u8f85\u52a9\u6570\u7ec4\nvar mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\ndefer mem_arena.deinit();\nconst mem_allocator = mem_arena.allocator();\nvar tmp = try mem_allocator.alloc(i32, right + 1 - left);\nstd.mem.copy(i32, tmp, nums[left..right+1]);\n// \u5de6\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15  \nvar leftStart = left - left;\nvar leftEnd = mid - left;\n// \u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15       \nvar rightStart = mid + 1 - left;\nvar rightEnd = right - left;\n// i, j \u5206\u522b\u6307\u5411\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\u7684\u9996\u5143\u7d20\nvar i = leftStart;\nvar j = rightStart;\n// \u901a\u8fc7\u8986\u76d6\u539f\u6570\u7ec4 nums \u6765\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\nvar k = left;\nwhile (k <= right) : (k += 1) {\n// \u82e5\u201c\u5de6\u5b50\u6570\u7ec4\u5df2\u5168\u90e8\u5408\u5e76\u5b8c\u201d\uff0c\u5219\u9009\u53d6\u53f3\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 j++\nif (i > leftEnd) {\nnums[k] = tmp[j];\nj += 1;\n// \u5426\u5219\uff0c\u82e5\u201c\u53f3\u5b50\u6570\u7ec4\u5df2\u5168\u90e8\u5408\u5e76\u5b8c\u201d\u6216\u201c\u5de6\u5b50\u6570\u7ec4\u5143\u7d20 <= \u53f3\u5b50\u6570\u7ec4\u5143\u7d20\u201d\uff0c\u5219\u9009\u53d6\u5de6\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 i++\n} else if  (j > rightEnd or tmp[i] <= tmp[j]) {\nnums[k] = tmp[i];\ni += 1;\n// \u5426\u5219\uff0c\u82e5\u201c\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u672a\u5168\u90e8\u5408\u5e76\u5b8c\u201d\u4e14\u201c\u5de6\u5b50\u6570\u7ec4\u5143\u7d20 > \u53f3\u5b50\u6570\u7ec4\u5143\u7d20\u201d\uff0c\u5219\u9009\u53d6\u53f3\u5b50\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14 j++\n} else {\nnums[k] = tmp[j];\nj += 1;\n}\n}\n}\n// \u5f52\u5e76\u6392\u5e8f\nfn mergeSort(nums: []i32, left: usize, right: usize) !void {\n// \u7ec8\u6b62\u6761\u4ef6\nif (left >= right) return;              // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n// \u5212\u5206\u9636\u6bb5\nvar mid = (left + right) / 2;           // \u8ba1\u7b97\u4e2d\u70b9\ntry mergeSort(nums, left, mid);         // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\ntry mergeSort(nums, mid + 1, right);    // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n// \u5408\u5e76\u9636\u6bb5\ntry merge(nums, left, mid, right);\n}\n
        "},{"location":"chapter_sorting/merge_sort/#1162","title":"11.6.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5212\u5206\u4ea7\u751f\u9ad8\u5ea6\u4e3a \\(\\log n\\) \u7684\u9012\u5f52\u6811\uff0c\u6bcf\u5c42\u5408\u5e76\u7684\u603b\u64cd\u4f5c\u6570\u91cf\u4e3a \\(n\\) \uff0c\u56e0\u6b64\u603b\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u9012\u5f52\u6df1\u5ea6\u4e3a \\(\\log n\\) \uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\u3002\u5408\u5e76\u64cd\u4f5c\u9700\u8981\u501f\u52a9\u8f85\u52a9\u6570\u7ec4\u5b9e\u73b0\uff0c\u4f7f\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u5408\u5e76\u8fc7\u7a0b\u4e2d\uff0c\u76f8\u7b49\u5143\u7d20\u7684\u6b21\u5e8f\u4fdd\u6301\u4e0d\u53d8\u3002
        "},{"location":"chapter_sorting/merge_sort/#1163","title":"11.6.3 \u00a0 \u94fe\u8868\u6392\u5e8f","text":"

        \u5bf9\u4e8e\u94fe\u8868\uff0c\u5f52\u5e76\u6392\u5e8f\u76f8\u8f83\u4e8e\u5176\u4ed6\u6392\u5e8f\u7b97\u6cd5\u5177\u6709\u663e\u8457\u4f18\u52bf\uff0c\u53ef\u4ee5\u5c06\u94fe\u8868\u6392\u5e8f\u4efb\u52a1\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(1)\\) \u3002

        • \u5212\u5206\u9636\u6bb5\uff1a\u53ef\u4ee5\u4f7f\u7528\u201c\u8fed\u4ee3\u201d\u66ff\u4ee3\u201c\u9012\u5f52\u201d\u6765\u5b9e\u73b0\u94fe\u8868\u5212\u5206\u5de5\u4f5c\uff0c\u4ece\u800c\u7701\u53bb\u9012\u5f52\u4f7f\u7528\u7684\u6808\u5e27\u7a7a\u95f4\u3002
        • \u5408\u5e76\u9636\u6bb5\uff1a\u5728\u94fe\u8868\u4e2d\uff0c\u8282\u70b9\u589e\u5220\u64cd\u4f5c\u4ec5\u9700\u6539\u53d8\u5f15\u7528\uff08\u6307\u9488\uff09\u5373\u53ef\u5b9e\u73b0\uff0c\u56e0\u6b64\u5408\u5e76\u9636\u6bb5\uff08\u5c06\u4e24\u4e2a\u77ed\u6709\u5e8f\u94fe\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u957f\u6709\u5e8f\u94fe\u8868\uff09\u65e0\u987b\u521b\u5efa\u989d\u5916\u94fe\u8868\u3002

        \u5177\u4f53\u5b9e\u73b0\u7ec6\u8282\u6bd4\u8f83\u590d\u6742\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u67e5\u9605\u76f8\u5173\u8d44\u6599\u8fdb\u884c\u5b66\u4e60\u3002

        "},{"location":"chapter_sorting/quick_sort/","title":"11.5 \u00a0 \u5feb\u901f\u6392\u5e8f","text":"

        \u300c\u5feb\u901f\u6392\u5e8f quick sort\u300d\u662f\u4e00\u79cd\u57fa\u4e8e\u5206\u6cbb\u7b56\u7565\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u8fd0\u884c\u9ad8\u6548\uff0c\u5e94\u7528\u5e7f\u6cdb\u3002

        \u5feb\u901f\u6392\u5e8f\u7684\u6838\u5fc3\u64cd\u4f5c\u662f\u201c\u54e8\u5175\u5212\u5206\u201d\uff0c\u5176\u76ee\u6807\u662f\uff1a\u9009\u62e9\u6570\u7ec4\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u4f5c\u4e3a\u201c\u57fa\u51c6\u6570\u201d\uff0c\u5c06\u6240\u6709\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\u79fb\u5230\u5176\u5de6\u4fa7\uff0c\u800c\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\u79fb\u5230\u5176\u53f3\u4fa7\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u54e8\u5175\u5212\u5206\u7684\u6d41\u7a0b\u5982\u56fe 11-8 \u6240\u793a\u3002

        1. \u9009\u53d6\u6570\u7ec4\u6700\u5de6\u7aef\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\uff0c\u521d\u59cb\u5316\u4e24\u4e2a\u6307\u9488 i \u548c j \u5206\u522b\u6307\u5411\u6570\u7ec4\u7684\u4e24\u7aef\u3002
        2. \u8bbe\u7f6e\u4e00\u4e2a\u5faa\u73af\uff0c\u5728\u6bcf\u8f6e\u4e2d\u4f7f\u7528 i\uff08j\uff09\u5206\u522b\u5bfb\u627e\u7b2c\u4e00\u4e2a\u6bd4\u57fa\u51c6\u6570\u5927\uff08\u5c0f\uff09\u7684\u5143\u7d20\uff0c\u7136\u540e\u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\u3002
        3. \u5faa\u73af\u6267\u884c\u6b65\u9aa4 2. \uff0c\u76f4\u5230 i \u548c j \u76f8\u9047\u65f6\u505c\u6b62\uff0c\u6700\u540e\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u4e2a\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\u3002
        <1><2><3><4><5><6><7><8><9>

        \u56fe 11-8 \u00a0 \u54e8\u5175\u5212\u5206\u6b65\u9aa4

        \u54e8\u5175\u5212\u5206\u5b8c\u6210\u540e\uff0c\u539f\u6570\u7ec4\u88ab\u5212\u5206\u6210\u4e09\u90e8\u5206\uff1a\u5de6\u5b50\u6570\u7ec4\u3001\u57fa\u51c6\u6570\u3001\u53f3\u5b50\u6570\u7ec4\uff0c\u4e14\u6ee1\u8db3\u201c\u5de6\u5b50\u6570\u7ec4\u4efb\u610f\u5143\u7d20 \\(\\leq\\) \u57fa\u51c6\u6570 \\(\\leq\\) \u53f3\u5b50\u6570\u7ec4\u4efb\u610f\u5143\u7d20\u201d\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u53ea\u9700\u5bf9\u8fd9\u4e24\u4e2a\u5b50\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u3002

        \u5feb\u901f\u6392\u5e8f\u7684\u5206\u6cbb\u7b56\u7565

        \u54e8\u5175\u5212\u5206\u7684\u5b9e\u8d28\u662f\u5c06\u4e00\u4e2a\u8f83\u957f\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u7b80\u5316\u4e3a\u4e24\u4e2a\u8f83\u77ed\u6570\u7ec4\u7684\u6392\u5e8f\u95ee\u9898\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def partition(self, nums: list[int], left: int, right: int) -> int:\n\"\"\"\u54e8\u5175\u5212\u5206\"\"\"\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j = left, right\nwhile i < j:\nwhile i < j and nums[j] >= nums[left]:\nj -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile i < j and nums[i] <= nums[left]:\ni += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n# \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n# \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
        quick_sort.cpp
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(vector<int> &nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint partition(vector<int> &nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.java
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(int[] nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint partition(int[] nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.cs
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid Swap(int[] nums, int i, int j) {\n(nums[j], nums[i]) = (nums[i], nums[j]);\n}\n/* \u54e8\u5175\u5212\u5206 */\nint Partition(int[] nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nSwap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nSwap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.go
        /* \u54e8\u5175\u5212\u5206 */\nfunc (q *quickSort) partition(nums []int, left, right int) int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j := left, right\nfor i < j {\nfor i < j && nums[j] >= nums[left] {\nj-- // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nfor i < j && nums[i] <= nums[left] {\ni++ // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.swift
        /* \u5143\u7d20\u4ea4\u6362 */\nfunc swap(nums: inout [Int], i: Int, j: Int) {\nlet tmp = nums[i]\nnums[i] = nums[j]\nnums[j] = tmp\n}\n/* \u54e8\u5175\u5212\u5206 */\nfunc partition(nums: inout [Int], left: Int, right: Int) -> Int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left\nvar j = right\nwhile i < j {\nwhile i < j, nums[j] >= nums[left] {\nj -= 1 // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j, nums[i] <= nums[left] {\ni += 1 // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nswap(nums: &nums, i: i, j: j) // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums: &nums, i: i, j: left) // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.js
        /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums, i, j) {\nlet tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums, left, right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.ts
        /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums: number[], i: number, j: number): void {\nlet tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums: number[], left: number, right: number): number {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n// \u5143\u7d20\u4ea4\u6362\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.dart
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid _swap(List<int> nums, int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u54e8\u5175\u5212\u5206 */\nint _partition(List<int> nums, int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n_swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\n_swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.rs
        /* \u54e8\u5175\u5212\u5206 */\nfn partition(nums: &mut [i32], left: usize, right: usize) -> usize {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet (mut i, mut j) = (left, right);\nwhile i < j {\nwhile i < j && nums[j] >= nums[left] {\nj -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j && nums[i] <= nums[left] {\ni += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nnums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nnums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\ni                    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.c
        /* \u5143\u7d20\u4ea4\u6362 */\nvoid swap(int nums[], int i, int j) {\nint tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n/* \u5feb\u901f\u6392\u5e8f\u7c7b */\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u54e8\u5175\u5212\u5206\nint partition(int nums[], int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\n// \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nj--;\n}\nwhile (i < j && nums[i] <= nums[left]) {\n// \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\ni++;\n}\n// \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\nswap(nums, i, j);\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nswap(nums, i, left);\n// \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\nreturn i;\n}\n
        quick_sort.zig
        // \u5143\u7d20\u4ea4\u6362\nfn swap(nums: []i32, i: usize, j: usize) void {\nvar tmp = nums[i];\nnums[i] = nums[j];\nnums[j] = tmp;\n}\n// \u54e8\u5175\u5212\u5206\nfn partition(nums: []i32, left: usize, right: usize) usize {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left;\nvar j = right;\nwhile (i < j) {\nwhile (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j and nums[i] <= nums[left]) i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j);   // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;               // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1151","title":"11.5.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u5feb\u901f\u6392\u5e8f\u7684\u6574\u4f53\u6d41\u7a0b\u5982\u56fe 11-9 \u6240\u793a\u3002

        1. \u9996\u5148\uff0c\u5bf9\u539f\u6570\u7ec4\u6267\u884c\u4e00\u6b21\u201c\u54e8\u5175\u5212\u5206\u201d\uff0c\u5f97\u5230\u672a\u6392\u5e8f\u7684\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u3002
        2. \u7136\u540e\uff0c\u5bf9\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u5206\u522b\u9012\u5f52\u6267\u884c\u201c\u54e8\u5175\u5212\u5206\u201d\u3002
        3. \u6301\u7eed\u9012\u5f52\uff0c\u76f4\u81f3\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\uff0c\u4ece\u800c\u5b8c\u6210\u6574\u4e2a\u6570\u7ec4\u7684\u6392\u5e8f\u3002

        \u56fe 11-9 \u00a0 \u5feb\u901f\u6392\u5e8f\u6d41\u7a0b

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def quick_sort(self, nums: list[int], left: int, right: int):\n\"\"\"\u5feb\u901f\u6392\u5e8f\"\"\"\n# \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right:\nreturn\n# \u54e8\u5175\u5212\u5206\npivot = self.partition(nums, left, right)\n# \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nself.quick_sort(nums, left, pivot - 1)\nself.quick_sort(nums, pivot + 1, right)\n
        quick_sort.cpp
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(vector<int> &nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.java
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.cs
        /* \u5feb\u901f\u6392\u5e8f */\nvoid QuickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right)\nreturn;\n// \u54e8\u5175\u5212\u5206\nint pivot = Partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nQuickSort(nums, left, pivot - 1);\nQuickSort(nums, pivot + 1, right);\n}\n
        quick_sort.go
        /* \u5feb\u901f\u6392\u5e8f */\nfunc (q *quickSort) quickSort(nums []int, left, right int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn\n}\n// \u54e8\u5175\u5212\u5206\npivot := q.partition(nums, left, right)\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nq.quickSort(nums, left, pivot-1)\nq.quickSort(nums, pivot+1, right)\n}\n
        quick_sort.swift
        /* \u5feb\u901f\u6392\u5e8f */\nfunc quickSort(nums: inout [Int], left: Int, right: Int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn\n}\n// \u54e8\u5175\u5212\u5206\nlet pivot = partition(nums: &nums, left: left, right: right)\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums: &nums, left: left, right: pivot - 1)\nquickSort(nums: &nums, left: pivot + 1, right: right)\n}\n
        quick_sort.js
        /* \u5feb\u901f\u6392\u5e8f */\nquickSort(nums, left, right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nconst pivot = this.partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nthis.quickSort(nums, left, pivot - 1);\nthis.quickSort(nums, pivot + 1, right);\n}\n
        quick_sort.ts
        /* \u5feb\u901f\u6392\u5e8f */\nquickSort(nums: number[], left: number, right: number): void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nconst pivot = this.partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nthis.quickSort(nums, left, pivot - 1);\nthis.quickSort(nums, pivot + 1, right);\n}\n
        quick_sort.dart
        /* \u5feb\u901f\u6392\u5e8f */\nvoid quickSort(List<int> nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nint pivot = _partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.rs
        /* \u5feb\u901f\u6392\u5e8f */\npub fn quick_sort(left: i32, right: i32, nums: &mut [i32]) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif left >= right {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nlet pivot = Self::partition(nums, left as usize, right as usize) as i32;\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nSelf::quick_sort(left, pivot - 1, nums);\nSelf::quick_sort(pivot + 1, right, nums);\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b */\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u54e8\u5175\u5212\u5206\nint partition(int nums[], int left, int right) {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\n// \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nj--;\n}\nwhile (i < j && nums[i] <= nums[left]) {\n// \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\ni++;\n}\n// \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\nswap(nums, i, j);\n}\n// \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nswap(nums, i, left);\n// \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\nreturn i;\n}\n// \u5feb\u901f\u6392\u5e8f\u7c7b-\u5feb\u901f\u6392\u5e8f\nvoid quickSort(int nums[], int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) {\nreturn;\n}\n// \u54e8\u5175\u5212\u5206\nint pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        quick_sort.zig
        // \u5feb\u901f\u6392\u5e8f\nfn quickSort(nums: []i32, left: usize, right: usize) void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nif (left >= right) return;\n// \u54e8\u5175\u5212\u5206\nvar pivot = partition(nums, left, right);\n// \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\nquickSort(nums, left, pivot - 1);\nquickSort(nums, pivot + 1, right);\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1152","title":"11.5.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n \\log n)\\)\u3001\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5728\u5e73\u5747\u60c5\u51b5\u4e0b\uff0c\u54e8\u5175\u5212\u5206\u7684\u9012\u5f52\u5c42\u6570\u4e3a \\(\\log n\\) \uff0c\u6bcf\u5c42\u4e2d\u7684\u603b\u5faa\u73af\u6570\u4e3a \\(n\\) \uff0c\u603b\u4f53\u4f7f\u7528 \\(O(n \\log n)\\) \u65f6\u95f4\u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u90fd\u5c06\u957f\u5ea6\u4e3a \\(n\\) \u7684\u6570\u7ec4\u5212\u5206\u4e3a\u957f\u5ea6\u4e3a \\(0\\) \u548c \\(n - 1\\) \u7684\u4e24\u4e2a\u5b50\u6570\u7ec4\uff0c\u6b64\u65f6\u9012\u5f52\u5c42\u6570\u8fbe\u5230 \\(n\\) \uff0c\u6bcf\u5c42\u4e2d\u7684\u5faa\u73af\u6570\u4e3a \\(n\\) \uff0c\u603b\u4f53\u4f7f\u7528 \\(O(n^2)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u5728\u8f93\u5165\u6570\u7ec4\u5b8c\u5168\u5012\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u8fbe\u5230\u6700\u5dee\u9012\u5f52\u6df1\u5ea6 \\(n\\) \uff0c\u4f7f\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002\u6392\u5e8f\u64cd\u4f5c\u662f\u5728\u539f\u6570\u7ec4\u4e0a\u8fdb\u884c\u7684\uff0c\u672a\u501f\u52a9\u989d\u5916\u6570\u7ec4\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5728\u54e8\u5175\u5212\u5206\u7684\u6700\u540e\u4e00\u6b65\uff0c\u57fa\u51c6\u6570\u53ef\u80fd\u4f1a\u88ab\u4ea4\u6362\u81f3\u76f8\u7b49\u5143\u7d20\u7684\u53f3\u4fa7\u3002
        "},{"location":"chapter_sorting/quick_sort/#1153","title":"11.5.3 \u00a0 \u5feb\u901f\u6392\u5e8f\u4e3a\u4ec0\u4e48\u5feb","text":"

        \u4ece\u540d\u79f0\u4e0a\u5c31\u80fd\u770b\u51fa\uff0c\u5feb\u901f\u6392\u5e8f\u5728\u6548\u7387\u65b9\u9762\u5e94\u8be5\u5177\u6709\u4e00\u5b9a\u7684\u4f18\u52bf\u3002\u5c3d\u7ba1\u5feb\u901f\u6392\u5e8f\u7684\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u201c\u5f52\u5e76\u6392\u5e8f\u201d\u548c\u201c\u5806\u6392\u5e8f\u201d\u76f8\u540c\uff0c\u4f46\u901a\u5e38\u5feb\u901f\u6392\u5e8f\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u539f\u56e0\u3002

        • \u51fa\u73b0\u6700\u5dee\u60c5\u51b5\u7684\u6982\u7387\u5f88\u4f4e\uff1a\u867d\u7136\u5feb\u901f\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u6ca1\u6709\u5f52\u5e76\u6392\u5e8f\u7a33\u5b9a\uff0c\u4f46\u5728\u7edd\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5feb\u901f\u6392\u5e8f\u80fd\u5728 \\(O(n \\log n)\\) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0b\u8fd0\u884c\u3002
        • \u7f13\u5b58\u4f7f\u7528\u6548\u7387\u9ad8\uff1a\u5728\u6267\u884c\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u65f6\uff0c\u7cfb\u7edf\u53ef\u5c06\u6574\u4e2a\u5b50\u6570\u7ec4\u52a0\u8f7d\u5230\u7f13\u5b58\uff0c\u56e0\u6b64\u8bbf\u95ee\u5143\u7d20\u7684\u6548\u7387\u8f83\u9ad8\u3002\u800c\u50cf\u201c\u5806\u6392\u5e8f\u201d\u8fd9\u7c7b\u7b97\u6cd5\u9700\u8981\u8df3\u8dc3\u5f0f\u8bbf\u95ee\u5143\u7d20\uff0c\u4ece\u800c\u7f3a\u4e4f\u8fd9\u4e00\u7279\u6027\u3002
        • \u590d\u6742\u5ea6\u7684\u5e38\u6570\u7cfb\u6570\u5c0f\uff1a\u5728\u4e0a\u8ff0\u4e09\u79cd\u7b97\u6cd5\u4e2d\uff0c\u5feb\u901f\u6392\u5e8f\u7684\u6bd4\u8f83\u3001\u8d4b\u503c\u3001\u4ea4\u6362\u7b49\u64cd\u4f5c\u7684\u603b\u6570\u91cf\u6700\u5c11\u3002\u8fd9\u4e0e\u201c\u63d2\u5165\u6392\u5e8f\u201d\u6bd4\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u66f4\u5feb\u7684\u539f\u56e0\u7c7b\u4f3c\u3002
        "},{"location":"chapter_sorting/quick_sort/#1154","title":"11.5.4 \u00a0 \u57fa\u51c6\u6570\u4f18\u5316","text":"

        \u5feb\u901f\u6392\u5e8f\u5728\u67d0\u4e9b\u8f93\u5165\u4e0b\u7684\u65f6\u95f4\u6548\u7387\u53ef\u80fd\u964d\u4f4e\u3002\u4e3e\u4e00\u4e2a\u6781\u7aef\u4f8b\u5b50\uff0c\u5047\u8bbe\u8f93\u5165\u6570\u7ec4\u662f\u5b8c\u5168\u5012\u5e8f\u7684\uff0c\u7531\u4e8e\u6211\u4eec\u9009\u62e9\u6700\u5de6\u7aef\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\uff0c\u90a3\u4e48\u5728\u54e8\u5175\u5212\u5206\u5b8c\u6210\u540e\uff0c\u57fa\u51c6\u6570\u88ab\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u53f3\u7aef\uff0c\u5bfc\u81f4\u5de6\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(n - 1\\)\u3001\u53f3\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(0\\) \u3002\u5982\u6b64\u9012\u5f52\u4e0b\u53bb\uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u540e\u7684\u53f3\u5b50\u6570\u7ec4\u957f\u5ea6\u90fd\u4e3a \\(0\\) \uff0c\u5206\u6cbb\u7b56\u7565\u5931\u6548\uff0c\u5feb\u901f\u6392\u5e8f\u9000\u5316\u4e3a\u201c\u5192\u6ce1\u6392\u5e8f\u201d\u3002

        \u4e3a\u4e86\u5c3d\u91cf\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u53d1\u751f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f18\u5316\u54e8\u5175\u5212\u5206\u4e2d\u7684\u57fa\u51c6\u6570\u7684\u9009\u53d6\u7b56\u7565\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u968f\u673a\u9009\u53d6\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u57fa\u51c6\u6570\u3002\u7136\u800c\uff0c\u5982\u679c\u8fd0\u6c14\u4e0d\u4f73\uff0c\u6bcf\u6b21\u90fd\u9009\u5230\u4e0d\u7406\u60f3\u7684\u57fa\u51c6\u6570\uff0c\u6548\u7387\u4ecd\u7136\u4e0d\u5c3d\u5982\u4eba\u610f\u3002

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7f16\u7a0b\u8bed\u8a00\u901a\u5e38\u751f\u6210\u7684\u662f\u201c\u4f2a\u968f\u673a\u6570\u201d\u3002\u5982\u679c\u6211\u4eec\u9488\u5bf9\u4f2a\u968f\u673a\u6570\u5e8f\u5217\u6784\u5efa\u4e00\u4e2a\u7279\u5b9a\u7684\u6d4b\u8bd5\u6837\u4f8b\uff0c\u90a3\u4e48\u5feb\u901f\u6392\u5e8f\u7684\u6548\u7387\u4ecd\u7136\u53ef\u80fd\u52a3\u5316\u3002

        \u4e3a\u4e86\u8fdb\u4e00\u6b65\u6539\u8fdb\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6570\u7ec4\u4e2d\u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\uff08\u901a\u5e38\u4e3a\u6570\u7ec4\u7684\u9996\u3001\u5c3e\u3001\u4e2d\u70b9\u5143\u7d20\uff09\uff0c\u5e76\u5c06\u8fd9\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\u4f5c\u4e3a\u57fa\u51c6\u6570\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u57fa\u51c6\u6570\u201c\u65e2\u4e0d\u592a\u5c0f\u4e5f\u4e0d\u592a\u5927\u201d\u7684\u6982\u7387\u5c06\u5927\u5e45\u63d0\u5347\u3002\u5f53\u7136\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u9009\u53d6\u66f4\u591a\u5019\u9009\u5143\u7d20\uff0c\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u7b97\u6cd5\u7684\u7a33\u5065\u6027\u3002\u91c7\u7528\u8fd9\u79cd\u65b9\u6cd5\u540e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n^2)\\) \u7684\u6982\u7387\u5927\u5927\u964d\u4f4e\u3002

        \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def median_three(self, nums: list[int], left: int, mid: int, right: int) -> int:\n\"\"\"\u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\"\"\"\n# \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n# \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) ^ (nums[left] < nums[right]):\nreturn left\nelif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]):\nreturn mid\nreturn right\ndef partition(self, nums: list[int], left: int, right: int) -> int:\n\"\"\"\u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09\"\"\"\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nmed = self.median_three(nums, left, (left + right) // 2, right)\n# \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums[left], nums[med] = nums[med], nums[left]\n# \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j = left, right\nwhile i < j:\nwhile i < j and nums[j] >= nums[left]:\nj -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile i < j and nums[i] <= nums[left]:\ni += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n# \u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n# \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
        quick_sort.cpp
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint medianThree(vector<int> &nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint partition(vector<int> &nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.java
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint medianThree(int[] nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint partition(int[] nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.cs
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint MedianThree(int[] nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint Partition(int[] nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = MedianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nSwap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nSwap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nSwap(nums, i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.go
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc (q *quickSortMedian) medianThree(nums []int, left, mid, right int) int {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\uff08!= \u5728\u8fd9\u91cc\u8d77\u5230\u5f02\u6216\u7684\u4f5c\u7528\uff09\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\nreturn left\n} else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\nreturn mid\n}\nreturn right\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09*/\nfunc (q *quickSortMedian) partition(nums []int, left, right int) int {\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nmed := q.medianThree(nums, left, (left+right)/2, right)\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums[left], nums[med] = nums[med], nums[left]\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\ni, j := left, right\nfor i < j {\nfor i < j && nums[j] >= nums[left] {\nj-- //\u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nfor i < j && nums[i] <= nums[left] {\ni++ //\u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\n//\u5143\u7d20\u4ea4\u6362\nnums[i], nums[j] = nums[j], nums[i]\n}\n//\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nnums[i], nums[left] = nums[left], nums[i]\nreturn i //\u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.swift
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc medianThree(nums: [Int], left: Int, mid: Int, right: Int) -> Int {\nif (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\nreturn left\n} else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\nreturn mid\n} else {\nreturn right\n}\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nfunc partitionMedian(nums: inout [Int], left: Int, right: Int) -> Int {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = medianThree(nums: nums, left: left, mid: (left + right) / 2, right: right)\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums: &nums, i: left, j: med)\nreturn partition(nums: &nums, left: left, right: right)\n}\n
        quick_sort.js
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(nums, left, mid, right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse return right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\npartition(nums, left, right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = this.medianThree(\nnums,\nleft,\nMath.floor((left + right) / 2),\nright\n);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nthis.swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.ts
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(\nnums: number[],\nleft: number,\nmid: number,\nright: number\n): number {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) {\nreturn left;\n} else if (\nNumber(nums[mid] < nums[left]) ^ Number(nums[mid] < nums[right])\n) {\nreturn mid;\n} else {\nreturn right;\n}\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\npartition(nums: number[], left: number, right: number): number {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = this.medianThree(\nnums,\nleft,\nMath.floor((left + right) / 2),\nright\n);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nthis.swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet i = left,\nj = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) {\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile (i < j && nums[i] <= nums[left]) {\ni++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nthis.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nthis.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.dart
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nint _medianThree(List<int> nums, int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nint _partition(List<int> nums, int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = _medianThree(nums, left, (left + right) ~/ 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n_swap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n_swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\n_swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.rs
        /* \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) {\nreturn left;\n} else if (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]) {\nreturn mid;\n} right\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */\nfn partition(nums: &mut [i32], left: usize, right: usize) -> usize {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nlet med = Self::median_three(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nnums.swap(left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nlet (mut i, mut j) = (left, right);\nwhile i < j {\nwhile i < j && nums[j] >= nums[left] {\nj -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nwhile i < j && nums[i] <= nums[left] {\ni += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n}\nnums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nnums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\ni                    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b\uff08\u4e2d\u4f4d\u57fa\u51c6\u6570\u4f18\u5316\uff09 */\n// \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint medianThree(int nums[], int left, int mid, int right) {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\nreturn left;\nelse if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\nreturn mid;\nelse\nreturn right;\n}\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */ int partitionMedian(int nums[], int left, int right) {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nint med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nint i = left, j = right;\nwhile (i < j) {\nwhile (i < j && nums[j] >= nums[left])\nj--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j && nums[i] <= nums[left])\ni++;          // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        quick_sort.zig
        // \u9009\u53d6\u4e09\u4e2a\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nfn medianThree(nums: []i32, left: usize, mid: usize, right: usize) usize {\n// \u6b64\u5904\u4f7f\u7528\u5f02\u6216\u8fd0\u7b97\u6765\u7b80\u5316\u4ee3\u7801\n// \u5f02\u6216\u89c4\u5219\u4e3a 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1\nif ((nums[left] < nums[mid]) != (nums[left] < nums[right])) {\nreturn left;\n} else if ((nums[mid] < nums[left]) != (nums[mid] < nums[right])) {\nreturn mid;\n} else {\nreturn right;\n}\n}\n// \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09\nfn partition(nums: []i32, left: usize, right: usize) usize {\n// \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\nvar med = medianThree(nums, left, (left + right) / 2, right);\n// \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\nswap(nums, left, med);\n// \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\nvar i = left;\nvar j = right;\nwhile (i < j) {\nwhile (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nwhile (i < j and nums[i] <= nums[left]) i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\nswap(nums, i, j);   // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n}\nswap(nums, i, left);    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\nreturn i;               // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
        "},{"location":"chapter_sorting/quick_sort/#1155","title":"11.5.5 \u00a0 \u5c3e\u9012\u5f52\u4f18\u5316","text":"

        \u5728\u67d0\u4e9b\u8f93\u5165\u4e0b\uff0c\u5feb\u901f\u6392\u5e8f\u53ef\u80fd\u5360\u7528\u7a7a\u95f4\u8f83\u591a\u3002\u4ee5\u5b8c\u5168\u5012\u5e8f\u7684\u8f93\u5165\u6570\u7ec4\u4e3a\u4f8b\uff0c\u8bbe\u9012\u5f52\u4e2d\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a \\(m\\) \uff0c\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u90fd\u5c06\u4ea7\u751f\u957f\u5ea6\u4e3a \\(0\\) \u7684\u5de6\u5b50\u6570\u7ec4\u548c\u957f\u5ea6\u4e3a \\(m - 1\\) \u7684\u53f3\u5b50\u6570\u7ec4\uff0c\u8fd9\u610f\u5473\u7740\u6bcf\u4e00\u5c42\u9012\u5f52\u8c03\u7528\u51cf\u5c11\u7684\u95ee\u9898\u89c4\u6a21\u975e\u5e38\u5c0f\uff08\u53ea\u51cf\u5c11\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u9012\u5f52\u6811\u7684\u9ad8\u5ea6\u4f1a\u8fbe\u5230 \\(n - 1\\) \uff0c\u6b64\u65f6\u9700\u8981\u5360\u7528 \\(O(n)\\) \u5927\u5c0f\u7684\u6808\u5e27\u7a7a\u95f4\u3002

        \u4e3a\u4e86\u9632\u6b62\u6808\u5e27\u7a7a\u95f4\u7684\u7d2f\u79ef\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u8f6e\u54e8\u5175\u6392\u5e8f\u5b8c\u6210\u540e\uff0c\u6bd4\u8f83\u4e24\u4e2a\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u4ec5\u5bf9\u8f83\u77ed\u7684\u5b50\u6570\u7ec4\u8fdb\u884c\u9012\u5f52\u3002\u7531\u4e8e\u8f83\u77ed\u5b50\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u4f1a\u8d85\u8fc7 \\(n / 2\\) \uff0c\u56e0\u6b64\u8fd9\u79cd\u65b9\u6cd5\u80fd\u786e\u4fdd\u9012\u5f52\u6df1\u5ea6\u4e0d\u8d85\u8fc7 \\(\\log n\\) \uff0c\u4ece\u800c\u5c06\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3 \\(O(\\log n)\\) \u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig quick_sort.py
        def quick_sort(self, nums: list[int], left: int, right: int):\n\"\"\"\u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\"\"\"\n# \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right:\n# \u54e8\u5175\u5212\u5206\u64cd\u4f5c\npivot = self.partition(nums, left, right)\n# \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif pivot - left < right - pivot:\nself.quick_sort(nums, left, pivot - 1)  # \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\nelse:\nself.quick_sort(nums, pivot + 1, right)  # \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n
        quick_sort.cpp
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(vector<int> &nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.java
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.cs
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid QuickSort(int[] nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = Partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nQuickSort(nums, left, pivot - 1);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nQuickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.go
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09*/\nfunc (q *quickSortTailCall) quickSort(nums []int, left, right int) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nfor left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\npivot := q.partition(nums, left, right)\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif pivot-left < right-pivot {\nq.quickSort(nums, left, pivot-1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nq.quickSort(nums, pivot+1, right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.swift
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nfunc quickSortTailCall(nums: inout [Int], left: Int, right: Int) {\nvar left = left\nvar right = right\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = partition(nums: &nums, left: left, right: right)\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left) < (right - pivot) {\nquickSortTailCall(nums: &nums, left: left, right: pivot - 1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSortTailCall(nums: &nums, left: pivot + 1, right: right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.js
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nquickSort(nums, left, right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = this.partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nthis.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nthis.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.ts
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nquickSort(nums: number[], left: number, right: number): void {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = this.partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nthis.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nthis.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.dart
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\nvoid quickSort(List<int> nums, int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = _partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.rs
        /* \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\npub fn quick_sort(mut left: i32, mut right: i32, nums: &mut [i32]) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile left < right {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nlet pivot = Self::partition(nums, left as usize, right as usize) as i32;\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif  pivot - left < right - pivot {\nSelf::quick_sort(left, pivot - 1, nums);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nSelf::quick_sort(pivot + 1, right, nums); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.c
        /* \u5feb\u901f\u6392\u5e8f\u7c7b\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09 */\n// \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\nvoid quickSortTailCall(int nums[], int left, int right) {\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nint pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSortTailCall(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSortTailCall(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        quick_sort.zig
        // \u5feb\u901f\u6392\u5e8f\uff08\u5c3e\u9012\u5f52\u4f18\u5316\uff09\nfn quickSort(nums: []i32, left_: usize, right_: usize) void {\nvar left = left_;\nvar right = right_;\n// \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\nwhile (left < right) {\n// \u54e8\u5175\u5212\u5206\u64cd\u4f5c\nvar pivot = partition(nums, left, right);\n// \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\nif (pivot - left < right - pivot) {\nquickSort(nums, left, pivot - 1);   // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\nleft = pivot + 1;                   // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n} else {\nquickSort(nums, pivot + 1, right);  // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\nright = pivot - 1;                  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [left, pivot - 1]\n}\n}\n}\n
        "},{"location":"chapter_sorting/radix_sort/","title":"11.10 \u00a0 \u57fa\u6570\u6392\u5e8f","text":"

        \u4e0a\u4e00\u8282\u4ecb\u7ecd\u4e86\u8ba1\u6570\u6392\u5e8f\uff0c\u5b83\u9002\u7528\u4e8e\u6570\u636e\u91cf \\(n\\) \u8f83\u5927\u4f46\u6570\u636e\u8303\u56f4 \\(m\\) \u8f83\u5c0f\u7684\u60c5\u51b5\u3002\u5047\u8bbe\u6211\u4eec\u9700\u8981\u5bf9 \\(n = 10^6\\) \u4e2a\u5b66\u53f7\u8fdb\u884c\u6392\u5e8f\uff0c\u800c\u5b66\u53f7\u662f\u4e00\u4e2a \\(8\\) \u4f4d\u6570\u5b57\uff0c\u8fd9\u610f\u5473\u7740\u6570\u636e\u8303\u56f4 \\(m = 10^8\\) \u975e\u5e38\u5927\uff0c\u4f7f\u7528\u8ba1\u6570\u6392\u5e8f\u9700\u8981\u5206\u914d\u5927\u91cf\u5185\u5b58\u7a7a\u95f4\uff0c\u800c\u57fa\u6570\u6392\u5e8f\u53ef\u4ee5\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002

        \u300c\u57fa\u6570\u6392\u5e8f radix sort\u300d\u7684\u6838\u5fc3\u601d\u60f3\u4e0e\u8ba1\u6570\u6392\u5e8f\u4e00\u81f4\uff0c\u4e5f\u901a\u8fc7\u7edf\u8ba1\u4e2a\u6570\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u57fa\u6570\u6392\u5e8f\u5229\u7528\u6570\u5b57\u5404\u4f4d\u4e4b\u95f4\u7684\u9012\u8fdb\u5173\u7cfb\uff0c\u4f9d\u6b21\u5bf9\u6bcf\u4e00\u4f4d\u8fdb\u884c\u6392\u5e8f\uff0c\u4ece\u800c\u5f97\u5230\u6700\u7ec8\u7684\u6392\u5e8f\u7ed3\u679c\u3002

        "},{"location":"chapter_sorting/radix_sort/#11101","title":"11.10.1 \u00a0 \u7b97\u6cd5\u6d41\u7a0b","text":"

        \u4ee5\u5b66\u53f7\u6570\u636e\u4e3a\u4f8b\uff0c\u5047\u8bbe\u6570\u5b57\u7684\u6700\u4f4e\u4f4d\u662f\u7b2c \\(1\\) \u4f4d\uff0c\u6700\u9ad8\u4f4d\u662f\u7b2c \\(8\\) \u4f4d\uff0c\u57fa\u6570\u6392\u5e8f\u7684\u6d41\u7a0b\u5982\u56fe 11-18 \u6240\u793a\u3002

        1. \u521d\u59cb\u5316\u4f4d\u6570 \\(k = 1\\) \u3002
        2. \u5bf9\u5b66\u53f7\u7684\u7b2c \\(k\\) \u4f4d\u6267\u884c\u201c\u8ba1\u6570\u6392\u5e8f\u201d\u3002\u5b8c\u6210\u540e\uff0c\u6570\u636e\u4f1a\u6839\u636e\u7b2c \\(k\\) \u4f4d\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u3002
        3. \u5c06 \\(k\\) \u589e\u52a0 \\(1\\) \uff0c\u7136\u540e\u8fd4\u56de\u6b65\u9aa4 2. \u7ee7\u7eed\u8fed\u4ee3\uff0c\u76f4\u5230\u6240\u6709\u4f4d\u90fd\u6392\u5e8f\u5b8c\u6210\u540e\u7ed3\u675f\u3002

        \u56fe 11-18 \u00a0 \u57fa\u6570\u6392\u5e8f\u7b97\u6cd5\u6d41\u7a0b

        \u4e0b\u9762\u5256\u6790\u4ee3\u7801\u5b9e\u73b0\u3002\u5bf9\u4e8e\u4e00\u4e2a \\(d\\) \u8fdb\u5236\u7684\u6570\u5b57 \\(x\\) \uff0c\u8981\u83b7\u53d6\u5176\u7b2c \\(k\\) \u4f4d \\(x_k\\) \uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8ba1\u7b97\u516c\u5f0f\uff1a

        \\[ x_k = \\lfloor\\frac{x}{d^{k-1}}\\rfloor \\bmod d \\]

        \u5176\u4e2d \\(\\lfloor a \\rfloor\\) \u8868\u793a\u5bf9\u6d6e\u70b9\u6570 \\(a\\) \u5411\u4e0b\u53d6\u6574\uff0c\u800c \\(\\bmod \\: d\\) \u8868\u793a\u5bf9 \\(d\\) \u53d6\u4f59\u3002\u5bf9\u4e8e\u5b66\u53f7\u6570\u636e\uff0c\\(d = 10\\) \u4e14 \\(k \\in [1, 8]\\) \u3002

        \u6b64\u5916\uff0c\u6211\u4eec\u9700\u8981\u5c0f\u5e45\u6539\u52a8\u8ba1\u6570\u6392\u5e8f\u4ee3\u7801\uff0c\u4f7f\u4e4b\u53ef\u4ee5\u6839\u636e\u6570\u5b57\u7684\u7b2c \\(k\\) \u4f4d\u8fdb\u884c\u6392\u5e8f\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig radix_sort.py
        def digit(num: int, exp: int) -> int:\n\"\"\"\u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1)\"\"\"\n# \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num // exp) % 10\ndef counting_sort_digit(nums: list[int], exp: int):\n\"\"\"\u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09\"\"\"\n# \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\ncounter = [0] * 10\nn = len(nums)\n# \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in range(n):\nd = digit(nums[i], exp)  # \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1  # \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n# \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in range(1, 10):\ncounter[i] += counter[i - 1]\n# \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nres = [0] * n\nfor i in range(n - 1, -1, -1):\nd = digit(nums[i], exp)\nj = counter[d] - 1  # \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]  # \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1  # \u5c06 d \u7684\u6570\u91cf\u51cf 1\n# \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in range(n):\nnums[i] = res[i]\ndef radix_sort(nums: list[int]):\n\"\"\"\u57fa\u6570\u6392\u5e8f\"\"\"\n# \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nm = max(nums)\n# \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nexp = 1\nwhile exp <= m:\n# \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n# k = 1 -> exp = 1\n# k = 2 -> exp = 10\n# \u5373 exp = 10^(k-1)\ncounting_sort_digit(nums, exp)\nexp *= 10\n
        radix_sort.cpp
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(vector<int> &nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvector<int> counter(10, 0);\nint n = nums.size();\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvector<int> res(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++)\nnums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(vector<int> &nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = *max_element(nums.begin(), nums.end());\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.java
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(int[] nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint[] counter = new int[10];\nint n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++)\nnums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(int[] nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = Integer.MIN_VALUE;\nfor (int num : nums)\nif (num > m)\nm = num;\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.cs
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint Digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid CountingSortDigit(int[] nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint[] counter = new int[10];\nint n = nums.Length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = Digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++;                // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint[] res = new int[n];\nfor (int i = n - 1; i >= 0; i--) {\nint d = Digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid RadixSort(int[] nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint m = int.MinValue;\nforeach (int num in nums) {\nif (num > m) m = num;\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\nCountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.go
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunc digit(num, exp int) int {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunc countingSortDigit(nums []int, exp int) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\ncounter := make([]int, 10)\nn := len(nums)\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i := 0; i < n; i++ {\nd := digit(nums[i], exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++             // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i := 1; i < 10; i++ {\ncounter[i] += counter[i-1]\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nres := make([]int, n)\nfor i := n - 1; i >= 0; i-- {\nd := digit(nums[i], exp)\nj := counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]    // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i := 0; i < n; i++ {\nnums[i] = res[i]\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunc radixSort(nums []int) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nmax := math.MinInt\nfor _, num := range nums {\nif num > max {\nmax = num\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor exp := 1; max >= exp; exp *= 10 {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp)\n}\n}\n
        radix_sort.swift
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunc digit(num: Int, exp: Int) -> Int {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\n(num / exp) % 10\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunc countingSortDigit(nums: inout [Int], exp: Int) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvar counter = Array(repeating: 0, count: 10)\nlet n = nums.count\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in nums.indices {\nlet d = digit(num: nums[i], exp: exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1 // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in 1 ..< 10 {\ncounter[i] += counter[i - 1]\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvar res = Array(repeating: 0, count: n)\nfor i in stride(from: n - 1, through: 0, by: -1) {\nlet d = digit(num: nums[i], exp: exp)\nlet j = counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i] // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1 // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in nums.indices {\nnums[i] = res[i]\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunc radixSort(nums: inout [Int]) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nvar m = Int.min\nfor num in nums {\nif num > m {\nm = num\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor exp in sequence(first: 1, next: { m >= ($0 * 10) ? $0 * 10 : nil }) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums: &nums, exp: exp)\n}\n}\n
        radix_sort.js
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunction digit(num, exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn Math.floor(num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunction countingSortDigit(nums, exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nconst counter = new Array(10).fill(0);\nconst n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (let i = 0; i < n; i++) {\nconst d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (let i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nconst res = new Array(n).fill(0);\nfor (let i = n - 1; i >= 0; i--) {\nconst d = digit(nums[i], exp);\nconst j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunction radixSort(nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = Number.MIN_VALUE;\nfor (const num of nums) {\nif (num > m) {\nm = num;\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (let exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.ts
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfunction digit(num: number, exp: number): number {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn Math.floor(num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfunction countingSortDigit(nums: number[], exp: number): void {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nconst counter = new Array(10).fill(0);\nconst n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (let i = 0; i < n; i++) {\nconst d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (let i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nconst res = new Array(n).fill(0);\nfor (let i = n - 1; i >= 0; i--) {\nconst d = digit(nums[i], exp);\nconst j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (let i = 0; i < n; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfunction radixSort(nums: number[]): void {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = Number.MIN_VALUE;\nfor (const num of nums) {\nif (num > m) {\nm = num;\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (let exp = 1; exp <= m; exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n}\n
        radix_sort.dart
        /* \u83b7\u53d6\u5143\u7d20 _num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int _num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (_num ~/ exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(List<int> nums, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nList<int> counter = List<int>.filled(10, 0);\nint n = nums.length;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < n; i++) {\nint d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d]++; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nList<int> res = List<int>.filled(n, 0);\nfor (int i = n - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < n; i++) nums[i] = res[i];\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(List<int> nums) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\n// dart \u4e2d int \u7684\u957f\u5ea6\u662f 64 \u4f4d\u7684\nint m = -1 << 63;\nfor (int _num in nums) if (_num > m) m = _num;\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; exp <= m; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, exp);\n}\n
        radix_sort.rs
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nfn digit(num: i32, exp: i32) -> usize {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn ((num / exp) % 10) as usize;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nfn counting_sort_digit(nums: &mut [i32], exp: i32) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nlet mut counter = [0; 10];\nlet n = nums.len();\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor i in 0..n {\nlet d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor i in 1..10 {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nlet mut res = vec![0; n];\nfor i in (0..n).rev() {\nlet d = digit(nums[i], exp);\nlet j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor i in 0..n {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nfn radix_sort(nums: &mut [i32]) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nlet m = *nums.into_iter().max().unwrap();\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nlet mut exp = 1;\nwhile exp <= m {\ncounting_sort_digit(nums, exp);\nexp *= 10;\n}\n}\n
        radix_sort.c
        /* \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1) */\nint digit(int num, int exp) {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn (num / exp) % 10;\n}\n/* \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09 */\nvoid countingSortDigit(int nums[], int size, int exp) {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nint *counter = (int *)malloc((sizeof(int) * 10));\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (int i = 0; i < size; i++) {\n// \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\nint d = digit(nums[i], exp);\n// \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\ncounter[d]++;\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nfor (int i = 1; i < 10; i++) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nint *res = (int *)malloc(sizeof(int) * size);\nfor (int i = size - 1; i >= 0; i--) {\nint d = digit(nums[i], exp);\nint j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\nfor (int i = 0; i < size; i++) {\nnums[i] = res[i];\n}\n}\n/* \u57fa\u6570\u6392\u5e8f */\nvoid radixSort(int nums[], int size) {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nint max = INT32_MIN;\nfor (size_t i = 0; i < size - 1; i++) {\nif (nums[i] > max) {\nmax = nums[i];\n}\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nfor (int exp = 1; max >= exp; exp *= 10)\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ncountingSortDigit(nums, size, exp);\n}\n
        radix_sort.zig
        // \u83b7\u53d6\u5143\u7d20 num \u7684\u7b2c k \u4f4d\uff0c\u5176\u4e2d exp = 10^(k-1)\nfn digit(num: i32, exp: i32) i32 {\n// \u4f20\u5165 exp \u800c\u975e k \u53ef\u4ee5\u907f\u514d\u5728\u6b64\u91cd\u590d\u6267\u884c\u6602\u8d35\u7684\u6b21\u65b9\u8ba1\u7b97\nreturn @mod(@divFloor(num, exp), 10);\n}\n// \u8ba1\u6570\u6392\u5e8f\uff08\u6839\u636e nums \u7b2c k \u4f4d\u6392\u5e8f\uff09\nfn countingSortDigit(nums: []i32, exp: i32) !void {\n// \u5341\u8fdb\u5236\u7684\u4f4d\u8303\u56f4\u4e3a 0~9 \uff0c\u56e0\u6b64\u9700\u8981\u957f\u5ea6\u4e3a 10 \u7684\u6876\u6570\u7ec4\nvar mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n// defer mem_arena.deinit();\nconst mem_allocator = mem_arena.allocator();\nvar counter = try mem_allocator.alloc(usize, 10);\n@memset(counter, 0);\nvar n = nums.len;\n// \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\nfor (nums) |num| {\nvar d: u32 = @bitCast(digit(num, exp)); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\ncounter[d] += 1; // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n}\n// \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\nvar i: usize = 1;\nwhile (i < 10) : (i += 1) {\ncounter[i] += counter[i - 1];\n}\n// \u5012\u5e8f\u904d\u5386\uff0c\u6839\u636e\u6876\u5185\u7edf\u8ba1\u7ed3\u679c\uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165 res\nvar res = try mem_allocator.alloc(i32, n);\ni = n - 1;\nwhile (i >= 0) : (i -= 1) {\nvar d: u32 = @bitCast(digit(nums[i], exp));\nvar j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\nres[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\ncounter[d] -= 1;        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\nif (i == 0) break;\n}\n// \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\ni = 0;\nwhile (i < n) : (i += 1) {\nnums[i] = res[i];\n}\n}\n// \u57fa\u6570\u6392\u5e8f\nfn radixSort(nums: []i32) !void {\n// \u83b7\u53d6\u6570\u7ec4\u7684\u6700\u5927\u5143\u7d20\uff0c\u7528\u4e8e\u5224\u65ad\u6700\u5927\u4f4d\u6570\nvar m: i32 = std.math.minInt(i32);\nfor (nums) |num| {\nif (num > m) m = num;\n}\n// \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\nvar exp: i32 = 1;\nwhile (exp <= m) : (exp *= 10) {\n// \u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u7b2c k \u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\n// k = 1 -> exp = 1\n// k = 2 -> exp = 10\n// \u5373 exp = 10^(k-1)\ntry countingSortDigit(nums, exp);    }\n} 

        \u4e3a\u4ec0\u4e48\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb\u6392\u5e8f\uff1f

        \u5728\u8fde\u7eed\u7684\u6392\u5e8f\u8f6e\u6b21\u4e2d\uff0c\u540e\u4e00\u8f6e\u6392\u5e8f\u4f1a\u8986\u76d6\u524d\u4e00\u8f6e\u6392\u5e8f\u7684\u7ed3\u679c\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u7b2c\u4e00\u8f6e\u6392\u5e8f\u7ed3\u679c \\(a < b\\) \uff0c\u800c\u7b2c\u4e8c\u8f6e\u6392\u5e8f\u7ed3\u679c \\(a > b\\) \uff0c\u90a3\u4e48\u7b2c\u4e8c\u8f6e\u7684\u7ed3\u679c\u5c06\u53d6\u4ee3\u7b2c\u4e00\u8f6e\u7684\u7ed3\u679c\u3002\u7531\u4e8e\u6570\u5b57\u7684\u9ad8\u4f4d\u4f18\u5148\u7ea7\u9ad8\u4e8e\u4f4e\u4f4d\uff0c\u56e0\u6b64\u5e94\u8be5\u5148\u6392\u5e8f\u4f4e\u4f4d\u518d\u6392\u5e8f\u9ad8\u4f4d\u3002

        "},{"location":"chapter_sorting/radix_sort/#11102","title":"11.10.2 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"

        \u76f8\u8f83\u4e8e\u8ba1\u6570\u6392\u5e8f\uff0c\u57fa\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u503c\u8303\u56f4\u8f83\u5927\u7684\u60c5\u51b5\uff0c\u4f46\u524d\u63d0\u662f\u6570\u636e\u5fc5\u987b\u53ef\u4ee5\u8868\u793a\u4e3a\u56fa\u5b9a\u4f4d\u6570\u7684\u683c\u5f0f\uff0c\u4e14\u4f4d\u6570\u4e0d\u80fd\u8fc7\u5927\u3002\u4f8b\u5982\uff0c\u6d6e\u70b9\u6570\u4e0d\u9002\u5408\u4f7f\u7528\u57fa\u6570\u6392\u5e8f\uff0c\u56e0\u4e3a\u5176\u4f4d\u6570 \\(k\\) \u8fc7\u5927\uff0c\u53ef\u80fd\u5bfc\u81f4\u65f6\u95f4\u590d\u6742\u5ea6 \\(O(nk) \\gg O(n^2)\\) \u3002

        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(nk)\\)\uff1a\u8bbe\u6570\u636e\u91cf\u4e3a \\(n\\)\u3001\u6570\u636e\u4e3a \\(d\\) \u8fdb\u5236\u3001\u6700\u5927\u4f4d\u6570\u4e3a \\(k\\) \uff0c\u5219\u5bf9\u67d0\u4e00\u4f4d\u6267\u884c\u8ba1\u6570\u6392\u5e8f\u4f7f\u7528 \\(O(n + d)\\) \u65f6\u95f4\uff0c\u6392\u5e8f\u6240\u6709 \\(k\\) \u4f4d\u4f7f\u7528 \\(O((n + d)k)\\) \u65f6\u95f4\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\\(d\\) \u548c \\(k\\) \u90fd\u76f8\u5bf9\u8f83\u5c0f\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u8d8b\u5411 \\(O(n)\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n + d)\\)\u3001\u975e\u539f\u5730\u6392\u5e8f\uff1a\u4e0e\u8ba1\u6570\u6392\u5e8f\u76f8\u540c\uff0c\u57fa\u6570\u6392\u5e8f\u9700\u8981\u501f\u52a9\u957f\u5ea6\u4e3a \\(n\\) \u548c \\(d\\) \u7684\u6570\u7ec4 res \u548c counter \u3002
        • \u7a33\u5b9a\u6392\u5e8f\uff1a\u4e0e\u8ba1\u6570\u6392\u5e8f\u76f8\u540c\u3002
        "},{"location":"chapter_sorting/selection_sort/","title":"11.2 \u00a0 \u9009\u62e9\u6392\u5e8f","text":"

        \u300c\u9009\u62e9\u6392\u5e8f selection sort\u300d\u7684\u5de5\u4f5c\u539f\u7406\u975e\u5e38\u7b80\u5355\uff1a\u5f00\u542f\u4e00\u4e2a\u5faa\u73af\uff0c\u6bcf\u8f6e\u4ece\u672a\u6392\u5e8f\u533a\u95f4\u9009\u62e9\u6700\u5c0f\u7684\u5143\u7d20\uff0c\u5c06\u5176\u653e\u5230\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u672b\u5c3e\u3002

        \u8bbe\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u9009\u62e9\u6392\u5e8f\u7684\u7b97\u6cd5\u6d41\u7a0b\u5982\u56fe 11-2 \u6240\u793a\u3002

        1. \u521d\u59cb\u72b6\u6001\u4e0b\uff0c\u6240\u6709\u5143\u7d20\u672a\u6392\u5e8f\uff0c\u5373\u672a\u6392\u5e8f\uff08\u7d22\u5f15\uff09\u533a\u95f4\u4e3a \\([0, n-1]\\) \u3002
        2. \u9009\u53d6\u533a\u95f4 \\([0, n-1]\\) \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u7d22\u5f15 \\(0\\) \u5904\u7684\u5143\u7d20\u4ea4\u6362\u3002\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u524d 1 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        3. \u9009\u53d6\u533a\u95f4 \\([1, n-1]\\) \u4e2d\u7684\u6700\u5c0f\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u7d22\u5f15 \\(1\\) \u5904\u7684\u5143\u7d20\u4ea4\u6362\u3002\u5b8c\u6210\u540e\uff0c\u6570\u7ec4\u524d 2 \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        4. \u4ee5\u6b64\u7c7b\u63a8\u3002\u7ecf\u8fc7 \\(n - 1\\) \u8f6e\u9009\u62e9\u4e0e\u4ea4\u6362\u540e\uff0c\u6570\u7ec4\u524d \\(n - 1\\) \u4e2a\u5143\u7d20\u5df2\u6392\u5e8f\u3002
        5. \u4ec5\u5269\u7684\u4e00\u4e2a\u5143\u7d20\u5fc5\u5b9a\u662f\u6700\u5927\u5143\u7d20\uff0c\u65e0\u987b\u6392\u5e8f\uff0c\u56e0\u6b64\u6570\u7ec4\u6392\u5e8f\u5b8c\u6210\u3002
        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 11-2 \u00a0 \u9009\u62e9\u6392\u5e8f\u6b65\u9aa4

        \u5728\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u7528 \\(k\\) \u6765\u8bb0\u5f55\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig selection_sort.py
        def selection_sort(nums: list[int]):\n\"\"\"\u9009\u62e9\u6392\u5e8f\"\"\"\nn = len(nums)\n# \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in range(n - 1):\n# \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nk = i\nfor j in range(i + 1, n):\nif nums[j] < nums[k]:\nk = j  # \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n# \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums[i], nums[k] = nums[k], nums[i]\n
        selection_sort.cpp
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(vector<int> &nums) {\nint n = nums.size();\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nswap(nums[i], nums[k]);\n}\n}\n
        selection_sort.java
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int[] nums) {\nint n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.cs
        /* \u9009\u62e9\u6392\u5e8f */\nvoid SelectionSort(int[] nums) {\nint n = nums.Length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n(nums[k], nums[i]) = (nums[i], nums[k]);\n}\n}\n
        selection_sort.go
        /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums []int) {\nn := len(nums)\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i := 0; i < n-1; i++ {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nk := i\nfor j := i + 1; j < n; j++ {\nif nums[j] < nums[k] {\n// \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\nk = j\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums[i], nums[k] = nums[k], nums[i]\n}\n}\n
        selection_sort.swift
        /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums: inout [Int]) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in nums.indices.dropLast() {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nvar k = i\nfor j in nums.indices.dropFirst(i + 1) {\nif nums[j] < nums[k] {\nk = j // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums.swapAt(i, k)\n}\n}\n
        selection_sort.js
        /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums) {\nlet n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (let i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet k = i;\nfor (let j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n[nums[i], nums[k]] = [nums[k], nums[i]];\n}\n}\n
        selection_sort.ts
        /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums: number[]): void {\nlet n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (let i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet k = i;\nfor (let j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\n[nums[i], nums[k]] = [nums[k], nums[i]];\n}\n}\n
        selection_sort.dart
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(List<int> nums) {\nint n = nums.length;\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k]) k = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.rs
        /* \u9009\u62e9\u6392\u5e8f */\nfn selection_sort(nums: &mut [i32]) {\nlet n = nums.len();\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor i in 0..n-1 {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nlet mut k = i;\nfor j in i+1..n {\nif nums[j] < nums[k] {\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nnums.swap(i, k);\n}\n}\n
        selection_sort.c
        /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int nums[], int n) {\n// \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\nfor (int i = 0; i < n - 1; i++) {\n// \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\nint k = i;\nfor (int j = i + 1; j < n; j++) {\nif (nums[j] < nums[k])\nk = j; // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n}\n// \u5c06\u8be5\u6700\u5c0f\u5143\u7d20\u4e0e\u672a\u6392\u5e8f\u533a\u95f4\u7684\u9996\u4e2a\u5143\u7d20\u4ea4\u6362\nint temp = nums[i];\nnums[i] = nums[k];\nnums[k] = temp;\n}\n}\n
        selection_sort.zig
        [class]{}-[func]{selectionSort}\n
        "},{"location":"chapter_sorting/selection_sort/#1121","title":"11.2.1 \u00a0 \u7b97\u6cd5\u7279\u6027","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\)\u3001\u975e\u81ea\u9002\u5e94\u6392\u5e8f\uff1a\u5916\u5faa\u73af\u5171 \\(n - 1\\) \u8f6e\uff0c\u7b2c\u4e00\u8f6e\u7684\u672a\u6392\u5e8f\u533a\u95f4\u957f\u5ea6\u4e3a \\(n\\) \uff0c\u6700\u540e\u4e00\u8f6e\u7684\u672a\u6392\u5e8f\u533a\u95f4\u957f\u5ea6\u4e3a \\(2\\) \uff0c\u5373\u5404\u8f6e\u5916\u5faa\u73af\u5206\u522b\u5305\u542b \\(n\\)\u3001\\(n - 1\\)\u3001\\(\\dots\\)\u3001\\(3\\)\u3001\\(2\\) \u8f6e\u5185\u5faa\u73af\uff0c\u6c42\u548c\u4e3a \\(\\frac{(n - 1)(n + 2)}{2}\\) \u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(1)\\)\u3001\u539f\u5730\u6392\u5e8f\uff1a\u6307\u9488 \\(i\\) \u548c \\(j\\) \u4f7f\u7528\u5e38\u6570\u5927\u5c0f\u7684\u989d\u5916\u7a7a\u95f4\u3002
        • \u975e\u7a33\u5b9a\u6392\u5e8f\uff1a\u5982\u56fe 11-3 \u6240\u793a\uff0c\u5143\u7d20 nums[i] \u6709\u53ef\u80fd\u88ab\u4ea4\u6362\u81f3\u4e0e\u5176\u76f8\u7b49\u7684\u5143\u7d20\u7684\u53f3\u8fb9\uff0c\u5bfc\u81f4\u4e24\u8005\u7684\u76f8\u5bf9\u987a\u5e8f\u53d1\u751f\u6539\u53d8\u3002

        \u56fe 11-3 \u00a0 \u9009\u62e9\u6392\u5e8f\u975e\u7a33\u5b9a\u793a\u4f8b

        "},{"location":"chapter_sorting/sorting_algorithm/","title":"11.1 \u00a0 \u6392\u5e8f\u7b97\u6cd5","text":"

        \u300c\u6392\u5e8f\u7b97\u6cd5 sorting algorithm\u300d\u7528\u4e8e\u5bf9\u4e00\u7ec4\u6570\u636e\u6309\u7167\u7279\u5b9a\u987a\u5e8f\u8fdb\u884c\u6392\u5217\u3002\u6392\u5e8f\u7b97\u6cd5\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u56e0\u4e3a\u6709\u5e8f\u6570\u636e\u901a\u5e38\u80fd\u591f\u88ab\u66f4\u9ad8\u6548\u5730\u67e5\u627e\u3001\u5206\u6790\u548c\u5904\u7406\u3002

        \u5982\u56fe 11-1 \u6240\u793a\uff0c\u6392\u5e8f\u7b97\u6cd5\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u662f\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\u7b49\u3002\u6392\u5e8f\u7684\u5224\u65ad\u89c4\u5219\u53ef\u6839\u636e\u9700\u6c42\u8bbe\u5b9a\uff0c\u5982\u6570\u5b57\u5927\u5c0f\u3001\u5b57\u7b26 ASCII \u7801\u987a\u5e8f\u6216\u81ea\u5b9a\u4e49\u89c4\u5219\u3002

        \u56fe 11-1 \u00a0 \u6570\u636e\u7c7b\u578b\u548c\u5224\u65ad\u89c4\u5219\u793a\u4f8b

        "},{"location":"chapter_sorting/sorting_algorithm/#1111","title":"11.1.1 \u00a0 \u8bc4\u4ef7\u7ef4\u5ea6","text":"

        \u8fd0\u884c\u6548\u7387\uff1a\u6211\u4eec\u671f\u671b\u6392\u5e8f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c3d\u91cf\u4f4e\uff0c\u4e14\u603b\u4f53\u64cd\u4f5c\u6570\u91cf\u8f83\u5c11\uff08\u65f6\u95f4\u590d\u6742\u5ea6\u4e2d\u7684\u5e38\u6570\u9879\u53d8\u5c0f\uff09\u3002\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u60c5\u51b5\uff0c\u8fd0\u884c\u6548\u7387\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002

        \u5c31\u5730\u6027\uff1a\u987e\u540d\u601d\u4e49\uff0c\u300c\u539f\u5730\u6392\u5e8f\u300d\u901a\u8fc7\u5728\u539f\u6570\u7ec4\u4e0a\u76f4\u63a5\u64cd\u4f5c\u5b9e\u73b0\u6392\u5e8f\uff0c\u65e0\u987b\u501f\u52a9\u989d\u5916\u7684\u8f85\u52a9\u6570\u7ec4\uff0c\u4ece\u800c\u8282\u7701\u5185\u5b58\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u539f\u5730\u6392\u5e8f\u7684\u6570\u636e\u642c\u8fd0\u64cd\u4f5c\u8f83\u5c11\uff0c\u8fd0\u884c\u901f\u5ea6\u4e5f\u66f4\u5feb\u3002

        \u7a33\u5b9a\u6027\uff1a\u300c\u7a33\u5b9a\u6392\u5e8f\u300d\u5728\u5b8c\u6210\u6392\u5e8f\u540e\uff0c\u76f8\u7b49\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u76f8\u5bf9\u987a\u5e8f\u4e0d\u53d1\u751f\u6539\u53d8\u3002

        \u7a33\u5b9a\u6392\u5e8f\u662f\u591a\u7ea7\u6392\u5e8f\u573a\u666f\u7684\u5fc5\u8981\u6761\u4ef6\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5b58\u50a8\u5b66\u751f\u4fe1\u606f\u7684\u8868\u683c\uff0c\u7b2c 1 \u5217\u548c\u7b2c 2 \u5217\u5206\u522b\u662f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u300c\u975e\u7a33\u5b9a\u6392\u5e8f\u300d\u53ef\u80fd\u5bfc\u81f4\u8f93\u5165\u6570\u636e\u7684\u6709\u5e8f\u6027\u4e27\u5931\uff1a

        # \u8f93\u5165\u6570\u636e\u662f\u6309\u7167\u59d3\u540d\u6392\u5e8f\u597d\u7684\n# (name, age)\n('A', 19)\n('B', 18)\n('C', 21)\n('D', 19)\n('E', 23)\n# \u5047\u8bbe\u4f7f\u7528\u975e\u7a33\u5b9a\u6392\u5e8f\u7b97\u6cd5\u6309\u5e74\u9f84\u6392\u5e8f\u5217\u8868\uff0c\n# \u7ed3\u679c\u4e2d ('D', 19) \u548c ('A', 19) \u7684\u76f8\u5bf9\u4f4d\u7f6e\u6539\u53d8\uff0c\n# \u8f93\u5165\u6570\u636e\u6309\u59d3\u540d\u6392\u5e8f\u7684\u6027\u8d28\u4e22\u5931\n('B', 18)\n('D', 19)\n('A', 19)\n('C', 21)\n('E', 23)\n

        \u81ea\u9002\u5e94\u6027\uff1a\u300c\u81ea\u9002\u5e94\u6392\u5e8f\u300d\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u53d7\u8f93\u5165\u6570\u636e\u7684\u5f71\u54cd\uff0c\u5373\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u3001\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u5e76\u4e0d\u5b8c\u5168\u76f8\u7b49\u3002

        \u81ea\u9002\u5e94\u6027\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u6765\u8bc4\u4f30\u3002\u5982\u679c\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u5dee\u4e8e\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u8bf4\u660e\u6392\u5e8f\u7b97\u6cd5\u5728\u67d0\u4e9b\u6570\u636e\u4e0b\u6027\u80fd\u53ef\u80fd\u52a3\u5316\uff0c\u56e0\u6b64\u88ab\u89c6\u4e3a\u8d1f\u9762\u5c5e\u6027\uff1b\u800c\u5982\u679c\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u4e8e\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u5219\u88ab\u89c6\u4e3a\u6b63\u9762\u5c5e\u6027\u3002

        \u662f\u5426\u57fa\u4e8e\u6bd4\u8f83\uff1a\u300c\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u300d\u4f9d\u8d56\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\\(<\\)\u3001\\(=\\)\u3001\\(>\\)\uff09\u6765\u5224\u65ad\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\uff0c\u4ece\u800c\u6392\u5e8f\u6574\u4e2a\u6570\u7ec4\uff0c\u7406\u8bba\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n \\log n)\\) \u3002\u800c\u300c\u975e\u6bd4\u8f83\u6392\u5e8f\u300d\u4e0d\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u8fbe \\(O(n)\\) \uff0c\u4f46\u5176\u901a\u7528\u6027\u76f8\u5bf9\u8f83\u5dee\u3002

        "},{"location":"chapter_sorting/sorting_algorithm/#1112","title":"11.1.2 \u00a0 \u7406\u60f3\u6392\u5e8f\u7b97\u6cd5","text":"

        \u8fd0\u884c\u5feb\u3001\u539f\u5730\u3001\u7a33\u5b9a\u3001\u6b63\u5411\u81ea\u9002\u5e94\u3001\u901a\u7528\u6027\u597d\u3002\u663e\u7136\uff0c\u8fc4\u4eca\u4e3a\u6b62\u5c1a\u672a\u53d1\u73b0\u517c\u5177\u4ee5\u4e0a\u6240\u6709\u7279\u6027\u7684\u6392\u5e8f\u7b97\u6cd5\u3002\u56e0\u6b64\uff0c\u5728\u9009\u62e9\u6392\u5e8f\u7b97\u6cd5\u65f6\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u7279\u70b9\u548c\u95ee\u9898\u9700\u6c42\u6765\u51b3\u5b9a\u3002

        \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u5171\u540c\u5b66\u4e60\u5404\u79cd\u6392\u5e8f\u7b97\u6cd5\uff0c\u5e76\u57fa\u4e8e\u4e0a\u8ff0\u8bc4\u4ef7\u7ef4\u5ea6\u5bf9\u5404\u4e2a\u6392\u5e8f\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u8fdb\u884c\u5206\u6790\u3002

        "},{"location":"chapter_sorting/summary/","title":"11.11 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_sorting/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u5192\u6ce1\u6392\u5e8f\u901a\u8fc7\u4ea4\u6362\u76f8\u90bb\u5143\u7d20\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2a\u6807\u5fd7\u4f4d\u6765\u5b9e\u73b0\u63d0\u524d\u8fd4\u56de\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5192\u6ce1\u6392\u5e8f\u7684\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u5230 \\(O(n)\\) \u3002
        • \u63d2\u5165\u6392\u5e8f\u6bcf\u8f6e\u5c06\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u5143\u7d20\u63d2\u5165\u5230\u5df2\u6392\u5e8f\u533a\u95f4\u7684\u6b63\u786e\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b8c\u6210\u6392\u5e8f\u3002\u867d\u7136\u63d2\u5165\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \uff0c\u4f46\u7531\u4e8e\u5355\u5143\u64cd\u4f5c\u76f8\u5bf9\u8f83\u5c11\uff0c\u56e0\u6b64\u5728\u5c0f\u6570\u636e\u91cf\u7684\u6392\u5e8f\u4efb\u52a1\u4e2d\u975e\u5e38\u53d7\u6b22\u8fce\u3002
        • \u5feb\u901f\u6392\u5e8f\u57fa\u4e8e\u54e8\u5175\u5212\u5206\u64cd\u4f5c\u5b9e\u73b0\u6392\u5e8f\u3002\u5728\u54e8\u5175\u5212\u5206\u4e2d\uff0c\u6709\u53ef\u80fd\u6bcf\u6b21\u90fd\u9009\u53d6\u5230\u6700\u5dee\u7684\u57fa\u51c6\u6570\uff0c\u5bfc\u81f4\u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u81f3 \\(O(n^2)\\) \u3002\u5f15\u5165\u4e2d\u4f4d\u6570\u57fa\u51c6\u6570\u6216\u968f\u673a\u57fa\u51c6\u6570\u53ef\u4ee5\u964d\u4f4e\u8fd9\u79cd\u52a3\u5316\u7684\u6982\u7387\u3002\u5c3e\u9012\u5f52\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u51cf\u5c11\u9012\u5f52\u6df1\u5ea6\uff0c\u5c06\u7a7a\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u5230 \\(O(\\log n)\\) \u3002
        • \u5f52\u5e76\u6392\u5e8f\u5305\u62ec\u5212\u5206\u548c\u5408\u5e76\u4e24\u4e2a\u9636\u6bb5\uff0c\u5178\u578b\u5730\u4f53\u73b0\u4e86\u5206\u6cbb\u7b56\u7565\u3002\u5728\u5f52\u5e76\u6392\u5e8f\u4e2d\uff0c\u6392\u5e8f\u6570\u7ec4\u9700\u8981\u521b\u5efa\u8f85\u52a9\u6570\u7ec4\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff1b\u7136\u800c\u6392\u5e8f\u94fe\u8868\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u53ef\u4ee5\u4f18\u5316\u81f3 \\(O(1)\\) \u3002
        • \u6876\u6392\u5e8f\u5305\u542b\u4e09\u4e2a\u6b65\u9aa4\uff1a\u6570\u636e\u5206\u6876\u3001\u6876\u5185\u6392\u5e8f\u548c\u5408\u5e76\u7ed3\u679c\u3002\u5b83\u540c\u6837\u4f53\u73b0\u4e86\u5206\u6cbb\u7b56\u7565\uff0c\u9002\u7528\u4e8e\u6570\u636e\u4f53\u91cf\u5f88\u5927\u7684\u60c5\u51b5\u3002\u6876\u6392\u5e8f\u7684\u5173\u952e\u5728\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u5e73\u5747\u5206\u914d\u3002
        • \u8ba1\u6570\u6392\u5e8f\u662f\u6876\u6392\u5e8f\u7684\u4e00\u4e2a\u7279\u4f8b\uff0c\u5b83\u901a\u8fc7\u7edf\u8ba1\u6570\u636e\u51fa\u73b0\u7684\u6b21\u6570\u6765\u5b9e\u73b0\u6392\u5e8f\u3002\u8ba1\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u6570\u636e\u91cf\u5927\u4f46\u6570\u636e\u8303\u56f4\u6709\u9650\u7684\u60c5\u51b5\uff0c\u5e76\u4e14\u8981\u6c42\u6570\u636e\u80fd\u591f\u8f6c\u6362\u4e3a\u6b63\u6574\u6570\u3002
        • \u57fa\u6570\u6392\u5e8f\u901a\u8fc7\u9010\u4f4d\u6392\u5e8f\u6765\u5b9e\u73b0\u6570\u636e\u6392\u5e8f\uff0c\u8981\u6c42\u6570\u636e\u80fd\u591f\u8868\u793a\u4e3a\u56fa\u5b9a\u4f4d\u6570\u7684\u6570\u5b57\u3002
        • \u603b\u7684\u6765\u8bf4\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u5230\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff0c\u5177\u6709\u9ad8\u6548\u7387\u3001\u7a33\u5b9a\u3001\u539f\u5730\u4ee5\u53ca\u6b63\u5411\u81ea\u9002\u5e94\u6027\u7b49\u4f18\u70b9\u3002\u7136\u800c\uff0c\u6b63\u5982\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u4e00\u6837\uff0c\u6ca1\u6709\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\u80fd\u591f\u540c\u65f6\u6ee1\u8db3\u6240\u6709\u8fd9\u4e9b\u6761\u4ef6\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u6570\u636e\u7684\u7279\u6027\u6765\u9009\u62e9\u5408\u9002\u7684\u6392\u5e8f\u7b97\u6cd5\u3002
        • \u56fe 11-19 \u5bf9\u6bd4\u4e86\u4e3b\u6d41\u6392\u5e8f\u7b97\u6cd5\u7684\u6548\u7387\u3001\u7a33\u5b9a\u6027\u3001\u5c31\u5730\u6027\u548c\u81ea\u9002\u5e94\u6027\u7b49\u3002

        \u56fe 11-19 \u00a0 \u6392\u5e8f\u7b97\u6cd5\u5bf9\u6bd4

        "},{"location":"chapter_sorting/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6392\u5e8f\u7b97\u6cd5\u7a33\u5b9a\u6027\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u662f\u5fc5\u9700\u7684\uff1f

        \u5728\u73b0\u5b9e\u4e2d\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u662f\u57fa\u4e8e\u5bf9\u8c61\u7684\u67d0\u4e2a\u5c5e\u6027\u8fdb\u884c\u6392\u5e8f\u3002\u4f8b\u5982\uff0c\u5b66\u751f\u6709\u59d3\u540d\u548c\u8eab\u9ad8\u4e24\u4e2a\u5c5e\u6027\uff0c\u6211\u4eec\u5e0c\u671b\u5b9e\u73b0\u4e00\u4e2a\u591a\u7ea7\u6392\u5e8f\uff1a

        \u5148\u6309\u7167\u59d3\u540d\u8fdb\u884c\u6392\u5e8f\uff0c\u5f97\u5230 (A, 180) (B, 185) (C, 170) (D, 170) \uff1b\u518d\u5bf9\u8eab\u9ad8\u8fdb\u884c\u6392\u5e8f\u3002\u7531\u4e8e\u6392\u5e8f\u7b97\u6cd5\u4e0d\u7a33\u5b9a\uff0c\u56e0\u6b64\u53ef\u80fd\u5f97\u5230 (D, 170) (C, 170) (A, 180) (B, 185) \u3002

        \u53ef\u4ee5\u53d1\u73b0\uff0c\u5b66\u751f D \u548c C \u7684\u4f4d\u7f6e\u53d1\u751f\u4e86\u4ea4\u6362\uff0c\u59d3\u540d\u7684\u6709\u5e8f\u6027\u88ab\u7834\u574f\u4e86\uff0c\u800c\u8fd9\u662f\u6211\u4eec\u4e0d\u5e0c\u671b\u770b\u5230\u7684\u3002

        \u54e8\u5175\u5212\u5206\u4e2d\u201c\u4ece\u53f3\u5f80\u5de6\u67e5\u627e\u201d\u4e0e\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u7684\u987a\u5e8f\u53ef\u4ee5\u4ea4\u6362\u5417\uff1f

        \u4e0d\u884c\uff0c\u5f53\u6211\u4eec\u4ee5\u6700\u5de6\u7aef\u5143\u7d20\u4e3a\u57fa\u51c6\u6570\u65f6\uff0c\u5fc5\u987b\u5148\u201c\u4ece\u53f3\u5f80\u5de6\u67e5\u627e\u201d\u518d\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u3002\u8fd9\u4e2a\u7ed3\u8bba\u6709\u4e9b\u53cd\u76f4\u89c9\uff0c\u6211\u4eec\u6765\u5256\u6790\u4e00\u4e0b\u539f\u56e0\u3002

        \u54e8\u5175\u5212\u5206 partition() \u7684\u6700\u540e\u4e00\u6b65\u662f\u4ea4\u6362 nums[left] \u548c nums[i] \u3002\u5b8c\u6210\u4ea4\u6362\u540e\uff0c\u57fa\u51c6\u6570\u5de6\u8fb9\u7684\u5143\u7d20\u90fd <= \u57fa\u51c6\u6570\uff0c\u8fd9\u5c31\u8981\u6c42\u6700\u540e\u4e00\u6b65\u4ea4\u6362\u524d nums[left] >= nums[i] \u5fc5\u987b\u6210\u7acb\u3002\u5047\u8bbe\u6211\u4eec\u5148\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\uff0c\u90a3\u4e48\u5982\u679c\u627e\u4e0d\u5230\u6bd4\u57fa\u51c6\u6570\u66f4\u5c0f\u7684\u5143\u7d20\uff0c\u5219\u4f1a\u5728 i == j \u65f6\u8df3\u51fa\u5faa\u73af\uff0c\u6b64\u65f6\u53ef\u80fd nums[j] == nums[i] > nums[left]\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6b64\u65f6\u6700\u540e\u4e00\u6b65\u4ea4\u6362\u64cd\u4f5c\u4f1a\u628a\u4e00\u4e2a\u6bd4\u57fa\u51c6\u6570\u66f4\u5927\u7684\u5143\u7d20\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\uff0c\u5bfc\u81f4\u54e8\u5175\u5212\u5206\u5931\u8d25\u3002

        \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u7ed9\u5b9a\u6570\u7ec4 [0, 0, 0, 0, 1] \uff0c\u5982\u679c\u5148\u201c\u4ece\u5de6\u5411\u53f3\u67e5\u627e\u201d\uff0c\u54e8\u5175\u5212\u5206\u540e\u6570\u7ec4\u4e3a [1, 0, 0, 0, 0] \uff0c\u8fd9\u4e2a\u7ed3\u679c\u662f\u4e0d\u6b63\u786e\u7684\u3002

        \u518d\u6df1\u5165\u601d\u8003\u4e00\u4e0b\uff0c\u5982\u679c\u6211\u4eec\u9009\u62e9 nums[right] \u4e3a\u57fa\u51c6\u6570\uff0c\u90a3\u4e48\u6b63\u597d\u53cd\u8fc7\u6765\uff0c\u5fc5\u987b\u5148\u201c\u4ece\u5de6\u5f80\u53f3\u67e5\u627e\u201d\u3002

        \u5173\u4e8e\u5c3e\u9012\u5f52\u4f18\u5316\uff0c\u4e3a\u4ec0\u4e48\u9009\u77ed\u7684\u6570\u7ec4\u80fd\u4fdd\u8bc1\u9012\u5f52\u6df1\u5ea6\u4e0d\u8d85\u8fc7 \\(\\log n\\) \uff1f

        \u9012\u5f52\u6df1\u5ea6\u5c31\u662f\u5f53\u524d\u672a\u8fd4\u56de\u7684\u9012\u5f52\u65b9\u6cd5\u7684\u6570\u91cf\u3002\u6bcf\u8f6e\u54e8\u5175\u5212\u5206\u6211\u4eec\u5c06\u539f\u6570\u7ec4\u5212\u5206\u4e3a\u4e24\u4e2a\u5b50\u6570\u7ec4\u3002\u5728\u5c3e\u9012\u5f52\u4f18\u5316\u540e\uff0c\u5411\u4e0b\u9012\u5f52\u7684\u5b50\u6570\u7ec4\u957f\u5ea6\u6700\u5927\u4e3a\u539f\u6570\u7ec4\u957f\u5ea6\u7684\u4e00\u534a\u3002\u5047\u8bbe\u6700\u5dee\u60c5\u51b5\uff0c\u4e00\u76f4\u4e3a\u4e00\u534a\u957f\u5ea6\uff0c\u90a3\u4e48\u6700\u7ec8\u7684\u9012\u5f52\u6df1\u5ea6\u5c31\u662f \\(\\log n\\) \u3002

        \u56de\u987e\u539f\u59cb\u7684\u5feb\u901f\u6392\u5e8f\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u4f1a\u8fde\u7eed\u5730\u9012\u5f52\u957f\u5ea6\u8f83\u5927\u7684\u6570\u7ec4\uff0c\u6700\u5dee\u60c5\u51b5\u4e0b\u4e3a \\(n\\)\u3001\\(n - 1\\)\u3001\\(\\dots\\)\u3001\\(2\\)\u3001\\(1\\) \uff0c\u9012\u5f52\u6df1\u5ea6\u4e3a \\(n\\) \u3002\u5c3e\u9012\u5f52\u4f18\u5316\u53ef\u4ee5\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u3002

        \u5f53\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u76f8\u7b49\u65f6\uff0c\u5feb\u901f\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f \\(O(n^2)\\) \u5417\uff1f\u8be5\u5982\u4f55\u5904\u7406\u8fd9\u79cd\u9000\u5316\u60c5\u51b5\uff1f

        \u662f\u7684\u3002\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u8003\u8651\u901a\u8fc7\u54e8\u5175\u5212\u5206\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff1a\u5c0f\u4e8e\u3001\u7b49\u4e8e\u3001\u5927\u4e8e\u57fa\u51c6\u6570\u3002\u4ec5\u5411\u4e0b\u9012\u5f52\u5c0f\u4e8e\u548c\u5927\u4e8e\u7684\u4e24\u90e8\u5206\u3002\u5728\u8be5\u65b9\u6cd5\u4e0b\uff0c\u8f93\u5165\u5143\u7d20\u5168\u90e8\u76f8\u7b49\u7684\u6570\u7ec4\uff0c\u4ec5\u4e00\u8f6e\u54e8\u5175\u5212\u5206\u5373\u53ef\u5b8c\u6210\u6392\u5e8f\u3002

        \u6876\u6392\u5e8f\u7684\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u4ec0\u4e48\u662f \\(O(n^2)\\) \uff1f

        \u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5143\u7d20\u88ab\u5206\u81f3\u540c\u4e00\u4e2a\u6876\u4e2d\u3002\u5982\u679c\u6211\u4eec\u91c7\u7528\u4e00\u4e2a \\(O(n^2)\\) \u7b97\u6cd5\u6765\u6392\u5e8f\u8fd9\u4e9b\u5143\u7d20\uff0c\u5219\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n^2)\\) \u3002

        "},{"location":"chapter_stack_and_queue/","title":"\u7b2c 5 \u7ae0 \u00a0 \u6808\u4e0e\u961f\u5217","text":"

        Abstract

        \u6808\u5982\u540c\u53e0\u732b\u732b\uff0c\u800c\u961f\u5217\u5c31\u50cf\u732b\u732b\u6392\u961f\u3002

        \u4e24\u8005\u5206\u522b\u4ee3\u8868\u5148\u5165\u540e\u51fa\u548c\u5148\u5165\u5148\u51fa\u7684\u903b\u8f91\u5173\u7cfb\u3002

        "},{"location":"chapter_stack_and_queue/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 5.1 \u00a0 \u6808
        • 5.2 \u00a0 \u961f\u5217
        • 5.3 \u00a0 \u53cc\u5411\u961f\u5217
        • 5.4 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_stack_and_queue/deque/","title":"5.3 \u00a0 \u53cc\u5411\u961f\u5217","text":"

        \u5728\u961f\u5217\u4e2d\uff0c\u6211\u4eec\u4ec5\u80fd\u5220\u9664\u5934\u90e8\u5143\u7d20\u6216\u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u3002\u5982\u56fe 5-7 \u6240\u793a\uff0c\u300c\u53cc\u5411\u961f\u5217 double-ended queue\u300d\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u5728\u5934\u90e8\u548c\u5c3e\u90e8\u6267\u884c\u5143\u7d20\u7684\u6dfb\u52a0\u6216\u5220\u9664\u64cd\u4f5c\u3002

        \u56fe 5-7 \u00a0 \u53cc\u5411\u961f\u5217\u7684\u64cd\u4f5c

        "},{"location":"chapter_stack_and_queue/deque/#531","title":"5.3.1 \u00a0 \u53cc\u5411\u961f\u5217\u5e38\u7528\u64cd\u4f5c","text":"

        \u53cc\u5411\u961f\u5217\u7684\u5e38\u7528\u64cd\u4f5c\u5982\u8868 5-3 \u6240\u793a\uff0c\u5177\u4f53\u7684\u65b9\u6cd5\u540d\u79f0\u9700\u8981\u6839\u636e\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002

        \u8868 5-3 \u00a0 \u53cc\u5411\u961f\u5217\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 pushFirst() \u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u9996 \\(O(1)\\) pushLast() \u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u5c3e \\(O(1)\\) popFirst() \u5220\u9664\u961f\u9996\u5143\u7d20 \\(O(1)\\) popLast() \u5220\u9664\u961f\u5c3e\u5143\u7d20 \\(O(1)\\) peekFirst() \u8bbf\u95ee\u961f\u9996\u5143\u7d20 \\(O(1)\\) peekLast() \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 \\(O(1)\\)

        \u540c\u6837\u5730\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5df2\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\u7c7b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig deque.py
        from collections import deque\n# \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217\ndeque: deque[int] = deque()\n# \u5143\u7d20\u5165\u961f\ndeque.append(2)      # \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.append(5)\ndeque.append(4)\ndeque.appendleft(3)  # \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.appendleft(1)\n# \u8bbf\u95ee\u5143\u7d20\nfront: int = deque[0]  # \u961f\u9996\u5143\u7d20\nrear: int = deque[-1]  # \u961f\u5c3e\u5143\u7d20\n# \u5143\u7d20\u51fa\u961f\npop_front: int = deque.popleft()  # \u961f\u9996\u5143\u7d20\u51fa\u961f\npop_rear: int = deque.pop()       # \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n# \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(deque)\n# \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(deque) == 0\n
        deque.cpp
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\ndeque<int> deque;\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.push_back(5);\ndeque.push_back(4);\ndeque.push_front(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.push_front(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint front = deque.front(); // \u961f\u9996\u5143\u7d20\nint back = deque.back();   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.pop_front();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.pop_back();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty = deque.empty();\n
        deque.java
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\nDeque<Integer> deque = new LinkedList<>();\n/* \u5143\u7d20\u5165\u961f */\ndeque.offerLast(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.offerLast(5);\ndeque.offerLast(4);\ndeque.offerFirst(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.offerFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.peekFirst();  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.peekLast();    // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\nint popFirst = deque.pollFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\nint popLast = deque.pollLast();    // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = deque.isEmpty();\n
        deque.cs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 C# \u4e2d\uff0c\u5c06\u94fe\u8868 LinkedList \u770b\u4f5c\u53cc\u5411\u961f\u5217\u6765\u4f7f\u7528\nLinkedList<int> deque = new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.AddLast(2);   // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.AddLast(5);\ndeque.AddLast(4);\ndeque.AddFirst(3);  // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.AddFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.First.Value;  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.Last.Value;    // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.RemoveFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.RemoveLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.Count;\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = deque.Count == 0;\n
        deque_test.go
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Go \u4e2d\uff0c\u5c06 list \u4f5c\u4e3a\u53cc\u5411\u961f\u5217\u4f7f\u7528\ndeque := list.New()\n/* \u5143\u7d20\u5165\u961f */\ndeque.PushBack(2)      // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.PushBack(5)\ndeque.PushBack(4)\ndeque.PushFront(3)     // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.PushFront(1)\n/* \u8bbf\u95ee\u5143\u7d20 */\nfront := deque.Front() // \u961f\u9996\u5143\u7d20\nrear := deque.Back()   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\ndeque.Remove(front)    // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.Remove(rear)     // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize := deque.Len()\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty := deque.Len() == 0\n
        deque.swift
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u5411\u961f\u5217\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u53cc\u5411\u961f\u5217\u6765\u4f7f\u7528\nvar deque: [Int] = []\n/* \u5143\u7d20\u5165\u961f */\ndeque.append(2) // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.append(5)\ndeque.append(4)\ndeque.insert(3, at: 0) // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.insert(1, at: 0)\n/* \u8bbf\u95ee\u5143\u7d20 */\nlet peekFirst = deque.first! // \u961f\u9996\u5143\u7d20\nlet peekLast = deque.last! // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\n// \u4f7f\u7528 Array \u6a21\u62df\u65f6 popFirst \u7684\u590d\u6742\u5ea6\u4e3a O(n)\nlet popFirst = deque.removeFirst() // \u961f\u9996\u5143\u7d20\u51fa\u961f\nlet popLast = deque.removeLast() // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.count\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = deque.isEmpty\n
        deque.js
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// JavaScript \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\uff0c\u53ea\u80fd\u628a Array \u5f53\u4f5c\u53cc\u7aef\u961f\u5217\u6765\u4f7f\u7528\nconst deque = [];\n/* \u5143\u7d20\u5165\u961f */\ndeque.push(2);\ndeque.push(5);\ndeque.push(4);\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cunshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndeque.unshift(3);\ndeque.unshift(1);\nconsole.log(\"\u53cc\u5411\u961f\u5217 deque = \", deque);\n/* \u8bbf\u95ee\u5143\u7d20 */\nconst peekFirst = deque[0];\nconsole.log(\"\u961f\u9996\u5143\u7d20 peekFirst = \" + peekFirst);\nconst peekLast = deque[deque.length - 1];\nconsole.log(\"\u961f\u5c3e\u5143\u7d20 peekLast = \" + peekLast);\n/* \u5143\u7d20\u51fa\u961f */\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst popFront = deque.shift();\nconsole.log(\"\u961f\u9996\u51fa\u961f\u5143\u7d20 popFront = \" + popFront + \"\uff0c\u961f\u9996\u51fa\u961f\u540e deque = \" + deque);\nconst popBack = deque.pop();\nconsole.log(\"\u961f\u5c3e\u51fa\u961f\u5143\u7d20 popBack = \" + popBack + \"\uff0c\u961f\u5c3e\u51fa\u961f\u540e deque = \" + deque);\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = deque.length;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u957f\u5ea6 size = \" + size);\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst isEmpty = size === 0;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a = \" + isEmpty);\n
        deque.ts
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// TypeScript \u6ca1\u6709\u5185\u7f6e\u7684\u53cc\u7aef\u961f\u5217\uff0c\u53ea\u80fd\u628a Array \u5f53\u4f5c\u53cc\u7aef\u961f\u5217\u6765\u4f7f\u7528\nconst deque: number[] = [];\n/* \u5143\u7d20\u5165\u961f */\ndeque.push(2);\ndeque.push(5);\ndeque.push(4);\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cunshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\ndeque.unshift(3);\ndeque.unshift(1);\nconsole.log(\"\u53cc\u5411\u961f\u5217 deque = \", deque);\n/* \u8bbf\u95ee\u5143\u7d20 */\nconst peekFirst: number = deque[0];\nconsole.log(\"\u961f\u9996\u5143\u7d20 peekFirst = \" + peekFirst);\nconst peekLast: number = deque[deque.length - 1];\nconsole.log(\"\u961f\u5c3e\u5143\u7d20 peekLast = \" + peekLast);\n/* \u5143\u7d20\u51fa\u961f */\n// \u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u662f\u6570\u7ec4\uff0cshift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst popFront: number = deque.shift() as number;\nconsole.log(\"\u961f\u9996\u51fa\u961f\u5143\u7d20 popFront = \" + popFront + \"\uff0c\u961f\u9996\u51fa\u961f\u540e deque = \" + deque);\nconst popBack: number = deque.pop() as number;\nconsole.log(\"\u961f\u5c3e\u51fa\u961f\u5143\u7d20 popBack = \" + popBack + \"\uff0c\u961f\u5c3e\u51fa\u961f\u540e deque = \" + deque);\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nconst size: number = deque.length;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u957f\u5ea6 size = \" + size);\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst isEmpty: boolean = size === 0;\nconsole.log(\"\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a = \" + isEmpty);\n
        deque.dart
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Dart \u4e2d\uff0cQueue \u88ab\u5b9a\u4e49\u4e3a\u53cc\u5411\u961f\u5217\nQueue<int> deque = Queue<int>();\n/* \u5143\u7d20\u5165\u961f */\ndeque.addLast(2);  // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.addLast(5);\ndeque.addLast(4);\ndeque.addFirst(3); // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.addFirst(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.first; // \u961f\u9996\u5143\u7d20\nint peekLast = deque.last;   // \u961f\u5c3e\u5143\u7d20\n/* \u5143\u7d20\u51fa\u961f */\nint popFirst = deque.removeFirst(); // \u961f\u9996\u5143\u7d20\u51fa\u961f\nint popLast = deque.removeLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.length;\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = deque.isEmpty;W\n
        deque.rs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\nlet mut deque: VecDeque<u32> = VecDeque::new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(2);  // \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque.push_back(5);\ndeque.push_back(4);\ndeque.push_front(3); // \u6dfb\u52a0\u81f3\u961f\u9996\ndeque.push_front(1);\n/* \u8bbf\u95ee\u5143\u7d20 */\nif let Some(front) = deque.front() { // \u961f\u9996\u5143\u7d20\n}\nif let Some(rear) = deque.back() {   // \u961f\u5c3e\u5143\u7d20\n}\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop_front) = deque.pop_front() { // \u961f\u9996\u5143\u7d20\u51fa\u961f\n}\nif let Some(pop_rear) = deque.pop_back() {   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = deque.is_empty();\n
        deque.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u53cc\u5411\u961f\u5217\n
        deque.zig
        \n
        "},{"location":"chapter_stack_and_queue/deque/#532","title":"5.3.2 \u00a0 \u53cc\u5411\u961f\u5217\u5b9e\u73b0 *","text":"

        \u53cc\u5411\u961f\u5217\u7684\u5b9e\u73b0\u4e0e\u961f\u5217\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u9009\u62e9\u94fe\u8868\u6216\u6570\u7ec4\u4f5c\u4e3a\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002

        "},{"location":"chapter_stack_and_queue/deque/#1","title":"1. \u00a0 \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u56de\u987e\u4e0a\u4e00\u8282\u5185\u5bb9\uff0c\u6211\u4eec\u4f7f\u7528\u666e\u901a\u5355\u5411\u94fe\u8868\u6765\u5b9e\u73b0\u961f\u5217\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u5220\u9664\u5934\u8282\u70b9\uff08\u5bf9\u5e94\u51fa\u961f\u64cd\u4f5c\uff09\u548c\u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0\u65b0\u8282\u70b9\uff08\u5bf9\u5e94\u5165\u961f\u64cd\u4f5c\uff09\u3002

        \u5bf9\u4e8e\u53cc\u5411\u961f\u5217\u800c\u8a00\uff0c\u5934\u90e8\u548c\u5c3e\u90e8\u90fd\u53ef\u4ee5\u6267\u884c\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u53cc\u5411\u961f\u5217\u9700\u8981\u5b9e\u73b0\u53e6\u4e00\u4e2a\u5bf9\u79f0\u65b9\u5411\u7684\u64cd\u4f5c\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u91c7\u7528\u201c\u53cc\u5411\u94fe\u8868\u201d\u4f5c\u4e3a\u53cc\u5411\u961f\u5217\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002

        \u5982\u56fe 5-8 \u6240\u793a\uff0c\u6211\u4eec\u5c06\u53cc\u5411\u94fe\u8868\u7684\u5934\u8282\u70b9\u548c\u5c3e\u8282\u70b9\u89c6\u4e3a\u53cc\u5411\u961f\u5217\u7684\u961f\u9996\u548c\u961f\u5c3e\uff0c\u540c\u65f6\u5b9e\u73b0\u5728\u4e24\u7aef\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u7684\u529f\u80fd\u3002

        LinkedListDequepushLast()pushFirst()popLast()popFirst()

        \u56fe 5-8 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_deque.py
        class ListNode:\n\"\"\"\u53cc\u5411\u94fe\u8868\u8282\u70b9\"\"\"\ndef __init__(self, val: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself.val: int = val\nself.next: ListNode | None = None  # \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nself.prev: ListNode | None = None  # \u524d\u9a71\u8282\u70b9\u5f15\u7528\nclass LinkedListDeque:\n\"\"\"\u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._front: ListNode | None = None  # \u5934\u8282\u70b9 front\nself._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\nself._size: int = 0  # \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self.size() == 0\ndef push(self, num: int, is_front: bool):\n\"\"\"\u5165\u961f\u64cd\u4f5c\"\"\"\nnode = ListNode(num)\n# \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif self.is_empty():\nself._front = self._rear = node\n# \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelif is_front:\n# \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nself._front.prev = node\nnode.next = self._front\nself._front = node  # \u66f4\u65b0\u5934\u8282\u70b9\n# \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse:\n# \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nself._rear.next = node\nnode.prev = self._rear\nself._rear = node  # \u66f4\u65b0\u5c3e\u8282\u70b9\nself._size += 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\ndef push_first(self, num: int):\n\"\"\"\u961f\u9996\u5165\u961f\"\"\"\nself.push(num, True)\ndef push_last(self, num: int):\n\"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\nself.push(num, False)\ndef pop(self, is_front: bool) -> int:\n\"\"\"\u51fa\u961f\u64cd\u4f5c\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n# \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif is_front:\nval: int = self._front.val  # \u6682\u5b58\u5934\u8282\u70b9\u503c\n# \u5220\u9664\u5934\u8282\u70b9\nfnext: ListNode | None = self._front.next\nif fnext != None:\nfnext.prev = None\nself._front.next = None\nself._front = fnext  # \u66f4\u65b0\u5934\u8282\u70b9\n# \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse:\nval: int = self._rear.val  # \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n# \u5220\u9664\u5c3e\u8282\u70b9\nrprev: ListNode | None = self._rear.prev\nif rprev != None:\nrprev.next = None\nself._rear.prev = None\nself._rear = rprev  # \u66f4\u65b0\u5c3e\u8282\u70b9\nself._size -= 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val\ndef pop_first(self) -> int:\n\"\"\"\u961f\u9996\u51fa\u961f\"\"\"\nreturn self.pop(True)\ndef pop_last(self) -> int:\n\"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\nreturn self.pop(False)\ndef peek_first(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._front.val\ndef peek_last(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._rear.val\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\nnode = self._front\nres = [0] * self.size()\nfor i in range(self.size()):\nres[i] = node.val\nnode = node.next\nreturn res\n
        linkedlist_deque.cpp
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nstruct DoublyListNode {\nint val;              // \u8282\u70b9\u503c\nDoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\u6307\u9488\nDoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\u6307\u9488\nDoublyListNode(int val) : val(val), prev(nullptr), next(nullptr) {\n}\n};\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate:\nDoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize = 0;              // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nLinkedListDeque() : front(nullptr), rear(nullptr) {\n}\n/* \u6790\u6784\u65b9\u6cd5 */\n~LinkedListDeque() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nDoublyListNode *pre, *cur = front;\nwhile (cur != nullptr) {\npre = cur;\ncur = cur->next;\ndelete pre;\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid push(int num, bool isFront) {\nDoublyListNode *node = new DoublyListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (isEmpty())\nfront = rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront->prev = node;\nnode->next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear->next = node;\nnode->prev = rear;\nrear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int num) {\npush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int num) {\npush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint pop(bool isFront) {\nif (isEmpty())\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front->val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nDoublyListNode *fNext = front->next;\nif (fNext != nullptr) {\nfNext->prev = nullptr;\nfront->next = nullptr;\ndelete front;\n}\nfront = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = rear->val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nDoublyListNode *rPrev = rear->prev;\nif (rPrev != nullptr) {\nrPrev->next = nullptr;\nrear->prev = nullptr;\ndelete rear;\n}\nrear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn front->val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn rear->val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\nDoublyListNode *node = front;\nvector<int> res(size());\nfor (int i = 0; i < res.size(); i++) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_deque.java
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nListNode prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\nListNode(int val) {\nthis.val = val;\nprev = next = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nprivate int queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic LinkedListDeque() {\nfront = rear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nprivate void push(int num, boolean isFront) {\nListNode node = new ListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (isEmpty())\nfront = rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront.prev = node;\nnode.next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear.next = node;\nnode.prev = rear;\nrear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npublic void pushFirst(int num) {\npush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void pushLast(int num) {\npush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nprivate int pop(boolean isFront) {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode fNext = front.next;\nif (fNext != null) {\nfNext.prev = null;\nfront.next = null;\n}\nfront = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = rear.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode rPrev = rear.prev;\nif (rPrev != null) {\nrPrev.next = null;\nrear.prev = null;\n}\nrear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peekFirst() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn front.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int peekLast() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn rear.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] toArray() {\nListNode node = front;\nint[] res = new int[size()];\nfor (int i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.cs
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode(int val) {\npublic int val = val;       // \u8282\u70b9\u503c\npublic ListNode? next = null; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\npublic ListNode? prev = null; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nListNode? front, rear; // \u5934\u8282\u70b9 front, \u5c3e\u8282\u70b9 rear\nint queSize = 0;      // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npublic LinkedListDeque() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid Push(int num, bool isFront) {\nListNode node = new(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (IsEmpty()) {\nfront = node;\nrear = node;\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront!.prev = node;\nnode.next = front;\nfront = node; // \u66f4\u65b0\u5934\u8282\u70b9                           \n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear!.next = node;\nnode.prev = rear;\nrear = node;  // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npublic void PushFirst(int num) {\nPush(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void PushLast(int num) {\nPush(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint? Pop(bool isFront) {\nif (IsEmpty())\nthrow new Exception();\nint? val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = front?.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode? fNext = front?.next;\nif (fNext != null) {\nfNext.prev = null;\nfront!.next = null;\n}\nfront = fNext;   // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = rear?.val;  // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode? rPrev = rear?.prev;\nif (rPrev != null) {\nrPrev.next = null;\nrear!.prev = null;\n}\nrear = rPrev;    // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int? PopFirst() {\nreturn Pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int? PopLast() {\nreturn Pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int? PeekFirst() {\nif (IsEmpty())\nthrow new Exception();\nreturn front?.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int? PeekLast() {\nif (IsEmpty())\nthrow new Exception();\nreturn rear?.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int?[] ToArray() {\nListNode? node = front;\nint?[] res = new int?[Size()];\nfor (int i = 0; i < res.Length; i++) {\nres[i] = node?.val;\nnode = node?.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.go
        /* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype linkedListDeque struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u53cc\u7aef\u961f\u5217 */\nfunc newLinkedListDeque() *linkedListDeque {\nreturn &linkedListDeque{\ndata: list.New(),\n}\n}\n/* \u961f\u9996\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushFirst(value any) {\ns.data.PushFront(value)\n}\n/* \u961f\u5c3e\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushLast(value any) {\ns.data.PushBack(value)\n}\n/* \u961f\u9996\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popFirst() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u961f\u5c3e\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popLast() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListDeque) peekFirst() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (s *linkedListDeque) peekLast() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\nreturn e.Value\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListDeque) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListDeque) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListDeque) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_deque.swift
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nvar val: Int // \u8282\u70b9\u503c\nvar next: ListNode? // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nweak var prev: ListNode? // \u524d\u9a71\u8282\u70b9\u5f15\u7528\ninit(val: Int) {\nself.val = val\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate var front: ListNode? // \u5934\u8282\u70b9 front\nprivate var rear: ListNode? // \u5c3e\u8282\u70b9 rear\nprivate var queSize: Int // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\ninit() {\nqueSize = 0\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u961f\u64cd\u4f5c */\nprivate func push(num: Int, isFront: Bool) {\nlet node = ListNode(val: num)\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif isEmpty() {\nfront = node\nrear = node\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if isFront {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nfront?.prev = node\nnode.next = front\nfront = node // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nrear?.next = node\nnode.prev = rear\nrear = node // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize += 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nfunc pushFirst(num: Int) {\npush(num: num, isFront: true)\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc pushLast(num: Int) {\npush(num: num, isFront: false)\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nprivate func pop(isFront: Bool) -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\nlet val: Int\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif isFront {\nval = front!.val // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet fNext = front?.next\nif fNext != nil {\nfNext?.prev = nil\nfront?.next = nil\n}\nfront = fNext // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = rear!.val // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet rPrev = rear?.prev\nif rPrev != nil {\nrPrev?.next = nil\nrear?.prev = nil\n}\nrear = rPrev // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nqueSize -= 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc popFirst() -> Int {\npop(isFront: true)\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc popLast() -> Int {\npop(isFront: false)\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peekFirst() -> Int? {\nisEmpty() ? nil : front?.val\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc peekLast() -> Int? {\nisEmpty() ? nil : rear?.val\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfunc toArray() -> [Int] {\nvar node = front\nvar res = Array(repeating: 0, count: size())\nfor i in res.indices {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_deque.js
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nprev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nnext; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nval; // \u8282\u70b9\u503c\nconstructor(val) {\nthis.val = val;\nthis.next = null;\nthis.prev = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n#front; // \u5934\u8282\u70b9 front\n#rear; // \u5c3e\u8282\u70b9 rear\n#queSize; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nconstructor() {\nthis.#front = null;\nthis.#rear = null;\nthis.#queSize = 0;\n}\n/* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\npushLast(val) {\nconst node = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.#queSize === 0) {\nthis.#front = node;\nthis.#rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nthis.#rear.next = node;\nnode.prev = this.#rear;\nthis.#rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nthis.#queSize++;\n}\n/* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\npushFirst(val) {\nconst node = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.#queSize === 0) {\nthis.#front = node;\nthis.#rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nthis.#front.prev = node;\nnode.next = this.#front;\nthis.#front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\nthis.#queSize++;\n}\n/* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\npopLast() {\nif (this.#queSize === 0) {\nreturn null;\n}\nconst value = this.#rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet temp = this.#rear.prev;\nif (temp !== null) {\ntemp.next = null;\nthis.#rear.prev = null;\n}\nthis.#rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\nthis.#queSize--;\nreturn value;\n}\n/* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\npopFirst() {\nif (this.#queSize === 0) {\nreturn null;\n}\nconst value = this.#front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet temp = this.#front.next;\nif (temp !== null) {\ntemp.prev = null;\nthis.#front.next = null;\n}\nthis.#front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\nthis.#queSize--;\nreturn value;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast() {\nreturn this.#queSize === 0 ? null : this.#rear.val;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst() {\nreturn this.#queSize === 0 ? null : this.#front.val;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u6253\u5370\u53cc\u5411\u961f\u5217 */\nprint() {\nconst arr = [];\nlet temp = this.#front;\nwhile (temp !== null) {\narr.push(temp.val);\ntemp = temp.next;\n}\nconsole.log('[' + arr.join(', ') + ']');\n}\n}\n
        linkedlist_deque.ts
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nprev: ListNode; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nnext: ListNode; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\nval: number; // \u8282\u70b9\u503c\nconstructor(val: number) {\nthis.val = val;\nthis.next = null;\nthis.prev = null;\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\nprivate front: ListNode; // \u5934\u8282\u70b9 front\nprivate rear: ListNode; // \u5c3e\u8282\u70b9 rear\nprivate queSize: number; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nconstructor() {\nthis.front = null;\nthis.rear = null;\nthis.queSize = 0;\n}\n/* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\npushLast(val: number): void {\nconst node: ListNode = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.queSize === 0) {\nthis.front = node;\nthis.rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nthis.rear.next = node;\nnode.prev = this.rear;\nthis.rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nthis.queSize++;\n}\n/* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\npushFirst(val: number): void {\nconst node: ListNode = new ListNode(val);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (this.queSize === 0) {\nthis.front = node;\nthis.rear = node;\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nthis.front.prev = node;\nnode.next = this.front;\nthis.front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\nthis.queSize++;\n}\n/* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\npopLast(): number {\nif (this.queSize === 0) {\nreturn null;\n}\nconst value: number = this.rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nlet temp: ListNode = this.rear.prev;\nif (temp !== null) {\ntemp.next = null;\nthis.rear.prev = null;\n}\nthis.rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\nthis.queSize--;\nreturn value;\n}\n/* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\npopFirst(): number {\nif (this.queSize === 0) {\nreturn null;\n}\nconst value: number = this.front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nlet temp: ListNode = this.front.next;\nif (temp !== null) {\ntemp.prev = null;\nthis.front.next = null;\n}\nthis.front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\nthis.queSize--;\nreturn value;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast(): number {\nreturn this.queSize === 0 ? null : this.rear.val;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst(): number {\nreturn this.queSize === 0 ? null : this.front.val;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u6253\u5370\u53cc\u5411\u961f\u5217 */\nprint(): void {\nconst arr: number[] = [];\nlet temp: ListNode = this.front;\nwhile (temp !== null) {\narr.push(temp.val);\ntemp = temp.next;\n}\nconsole.log('[' + arr.join(', ') + ']');\n}\n}\n
        linkedlist_deque.dart
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\nint val; // \u8282\u70b9\u503c\nListNode? next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\nListNode? prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\nListNode(this.val, {this.next, this.prev});\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u5bf9\u5217 */\nclass LinkedListDeque {\nlate ListNode? _front; // \u5934\u8282\u70b9 _front\nlate ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\nint _queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nLinkedListDeque() {\nthis._front = null;\nthis._rear = null;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u957f\u5ea6 */\nint size() {\nreturn this._queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\nvoid push(int _num, bool isFront) {\nfinal ListNode node = ListNode(_num);\nif (isEmpty()) {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 _front \u548c _rear \u90fd\u6307\u5411 node\n_front = _rear = node;\n} else if (isFront) {\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n_front!.prev = node;\nnode.next = _front;\n_front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n} else {\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n_rear!.next = node;\nnode.prev = _rear;\n_rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n_queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int _num) {\npush(_num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int _num) {\npush(_num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\nint? pop(bool isFront) {\n// \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de null\nif (isEmpty()) {\nreturn null;\n}\nfinal int val;\nif (isFront) {\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nval = _front!.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nListNode? fNext = _front!.next;\nif (fNext != null) {\nfNext.prev = null;\n_front!.next = null;\n}\n_front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n} else {\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nval = _rear!.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nListNode? rPrev = _rear!.prev;\nif (rPrev != null) {\nrPrev.next = null;\n_rear!.prev = null;\n}\n_rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n_queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint? popFirst() {\nreturn pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint? popLast() {\nreturn pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint? peekFirst() {\nreturn _front?.val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint? peekLast() {\nreturn _rear?.val;\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nList<int> toArray() {\nListNode? node = _front;\nfinal List<int> res = [];\nfor (int i = 0; i < _queSize; i++) {\nres.add(node!.val);\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_deque.rs
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\npub struct ListNode<T> {\npub val: T,                                 // \u8282\u70b9\u503c\npub next: Option<Rc<RefCell<ListNode<T>>>>, // \u540e\u7ee7\u8282\u70b9\u6307\u9488\npub prev: Option<Rc<RefCell<ListNode<T>>>>, // \u524d\u9a71\u8282\u70b9\u6307\u9488\n}\nimpl<T> ListNode<T> {\npub fn new(val: T) -> Rc<RefCell<ListNode<T>>> {\nRc::new(RefCell::new(ListNode {\nval,\nnext: None,\nprev: None,\n}))\n}\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListDeque<T> {\nfront: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\nrear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \nque_size: usize,                            // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListDeque<T> {\npub fn new() -> Self {\nSelf {\nfront: None,\nrear: None,\nque_size: 0, }\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.que_size;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u961f\u64cd\u4f5c */\npub fn push(&mut self, num: T, is_front: bool) {\nlet node = ListNode::new(num);\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nif is_front {\nmatch self.front.take() {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nNone => {\nself.rear = Some(node.clone());\nself.front = Some(node);\n}\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nSome(old_front) => {\nold_front.borrow_mut().prev = Some(node.clone());\nnode.borrow_mut().next = Some(old_front);\nself.front = Some(node); // \u66f4\u65b0\u5934\u8282\u70b9\n}\n}\n} // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\nmatch self.rear.take() {\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nNone => {\nself.front = Some(node.clone());\nself.rear = Some(node);\n}\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nSome(old_rear) => {\nold_rear.borrow_mut().next = Some(node.clone());\nnode.borrow_mut().prev = Some(old_rear);\nself.rear = Some(node); // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\n}\n}\nself.que_size += 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\npub fn push_first(&mut self, num: T) {\nself.push(num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\npub fn push_last(&mut self, num: T) {\nself.push(num, false);\n}\n/* \u51fa\u961f\u64cd\u4f5c */\npub fn pop(&mut self, is_front: bool) -> Option<T> {\n// \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de None\nif self.is_empty() { return None };\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif is_front {\nself.front.take().map(|old_front| {\nmatch old_front.borrow_mut().next.take() {\nSome(new_front) => {\nnew_front.borrow_mut().prev.take();\nself.front = Some(new_front);   // \u66f4\u65b0\u5934\u8282\u70b9\n}\nNone => {\nself.rear.take();\n}\n}\nself.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nRc::try_unwrap(old_front).ok().unwrap().into_inner().val\n})\n} // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nself.rear.take().map(|old_rear| {\nmatch old_rear.borrow_mut().prev.take() {\nSome(new_rear) => {\nnew_rear.borrow_mut().next.take();\nself.rear = Some(new_rear);     // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nNone => {\nself.front.take();\n}\n}\nself.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nRc::try_unwrap(old_rear).ok().unwrap().into_inner().val\n})\n}\n}\n/* \u961f\u9996\u51fa\u961f */\npub fn pop_first(&mut self) -> Option<T> {\nreturn self.pop(true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\npub fn pop_last(&mut self) -> Option<T> {\nreturn self.pop(false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npub fn peek_first(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.front.as_ref()\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npub fn peek_last(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.rear.as_ref()\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.insert(0, node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_deque.c
        /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\ntypedef struct DoublyListNode {\nint val;                     // \u8282\u70b9\u503c\nstruct DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\nstruct DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\n} DoublyListNode;\n/* \u6784\u9020\u51fd\u6570 */\nDoublyListNode *newDoublyListNode(int num) {\nDoublyListNode *new = (DoublyListNode *)malloc(sizeof(DoublyListNode));\nnew->val = num;\nnew->next = NULL;\nnew->prev = NULL;\nreturn new;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delDoublyListNode(DoublyListNode *node) {\nfree(node);\n}\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\nDoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize;                  // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n} LinkedListDeque;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListDeque *newLinkedListDeque() {\nLinkedListDeque *deque = (LinkedListDeque *)malloc(sizeof(LinkedListDeque));\ndeque->front = NULL;\ndeque->rear = NULL;\ndeque->queSize = 0;\nreturn deque;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListdeque(LinkedListDeque *deque) {\n// \u91ca\u653e\u6240\u6709\u8282\u70b9\nfor (int i = 0; i < deque->queSize && deque->front != NULL; i++) {\nDoublyListNode *tmp = deque->front;\ndeque->front = deque->front->next;\nfree(tmp);\n}\n// \u91ca\u653e deque \u7ed3\u6784\u4f53\nfree(deque);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListDeque *deque) {\nreturn deque->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListDeque *deque) {\nreturn (size(deque) == 0);\n}\n/* \u5165\u961f */\nvoid push(LinkedListDeque *deque, int num, bool isFront) {\nDoublyListNode *node = newDoublyListNode(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411node\nif (empty(deque)) {\ndeque->front = deque->rear = node;\n}\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\nelse if (isFront) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\ndeque->front->prev = node;\nnode->next = deque->front;\ndeque->front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\nelse {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\ndeque->rear->next = node;\nnode->prev = deque->rear;\ndeque->rear = node;\n}\ndeque->queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(LinkedListDeque *deque, int num) {\npush(deque, num, true);\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(LinkedListDeque *deque, int num) {\npush(deque, num, false);\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(LinkedListDeque *deque) {\nassert(size(deque) && deque->front);\nreturn deque->front->val;\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(LinkedListDeque *deque) {\nassert(size(deque) && deque->rear);\nreturn deque->rear->val;\n}\n/* \u51fa\u961f */\nint pop(LinkedListDeque *deque, bool isFront) {\nif (empty(deque))\nreturn -1;\nint val;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (isFront) {\nval = peekFirst(deque); // \u6682\u5b58\u5934\u8282\u70b9\u503c\nDoublyListNode *fNext = deque->front->next;\nif (fNext) {\nfNext->prev = NULL;\ndeque->front->next = NULL;\ndelDoublyListNode(deque->front);\n}\ndeque->front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n}\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\nelse {\nval = peekLast(deque); // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\nDoublyListNode *rPrev = deque->rear->prev;\nif (rPrev) {\nrPrev->next = NULL;\ndeque->rear->prev = NULL;\ndelDoublyListNode(deque->rear);\n}\ndeque->rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\ndeque->queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(LinkedListDeque *deque) {\nreturn pop(deque, true);\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(LinkedListDeque *deque) {\nreturn pop(deque, false);\n}\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListDeque(LinkedListDeque *deque) {\nint *arr = malloc(sizeof(int) * deque->queSize);\n// \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\nint i;\nDoublyListNode *node;\nfor (i = 0, node = deque->front; i < deque->queSize; i++) {\narr[i] = node->val;\nnode = node->next;\n}\nprintArray(arr, deque->queSize);\nfree(arr);\n}\n
        linkedlist_deque.zig
        // \u53cc\u5411\u94fe\u8868\u8282\u70b9\nfn ListNode(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nval: T = undefined,     // \u8282\u70b9\u503c\nnext: ?*Self = null,    // \u540e\u7ee7\u8282\u70b9\u6307\u9488\nprev: ?*Self = null,    // \u524d\u9a71\u8282\u70b9\u6307\u9488\n// Initialize a list node with specific value\npub fn init(self: *Self, x: i32) void {\nself.val = x;\nself.next = null;\nself.prev = null;\n}\n};\n}\n// \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\nfn LinkedListDeque(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nfront: ?*ListNode(T) = null,                    // \u5934\u8282\u70b9 front\nrear: ?*ListNode(T) = null,                     // \u5c3e\u8282\u70b9 rear\nque_size: usize = 0,                             // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.front = null;\nself.rear = null;\nself.que_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.que_size;\n}\n// \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u5165\u961f\u64cd\u4f5c\npub fn push(self: *Self, num: T, is_front: bool) !void {\nvar node = try self.mem_allocator.create(ListNode(T));\nnode.init(num);\n// \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\nif (self.isEmpty()) {\nself.front = node;\nself.rear = node;\n// \u961f\u9996\u5165\u961f\u64cd\u4f5c\n} else if (is_front) {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\nself.front.?.prev = node;\nnode.next = self.front;\nself.front = node;  // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n} else {\n// \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\nself.rear.?.next = node;\nnode.prev = self.rear;\nself.rear = node;   // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nself.que_size += 1;      // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n} // \u961f\u9996\u5165\u961f\npub fn pushFirst(self: *Self, num: T) !void {\ntry self.push(num, true);\n} // \u961f\u5c3e\u5165\u961f\npub fn pushLast(self: *Self, num: T) !void {\ntry self.push(num, false);\n} // \u51fa\u961f\u64cd\u4f5c\npub fn pop(self: *Self, is_front: bool) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nvar val: T = undefined;\n// \u961f\u9996\u51fa\u961f\u64cd\u4f5c\nif (is_front) {\nval = self.front.?.val;     // \u6682\u5b58\u5934\u8282\u70b9\u503c\n// \u5220\u9664\u5934\u8282\u70b9\nvar fNext = self.front.?.next;\nif (fNext != null) {\nfNext.?.prev = null;\nself.front.?.next = null;\n}\nself.front = fNext;         // \u66f4\u65b0\u5934\u8282\u70b9\n// \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n} else {\nval = self.rear.?.val;      // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n// \u5220\u9664\u5c3e\u8282\u70b9\nvar rPrev = self.rear.?.prev;\nif (rPrev != null) {\nrPrev.?.next = null;\nself.rear.?.prev = null;\n}\nself.rear = rPrev;          // \u66f4\u65b0\u5c3e\u8282\u70b9\n}\nself.que_size -= 1;              // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\nreturn val;\n} // \u961f\u9996\u51fa\u961f\npub fn popFirst(self: *Self) T {\nreturn self.pop(true);\n} // \u961f\u5c3e\u51fa\u961f\npub fn popLast(self: *Self) T {\nreturn self.pop(false);\n} // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peekFirst(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn self.front.?.val;\n}  // \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\npub fn peekLast(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn self.rear.?.val;\n}\n// \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\npub fn toArray(self: *Self) ![]T {\nvar node = self.front;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[i] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/deque/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u5982\u56fe 5-9 \u6240\u793a\uff0c\u4e0e\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u961f\u5217\u7c7b\u4f3c\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u73af\u5f62\u6570\u7ec4\u6765\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u3002

        ArrayDequepushLast()pushFirst()popLast()popFirst()

        \u56fe 5-9 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u53cc\u5411\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u5728\u961f\u5217\u7684\u5b9e\u73b0\u57fa\u7840\u4e0a\uff0c\u4ec5\u9700\u589e\u52a0\u201c\u961f\u9996\u5165\u961f\u201d\u548c\u201c\u961f\u5c3e\u51fa\u961f\u201d\u7684\u65b9\u6cd5\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_deque.py
        class ArrayDeque:\n\"\"\"\u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\ndef __init__(self, capacity: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._nums: list[int] = [0] * capacity\nself._front: int = 0\nself._size: int = 0\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\nreturn len(self._nums)\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._size == 0\ndef index(self, i: int) -> int:\n\"\"\"\u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15\"\"\"\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n# \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n# \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + self.capacity()) % self.capacity()\ndef push_first(self, num: int):\n\"\"\"\u961f\u9996\u5165\u961f\"\"\"\nif self._size == self.capacity():\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n# \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nself._front = self.index(self._front - 1)\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nself._nums[self._front] = num\nself._size += 1\ndef push_last(self, num: int):\n\"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\nif self._size == self.capacity():\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n# \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nrear = self.index(self._front + self._size)\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself._nums[rear] = num\nself._size += 1\ndef pop_first(self) -> int:\n\"\"\"\u961f\u9996\u51fa\u961f\"\"\"\nnum = self.peek_first()\n# \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nself._front = self.index(self._front + 1)\nself._size -= 1\nreturn num\ndef pop_last(self) -> int:\n\"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\nnum = self.peek_last()\nself._size -= 1\nreturn num\ndef peek_first(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\nreturn self._nums[self._front]\ndef peek_last(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n# \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlast = self.index(self._front + self._size - 1)\nreturn self._nums[last]\ndef to_array(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\n# \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nres = []\nfor i in range(self._size):\nres.append(self._nums[self.index(self._front + i)])\nreturn res\n
        array_deque.cpp
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate:\nvector<int> nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;        // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;      // \u53cc\u5411\u961f\u5217\u957f\u5ea6\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayDeque(int capacity) {\nnums.resize(capacity);\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn nums.size();\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int num) {\nif (queSize == capacity()) {\ncout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int num) {\nif (queSize == capacity()) {\ncout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nint num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nint num = peekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty())\nthrow out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> res(queSize);\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[index(j)];\n}\nreturn res;\n}\n};\n
        array_deque.java
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate int[] nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayDeque(int capacity) {\nthis.nums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\npublic int capacity() {\nreturn nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nprivate int index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npublic void pushFirst(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void pushLast(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int popFirst() {\nint num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int popLast() {\nint num = peekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peekFirst() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int peekLast() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.cs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nint[] nums;  // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayDeque(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint Capacity() {\nreturn nums.Length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint Index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + Capacity()) % Capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npublic void PushFirst(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = Index(front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num;\nqueSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npublic void PushLast(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = Index(front + queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npublic int PopFirst() {\nint num = PeekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = Index(front + 1);\nqueSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npublic int PopLast() {\nint num = PeekLast();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int PeekFirst() {\nif (IsEmpty()) {\nthrow new InvalidOperationException();\n}\nreturn nums[front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npublic int PeekLast() {\nif (IsEmpty()) {\nthrow new InvalidOperationException();\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = Index(front + queSize - 1);\nreturn nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[Index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.go
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype arrayDeque struct {\nnums        []int // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize     int   // \u53cc\u5411\u961f\u5217\u957f\u5ea6\nqueCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayDeque(queCapacity int) *arrayDeque {\nreturn &arrayDeque{\nnums:        make([]int, queCapacity),\nqueCapacity: queCapacity,\nfront:       0,\nqueSize:     0,\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayDeque) size() int {\nreturn q.queSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayDeque) isEmpty() bool {\nreturn q.queSize == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nfunc (q *arrayDeque) index(i int) int {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + q.queCapacity) % q.queCapacity\n}\n/* \u961f\u9996\u5165\u961f */\nfunc (q *arrayDeque) pushFirst(num int) {\nif q.queSize == q.queCapacity {\nfmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nq.front = q.index(q.front - 1)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nq.nums[q.front] = num\nq.queSize++\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc (q *arrayDeque) pushLast(num int) {\nif q.queSize == q.queCapacity {\nfmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nrear := q.index(q.front + q.queSize)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nq.nums[rear] = num\nq.queSize++\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc (q *arrayDeque) popFirst() any {\nnum := q.peekFirst()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nq.front = q.index(q.front + 1)\nq.queSize--\nreturn num\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc (q *arrayDeque) popLast() any {\nnum := q.peekLast()\nq.queSize--\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayDeque) peekFirst() any {\nif q.isEmpty() {\nreturn nil\n}\nreturn q.nums[q.front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (q *arrayDeque) peekLast() any {\nif q.isEmpty() {\nreturn nil\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlast := q.index(q.front + q.queSize - 1)\nreturn q.nums[last]\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayDeque) toSlice() []int {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nres := make([]int, q.queSize)\nfor i, j := 0, q.front; i < q.queSize; i++ {\nres[i] = q.nums[q.index(j)]\nj++\n}\nreturn res\n}\n
        array_deque.swift
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate var front: Int // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate var queSize: Int // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(capacity: Int) {\nnums = Array(repeating: 0, count: capacity)\nfront = 0\nqueSize = 0\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nfunc capacity() -> Int {\nnums.count\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nprivate func index(i: Int) -> Int {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\n(i + capacity()) % capacity()\n}\n/* \u961f\u9996\u5165\u961f */\nfunc pushFirst(num: Int) {\nif size() == capacity() {\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nfront = index(i: front - 1)\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nnums[front] = num\nqueSize += 1\n}\n/* \u961f\u5c3e\u5165\u961f */\nfunc pushLast(num: Int) {\nif size() == capacity() {\nprint(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nlet rear = index(i: front + size())\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num\nqueSize += 1\n}\n/* \u961f\u9996\u51fa\u961f */\nfunc popFirst() -> Int {\nlet num = peekFirst()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nfront = index(i: front + 1)\nqueSize -= 1\nreturn num\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfunc popLast() -> Int {\nlet num = peekLast()\nqueSize -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peekFirst() -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn nums[front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc peekLast() -> Int {\nif isEmpty() {\nfatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlet last = index(i: front + size() - 1)\nreturn nums[last]\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfunc toArray() -> [Int] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = Array(repeating: 0, count: size())\nfor (i, j) in sequence(first: (0, front), next: { $0 < self.size() - 1 ? ($0 + 1, $1 + 1) : nil }) {\nres[i] = nums[index(i: j)]\n}\nreturn res\n}\n}\n
        array_deque.js
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n#nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n#front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n#queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(capacity) {\nthis.#nums = new Array(capacity);\nthis.#front = 0;\nthis.#queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\ncapacity() {\nreturn this.#nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nindex(i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + this.capacity()) % this.capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npushFirst(num) {\nif (this.#queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nthis.#front = this.index(this.#front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nthis.#nums[this.#front] = num;\nthis.#queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npushLast(num) {\nif (this.#queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nconst rear = this.index(this.#front + this.#queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.#nums[rear] = num;\nthis.#queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npopFirst() {\nconst num = this.peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nthis.#front = this.index(this.#front + 1);\nthis.#queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npopLast() {\nconst num = this.peekLast();\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst() {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\nreturn this.#nums[this.#front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast() {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nconst last = this.index(this.#front + this.#queSize - 1);\nreturn this.#nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\ntoArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst res = [];\nfor (let i = 0, j = this.#front; i < this.#queSize; i++, j++) {\nres[i] = this.#nums[this.index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.ts
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nprivate nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate queSize: number; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(capacity: number) {\nthis.nums = new Array(capacity);\nthis.front = 0;\nthis.queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\ncapacity(): number {\nreturn this.nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nindex(i: number): number {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + this.capacity()) % this.capacity();\n}\n/* \u961f\u9996\u5165\u961f */\npushFirst(num: number): void {\nif (this.queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nthis.front = this.index(this.front - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nthis.nums[this.front] = num;\nthis.queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\npushLast(num: number): void {\nif (this.queSize === this.capacity()) {\nconsole.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nconst rear: number = this.index(this.front + this.queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.nums[rear] = num;\nthis.queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\npopFirst(): number {\nconst num: number = this.peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nthis.front = this.index(this.front + 1);\nthis.queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\npopLast(): number {\nconst num: number = this.peekLast();\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeekFirst(): number {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\nreturn this.nums[this.front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\npeekLast(): number {\nif (this.isEmpty()) throw new Error('The Deque Is Empty.');\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nconst last = this.index(this.front + this.queSize - 1);\nreturn this.nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\ntoArray(): number[] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst res: number[] = [];\nfor (let i = 0, j = this.front; i < this.queSize; i++, j++) {\nres[i] = this.nums[this.index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.dart
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\nlate List<int> _nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nlate int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nlate int _queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayDeque(int capacity) {\nthis._nums = List.filled(capacity, 0);\nthis._front = this._queSize = 0;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn _nums.length;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint index(int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn (i + capacity()) % capacity();\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(int _num) {\nif (_queSize == capacity()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 _front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n_front = index(_front - 1);\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u9996\n_nums[_front] = _num;\n_queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(int _num) {\nif (_queSize == capacity()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = index(_front + _queSize);\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n_nums[rear] = _num;\n_queSize++;\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst() {\nint _num = peekFirst();\n// \u961f\u9996\u6307\u9488\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n_front = index(_front + 1);\n_queSize--;\nreturn _num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast() {\nint _num = peekLast();\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst() {\nif (isEmpty()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n}\nreturn _nums[_front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast() {\nif (isEmpty()) {\nthrow Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n}\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nint last = index(_front + _queSize - 1);\nreturn _nums[last];\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nList<int> toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nList<int> res = List.filled(_queSize, 0);\nfor (int i = 0, j = _front; i < _queSize; i++, j++) {\nres[i] = _nums[index(j)];\n}\nreturn res;\n}\n}\n
        array_deque.rs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nstruct ArrayDeque {\nnums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront: usize,       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nque_size: usize,    // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n}\nimpl ArrayDeque {\n/* \u6784\u9020\u65b9\u6cd5 */\npub fn new(capacity: usize) -> Self {\nSelf {\nnums: vec![0; capacity],\nfront: 0,\nque_size: 0,\n}\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\npub fn capacity(&self) -> usize {\nself.nums.len()\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nself.que_size\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nself.que_size == 0\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nfn index(&self, i: i32) -> usize {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn ((i + self.capacity() as i32) % self.capacity() as i32) as usize;\n}\n/* \u961f\u9996\u5165\u961f */\npub fn push_first(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\nself.front = self.index(self.front as i32 - 1);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\nself.nums[self.front] = num;\nself.que_size += 1;\n}\n/* \u961f\u5c3e\u5165\u961f */\npub fn push_last(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nlet rear = self.index(self.front as i32 + self.que_size as i32);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself.nums[rear] = num;\nself.que_size += 1;\n}\n/* \u961f\u9996\u51fa\u961f */\nfn pop_first(&mut self) -> i32 {\nlet num = self.peek_first();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\nself.front = self.index(self.front as i32 + 1);\nself.que_size -= 1;\nnum\n}\n/* \u961f\u5c3e\u51fa\u961f */\nfn pop_last(&mut self) -> i32 {\nlet num = self.peek_last();\nself.que_size -= 1;\nnum\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfn peek_first(&self) -> i32 {\nif self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\nself.nums[self.front]\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfn peek_last(&self) -> i32 {\nif self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n// \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\nlet last = self.index(self.front as i32 + self.que_size as i32 - 1);\nself.nums[last]\n}\n/* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\nfn to_array(&self) -> Vec<i32> {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nlet mut res = vec![0; self.que_size];\nlet mut j = self.front;\nfor i in 0..self.que_size {\nres[i] = self.nums[self.index(j as i32)];\nj += 1;\n}\nres\n}\n}\n
        array_deque.c
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayDeque;\n/* \u6784\u9020\u51fd\u6570 */\nArrayDeque *newArrayDeque(int capacity) {\nArrayDeque *deque = (ArrayDeque *)malloc(sizeof(ArrayDeque));\n// \u521d\u59cb\u5316\u6570\u7ec4\ndeque->queCapacity = capacity;\ndeque->nums = (int *)malloc(sizeof(int) * deque->queCapacity);\ndeque->front = deque->queSize = 0;\nreturn deque;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayDeque(ArrayDeque *deque) {\nfree(deque->nums);\nfree(deque);\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayDeque *deque) {\nreturn deque->queCapacity;\n}\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayDeque *deque) {\nreturn deque->queSize;\n}\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayDeque *deque) {\nreturn deque->queSize == 0;\n}\n/* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\nint dequeIndex(ArrayDeque *deque, int i) {\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0\u6570\u7ec4\u9996\u5c3e\u76f8\u8fde\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u56de\u5230\u5934\u90e8\n// \u5f53 i \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\uff0c\u56de\u5230\u5c3e\u90e8\nreturn ((i + capacity(deque)) % capacity(deque));\n}\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(ArrayDeque *deque, int num) {\nif (deque->queSize == capacity(deque)) {\nprintf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u56de\u5230\u5c3e\u90e8\ndeque->front = dequeIndex(deque, deque->front - 1);\n// \u5c06 num \u6dfb\u52a0\u5230\u961f\u9996\ndeque->nums[deque->front] = num;\ndeque->queSize++;\n}\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(ArrayDeque *deque, int num) {\nif (deque->queSize == capacity(deque)) {\nprintf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\nint rear = dequeIndex(deque, deque->front + deque->queSize);\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\ndeque->nums[rear] = num;\ndeque->queSize++;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(ArrayDeque *deque) {\n// \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\nassert(empty(deque) == 0);\nreturn deque->nums[deque->front];\n}\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(ArrayDeque *deque) {\n// \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\nassert(empty(deque) == 0);\nint last = dequeIndex(deque, deque->front + deque->queSize - 1);\nreturn deque->nums[last];\n}\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(ArrayDeque *deque) {\nint num = peekFirst(deque);\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\ndeque->front = dequeIndex(deque, deque->front + 1);\ndeque->queSize--;\nreturn num;\n}\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(ArrayDeque *deque) {\nint num = peekLast(deque);\ndeque->queSize--;\nreturn num;\n}\n
        array_deque.zig
        [class]{ArrayDeque}-[func]{}\n
        "},{"location":"chapter_stack_and_queue/deque/#533","title":"5.3.3 \u00a0 \u53cc\u5411\u961f\u5217\u5e94\u7528","text":"

        \u53cc\u5411\u961f\u5217\u517c\u5177\u6808\u4e0e\u961f\u5217\u7684\u903b\u8f91\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e24\u8005\u7684\u6240\u6709\u5e94\u7528\u573a\u666f\uff0c\u540c\u65f6\u63d0\u4f9b\u66f4\u9ad8\u7684\u81ea\u7531\u5ea6\u3002

        \u6211\u4eec\u77e5\u9053\uff0c\u8f6f\u4ef6\u7684\u201c\u64a4\u9500\u201d\u529f\u80fd\u901a\u5e38\u4f7f\u7528\u6808\u6765\u5b9e\u73b0\uff1a\u7cfb\u7edf\u5c06\u6bcf\u6b21\u66f4\u6539\u64cd\u4f5c push \u5230\u6808\u4e2d\uff0c\u7136\u540e\u901a\u8fc7 pop \u5b9e\u73b0\u64a4\u9500\u3002\u7136\u800c\uff0c\u8003\u8651\u5230\u7cfb\u7edf\u8d44\u6e90\u7684\u9650\u5236\uff0c\u8f6f\u4ef6\u901a\u5e38\u4f1a\u9650\u5236\u64a4\u9500\u7684\u6b65\u6570\uff08\u4f8b\u5982\u4ec5\u5141\u8bb8\u4fdd\u5b58 \\(50\\) \u6b65\uff09\u3002\u5f53\u6808\u7684\u957f\u5ea6\u8d85\u8fc7 \\(50\\) \u65f6\uff0c\u8f6f\u4ef6\u9700\u8981\u5728\u6808\u5e95\uff08\u961f\u9996\uff09\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002\u4f46\u6808\u65e0\u6cd5\u5b9e\u73b0\u8be5\u529f\u80fd\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u4f7f\u7528\u53cc\u5411\u961f\u5217\u6765\u66ff\u4ee3\u6808\u3002\u8bf7\u6ce8\u610f\uff0c\u201c\u64a4\u9500\u201d\u7684\u6838\u5fc3\u903b\u8f91\u4ecd\u7136\u9075\u5faa\u6808\u7684\u5148\u5165\u540e\u51fa\u539f\u5219\uff0c\u53ea\u662f\u53cc\u5411\u961f\u5217\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u5b9e\u73b0\u4e00\u4e9b\u989d\u5916\u903b\u8f91\u3002

        "},{"location":"chapter_stack_and_queue/queue/","title":"5.2 \u00a0 \u961f\u5217","text":"

        \u300c\u961f\u5217 queue\u300d\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u5148\u51fa\u89c4\u5219\u7684\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002\u987e\u540d\u601d\u4e49\uff0c\u961f\u5217\u6a21\u62df\u4e86\u6392\u961f\u73b0\u8c61\uff0c\u5373\u65b0\u6765\u7684\u4eba\u4e0d\u65ad\u52a0\u5165\u961f\u5217\u5c3e\u90e8\uff0c\u800c\u4f4d\u4e8e\u961f\u5217\u5934\u90e8\u7684\u4eba\u9010\u4e2a\u79bb\u5f00\u3002

        \u5982\u56fe 5-4 \u6240\u793a\uff0c\u6211\u4eec\u5c06\u961f\u5217\u5934\u90e8\u79f0\u4e3a\u201c\u961f\u9996\u201d\uff0c\u5c3e\u90e8\u79f0\u4e3a\u201c\u961f\u5c3e\u201d\uff0c\u5c06\u628a\u5143\u7d20\u52a0\u5165\u961f\u5c3e\u7684\u64cd\u4f5c\u79f0\u4e3a\u201c\u5165\u961f\u201d\uff0c\u5220\u9664\u961f\u9996\u5143\u7d20\u7684\u64cd\u4f5c\u79f0\u4e3a\u201c\u51fa\u961f\u201d\u3002

        \u56fe 5-4 \u00a0 \u961f\u5217\u7684\u5148\u5165\u5148\u51fa\u89c4\u5219

        "},{"location":"chapter_stack_and_queue/queue/#521","title":"5.2.1 \u00a0 \u961f\u5217\u5e38\u7528\u64cd\u4f5c","text":"

        \u961f\u5217\u7684\u5e38\u89c1\u64cd\u4f5c\u5982\u8868 5-2 \u6240\u793a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u7684\u65b9\u6cd5\u540d\u79f0\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u6211\u4eec\u5728\u6b64\u91c7\u7528\u4e0e\u6808\u76f8\u540c\u7684\u65b9\u6cd5\u547d\u540d\u3002

        \u8868 5-2 \u00a0 \u961f\u5217\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5\u540d \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u961f\uff0c\u5373\u5c06\u5143\u7d20\u6dfb\u52a0\u81f3\u961f\u5c3e \\(O(1)\\) pop() \u961f\u9996\u5143\u7d20\u51fa\u961f \\(O(1)\\) peek() \u8bbf\u95ee\u961f\u9996\u5143\u7d20 \\(O(1)\\)

        \u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u4e2d\u73b0\u6210\u7684\u961f\u5217\u7c7b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig queue.py
        from collections import deque\n# \u521d\u59cb\u5316\u961f\u5217\n# \u5728 Python \u4e2d\uff0c\u6211\u4eec\u4e00\u822c\u5c06\u53cc\u5411\u961f\u5217\u7c7b deque \u5f53\u4f5c\u961f\u5217\u4f7f\u7528\n# \u867d\u7136 queue.Queue() \u662f\u7eaf\u6b63\u7684\u961f\u5217\u7c7b\uff0c\u4f46\u4e0d\u592a\u597d\u7528\uff0c\u56e0\u6b64\u4e0d\u63a8\u8350\nque: deque[int] = deque()\n# \u5143\u7d20\u5165\u961f\nque.append(1)\nque.append(3)\nque.append(2)\nque.append(5)\nque.append(4)\n# \u8bbf\u95ee\u961f\u9996\u5143\u7d20\nfront: int = que[0];\n# \u5143\u7d20\u51fa\u961f\npop: int = que.popleft()\n# \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(que)\n# \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(que) == 0\n
        queue.cpp
        /* \u521d\u59cb\u5316\u961f\u5217 */\nqueue<int> queue;\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint front = queue.front();\n/* \u5143\u7d20\u51fa\u961f */\nqueue.pop();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty = queue.empty();\n
        queue.java
        /* \u521d\u59cb\u5316\u961f\u5217 */\nQueue<Integer> queue = new LinkedList<>();\n/* \u5143\u7d20\u5165\u961f */\nqueue.offer(1);\nqueue.offer(3);\nqueue.offer(2);\nqueue.offer(5);\nqueue.offer(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.peek();\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.poll();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = queue.isEmpty();\n
        queue.cs
        /* \u521d\u59cb\u5316\u961f\u5217 */\nQueue<int> queue = new();\n/* \u5143\u7d20\u5165\u961f */\nqueue.Enqueue(1);\nqueue.Enqueue(3);\nqueue.Enqueue(2);\nqueue.Enqueue(5);\nqueue.Enqueue(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.Peek();\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.Dequeue();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.Count;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = queue.Count == 0;\n
        queue_test.go
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// \u5728 Go \u4e2d\uff0c\u5c06 list \u4f5c\u4e3a\u961f\u5217\u6765\u4f7f\u7528\nqueue := list.New()\n/* \u5143\u7d20\u5165\u961f */\nqueue.PushBack(1)\nqueue.PushBack(3)\nqueue.PushBack(2)\nqueue.PushBack(5)\nqueue.PushBack(4)\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek := queue.Front()\n/* \u5143\u7d20\u51fa\u961f */\npop := queue.Front()\nqueue.Remove(pop)\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nsize := queue.Len()\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty := queue.Len() == 0\n
        queue.swift
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528\nvar queue: [Int] = []\n/* \u5143\u7d20\u5165\u961f */\nqueue.append(1)\nqueue.append(3)\nqueue.append(2)\nqueue.append(5)\nqueue.append(4)\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nlet peek = queue.first!\n/* \u5143\u7d20\u51fa\u961f */\n// \u7531\u4e8e\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 removeFirst \u7684\u590d\u6742\u5ea6\u4e3a O(n)\nlet pool = queue.removeFirst()\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = queue.count\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = queue.isEmpty\n
        queue.js
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// JavaScript \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528\nconst queue = [];\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n/* \u5143\u7d20\u51fa\u961f */\n// \u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 shift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst pop = queue.shift();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst empty = queue.length === 0;\n
        queue.ts
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// TypeScript \u6ca1\u6709\u5185\u7f6e\u7684\u961f\u5217\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u961f\u5217\u6765\u4f7f\u7528 \nconst queue: number[] = [];\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n/* \u5143\u7d20\u51fa\u961f */\n// \u5e95\u5c42\u662f\u6570\u7ec4\uff0c\u56e0\u6b64 shift() \u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\nconst pop = queue.shift();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nconst empty = queue.length === 0;\n
        queue.dart
        /* \u521d\u59cb\u5316\u961f\u5217 */\n// \u5728 Dart \u4e2d\uff0c\u961f\u5217\u7c7b Qeque \u662f\u53cc\u5411\u961f\u5217\uff0c\u4e5f\u53ef\u4f5c\u4e3a\u961f\u5217\u4f7f\u7528\nQueue<int> queue = Queue();\n/* \u5143\u7d20\u5165\u961f */\nqueue.add(1);\nqueue.add(3);\nqueue.add(2);\nqueue.add(5);\nqueue.add(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.first;\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.removeFirst();\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.length;\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = queue.isEmpty;\n
        queue.rs
        /* \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217 */\n// \u5728 Rust \u4e2d\u4f7f\u7528\u53cc\u5411\u961f\u5217\u4f5c\u4e3a\u666e\u901a\u961f\u5217\u6765\u4f7f\u7528\nlet mut deque: VecDeque<u32> = VecDeque::new();\n/* \u5143\u7d20\u5165\u961f */\ndeque.push_back(1);\ndeque.push_back(3);\ndeque.push_back(2);\ndeque.push_back(5);\ndeque.push_back(4);\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nif let Some(front) = deque.front() {\n}\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop) = deque.pop_front() {\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = deque.is_empty();\n
        queue.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u961f\u5217\n
        queue.zig
        \n
        "},{"location":"chapter_stack_and_queue/queue/#522","title":"5.2.2 \u00a0 \u961f\u5217\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u5b9e\u73b0\u961f\u5217\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u5728\u4e00\u7aef\u6dfb\u52a0\u5143\u7d20\uff0c\u5e76\u5728\u53e6\u4e00\u7aef\u5220\u9664\u5143\u7d20\u3002\u94fe\u8868\u548c\u6570\u7ec4\u90fd\u7b26\u5408\u8981\u6c42\u3002

        "},{"location":"chapter_stack_and_queue/queue/#1","title":"1. \u00a0 \u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u5982\u56fe 5-5 \u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u94fe\u8868\u7684\u201c\u5934\u8282\u70b9\u201d\u548c\u201c\u5c3e\u8282\u70b9\u201d\u5206\u522b\u89c6\u4e3a\u201c\u961f\u9996\u201d\u548c\u201c\u961f\u5c3e\u201d\uff0c\u89c4\u5b9a\u961f\u5c3e\u4ec5\u53ef\u6dfb\u52a0\u8282\u70b9\uff0c\u961f\u9996\u4ec5\u53ef\u5220\u9664\u8282\u70b9\u3002

        LinkedListQueuepush()pop()

        \u56fe 5-5 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u4ee5\u4e0b\u662f\u7528\u94fe\u8868\u5b9e\u73b0\u961f\u5217\u7684\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_queue.py
        class LinkedListQueue:\n\"\"\"\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._front: ListNode | None = None  # \u5934\u8282\u70b9 front\nself._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\nself._size: int = 0\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn not self._front\ndef push(self, num: int):\n\"\"\"\u5165\u961f\"\"\"\n# \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nnode = ListNode(num)\n# \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif self._front is None:\nself._front = node\nself._rear = node\n# \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse:\nself._rear.next = node\nself._rear = node\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u961f\"\"\"\nnum = self.peek()\n# \u5220\u9664\u5934\u8282\u70b9\nself._front = self._front.next\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\nreturn self._front.val\ndef to_list(self) -> list[int]:\n\"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nqueue = []\ntemp = self._front\nwhile temp:\nqueue.append(temp.val)\ntemp = temp.next\nreturn queue\n
        linkedlist_queue.cpp
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate:\nListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nint queSize;\npublic:\nLinkedListQueue() {\nfront = nullptr;\nrear = nullptr;\nqueSize = 0;\n}\n~LinkedListQueue() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nfreeMemoryLinkedList(front);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode *node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == nullptr) {\nfront = node;\nrear = node;\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nrear->next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\nvoid pop() {\nint num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\nListNode *tmp = front;\nfront = front->next;\n// \u91ca\u653e\u5185\u5b58\ndelete tmp;\nqueSize--;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (size() == 0)\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn front->val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\nvector<int> toVector() {\nListNode *node = front;\nvector<int> res(size());\nfor (int i = 0; i < res.size(); i++) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_queue.java
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\nprivate int queSize = 0;\npublic LinkedListQueue() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f */\npublic void push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == null) {\nfront = node;\nrear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nrear.next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int pop() {\nint num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front.next;\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn front.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] toArray() {\nListNode node = front;\nint[] res = new int[size()];\nfor (int i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.cs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nListNode? front, rear;  // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear \nint queSize = 0;\npublic LinkedListQueue() {\nfront = null;\nrear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u961f */\npublic void Push(int num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nListNode node = new(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (front == null) {\nfront = node;\nrear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else if (rear != null) {\nrear.next = node;\nrear = node;\n}\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int Pop() {\nint num = Peek();\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front?.next;\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nif (front == null)\nreturn [];\nListNode? node = front;\nint[] res = new int[Size()];\nfor (int i = 0; i < res.Length; i++) {\nres[i] = node!.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.go
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntype linkedListQueue struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list \u6765\u5b9e\u73b0\u961f\u5217\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newLinkedListQueue() *linkedListQueue {\nreturn &linkedListQueue{\ndata: list.New(),\n}\n}\n/* \u5165\u961f */\nfunc (s *linkedListQueue) push(value any) {\ns.data.PushBack(value)\n}\n/* \u51fa\u961f */\nfunc (s *linkedListQueue) pop() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListQueue) peek() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Front()\nreturn e.Value\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListQueue) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListQueue) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListQueue) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_queue.swift
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate var front: ListNode? // \u5934\u8282\u70b9\nprivate var rear: ListNode? // \u5c3e\u8282\u70b9\nprivate var _size = 0\ninit() {}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\n_size\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u961f */\nfunc push(num: Int) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nlet node = ListNode(x: num)\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif front == nil {\nfront = node\nrear = node\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nrear?.next = node\nrear = node\n}\n_size += 1\n}\n/* \u51fa\u961f */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n// \u5220\u9664\u5934\u8282\u70b9\nfront = front?.next\n_size -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn front!.val\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nvar node = front\nvar res = Array(repeating: 0, count: size())\nfor i in res.indices {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_queue.js
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n#front; // \u5934\u8282\u70b9 #front\n#rear; // \u5c3e\u8282\u70b9 #rear\n#queSize = 0;\nconstructor() {\nthis.#front = null;\nthis.#rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.size === 0;\n}\n/* \u5165\u961f */\npush(num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nconst node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (!this.#front) {\nthis.#front = node;\nthis.#rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nthis.#rear.next = node;\nthis.#rear = node;\n}\nthis.#queSize++;\n}\n/* \u51fa\u961f */\npop() {\nconst num = this.peek();\n// \u5220\u9664\u5934\u8282\u70b9\nthis.#front = this.#front.next;\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek() {\nif (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.#front.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray() {\nlet node = this.#front;\nconst res = new Array(this.size);\nfor (let i = 0; i < res.length; i++) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.ts
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nprivate front: ListNode | null; // \u5934\u8282\u70b9 front\nprivate rear: ListNode | null; // \u5c3e\u8282\u70b9 rear\nprivate queSize: number = 0;\nconstructor() {\nthis.front = null;\nthis.rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.size === 0;\n}\n/* \u5165\u961f */\npush(num: number): void {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nconst node = new ListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (!this.front) {\nthis.front = node;\nthis.rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nthis.rear!.next = node;\nthis.rear = node;\n}\nthis.queSize++;\n}\n/* \u51fa\u961f */\npop(): number {\nconst num = this.peek();\nif (!this.front) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n// \u5220\u9664\u5934\u8282\u70b9\nthis.front = this.front.next;\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek(): number {\nif (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray(): number[] {\nlet node = this.front;\nconst res = new Array<number>(this.size);\nfor (let i = 0; i < res.length; i++) {\nres[i] = node!.val;\nnode = node!.next;\n}\nreturn res;\n}\n}\n
        linkedlist_queue.dart
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\nListNode? _front; // \u5934\u8282\u70b9 _front\nListNode? _rear; // \u5c3e\u8282\u70b9 _rear\nint _queSize = 0; // \u961f\u5217\u957f\u5ea6\nLinkedListQueue() {\n_front = null;\n_rear = null;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int _num) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 _num\nfinal node = ListNode(_num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (_front == null) {\n_front = node;\n_rear = node;\n} else {\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n_rear!.next = node;\n_rear = node;\n}\n_queSize++;\n}\n/* \u51fa\u961f */\nint pop() {\nfinal int _num = peek();\n// \u5220\u9664\u5934\u8282\u70b9\n_front = _front!.next;\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (_queSize == 0) {\nthrow Exception('\u961f\u5217\u4e3a\u7a7a');\n}\nreturn _front!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nList<int> toArray() {\nListNode? node = _front;\nfinal List<int> queue = [];\nwhile (node != null) {\nqueue.add(node.val);\nnode = node.next;\n}\nreturn queue;\n}\n}\n
        linkedlist_queue.rs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListQueue<T> {\nfront: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\nrear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \nque_size: usize,                            // \u961f\u5217\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListQueue<T> {\npub fn new() -> Self {\nSelf {\nfront: None,\nrear: None,\nque_size: 0, }\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.que_size;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u961f */\npub fn push(&mut self, num: T) {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nlet new_rear = ListNode::new(num);\nmatch self.rear.take() {\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nSome(old_rear) => {\nold_rear.borrow_mut().next = Some(new_rear.clone());\nself.rear = Some(new_rear);\n}\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nNone => {\nself.front = Some(new_rear.clone());\nself.rear = Some(new_rear);\n}\n}\nself.que_size += 1;\n}\n/* \u51fa\u961f */\npub fn pop(&mut self) -> Option<T> {\nself.front.take().map(|old_front| {\nmatch old_front.borrow_mut().next.take() {\nSome(new_front) => {\nself.front = Some(new_front);\n}\nNone => {\nself.rear.take();\n}\n}\nself.que_size -= 1;\nRc::try_unwrap(old_front).ok().unwrap().into_inner().val\n})\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.front.as_ref()\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.insert(0, node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_queue.c
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\nListNode *front, *rear;\nint queSize;\n} LinkedListQueue;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListQueue *newLinkedListQueue() {\nLinkedListQueue *queue = (LinkedListQueue *)malloc(sizeof(LinkedListQueue));\nqueue->front = NULL;\nqueue->rear = NULL;\nqueue->queSize = 0;\nreturn queue;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListQueue(LinkedListQueue *queue) {\n// \u91ca\u653e\u6240\u6709\u8282\u70b9\nfor (int i = 0; i < queue->queSize && queue->front != NULL; i++) {\nListNode *tmp = queue->front;\nqueue->front = queue->front->next;\nfree(tmp);\n}\n// \u91ca\u653e queue \u7ed3\u6784\u4f53\nfree(queue);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListQueue *queue) {\nreturn queue->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListQueue *queue) {\nreturn (size(queue) == 0);\n}\n/* \u5165\u961f */\nvoid push(LinkedListQueue *queue, int num) {\n// \u5c3e\u8282\u70b9\u5904\u6dfb\u52a0 node\nListNode *node = newListNode(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (queue->front == NULL) {\nqueue->front = node;\nqueue->rear = node;\n}\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\nelse {\nqueue->rear->next = node;\nqueue->rear = node;\n}\nqueue->queSize++;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(LinkedListQueue *queue) {\nassert(size(queue) && queue->front);\nreturn queue->front->val;\n}\n/* \u51fa\u961f */\nvoid pop(LinkedListQueue *queue) {\nint num = peek(queue);\nListNode *tmp = queue->front;\nqueue->front = queue->front->next;\nfree(tmp);\nqueue->queSize--;\n}\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListQueue(LinkedListQueue *queue) {\nint *arr = malloc(sizeof(int) * queue->queSize);\n// \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\nint i;\nListNode *node;\nfor (i = 0, node = queue->front; i < queue->queSize; i++) {\narr[i] = node->val;\nnode = node->next;\n}\nprintArray(arr, queue->queSize);\nfree(arr);\n}\n
        linkedlist_queue.zig
        // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\nfn LinkedListQueue(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nfront: ?*inc.ListNode(T) = null,                // \u5934\u8282\u70b9 front\nrear: ?*inc.ListNode(T) = null,                 // \u5c3e\u8282\u70b9 rear\nque_size: usize = 0,                            // \u961f\u5217\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.front = null;\nself.rear = null;\nself.que_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.que_size;\n}\n// \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.size() == 0) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn self.front.?.val;\n}  // \u5165\u961f\npub fn push(self: *Self, num: T) !void {\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nvar node = try self.mem_allocator.create(inc.ListNode(T));\nnode.init(num);\n// \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\nif (self.front == null) {\nself.front = node;\nself.rear = node;\n// \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n} else {\nself.rear.?.next = node;\nself.rear = node;\n}\nself.que_size += 1;\n} // \u51fa\u961f\npub fn pop(self: *Self) T {\nvar num = self.peek();\n// \u5220\u9664\u5934\u8282\u70b9\nself.front = self.front.?.next;\nself.que_size -= 1;\nreturn num;\n} // \u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\nvar node = self.front;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[i] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/queue/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u5728\u6570\u7ec4\u4e2d\u5220\u9664\u9996\u5143\u7d20\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(O(n)\\) \uff0c\u8fd9\u4f1a\u5bfc\u81f4\u51fa\u961f\u64cd\u4f5c\u6548\u7387\u8f83\u4f4e\u3002\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u5de7\u5999\u65b9\u6cd5\u6765\u907f\u514d\u8fd9\u4e2a\u95ee\u9898\u3002

        \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf front \u6307\u5411\u961f\u9996\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5e76\u7ef4\u62a4\u4e00\u4e2a\u53d8\u91cf size \u7528\u4e8e\u8bb0\u5f55\u961f\u5217\u957f\u5ea6\u3002\u5b9a\u4e49 rear = front + size \uff0c\u8fd9\u4e2a\u516c\u5f0f\u8ba1\u7b97\u51fa\u7684 rear \u6307\u5411\u961f\u5c3e\u5143\u7d20\u4e4b\u540e\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u3002

        \u57fa\u4e8e\u6b64\u8bbe\u8ba1\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u5143\u7d20\u7684\u6709\u6548\u533a\u95f4\u4e3a [front, rear - 1]\uff0c\u5404\u79cd\u64cd\u4f5c\u7684\u5b9e\u73b0\u65b9\u6cd5\u5982\u56fe 5-6 \u6240\u793a\u3002

        • \u5165\u961f\u64cd\u4f5c\uff1a\u5c06\u8f93\u5165\u5143\u7d20\u8d4b\u503c\u7ed9 rear \u7d22\u5f15\u5904\uff0c\u5e76\u5c06 size \u589e\u52a0 1 \u3002
        • \u51fa\u961f\u64cd\u4f5c\uff1a\u53ea\u9700\u5c06 front \u589e\u52a0 1 \uff0c\u5e76\u5c06 size \u51cf\u5c11 1 \u3002

        \u53ef\u4ee5\u770b\u5230\uff0c\u5165\u961f\u548c\u51fa\u961f\u64cd\u4f5c\u90fd\u53ea\u9700\u8fdb\u884c\u4e00\u6b21\u64cd\u4f5c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(1)\\) \u3002

        ArrayQueuepush()pop()

        \u56fe 5-6 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u961f\u5217\u7684\u5165\u961f\u51fa\u961f\u64cd\u4f5c

        \u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff1a\u5728\u4e0d\u65ad\u8fdb\u884c\u5165\u961f\u548c\u51fa\u961f\u7684\u8fc7\u7a0b\u4e2d\uff0cfront \u548c rear \u90fd\u5728\u5411\u53f3\u79fb\u52a8\uff0c\u5f53\u5b83\u4eec\u5230\u8fbe\u6570\u7ec4\u5c3e\u90e8\u65f6\u5c31\u65e0\u6cd5\u7ee7\u7eed\u79fb\u52a8\u4e86\u3002\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u89c6\u4e3a\u9996\u5c3e\u76f8\u63a5\u7684\u201c\u73af\u5f62\u6570\u7ec4\u201d\u3002

        \u5bf9\u4e8e\u73af\u5f62\u6570\u7ec4\uff0c\u6211\u4eec\u9700\u8981\u8ba9 front \u6216 rear \u5728\u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u65f6\uff0c\u76f4\u63a5\u56de\u5230\u6570\u7ec4\u5934\u90e8\u7ee7\u7eed\u904d\u5386\u3002\u8fd9\u79cd\u5468\u671f\u6027\u89c4\u5f8b\u53ef\u4ee5\u901a\u8fc7\u201c\u53d6\u4f59\u64cd\u4f5c\u201d\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_queue.py
        class ArrayQueue:\n\"\"\"\u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\"\"\"\ndef __init__(self, size: int):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._nums: list[int] = [0] * size  # \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nself._front: int = 0  # \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nself._size: int = 0  # \u961f\u5217\u957f\u5ea6\ndef capacity(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\nreturn len(self._nums)\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._size == 0\ndef push(self, num: int):\n\"\"\"\u5165\u961f\"\"\"\nif self._size == self.capacity():\nraise IndexError(\"\u961f\u5217\u5df2\u6ee1\")\n# \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n# \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nrear: int = (self._front + self._size) % self.capacity()\n# \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself._nums[rear] = num\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u961f\"\"\"\nnum: int = self.peek()\n# \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself._front = (self._front + 1) % self.capacity()\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\nreturn self._nums[self._front]\ndef to_list(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nres = [0] * self.size()\nj: int = self._front\nfor i in range(self.size()):\nres[i] = self._nums[(j % self.capacity())]\nj += 1\nreturn res\n
        array_queue.cpp
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate:\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u961f\u5217\u957f\u5ea6\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\npublic:\nArrayQueue(int capacity) {\n// \u521d\u59cb\u5316\u6570\u7ec4\nnums = new int[capacity];\nqueCapacity = capacity;\nfront = queSize = 0;\n}\n~ArrayQueue() {\ndelete[] nums;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity() {\nreturn queCapacity;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u961f */\nvoid push(int num) {\nif (queSize == queCapacity) {\ncout << \"\u961f\u5217\u5df2\u6ee1\" << endl;\nreturn;\n}\n// \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % queCapacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\nvoid pop() {\nint num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % queCapacity;\nqueSize--;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (isEmpty())\nthrow out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn nums[front];\n}\n/* \u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\nvector<int> toVector() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvector<int> arr(queSize);\nfor (int i = 0, j = front; i < queSize; i++, j++) {\narr[i] = nums[j % queCapacity];\n}\nreturn arr;\n}\n};\n
        array_queue.java
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate int[] nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate int queSize; // \u961f\u5217\u957f\u5ea6\npublic ArrayQueue(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\npublic int capacity() {\nreturn nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\npublic void push(int num) {\nif (queSize == capacity()) {\nSystem.out.println(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % capacity();\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int pop() {\nint num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % capacity();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn nums[front];\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\npublic int[] toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[j % capacity()];\n}\nreturn res;\n}\n}\n
        array_queue.cs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nint[] nums;  // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize; // \u961f\u5217\u957f\u5ea6\npublic ArrayQueue(int capacity) {\nnums = new int[capacity];\nfront = queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint Capacity() {\nreturn nums.Length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn queSize == 0;\n}\n/* \u5165\u961f */\npublic void Push(int num) {\nif (queSize == Capacity()) {\nConsole.WriteLine(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (front + queSize) % Capacity();\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num;\nqueSize++;\n}\n/* \u51fa\u961f */\npublic int Pop() {\nint num = Peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % Capacity();\nqueSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn nums[front];\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\npublic int[] ToArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nint[] res = new int[queSize];\nfor (int i = 0, j = front; i < queSize; i++, j++) {\nres[i] = nums[j % this.Capacity()];\n}\nreturn res;\n}\n}\n
        array_queue.go
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntype arrayQueue struct {\nnums        []int // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize     int   // \u961f\u5217\u957f\u5ea6\nqueCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayQueue(queCapacity int) *arrayQueue {\nreturn &arrayQueue{\nnums:        make([]int, queCapacity),\nqueCapacity: queCapacity,\nfront:       0,\nqueSize:     0,\n}\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayQueue) size() int {\nreturn q.queSize\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayQueue) isEmpty() bool {\nreturn q.queSize == 0\n}\n/* \u5165\u961f */\nfunc (q *arrayQueue) push(num int) {\n// \u5f53 rear == queCapacity \u8868\u793a\u961f\u5217\u5df2\u6ee1\nif q.queSize == q.queCapacity {\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nrear := (q.front + q.queSize) % q.queCapacity\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nq.nums[rear] = num\nq.queSize++\n}\n/* \u51fa\u961f */\nfunc (q *arrayQueue) pop() any {\nnum := q.peek()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nq.front = (q.front + 1) % q.queCapacity\nq.queSize--\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayQueue) peek() any {\nif q.isEmpty() {\nreturn nil\n}\nreturn q.nums[q.front]\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayQueue) toSlice() []int {\nrear := (q.front + q.queSize)\nif rear >= q.queCapacity {\nrear %= q.queCapacity\nreturn append(q.nums[q.front:], q.nums[:rear]...)\n}\nreturn q.nums[q.front:rear]\n}\n
        array_queue.swift
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate var front = 0 // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate var queSize = 0 // \u961f\u5217\u957f\u5ea6\ninit(capacity: Int) {\n// \u521d\u59cb\u5316\u6570\u7ec4\nnums = Array(repeating: 0, count: capacity)\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nfunc capacity() -> Int {\nnums.count\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nqueSize\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nqueSize == 0\n}\n/* \u5165\u961f */\nfunc push(num: Int) {\nif size() == capacity() {\nprint(\"\u961f\u5217\u5df2\u6ee1\")\nreturn\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nlet rear = (front + queSize) % capacity()\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nnums[rear] = num\nqueSize += 1\n}\n/* \u51fa\u961f */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nfront = (front + 1) % capacity()\nqueSize -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n}\nreturn nums[front]\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\nfunc toArray() -> [Int] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = Array(repeating: 0, count: queSize)\nfor (i, j) in sequence(first: (0, front), next: { $0 < self.queSize - 1 ? ($0 + 1, $1 + 1) : nil }) {\nres[i] = nums[j % capacity()]\n}\nreturn res\n}\n}\n
        array_queue.js
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n#nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n#front = 0; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n#queSize = 0; // \u961f\u5217\u957f\u5ea6\nconstructor(capacity) {\nthis.#nums = new Array(capacity);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nget capacity() {\nreturn this.#nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#queSize === 0;\n}\n/* \u5165\u961f */\npush(num) {\nif (this.size === this.capacity) {\nconsole.log('\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nconst rear = (this.#front + this.size) % this.capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.#nums[rear] = num;\nthis.#queSize++;\n}\n/* \u51fa\u961f */\npop() {\nconst num = this.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nthis.#front = (this.#front + 1) % this.capacity;\nthis.#queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek() {\nif (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.#nums[this.#front];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(this.size);\nfor (let i = 0, j = this.#front; i < this.size; i++, j++) {\narr[i] = this.#nums[j % this.capacity];\n}\nreturn arr;\n}\n}\n
        array_queue.ts
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nprivate nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nprivate front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nprivate queSize: number; // \u961f\u5217\u957f\u5ea6\nconstructor(capacity: number) {\nthis.nums = new Array(capacity);\nthis.front = this.queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nget capacity(): number {\nreturn this.nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.queSize === 0;\n}\n/* \u5165\u961f */\npush(num: number): void {\nif (this.size === this.capacity) {\nconsole.log('\u961f\u5217\u5df2\u6ee1');\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nconst rear = (this.front + this.queSize) % this.capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nthis.nums[rear] = num;\nthis.queSize++;\n}\n/* \u51fa\u961f */\npop(): number {\nconst num = this.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nthis.front = (this.front + 1) % this.capacity;\nthis.queSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek(): number {\nif (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\nreturn this.nums[this.front];\n}\n/* \u8fd4\u56de Array */\ntoArray(): number[] {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nconst arr = new Array(this.size);\nfor (let i = 0, j = this.front; i < this.size; i++, j++) {\narr[i] = this.nums[j % this.capacity];\n}\nreturn arr;\n}\n}\n
        array_queue.dart
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\nlate List<int> _nums; // \u7528\u4e8e\u50a8\u5b58\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nlate int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nlate int _queSize; // \u961f\u5217\u957f\u5ea6\nArrayQueue(int capacity) {\n_nums = List.filled(capacity, 0);\n_front = _queSize = 0;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capaCity() {\nreturn _nums.length;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size() {\nreturn _queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _queSize == 0;\n}\n/* \u5165\u961f */\nvoid push(int _num) {\nif (_queSize == capaCity()) {\nthrow Exception(\"\u961f\u5217\u5df2\u6ee1\");\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (_front + _queSize) % capaCity();\n// \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n_nums[rear] = _num;\n_queSize++;\n}\n/* \u51fa\u961f */\nint pop() {\nint _num = peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n_front = (_front + 1) % capaCity();\n_queSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek() {\nif (isEmpty()) {\nthrow Exception(\"\u961f\u5217\u4e3a\u7a7a\");\n}\nreturn _nums[_front];\n}\n/* \u8fd4\u56de Array */\nList<int> toArray() {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nfinal List<int> res = List.filled(_queSize, 0);\nfor (int i = 0, j = _front; i < _queSize; i++, j++) {\nres[i] = _nums[j % capaCity()];\n}\nreturn res;\n}\n}\n
        array_queue.rs
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nstruct ArrayQueue {\nnums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nfront: i32,         // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nque_size: i32,      // \u961f\u5217\u957f\u5ea6\nque_capacity: i32,  // \u961f\u5217\u5bb9\u91cf\n}\nimpl ArrayQueue {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(capacity: i32) -> ArrayQueue {\nArrayQueue {\nnums: vec![0; capacity as usize],\nfront: 0,\nque_size: 0,\nque_capacity: capacity,\n}\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nfn capacity(&self) -> i32 {\nself.que_capacity\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfn size(&self) -> i32 {\nself.que_size\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfn is_empty(&self) -> bool {\nself.que_size == 0\n}\n/* \u5165\u961f */\nfn push(&mut self, num: i32) {\nif self.que_size == self.capacity() {\nprintln!(\"\u961f\u5217\u5df2\u6ee1\");\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nlet rear = (self.front + self.que_size) % self.que_capacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nself.nums[rear as usize] = num;\nself.que_size += 1;\n}\n/* \u51fa\u961f */\nfn pop(&mut self) -> i32 {\nlet num = self.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself.front = (self.front + 1) % self.que_capacity;\nself.que_size -= 1;\nnum\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfn peek(&self) -> i32 {\nif self.is_empty() {\npanic!(\"index out of bounds\");\n}\nself.nums[self.front as usize]\n}\n/* \u8fd4\u56de\u6570\u7ec4 */\nfn to_vector(&self) -> Vec<i32> {\nlet cap = self.que_capacity;\nlet mut j = self.front;\nlet mut arr = vec![0; self.que_size as usize];\nfor i in 0..self.que_size {\narr[i as usize] = self.nums[(j % cap) as usize];\nj += 1;\n}\narr\n}\n}\n
        array_queue.c
        /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\nint *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\nint front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nint queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nint queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayQueue;\n/* \u6784\u9020\u51fd\u6570 */\nArrayQueue *newArrayQueue(int capacity) {\nArrayQueue *queue = (ArrayQueue *)malloc(sizeof(ArrayQueue));\n// \u521d\u59cb\u5316\u6570\u7ec4\nqueue->queCapacity = capacity;\nqueue->nums = (int *)malloc(sizeof(int) * queue->queCapacity);\nqueue->front = queue->queSize = 0;\nreturn queue;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayQueue(ArrayQueue *queue) {\nfree(queue->nums);\nfree(queue);\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayQueue *queue) {\nreturn queue->queCapacity;\n}\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayQueue *queue) {\nreturn queue->queSize;\n}\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayQueue *queue) {\nreturn queue->queSize == 0;\n}\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(ArrayQueue *queue) {\nassert(size(queue) != 0);\nreturn queue->nums[queue->front];\n}\n/* \u5165\u961f */\nvoid push(ArrayQueue *queue, int num) {\nif (size(queue) == capacity(queue)) {\nprintf(\"\u961f\u5217\u5df2\u6ee1\\r\\n\");\nreturn;\n}\n// \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nint rear = (queue->front + queue->queSize) % queue->queCapacity;\n// \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\nqueue->nums[rear] = num;\nqueue->queSize++;\n}\n/* \u51fa\u961f */\nvoid pop(ArrayQueue *queue) {\nint num = peek(queue);\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nqueue->front = (queue->front + 1) % queue->queCapacity;\nqueue->queSize--;\n}\n
        array_queue.zig
        // \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\nfn ArrayQueue(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nnums: []T = undefined,                          // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4     \ncap: usize = 0,                                 // \u961f\u5217\u5bb9\u91cf\nfront: usize = 0,                               // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\nqueSize: usize = 0,                             // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6570\u7ec4\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator, cap: usize) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.cap = cap;\nself.nums = try self.mem_allocator.alloc(T, self.cap);\n@memset(self.nums, @as(T, 0));\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\npub fn capacity(self: *Self) usize {\nreturn self.cap;\n}\n// \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.queSize;\n}\n// \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.queSize == 0;\n}\n// \u5165\u961f\npub fn push(self: *Self, num: T) !void {\nif (self.size() == self.capacity()) {\nstd.debug.print(\"\u961f\u5217\u5df2\u6ee1\\n\", .{});\nreturn;\n}\n// \u8ba1\u7b97\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n// \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\uff0c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\nvar rear = (self.front + self.queSize) % self.capacity();\n// \u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\nself.nums[rear] = num;\nself.queSize += 1;\n} // \u51fa\u961f\npub fn pop(self: *Self) T {\nvar num = self.peek();\n// \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\nself.front = (self.front + 1) % self.capacity();\nself.queSize -= 1;\nreturn num;\n} // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\nreturn self.nums[self.front];\n} // \u8fd4\u56de\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\n// \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nvar j: usize = self.front;\nwhile (i < self.size()) : ({ i += 1; j += 1; }) {\nres[i] = self.nums[j % self.capacity()];\n}\nreturn res;\n}\n};\n}\n

        \u4ee5\u4e0a\u5b9e\u73b0\u7684\u961f\u5217\u4ecd\u7136\u5177\u6709\u5c40\u9650\u6027\uff1a\u5176\u957f\u5ea6\u4e0d\u53ef\u53d8\u3002\u7136\u800c\uff0c\u8fd9\u4e2a\u95ee\u9898\u4e0d\u96be\u89e3\u51b3\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u66ff\u6362\u4e3a\u52a8\u6001\u6570\u7ec4\uff0c\u4ece\u800c\u5f15\u5165\u6269\u5bb9\u673a\u5236\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u5c1d\u8bd5\u81ea\u884c\u5b9e\u73b0\u3002

        \u4e24\u79cd\u5b9e\u73b0\u7684\u5bf9\u6bd4\u7ed3\u8bba\u4e0e\u6808\u4e00\u81f4\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

        "},{"location":"chapter_stack_and_queue/queue/#523","title":"5.2.3 \u00a0 \u961f\u5217\u5178\u578b\u5e94\u7528","text":"
        • \u6dd8\u5b9d\u8ba2\u5355\u3002\u8d2d\u7269\u8005\u4e0b\u5355\u540e\uff0c\u8ba2\u5355\u5c06\u52a0\u5165\u961f\u5217\u4e2d\uff0c\u7cfb\u7edf\u968f\u540e\u4f1a\u6839\u636e\u987a\u5e8f\u5904\u7406\u961f\u5217\u4e2d\u7684\u8ba2\u5355\u3002\u5728\u53cc\u5341\u4e00\u671f\u95f4\uff0c\u77ed\u65f6\u95f4\u5185\u4f1a\u4ea7\u751f\u6d77\u91cf\u8ba2\u5355\uff0c\u9ad8\u5e76\u53d1\u6210\u4e3a\u5de5\u7a0b\u5e08\u4eec\u9700\u8981\u91cd\u70b9\u653b\u514b\u7684\u95ee\u9898\u3002
        • \u5404\u7c7b\u5f85\u529e\u4e8b\u9879\u3002\u4efb\u4f55\u9700\u8981\u5b9e\u73b0\u201c\u5148\u6765\u540e\u5230\u201d\u529f\u80fd\u7684\u573a\u666f\uff0c\u4f8b\u5982\u6253\u5370\u673a\u7684\u4efb\u52a1\u961f\u5217\u3001\u9910\u5385\u7684\u51fa\u9910\u961f\u5217\u7b49\uff0c\u961f\u5217\u5728\u8fd9\u4e9b\u573a\u666f\u4e2d\u53ef\u4ee5\u6709\u6548\u5730\u7ef4\u62a4\u5904\u7406\u987a\u5e8f\u3002
        "},{"location":"chapter_stack_and_queue/stack/","title":"5.1 \u00a0 \u6808","text":"

        \u300c\u6808 stack\u300d\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u540e\u51fa\u7684\u903b\u8f91\u7684\u7ebf\u6027\u6570\u636e\u7ed3\u6784\u3002

        \u6211\u4eec\u53ef\u4ee5\u5c06\u6808\u7c7b\u6bd4\u4e3a\u684c\u9762\u4e0a\u7684\u4e00\u645e\u76d8\u5b50\uff0c\u5982\u679c\u60f3\u53d6\u51fa\u5e95\u90e8\u7684\u76d8\u5b50\uff0c\u5219\u9700\u8981\u5148\u5c06\u4e0a\u9762\u7684\u76d8\u5b50\u4f9d\u6b21\u79fb\u8d70\u3002\u6211\u4eec\u5c06\u76d8\u5b50\u66ff\u6362\u4e3a\u5404\u79cd\u7c7b\u578b\u7684\u5143\u7d20\uff08\u5982\u6574\u6570\u3001\u5b57\u7b26\u3001\u5bf9\u8c61\u7b49\uff09\uff0c\u5c31\u5f97\u5230\u4e86\u6808\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u3002

        \u5982\u56fe 5-1 \u6240\u793a\uff0c\u6211\u4eec\u628a\u5806\u53e0\u5143\u7d20\u7684\u9876\u90e8\u79f0\u4e3a\u201c\u6808\u9876\u201d\uff0c\u5e95\u90e8\u79f0\u4e3a\u201c\u6808\u5e95\u201d\u3002\u5c06\u628a\u5143\u7d20\u6dfb\u52a0\u5230\u6808\u9876\u7684\u64cd\u4f5c\u53eb\u4f5c\u201c\u5165\u6808\u201d\uff0c\u5220\u9664\u6808\u9876\u5143\u7d20\u7684\u64cd\u4f5c\u53eb\u4f5c\u201c\u51fa\u6808\u201d\u3002

        \u56fe 5-1 \u00a0 \u6808\u7684\u5148\u5165\u540e\u51fa\u89c4\u5219

        "},{"location":"chapter_stack_and_queue/stack/#511","title":"5.1.1 \u00a0 \u6808\u5e38\u7528\u64cd\u4f5c","text":"

        \u6808\u7684\u5e38\u7528\u64cd\u4f5c\u5982\u8868 5-1 \u6240\u793a\uff0c\u5177\u4f53\u7684\u65b9\u6cd5\u540d\u9700\u8981\u6839\u636e\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u6765\u786e\u5b9a\u3002\u5728\u6b64\uff0c\u6211\u4eec\u4ee5\u5e38\u89c1\u7684 push()\u3001pop()\u3001peek() \u547d\u540d\u4e3a\u4f8b\u3002

        \u8868 5-1 \u00a0 \u6808\u7684\u64cd\u4f5c\u6548\u7387

        \u65b9\u6cd5 \u63cf\u8ff0 \u65f6\u95f4\u590d\u6742\u5ea6 push() \u5143\u7d20\u5165\u6808\uff08\u6dfb\u52a0\u81f3\u6808\u9876\uff09 \\(O(1)\\) pop() \u6808\u9876\u5143\u7d20\u51fa\u6808 \\(O(1)\\) peek() \u8bbf\u95ee\u6808\u9876\u5143\u7d20 \\(O(1)\\)

        \u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u5185\u7f6e\u7684\u6808\u7c7b\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u8bed\u8a00\u53ef\u80fd\u6ca1\u6709\u4e13\u95e8\u63d0\u4f9b\u6808\u7c7b\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u5c06\u8be5\u8bed\u8a00\u7684\u201c\u6570\u7ec4\u201d\u6216\u201c\u94fe\u8868\u201d\u5f53\u4f5c\u6808\u6765\u4f7f\u7528\uff0c\u5e76\u5728\u7a0b\u5e8f\u903b\u8f91\u4e0a\u5ffd\u7565\u4e0e\u6808\u65e0\u5173\u7684\u64cd\u4f5c\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig stack.py
        # \u521d\u59cb\u5316\u6808\n# Python \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a List \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nstack: list[int] = []\n# \u5143\u7d20\u5165\u6808\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n# \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npeek: int = stack[-1]\n# \u5143\u7d20\u51fa\u6808\npop: int = stack.pop()\n# \u83b7\u53d6\u6808\u7684\u957f\u5ea6\nsize: int = len(stack)\n# \u5224\u65ad\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(stack) == 0\n
        stack.cpp
        /* \u521d\u59cb\u5316\u6808 */\nstack<int> stack;\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top = stack.top();\n/* \u5143\u7d20\u51fa\u6808 */\nstack.pop(); // \u65e0\u8fd4\u56de\u503c\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool empty = stack.empty();\n
        stack.java
        /* \u521d\u59cb\u5316\u6808 */\nStack<Integer> stack = new Stack<>();\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.peek();\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = stack.isEmpty();\n
        stack.cs
        /* \u521d\u59cb\u5316\u6808 */\nStack<int> stack = new();\n/* \u5143\u7d20\u5165\u6808 */\nstack.Push(1);\nstack.Push(3);\nstack.Push(2);\nstack.Push(5);\nstack.Push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.Peek();\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.Pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.Count;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = stack.Count == 0;\n
        stack_test.go
        /* \u521d\u59cb\u5316\u6808 */\n// \u5728 Go \u4e2d\uff0c\u63a8\u8350\u5c06 Slice \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nvar stack []int\n/* \u5143\u7d20\u5165\u6808 */\nstack = append(stack, 1)\nstack = append(stack, 3)\nstack = append(stack, 2)\nstack = append(stack, 5)\nstack = append(stack, 4)\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek := stack[len(stack)-1]\n/* \u5143\u7d20\u51fa\u6808 */\npop := stack[len(stack)-1]\nstack = stack[:len(stack)-1]\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nsize := len(stack)\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nisEmpty := len(stack) == 0\n
        stack.swift
        /* \u521d\u59cb\u5316\u6808 */\n// Swift \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nvar stack: [Int] = []\n/* \u5143\u7d20\u5165\u6808 */\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet peek = stack.last!\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.removeLast()\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.count\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nlet isEmpty = stack.isEmpty\n
        stack.js
        /* \u521d\u59cb\u5316\u6808 */\n// Javascript \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nconst stack = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length-1];\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nconst is_empty = stack.length === 0;\n
        stack.ts
        /* \u521d\u59cb\u5316\u6808 */\n// Typescript \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a Array \u5f53\u4f5c\u6808\u6765\u4f7f\u7528 \nconst stack: number[] = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length - 1];\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nconst is_empty = stack.length === 0;\n
        stack.dart
        /* \u521d\u59cb\u5316\u6808 */\n// Dart \u6ca1\u6709\u5185\u7f6e\u7684\u6808\u7c7b\uff0c\u53ef\u4ee5\u628a List \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nList<int> stack = [];\n/* \u5143\u7d20\u5165\u6808 */\nstack.add(1);\nstack.add(3);\nstack.add(2);\nstack.add(5);\nstack.add(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.last;\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.removeLast();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.length;\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = stack.isEmpty;\n
        stack.rs
        /* \u521d\u59cb\u5316\u6808 */\n// \u628a Vec \u5f53\u4f5c\u6808\u6765\u4f7f\u7528\nlet mut stack: Vec<i32> = Vec::new();\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet top = stack.last().unwrap();\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.pop().unwrap();\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.len();\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = stack.is_empty();\n
        stack.c
        // C \u672a\u63d0\u4f9b\u5185\u7f6e\u6808\n
        stack.zig
        \n
        "},{"location":"chapter_stack_and_queue/stack/#512","title":"5.1.2 \u00a0 \u6808\u7684\u5b9e\u73b0","text":"

        \u4e3a\u4e86\u6df1\u5165\u4e86\u89e3\u6808\u7684\u8fd0\u884c\u673a\u5236\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u81ea\u5df1\u5b9e\u73b0\u4e00\u4e2a\u6808\u7c7b\u3002

        \u6808\u9075\u5faa\u5148\u5165\u540e\u51fa\u7684\u539f\u5219\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u80fd\u5728\u6808\u9876\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u3002\u7136\u800c\uff0c\u6570\u7ec4\u548c\u94fe\u8868\u90fd\u53ef\u4ee5\u5728\u4efb\u610f\u4f4d\u7f6e\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\uff0c\u56e0\u6b64\u6808\u53ef\u4ee5\u89c6\u4e3a\u4e00\u79cd\u53d7\u9650\u5236\u7684\u6570\u7ec4\u6216\u94fe\u8868\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u201c\u5c4f\u853d\u201d\u6570\u7ec4\u6216\u94fe\u8868\u7684\u90e8\u5206\u65e0\u5173\u64cd\u4f5c\uff0c\u4f7f\u5176\u5bf9\u5916\u8868\u73b0\u7684\u903b\u8f91\u7b26\u5408\u6808\u7684\u7279\u6027\u3002

        "},{"location":"chapter_stack_and_queue/stack/#1","title":"1. \u00a0 \u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0","text":"

        \u4f7f\u7528\u94fe\u8868\u5b9e\u73b0\u6808\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u94fe\u8868\u7684\u5934\u8282\u70b9\u89c6\u4e3a\u6808\u9876\uff0c\u5c3e\u8282\u70b9\u89c6\u4e3a\u6808\u5e95\u3002

        \u5982\u56fe 5-2 \u6240\u793a\uff0c\u5bf9\u4e8e\u5165\u6808\u64cd\u4f5c\uff0c\u6211\u4eec\u53ea\u9700\u5c06\u5143\u7d20\u63d2\u5165\u94fe\u8868\u5934\u90e8\uff0c\u8fd9\u79cd\u8282\u70b9\u63d2\u5165\u65b9\u6cd5\u88ab\u79f0\u4e3a\u201c\u5934\u63d2\u6cd5\u201d\u3002\u800c\u5bf9\u4e8e\u51fa\u6808\u64cd\u4f5c\uff0c\u53ea\u9700\u5c06\u5934\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\u5373\u53ef\u3002

        LinkedListStackpush()pop()

        \u56fe 5-2 \u00a0 \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u6808\u7684\u5165\u6808\u51fa\u6808\u64cd\u4f5c

        \u4ee5\u4e0b\u662f\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u6808\u7684\u793a\u4f8b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig linkedlist_stack.py
        class LinkedListStack:\n\"\"\"\u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._peek: ListNode | None = None\nself._size: int = 0\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\nreturn self._size\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn not self._peek\ndef push(self, val: int):\n\"\"\"\u5165\u6808\"\"\"\nnode = ListNode(val)\nnode.next = self._peek\nself._peek = node\nself._size += 1\ndef pop(self) -> int:\n\"\"\"\u51fa\u6808\"\"\"\nnum = self.peek()\nself._peek = self._peek.next\nself._size -= 1\nreturn num\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._peek.val\ndef to_list(self) -> list[int]:\n\"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\narr = []\nnode = self._peek\nwhile node:\narr.append(node.val)\nnode = node.next\narr.reverse()\nreturn arr\n
        linkedlist_stack.cpp
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate:\nListNode *stackTop; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint stkSize;        // \u6808\u7684\u957f\u5ea6\npublic:\nLinkedListStack() {\nstackTop = nullptr;\nstkSize = 0;\n}\n~LinkedListStack() {\n// \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\nfreeMemoryLinkedList(stackTop);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\nvoid push(int num) {\nListNode *node = new ListNode(num);\nnode->next = stackTop;\nstackTop = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\nvoid pop() {\nint num = top();\nListNode *tmp = stackTop;\nstackTop = stackTop->next;\n// \u91ca\u653e\u5185\u5b58\ndelete tmp;\nstkSize--;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top() {\nif (isEmpty())\nthrow out_of_range(\"\u6808\u4e3a\u7a7a\");\nreturn stackTop->val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nvector<int> toVector() {\nListNode *node = stackTop;\nvector<int> res(size());\nfor (int i = res.size() - 1; i >= 0; i--) {\nres[i] = node->val;\nnode = node->next;\n}\nreturn res;\n}\n};\n
        linkedlist_stack.java
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate ListNode stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate int stkSize = 0; // \u6808\u7684\u957f\u5ea6\npublic LinkedListStack() {\nstackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\npublic void push(int num) {\nListNode node = new ListNode(num);\nnode.next = stackPeek;\nstackPeek = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\npublic int pop() {\nint num = peek();\nstackPeek = stackPeek.next;\nstkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stackPeek.val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] toArray() {\nListNode node = stackPeek;\nint[] res = new int[size()];\nfor (int i = res.length - 1; i >= 0; i--) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.cs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nListNode? stackPeek;  // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint stkSize = 0;   // \u6808\u7684\u957f\u5ea6\npublic LinkedListStack() {\nstackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u6808 */\npublic void Push(int num) {\nListNode node = new(num) {\nnext = stackPeek\n};\nstackPeek = node;\nstkSize++;\n}\n/* \u51fa\u6808 */\npublic int Pop() {\nint num = Peek();\nstackPeek = stackPeek!.next;\nstkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn stackPeek!.val;\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nif (stackPeek == null)\nreturn [];\nListNode? node = stackPeek;\nint[] res = new int[Size()];\nfor (int i = res.Length - 1; i >= 0; i--) {\nres[i] = node!.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.go
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntype linkedListStack struct {\n// \u4f7f\u7528\u5185\u7f6e\u5305 list \u6765\u5b9e\u73b0\u6808\ndata *list.List\n}\n/* \u521d\u59cb\u5316\u6808 */\nfunc newLinkedListStack() *linkedListStack {\nreturn &linkedListStack{\ndata: list.New(),\n}\n}\n/* \u5165\u6808 */\nfunc (s *linkedListStack) push(value int) {\ns.data.PushBack(value)\n}\n/* \u51fa\u6808 */\nfunc (s *linkedListStack) pop() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\ns.data.Remove(e)\nreturn e.Value\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc (s *linkedListStack) peek() any {\nif s.isEmpty() {\nreturn nil\n}\ne := s.data.Back()\nreturn e.Value\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc (s *linkedListStack) size() int {\nreturn s.data.Len()\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListStack) isEmpty() bool {\nreturn s.data.Len() == 0\n}\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListStack) toList() *list.List {\nreturn s.data\n}\n
        linkedlist_stack.swift
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate var _peek: ListNode? // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate var _size = 0 // \u6808\u7684\u957f\u5ea6\ninit() {}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc size() -> Int {\n_size\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nsize() == 0\n}\n/* \u5165\u6808 */\nfunc push(num: Int) {\nlet node = ListNode(x: num)\nnode.next = _peek\n_peek = node\n_size += 1\n}\n/* \u51fa\u6808 */\n@discardableResult\nfunc pop() -> Int {\nlet num = peek()\n_peek = _peek?.next\n_size -= 1\nreturn num\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn _peek!.val\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nvar node = _peek\nvar res = Array(repeating: 0, count: _size)\nfor i in sequence(first: res.count - 1, next: { $0 >= 0 + 1 ? $0 - 1 : nil }) {\nres[i] = node!.val\nnode = node?.next\n}\nreturn res\n}\n}\n
        linkedlist_stack.js
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n#stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n#stkSize = 0; // \u6808\u7684\u957f\u5ea6\nconstructor() {\nthis.#stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.size === 0;\n}\n/* \u5165\u6808 */\npush(num) {\nconst node = new ListNode(num);\nnode.next = this.#stackPeek;\nthis.#stackPeek = node;\nthis.#stkSize++;\n}\n/* \u51fa\u6808 */\npop() {\nconst num = this.peek();\nthis.#stackPeek = this.#stackPeek.next;\nthis.#stkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek() {\nif (!this.#stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stackPeek.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray() {\nlet node = this.#stackPeek;\nconst res = new Array(this.size);\nfor (let i = res.length - 1; i >= 0; i--) {\nres[i] = node.val;\nnode = node.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.ts
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nprivate stackPeek: ListNode | null; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nprivate stkSize: number = 0; // \u6808\u7684\u957f\u5ea6\nconstructor() {\nthis.stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.size === 0;\n}\n/* \u5165\u6808 */\npush(num: number): void {\nconst node = new ListNode(num);\nnode.next = this.stackPeek;\nthis.stackPeek = node;\nthis.stkSize++;\n}\n/* \u51fa\u6808 */\npop(): number {\nconst num = this.peek();\nif (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nthis.stackPeek = this.stackPeek.next;\nthis.stkSize--;\nreturn num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek(): number {\nif (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stackPeek.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\ntoArray(): number[] {\nlet node = this.stackPeek;\nconst res = new Array<number>(this.size);\nfor (let i = res.length - 1; i >= 0; i--) {\nres[i] = node!.val;\nnode = node!.next;\n}\nreturn res;\n}\n}\n
        linkedlist_stack.dart
        /* \u57fa\u4e8e\u94fe\u8868\u7c7b\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\nListNode? _stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint _stkSize = 0; // \u6808\u7684\u957f\u5ea6\nLinkedListStack() {\n_stackPeek = null;\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn _stkSize;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _stkSize == 0;\n}\n/* \u5165\u6808 */\nvoid push(int _num) {\nfinal ListNode node = ListNode(_num);\nnode.next = _stackPeek;\n_stackPeek = node;\n_stkSize++;\n}\n/* \u51fa\u6808 */\nint pop() {\nfinal int _num = peek();\n_stackPeek = _stackPeek!.next;\n_stkSize--;\nreturn _num;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek() {\nif (_stackPeek == null) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stackPeek!.val;\n}\n/* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a List \u5e76\u8fd4\u56de */\nList<int> toList() {\nListNode? node = _stackPeek;\nList<int> list = [];\nwhile (node != null) {\nlist.add(node.val);\nnode = node.next;\n}\nlist = list.reversed.toList();\nreturn list;\n}\n}\n
        linkedlist_stack.rs
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\n#[allow(dead_code)]\npub struct LinkedListStack<T> {\nstack_peek: Option<Rc<RefCell<ListNode<T>>>>,   // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nstk_size: usize,                                // \u6808\u7684\u957f\u5ea6\n}\nimpl<T: Copy> LinkedListStack<T> {\npub fn new() -> Self {\nSelf {\nstack_peek: None,\nstk_size: 0,\n}\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npub fn size(&self) -> usize {\nreturn self.stk_size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npub fn is_empty(&self) -> bool {\nreturn self.size() == 0;\n}\n/* \u5165\u6808 */\npub fn push(&mut self, num: T) {\nlet node = ListNode::new(num);\nnode.borrow_mut().next = self.stack_peek.take();\nself.stack_peek = Some(node);\nself.stk_size += 1;\n}\n/* \u51fa\u6808 */\npub fn pop(&mut self) -> Option<T> {\nself.stack_peek.take().map(|old_head| {\nmatch old_head.borrow_mut().next.take() {\nSome(new_head) => {\nself.stack_peek = Some(new_head);\n}\nNone => {\nself.stack_peek = None;\n}\n}\nself.stk_size -= 1;\nRc::try_unwrap(old_head).ok().unwrap().into_inner().val\n})\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\nself.stack_peek.as_ref()\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\nif let Some(node) = head {\nlet mut nums = self.to_array(node.borrow().next.as_ref());\nnums.push(node.borrow().val);\nreturn nums;\n}\nreturn Vec::new();\n}\n}\n
        linkedlist_stack.c
        /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\nListNode *top; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nint size;      // \u6808\u7684\u957f\u5ea6\n} LinkedListStack;\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListStack *newLinkedListStack() {\nLinkedListStack *s = malloc(sizeof(LinkedListStack));\ns->top = NULL;\ns->size = 0;\nreturn s;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListStack(LinkedListStack *s) {\nwhile (s->top) {\nListNode *n = s->top->next;\nfree(s->top);\ns->top = n;\n}\nfree(s);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(LinkedListStack *s) {\nassert(s);\nreturn s->size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(LinkedListStack *s) {\nassert(s);\nreturn size(s) == 0;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(LinkedListStack *s) {\nassert(s);\nassert(size(s) != 0);\nreturn s->top->val;\n}\n/* \u5165\u6808 */\nvoid push(LinkedListStack *s, int num) {\nassert(s);\nListNode *node = (ListNode *)malloc(sizeof(ListNode));\nnode->next = s->top; // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6307\u9488\u57df\nnode->val = num;     // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6570\u636e\u57df\ns->top = node;       // \u66f4\u65b0\u6808\u9876\ns->size++;           // \u66f4\u65b0\u6808\u5927\u5c0f\n}\n/* \u51fa\u6808 */\nint pop(LinkedListStack *s) {\nif (s->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nassert(s);\nint val = peek(s);\nListNode *tmp = s->top;\ns->top = s->top->next;\n// \u91ca\u653e\u5185\u5b58\nfree(tmp);\ns->size--;\nreturn val;\n}\n
        linkedlist_stack.zig
        // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\nfn LinkedListStack(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nstack_top: ?*inc.ListNode(T) = null,             // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\nstk_size: usize = 0,                             // \u6808\u7684\u957f\u5ea6\nmem_arena: ?std.heap.ArenaAllocator = null,\nmem_allocator: std.mem.Allocator = undefined,    // \u5185\u5b58\u5206\u914d\u5668\n// \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) !void {\nif (self.mem_arena == null) {\nself.mem_arena = std.heap.ArenaAllocator.init(allocator);\nself.mem_allocator = self.mem_arena.?.allocator();\n}\nself.stack_top = null;\nself.stk_size = 0;\n}\n// \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.mem_arena == null) return;\nself.mem_arena.?.deinit();\n}\n// \u83b7\u53d6\u6808\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.stk_size;\n}\n// \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.size() == 0) @panic(\"\u6808\u4e3a\u7a7a\");\nreturn self.stack_top.?.val;\n}  // \u5165\u6808\npub fn push(self: *Self, num: T) !void {\nvar node = try self.mem_allocator.create(inc.ListNode(T));\nnode.init(num);\nnode.next = self.stack_top;\nself.stack_top = node;\nself.stk_size += 1;\n} // \u51fa\u6808\npub fn pop(self: *Self) T {\nvar num = self.peek();\nself.stack_top = self.stack_top.?.next;\nself.stk_size -= 1;\nreturn num;\n} // \u5c06\u6808\u8f6c\u6362\u4e3a\u6570\u7ec4\npub fn toArray(self: *Self) ![]T {\nvar node = self.stack_top;\nvar res = try self.mem_allocator.alloc(T, self.size());\n@memset(res, @as(T, 0));\nvar i: usize = 0;\nwhile (i < res.len) : (i += 1) {\nres[res.len - i - 1] = node.?.val;\nnode = node.?.next;\n}\nreturn res;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/stack/#2","title":"2. \u00a0 \u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0","text":"

        \u4f7f\u7528\u6570\u7ec4\u5b9e\u73b0\u6808\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u7684\u5c3e\u90e8\u4f5c\u4e3a\u6808\u9876\u3002\u5982\u56fe 5-3 \u6240\u793a\uff0c\u5165\u6808\u4e0e\u51fa\u6808\u64cd\u4f5c\u5206\u522b\u5bf9\u5e94\u5728\u6570\u7ec4\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\u4e0e\u5220\u9664\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3a \\(O(1)\\) \u3002

        ArrayStackpush()pop()

        \u56fe 5-3 \u00a0 \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u6808\u7684\u5165\u6808\u51fa\u6808\u64cd\u4f5c

        \u7531\u4e8e\u5165\u6808\u7684\u5143\u7d20\u53ef\u80fd\u4f1a\u6e90\u6e90\u4e0d\u65ad\u5730\u589e\u52a0\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u52a8\u6001\u6570\u7ec4\uff0c\u8fd9\u6837\u5c31\u65e0\u987b\u81ea\u884c\u5904\u7406\u6570\u7ec4\u6269\u5bb9\u95ee\u9898\u3002\u4ee5\u4e0b\u4e3a\u793a\u4f8b\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_stack.py
        class ArrayStack:\n\"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\"\"\"\ndef __init__(self):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._stack: list[int] = []\ndef size(self) -> int:\n\"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\nreturn len(self._stack)\ndef is_empty(self) -> bool:\n\"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\nreturn self._stack == []\ndef push(self, item: int):\n\"\"\"\u5165\u6808\"\"\"\nself._stack.append(item)\ndef pop(self) -> int:\n\"\"\"\u51fa\u6808\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._stack.pop()\ndef peek(self) -> int:\n\"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\nif self.is_empty():\nraise IndexError(\"\u6808\u4e3a\u7a7a\")\nreturn self._stack[-1]\ndef to_list(self) -> list[int]:\n\"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\nreturn self._stack\n
        array_stack.cpp
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate:\nvector<int> stack;\npublic:\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn stack.size();\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn stack.size() == 0;\n}\n/* \u5165\u6808 */\nvoid push(int num) {\nstack.push_back(num);\n}\n/* \u51fa\u6808 */\nvoid pop() {\nint oldTop = top();\nstack.pop_back();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top() {\nif (isEmpty())\nthrow out_of_range(\"\u6808\u4e3a\u7a7a\");\nreturn stack.back();\n}\n/* \u8fd4\u56de Vector */\nvector<int> toVector() {\nreturn stack;\n}\n};\n
        array_stack.java
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate ArrayList<Integer> stack;\npublic ArrayStack() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = new ArrayList<>();\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int size() {\nreturn stack.size();\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic boolean isEmpty() {\nreturn size() == 0;\n}\n/* \u5165\u6808 */\npublic void push(int num) {\nstack.add(num);\n}\n/* \u51fa\u6808 */\npublic int pop() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stack.remove(size() - 1);\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int peek() {\nif (isEmpty())\nthrow new IndexOutOfBoundsException();\nreturn stack.get(size() - 1);\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic Object[] toArray() {\nreturn stack.toArray();\n}\n}\n
        array_stack.cs
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nList<int> stack;\npublic ArrayStack() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\npublic int Size() {\nreturn stack.Count;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\npublic bool IsEmpty() {\nreturn Size() == 0;\n}\n/* \u5165\u6808 */\npublic void Push(int num) {\nstack.Add(num);\n}\n/* \u51fa\u6808 */\npublic int Pop() {\nif (IsEmpty())\nthrow new Exception();\nvar val = Peek();\nstack.RemoveAt(Size() - 1);\nreturn val;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npublic int Peek() {\nif (IsEmpty())\nthrow new Exception();\nreturn stack[Size() - 1];\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\npublic int[] ToArray() {\nreturn [.. stack];\n}\n}\n
        array_stack.go
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntype arrayStack struct {\ndata []int // \u6570\u636e\n}\n/* \u521d\u59cb\u5316\u6808 */\nfunc newArrayStack() *arrayStack {\nreturn &arrayStack{\n// \u8bbe\u7f6e\u6808\u7684\u957f\u5ea6\u4e3a 0\uff0c\u5bb9\u91cf\u4e3a 16\ndata: make([]int, 0, 16),\n}\n}\n/* \u6808\u7684\u957f\u5ea6 */\nfunc (s *arrayStack) size() int {\nreturn len(s.data)\n}\n/* \u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *arrayStack) isEmpty() bool {\nreturn s.size() == 0\n}\n/* \u5165\u6808 */\nfunc (s *arrayStack) push(v int) {\n// \u5207\u7247\u4f1a\u81ea\u52a8\u6269\u5bb9\ns.data = append(s.data, v)\n}\n/* \u51fa\u6808 */\nfunc (s *arrayStack) pop() any {\nval := s.peek()\ns.data = s.data[:len(s.data)-1]\nreturn val\n}\n/* \u83b7\u53d6\u6808\u9876\u5143\u7d20 */\nfunc (s *arrayStack) peek() any {\nif s.isEmpty() {\nreturn nil\n}\nval := s.data[len(s.data)-1]\nreturn val\n}\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (s *arrayStack) toSlice() []int {\nreturn s.data\n}\n
        array_stack.swift
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate var stack: [Int]\ninit() {\n// \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\nstack = []\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc size() -> Int {\nstack.count\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc isEmpty() -> Bool {\nstack.isEmpty\n}\n/* \u5165\u6808 */\nfunc push(num: Int) {\nstack.append(num)\n}\n/* \u51fa\u6808 */\n@discardableResult\nfunc pop() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn stack.removeLast()\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc peek() -> Int {\nif isEmpty() {\nfatalError(\"\u6808\u4e3a\u7a7a\")\n}\nreturn stack.last!\n}\n/* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nfunc toArray() -> [Int] {\nstack\n}\n}\n
        array_stack.js
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n#stack;\nconstructor() {\nthis.#stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size() {\nreturn this.#stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty() {\nreturn this.#stack.length === 0;\n}\n/* \u5165\u6808 */\npush(num) {\nthis.#stack.push(num);\n}\n/* \u51fa\u6808 */\npop() {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stack.pop();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\ntop() {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.#stack[this.#stack.length - 1];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\nreturn this.#stack;\n}\n}\n
        array_stack.ts
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nprivate stack: number[];\nconstructor() {\nthis.stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nget size(): number {\nreturn this.stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nisEmpty(): boolean {\nreturn this.stack.length === 0;\n}\n/* \u5165\u6808 */\npush(num: number): void {\nthis.stack.push(num);\n}\n/* \u51fa\u6808 */\npop(): number | undefined {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stack.pop();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\ntop(): number | undefined {\nif (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\nreturn this.stack[this.stack.length - 1];\n}\n/* \u8fd4\u56de Array */\ntoArray() {\nreturn this.stack;\n}\n}\n
        array_stack.dart
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\nlate List<int> _stack;\nArrayStack() {\n_stack = [];\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size() {\nreturn _stack.length;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty() {\nreturn _stack.isEmpty;\n}\n/* \u5165\u6808 */\nvoid push(int _num) {\n_stack.add(_num);\n}\n/* \u51fa\u6808 */\nint pop() {\nif (isEmpty()) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stack.removeLast();\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek() {\nif (isEmpty()) {\nthrow Exception(\"\u6808\u4e3a\u7a7a\");\n}\nreturn _stack.last;\n}\n/* \u5c06\u6808\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\nList<int> toArray() => _stack;\n}\n
        array_stack.rs
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nstruct ArrayStack<T> {\nstack: Vec<T>,\n}\nimpl<T> ArrayStack<T> {\n/* \u521d\u59cb\u5316\u6808 */\nfn new() -> ArrayStack<T> {\nArrayStack::<T> { stack: Vec::<T>::new() }\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfn size(&self) -> usize {\nself.stack.len()\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfn is_empty(&self) -> bool {\nself.size() == 0\n}\n/* \u5165\u6808 */\nfn push(&mut self, num: T) {\nself.stack.push(num);\n}\n/* \u51fa\u6808 */\nfn pop(&mut self) -> Option<T> {\nmatch self.stack.pop() {\nSome(num) => Some(num),\nNone => None,\n}\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<&T> {\nif self.is_empty() { panic!(\"\u6808\u4e3a\u7a7a\") };\nself.stack.last()\n}\n/* \u8fd4\u56de &Vec */\nfn to_array(&self) -> &Vec<T> {\n&self.stack\n}\n}\n
        array_stack.c
        /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\nint *data;\nint size;\n} ArrayStack;\n/* \u6784\u9020\u51fd\u6570 */\nArrayStack *newArrayStack() {\nArrayStack *stack = malloc(sizeof(ArrayStack));\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5927\u5bb9\u91cf\uff0c\u907f\u514d\u6269\u5bb9\nstack->data = malloc(sizeof(int) * MAX_SIZE);\nstack->size = 0;\nreturn stack;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayStack(ArrayStack *stack) {\nfree(stack->data);\nfree(stack);\n}\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(ArrayStack *stack) {\nreturn stack->size;\n}\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(ArrayStack *stack) {\nreturn stack->size == 0;\n}\n/* \u5165\u6808 */\nvoid push(ArrayStack *stack, int num) {\nif (stack->size == MAX_SIZE) {\nprintf(\"stack is full.\\n\");\nreturn;\n}\nstack->data[stack->size] = num;\nstack->size++;\n}\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(ArrayStack *stack) {\nif (stack->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nreturn stack->data[stack->size - 1];\n}\n/* \u51fa\u6808 */\nint pop(ArrayStack *stack) {\nif (stack->size == 0) {\nprintf(\"stack is empty.\\n\");\nreturn INT_MAX;\n}\nint val = peek(stack);\nstack->size--;\nreturn val;\n}\n
        array_stack.zig
        // \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\nfn ArrayStack(comptime T: type) type {\nreturn struct {\nconst Self = @This();\nstack: ?std.ArrayList(T) = null,     // \u6784\u9020\u65b9\u6cd5\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\npub fn init(self: *Self, allocator: std.mem.Allocator) void {\nif (self.stack == null) {\nself.stack = std.ArrayList(T).init(allocator);\n}\n}\n// \u6790\u6784\u65b9\u6cd5\uff08\u91ca\u653e\u5185\u5b58\uff09\npub fn deinit(self: *Self) void {\nif (self.stack == null) return;\nself.stack.?.deinit();\n}\n// \u83b7\u53d6\u6808\u7684\u957f\u5ea6\npub fn size(self: *Self) usize {\nreturn self.stack.?.items.len;\n}\n// \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\npub fn isEmpty(self: *Self) bool {\nreturn self.size() == 0;\n}\n// \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npub fn peek(self: *Self) T {\nif (self.isEmpty()) @panic(\"\u6808\u4e3a\u7a7a\");\nreturn self.stack.?.items[self.size() - 1];\n}  // \u5165\u6808\npub fn push(self: *Self, num: T) !void {\ntry self.stack.?.append(num);\n} // \u51fa\u6808\npub fn pop(self: *Self) T {\nvar num = self.stack.?.pop();\nreturn num;\n} // \u8fd4\u56de ArrayList\npub fn toList(self: *Self) std.ArrayList(T) {\nreturn self.stack.?;\n}\n};\n}\n
        "},{"location":"chapter_stack_and_queue/stack/#513","title":"5.1.3 \u00a0 \u4e24\u79cd\u5b9e\u73b0\u5bf9\u6bd4","text":"

        \u652f\u6301\u64cd\u4f5c

        \u4e24\u79cd\u5b9e\u73b0\u90fd\u652f\u6301\u6808\u5b9a\u4e49\u4e2d\u7684\u5404\u9879\u64cd\u4f5c\u3002\u6570\u7ec4\u5b9e\u73b0\u989d\u5916\u652f\u6301\u968f\u673a\u8bbf\u95ee\uff0c\u4f46\u8fd9\u5df2\u8d85\u51fa\u4e86\u6808\u7684\u5b9a\u4e49\u8303\u7574\uff0c\u56e0\u6b64\u4e00\u822c\u4e0d\u4f1a\u7528\u5230\u3002

        \u65f6\u95f4\u6548\u7387

        \u5728\u57fa\u4e8e\u6570\u7ec4\u7684\u5b9e\u73b0\u4e2d\uff0c\u5165\u6808\u548c\u51fa\u6808\u64cd\u4f5c\u90fd\u5728\u9884\u5148\u5206\u914d\u597d\u7684\u8fde\u7eed\u5185\u5b58\u4e2d\u8fdb\u884c\uff0c\u5177\u6709\u5f88\u597d\u7684\u7f13\u5b58\u672c\u5730\u6027\uff0c\u56e0\u6b64\u6548\u7387\u8f83\u9ad8\u3002\u7136\u800c\uff0c\u5982\u679c\u5165\u6808\u65f6\u8d85\u51fa\u6570\u7ec4\u5bb9\u91cf\uff0c\u4f1a\u89e6\u53d1\u6269\u5bb9\u673a\u5236\uff0c\u5bfc\u81f4\u8be5\u6b21\u5165\u6808\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53d8\u4e3a \\(O(n)\\) \u3002

        \u5728\u57fa\u4e8e\u94fe\u8868\u7684\u5b9e\u73b0\u4e2d\uff0c\u94fe\u8868\u7684\u6269\u5bb9\u975e\u5e38\u7075\u6d3b\uff0c\u4e0d\u5b58\u5728\u4e0a\u8ff0\u6570\u7ec4\u6269\u5bb9\u65f6\u6548\u7387\u964d\u4f4e\u7684\u95ee\u9898\u3002\u4f46\u662f\uff0c\u5165\u6808\u64cd\u4f5c\u9700\u8981\u521d\u59cb\u5316\u8282\u70b9\u5bf9\u8c61\u5e76\u4fee\u6539\u6307\u9488\uff0c\u56e0\u6b64\u6548\u7387\u76f8\u5bf9\u8f83\u4f4e\u3002\u4e0d\u8fc7\uff0c\u5982\u679c\u5165\u6808\u5143\u7d20\u672c\u8eab\u5c31\u662f\u8282\u70b9\u5bf9\u8c61\uff0c\u90a3\u4e48\u53ef\u4ee5\u7701\u53bb\u521d\u59cb\u5316\u6b65\u9aa4\uff0c\u4ece\u800c\u63d0\u9ad8\u6548\u7387\u3002

        \u7efc\u4e0a\u6240\u8ff0\uff0c\u5f53\u5165\u6808\u4e0e\u51fa\u6808\u64cd\u4f5c\u7684\u5143\u7d20\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u65f6\uff0c\u4f8b\u5982 int \u6216 double \uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4ee5\u4e0b\u7ed3\u8bba\u3002

        • \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\u5728\u89e6\u53d1\u6269\u5bb9\u65f6\u6548\u7387\u4f1a\u964d\u4f4e\uff0c\u4f46\u7531\u4e8e\u6269\u5bb9\u662f\u4f4e\u9891\u64cd\u4f5c\uff0c\u56e0\u6b64\u5e73\u5747\u6548\u7387\u66f4\u9ad8\u3002
        • \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\u53ef\u4ee5\u63d0\u4f9b\u66f4\u52a0\u7a33\u5b9a\u7684\u6548\u7387\u8868\u73b0\u3002

        \u7a7a\u95f4\u6548\u7387

        \u5728\u521d\u59cb\u5316\u5217\u8868\u65f6\uff0c\u7cfb\u7edf\u4f1a\u4e3a\u5217\u8868\u5206\u914d\u201c\u521d\u59cb\u5bb9\u91cf\u201d\uff0c\u8be5\u5bb9\u91cf\u53ef\u80fd\u8d85\u51fa\u5b9e\u9645\u9700\u6c42\uff1b\u5e76\u4e14\uff0c\u6269\u5bb9\u673a\u5236\u901a\u5e38\u662f\u6309\u7167\u7279\u5b9a\u500d\u7387\uff08\u4f8b\u5982 2 \u500d\uff09\u8fdb\u884c\u6269\u5bb9\u7684\uff0c\u6269\u5bb9\u540e\u7684\u5bb9\u91cf\u4e5f\u53ef\u80fd\u8d85\u51fa\u5b9e\u9645\u9700\u6c42\u3002\u56e0\u6b64\uff0c\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\u53ef\u80fd\u9020\u6210\u4e00\u5b9a\u7684\u7a7a\u95f4\u6d6a\u8d39\u3002

        \u7136\u800c\uff0c\u7531\u4e8e\u94fe\u8868\u8282\u70b9\u9700\u8981\u989d\u5916\u5b58\u50a8\u6307\u9488\uff0c\u56e0\u6b64\u94fe\u8868\u8282\u70b9\u5360\u7528\u7684\u7a7a\u95f4\u76f8\u5bf9\u8f83\u5927\u3002

        \u7efc\u4e0a\uff0c\u6211\u4eec\u4e0d\u80fd\u7b80\u5355\u5730\u786e\u5b9a\u54ea\u79cd\u5b9e\u73b0\u66f4\u52a0\u8282\u7701\u5185\u5b58\uff0c\u9700\u8981\u9488\u5bf9\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u5206\u6790\u3002

        "},{"location":"chapter_stack_and_queue/stack/#514","title":"5.1.4 \u00a0 \u6808\u5178\u578b\u5e94\u7528","text":"
        • \u6d4f\u89c8\u5668\u4e2d\u7684\u540e\u9000\u4e0e\u524d\u8fdb\u3001\u8f6f\u4ef6\u4e2d\u7684\u64a4\u9500\u4e0e\u53cd\u64a4\u9500\u3002\u6bcf\u5f53\u6211\u4eec\u6253\u5f00\u65b0\u7684\u7f51\u9875\uff0c\u6d4f\u89c8\u5668\u5c31\u4f1a\u5bf9\u4e0a\u4e00\u4e2a\u7f51\u9875\u6267\u884c\u5165\u6808\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u540e\u9000\u64cd\u4f5c\u56de\u5230\u4e0a\u4e00\u4e2a\u7f51\u9875\u3002\u540e\u9000\u64cd\u4f5c\u5b9e\u9645\u4e0a\u662f\u5728\u6267\u884c\u51fa\u6808\u3002\u5982\u679c\u8981\u540c\u65f6\u652f\u6301\u540e\u9000\u548c\u524d\u8fdb\uff0c\u90a3\u4e48\u9700\u8981\u4e24\u4e2a\u6808\u6765\u914d\u5408\u5b9e\u73b0\u3002
        • \u7a0b\u5e8f\u5185\u5b58\u7ba1\u7406\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u7cfb\u7edf\u90fd\u4f1a\u5728\u6808\u9876\u6dfb\u52a0\u4e00\u4e2a\u6808\u5e27\uff0c\u7528\u4e8e\u8bb0\u5f55\u51fd\u6570\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u5728\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u5411\u4e0b\u9012\u63a8\u9636\u6bb5\u4f1a\u4e0d\u65ad\u6267\u884c\u5165\u6808\u64cd\u4f5c\uff0c\u800c\u5411\u4e0a\u56de\u6eaf\u9636\u6bb5\u5219\u4f1a\u4e0d\u65ad\u6267\u884c\u51fa\u6808\u64cd\u4f5c\u3002
        "},{"location":"chapter_stack_and_queue/summary/","title":"5.4 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_stack_and_queue/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u6808\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u540e\u51fa\u539f\u5219\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u901a\u8fc7\u6570\u7ec4\u6216\u94fe\u8868\u6765\u5b9e\u73b0\u3002
        • \u5728\u65f6\u95f4\u6548\u7387\u65b9\u9762\uff0c\u6808\u7684\u6570\u7ec4\u5b9e\u73b0\u5177\u6709\u8f83\u9ad8\u7684\u5e73\u5747\u6548\u7387\uff0c\u4f46\u5728\u6269\u5bb9\u8fc7\u7a0b\u4e2d\uff0c\u5355\u6b21\u5165\u6808\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u52a3\u5316\u81f3 \\(O(n)\\) \u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u6808\u7684\u94fe\u8868\u5b9e\u73b0\u5177\u6709\u66f4\u4e3a\u7a33\u5b9a\u7684\u6548\u7387\u8868\u73b0\u3002
        • \u5728\u7a7a\u95f4\u6548\u7387\u65b9\u9762\uff0c\u6808\u7684\u6570\u7ec4\u5b9e\u73b0\u53ef\u80fd\u5bfc\u81f4\u4e00\u5b9a\u7a0b\u5ea6\u7684\u7a7a\u95f4\u6d6a\u8d39\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u94fe\u8868\u8282\u70b9\u6240\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u6bd4\u6570\u7ec4\u5143\u7d20\u66f4\u5927\u3002
        • \u961f\u5217\u662f\u4e00\u79cd\u9075\u5faa\u5148\u5165\u5148\u51fa\u539f\u5219\u7684\u6570\u636e\u7ed3\u6784\uff0c\u540c\u6837\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4\u6216\u94fe\u8868\u6765\u5b9e\u73b0\u3002\u5728\u65f6\u95f4\u6548\u7387\u548c\u7a7a\u95f4\u6548\u7387\u7684\u5bf9\u6bd4\u4e0a\uff0c\u961f\u5217\u7684\u7ed3\u8bba\u4e0e\u524d\u8ff0\u6808\u7684\u7ed3\u8bba\u76f8\u4f3c\u3002
        • \u53cc\u5411\u961f\u5217\u662f\u4e00\u79cd\u5177\u6709\u66f4\u9ad8\u81ea\u7531\u5ea6\u7684\u961f\u5217\uff0c\u5b83\u5141\u8bb8\u5728\u4e24\u7aef\u8fdb\u884c\u5143\u7d20\u7684\u6dfb\u52a0\u548c\u5220\u9664\u64cd\u4f5c\u3002
        "},{"location":"chapter_stack_and_queue/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u6d4f\u89c8\u5668\u7684\u524d\u8fdb\u540e\u9000\u662f\u5426\u662f\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\uff1f

        \u6d4f\u89c8\u5668\u7684\u524d\u8fdb\u540e\u9000\u529f\u80fd\u672c\u8d28\u4e0a\u662f\u201c\u6808\u201d\u7684\u4f53\u73b0\u3002\u5f53\u7528\u6237\u8bbf\u95ee\u4e00\u4e2a\u65b0\u9875\u9762\u65f6\uff0c\u8be5\u9875\u9762\u4f1a\u88ab\u6dfb\u52a0\u5230\u6808\u9876\uff1b\u5f53\u7528\u6237\u70b9\u51fb\u540e\u9000\u6309\u94ae\u65f6\uff0c\u8be5\u9875\u9762\u4f1a\u4ece\u6808\u9876\u5f39\u51fa\u3002\u4f7f\u7528\u53cc\u5411\u961f\u5217\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u4e00\u4e9b\u989d\u5916\u64cd\u4f5c\uff0c\u8fd9\u4e2a\u5728\u201c\u53cc\u5411\u961f\u5217\u201d\u7ae0\u8282\u6709\u63d0\u5230\u3002

        \u5728\u51fa\u6808\u540e\uff0c\u662f\u5426\u9700\u8981\u91ca\u653e\u51fa\u6808\u8282\u70b9\u7684\u5185\u5b58\uff1f

        \u5982\u679c\u540e\u7eed\u4ecd\u9700\u8981\u4f7f\u7528\u5f39\u51fa\u8282\u70b9\uff0c\u5219\u4e0d\u9700\u8981\u91ca\u653e\u5185\u5b58\u3002\u82e5\u4e4b\u540e\u4e0d\u9700\u8981\u7528\u5230\uff0cJava \u548c Python \u7b49\u8bed\u8a00\u62e5\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\uff1b\u5728 C \u548c C++ \u4e2d\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\u3002

        \u53cc\u5411\u961f\u5217\u50cf\u662f\u4e24\u4e2a\u6808\u62fc\u63a5\u5728\u4e86\u4e00\u8d77\uff0c\u5b83\u7684\u7528\u9014\u662f\u4ec0\u4e48\uff1f

        \u53cc\u5411\u961f\u5217\u5c31\u50cf\u662f\u6808\u548c\u961f\u5217\u7684\u7ec4\u5408\uff0c\u6216\u4e24\u4e2a\u6808\u62fc\u5728\u4e86\u4e00\u8d77\u3002\u5b83\u8868\u73b0\u7684\u662f\u6808 + \u961f\u5217\u7684\u903b\u8f91\uff0c\u56e0\u6b64\u53ef\u4ee5\u5b9e\u73b0\u6808\u4e0e\u961f\u5217\u7684\u6240\u6709\u5e94\u7528\uff0c\u5e76\u4e14\u66f4\u52a0\u7075\u6d3b\u3002

        \u64a4\u9500\uff08undo\uff09\u548c\u53cd\u64a4\u9500\uff08redo\uff09\u5177\u4f53\u662f\u5982\u4f55\u5b9e\u73b0\u7684\uff1f

        \u4f7f\u7528\u4e24\u4e2a\u5806\u6808\uff0c\u6808 A \u7528\u4e8e\u64a4\u9500\uff0c\u6808 B \u7528\u4e8e\u53cd\u64a4\u9500\u3002

        1. \u6bcf\u5f53\u7528\u6237\u6267\u884c\u4e00\u4e2a\u64cd\u4f5c\uff0c\u5c06\u8fd9\u4e2a\u64cd\u4f5c\u538b\u5165\u6808 A \uff0c\u5e76\u6e05\u7a7a\u6808 B \u3002
        2. \u5f53\u7528\u6237\u6267\u884c\u201c\u64a4\u9500\u201d\u65f6\uff0c\u4ece\u6808 A \u4e2d\u5f39\u51fa\u6700\u8fd1\u7684\u64cd\u4f5c\uff0c\u5e76\u5c06\u5176\u538b\u5165\u6808 B \u3002
        3. \u5f53\u7528\u6237\u6267\u884c\u201c\u53cd\u64a4\u9500\u201d\u65f6\uff0c\u4ece\u6808 B \u4e2d\u5f39\u51fa\u6700\u8fd1\u7684\u64cd\u4f5c\uff0c\u5e76\u5c06\u5176\u538b\u5165\u6808 A \u3002
        "},{"location":"chapter_tree/","title":"\u7b2c 7 \u7ae0 \u00a0 \u6811","text":"

        Abstract

        \u53c2\u5929\u5927\u6811\u5145\u6ee1\u751f\u547d\u529b\uff0c\u6839\u6df1\u53f6\u8302\uff0c\u5206\u679d\u6276\u758f\u3002

        \u5b83\u4e3a\u6211\u4eec\u5c55\u73b0\u4e86\u6570\u636e\u5206\u6cbb\u7684\u751f\u52a8\u5f62\u6001\u3002

        "},{"location":"chapter_tree/#_1","title":"\u672c\u7ae0\u5185\u5bb9","text":"
        • 7.1 \u00a0 \u4e8c\u53c9\u6811
        • 7.2 \u00a0 \u4e8c\u53c9\u6811\u904d\u5386
        • 7.3 \u00a0 \u4e8c\u53c9\u6811\u6570\u7ec4\u8868\u793a
        • 7.4 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811
        • 7.5 \u00a0 AVL \u6811 *
        • 7.6 \u00a0 \u5c0f\u7ed3
        "},{"location":"chapter_tree/array_representation_of_tree/","title":"7.3 \u00a0 \u4e8c\u53c9\u6811\u6570\u7ec4\u8868\u793a","text":"

        \u5728\u94fe\u8868\u8868\u793a\u4e0b\uff0c\u4e8c\u53c9\u6811\u7684\u5b58\u50a8\u5355\u5143\u4e3a\u8282\u70b9 TreeNode \uff0c\u8282\u70b9\u4e4b\u95f4\u901a\u8fc7\u6307\u9488\u76f8\u8fde\u63a5\u3002\u4e0a\u4e00\u8282\u4ecb\u7ecd\u4e86\u94fe\u8868\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7684\u5404\u9879\u57fa\u672c\u64cd\u4f5c\u3002

        \u90a3\u4e48\uff0c\u6211\u4eec\u80fd\u5426\u7528\u6570\u7ec4\u6765\u8868\u793a\u4e8c\u53c9\u6811\u5462\uff1f\u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002

        "},{"location":"chapter_tree/array_representation_of_tree/#731","title":"7.3.1 \u00a0 \u8868\u793a\u5b8c\u7f8e\u4e8c\u53c9\u6811","text":"

        \u5148\u5206\u6790\u4e00\u4e2a\u7b80\u5355\u6848\u4f8b\u3002\u7ed9\u5b9a\u4e00\u68f5\u5b8c\u7f8e\u4e8c\u53c9\u6811\uff0c\u6211\u4eec\u5c06\u6240\u6709\u8282\u70b9\u6309\u7167\u5c42\u5e8f\u904d\u5386\u7684\u987a\u5e8f\u5b58\u50a8\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5219\u6bcf\u4e2a\u8282\u70b9\u90fd\u5bf9\u5e94\u552f\u4e00\u7684\u6570\u7ec4\u7d22\u5f15\u3002

        \u6839\u636e\u5c42\u5e8f\u904d\u5386\u7684\u7279\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u63a8\u5bfc\u51fa\u7236\u8282\u70b9\u7d22\u5f15\u4e0e\u5b50\u8282\u70b9\u7d22\u5f15\u4e4b\u95f4\u7684\u201c\u6620\u5c04\u516c\u5f0f\u201d\uff1a\u82e5\u67d0\u8282\u70b9\u7684\u7d22\u5f15\u4e3a \\(i\\) \uff0c\u5219\u8be5\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7d22\u5f15\u4e3a \\(2i + 2\\) \u3002\u56fe 7-12 \u5c55\u793a\u4e86\u5404\u4e2a\u8282\u70b9\u7d22\u5f15\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002

        \u56fe 7-12 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u6620\u5c04\u516c\u5f0f\u7684\u89d2\u8272\u76f8\u5f53\u4e8e\u94fe\u8868\u4e2d\u7684\u6307\u9488\u3002\u7ed9\u5b9a\u6570\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u8282\u70b9\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7\u6620\u5c04\u516c\u5f0f\u6765\u8bbf\u95ee\u5b83\u7684\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u3002

        "},{"location":"chapter_tree/array_representation_of_tree/#732","title":"7.3.2 \u00a0 \u8868\u793a\u4efb\u610f\u4e8c\u53c9\u6811","text":"

        \u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u4e00\u4e2a\u7279\u4f8b\uff0c\u5728\u4e8c\u53c9\u6811\u7684\u4e2d\u95f4\u5c42\u901a\u5e38\u5b58\u5728\u8bb8\u591a \\(\\text{None}\\) \u3002\u7531\u4e8e\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5e76\u4e0d\u5305\u542b\u8fd9\u4e9b \\(\\text{None}\\) \uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u6cd5\u4ec5\u51ed\u8be5\u5e8f\u5217\u6765\u63a8\u6d4b \\(\\text{None}\\) \u7684\u6570\u91cf\u548c\u5206\u5e03\u4f4d\u7f6e\u3002\u8fd9\u610f\u5473\u7740\u5b58\u5728\u591a\u79cd\u4e8c\u53c9\u6811\u7ed3\u6784\u90fd\u7b26\u5408\u8be5\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u3002

        \u5982\u56fe 7-13 \u6240\u793a\uff0c\u7ed9\u5b9a\u4e00\u68f5\u975e\u5b8c\u7f8e\u4e8c\u53c9\u6811\uff0c\u4e0a\u8ff0\u6570\u7ec4\u8868\u793a\u65b9\u6cd5\u5df2\u7ecf\u5931\u6548\u3002

        \u56fe 7-13 \u00a0 \u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5bf9\u5e94\u591a\u79cd\u4e8c\u53c9\u6811\u53ef\u80fd\u6027

        \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u5728\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u4e2d\u663e\u5f0f\u5730\u5199\u51fa\u6240\u6709 \\(\\text{None}\\) \u3002\u5982\u56fe 7-14 \u6240\u793a\uff0c\u8fd9\u6837\u5904\u7406\u540e\uff0c\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5c31\u53ef\u4ee5\u552f\u4e00\u8868\u793a\u4e8c\u53c9\u6811\u4e86\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        # \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a\n# \u4f7f\u7528 None \u6765\u8868\u793a\u7a7a\u4f4d\ntree = [1, 2, 3, 4, None, 6, 7, 8, 9, None, None, 12, None, None, 15]\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u6700\u5927\u503c INT_MAX \u6807\u8bb0\u7a7a\u4f4d\nvector<int> tree = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u7684\u5305\u88c5\u7c7b Integer \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nInteger[] tree = { 1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15 };\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nint?[] tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 any \u7c7b\u578b\u7684\u5207\u7247, \u5c31\u53ef\u4ee5\u4f7f\u7528 nil \u6765\u6807\u8bb0\u7a7a\u4f4d\ntree := []any{1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15}\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 Int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 nil \u6765\u6807\u8bb0\u7a7a\u4f4d\nlet tree: [Int?] = [1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15]\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 null \u6765\u8868\u793a\u7a7a\u4f4d\nlet tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 null \u6765\u8868\u793a\u7a7a\u4f4d\nlet tree: (number | null)[] = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int? \u53ef\u7a7a\u7c7b\u578b \uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 null \u6765\u6807\u8bb0\u7a7a\u4f4d\nList<int?> tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 None \u6765\u6807\u8bb0\u7a7a\u4f4d\nlet tree = [Some(1), Some(2), Some(3), Some(4), None, Some(6), Some(7), Some(8), Some(9), None, None, Some(12), None, None, Some(15)];\n
        /* \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a */\n// \u4f7f\u7528 int \u6700\u5927\u503c\u6807\u8bb0\u7a7a\u4f4d\uff0c\u56e0\u6b64\u8981\u6c42\u8282\u70b9\u503c\u4e0d\u80fd\u4e3a INT_MAX\nint tree[] = {1, 2, 3, 4, INT_MAX, 6, 7, 8, 9, INT_MAX, INT_MAX, 12, INT_MAX, INT_MAX, 15};\n
        \n

        \u56fe 7-14 \u00a0 \u4efb\u610f\u7c7b\u578b\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u503c\u5f97\u8bf4\u660e\u7684\u662f\uff0c\u5b8c\u5168\u4e8c\u53c9\u6811\u975e\u5e38\u9002\u5408\u4f7f\u7528\u6570\u7ec4\u6765\u8868\u793a\u3002\u56de\u987e\u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u5b9a\u4e49\uff0c\\(\\text{None}\\) \u53ea\u51fa\u73b0\u5728\u6700\u5e95\u5c42\u4e14\u9760\u53f3\u7684\u4f4d\u7f6e\uff0c\u56e0\u6b64\u6240\u6709 \\(\\text{None}\\) \u4e00\u5b9a\u51fa\u73b0\u5728\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u7684\u672b\u5c3e\u3002

        \u8fd9\u610f\u5473\u7740\u4f7f\u7528\u6570\u7ec4\u8868\u793a\u5b8c\u5168\u4e8c\u53c9\u6811\u65f6\uff0c\u53ef\u4ee5\u7701\u7565\u5b58\u50a8\u6240\u6709 \\(\\text{None}\\) \uff0c\u975e\u5e38\u65b9\u4fbf\u3002\u56fe 7-15 \u7ed9\u51fa\u4e86\u4e00\u4e2a\u4f8b\u5b50\u3002

        \u56fe 7-15 \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a

        \u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e00\u68f5\u57fa\u4e8e\u6570\u7ec4\u8868\u793a\u7684\u4e8c\u53c9\u6811\uff0c\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u64cd\u4f5c\u3002

        • \u7ed9\u5b9a\u67d0\u8282\u70b9\uff0c\u83b7\u53d6\u5b83\u7684\u503c\u3001\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u3001\u7236\u8282\u70b9\u3002
        • \u83b7\u53d6\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u3001\u540e\u5e8f\u904d\u5386\u3001\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig array_binary_tree.py
        class ArrayBinaryTree:\n\"\"\"\u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b\"\"\"\ndef __init__(self, arr: list[int | None]):\n\"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\nself._tree = list(arr)\ndef size(self):\n\"\"\"\u8282\u70b9\u6570\u91cf\"\"\"\nreturn len(self._tree)\ndef val(self, i: int) -> int:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c\"\"\"\n# \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 or i >= self.size():\nreturn None\nreturn self._tree[i]\ndef left(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn 2 * i + 1\ndef right(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn 2 * i + 2\ndef parent(self, i: int) -> int | None:\n\"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\nreturn (i - 1) // 2\ndef level_order(self) -> list[int]:\n\"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\nself.res = []\n# \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in range(self.size()):\nif self.val(i) is not None:\nself.res.append(self.val(i))\nreturn self.res\ndef dfs(self, i: int, order: str):\n\"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\nif self.val(i) is None:\nreturn\n# \u524d\u5e8f\u904d\u5386\nif order == \"pre\":\nself.res.append(self.val(i))\nself.dfs(self.left(i), order)\n# \u4e2d\u5e8f\u904d\u5386\nif order == \"in\":\nself.res.append(self.val(i))\nself.dfs(self.right(i), order)\n# \u540e\u5e8f\u904d\u5386\nif order == \"post\":\nself.res.append(self.val(i))\ndef pre_order(self) -> list[int]:\n\"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"pre\")\nreturn self.res\ndef in_order(self) -> list[int]:\n\"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"in\")\nreturn self.res\ndef post_order(self) -> list[int]:\n\"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\nself.res = []\nself.dfs(0, order=\"post\")\nreturn self.res\n
        array_binary_tree.cpp
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\npublic:\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayBinaryTree(vector<int> arr) {\ntree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nint size() {\nreturn tree.size();\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size())\nreturn INT_MAX;\nreturn tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nvector<int> levelOrder() {\nvector<int> res;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\nif (val(i) != INT_MAX)\nres.push_back(val(i));\n}\nreturn res;\n}\n/* \u524d\u5e8f\u904d\u5386 */\nvector<int> preOrder() {\nvector<int> res;\ndfs(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvector<int> inOrder() {\nvector<int> res;\ndfs(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvector<int> postOrder() {\nvector<int> res;\ndfs(0, \"post\", res);\nreturn res;\n}\nprivate:\nvector<int> tree;\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(int i, string order, vector<int> &res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == INT_MAX)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (order == \"pre\")\nres.push_back(val(i));\ndfs(left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == \"in\")\nres.push_back(val(i));\ndfs(right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == \"post\")\nres.push_back(val(i));\n}\n};\n
        array_binary_tree.java
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nprivate List<Integer> tree;\n/* \u6784\u9020\u65b9\u6cd5 */\npublic ArrayBinaryTree(List<Integer> arr) {\ntree = new ArrayList<>(arr);\n}\n/* \u8282\u70b9\u6570\u91cf */\npublic int size() {\nreturn tree.size();\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\npublic Integer val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size())\nreturn null;\nreturn tree.get(i);\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\npublic Integer parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\npublic List<Integer> levelOrder() {\nList<Integer> res = new ArrayList<>();\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(); i++) {\nif (val(i) != null)\nres.add(val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nprivate void dfs(Integer i, String order, List<Integer> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == null)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (\"pre\".equals(order))\nres.add(val(i));\ndfs(left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (\"in\".equals(order))\nres.add(val(i));\ndfs(right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (\"post\".equals(order))\nres.add(val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npublic List<Integer> preOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\npublic List<Integer> inOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npublic List<Integer> postOrder() {\nList<Integer> res = new ArrayList<>();\ndfs(0, \"post\", res);\nreturn res;\n}\n}\n
        array_binary_tree.cs
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree(List<int?> arr) {\nList<int?> tree = new(arr);\n/* \u8282\u70b9\u6570\u91cf */\npublic int Size() {\nreturn tree.Count;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\npublic int? Val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= Size())\nreturn null;\nreturn tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\npublic int Parent(int i) {\nreturn (i - 1) / 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\npublic List<int> LevelOrder() {\nList<int> res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < Size(); i++) {\nif (Val(i).HasValue)\nres.Add(Val(i)!.Value);\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid DFS(int i, string order, List<int> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (!Val(i).HasValue)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (order == \"pre\")\nres.Add(Val(i)!.Value);\nDFS(Left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == \"in\")\nres.Add(Val(i)!.Value);\nDFS(Right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == \"post\")\nres.Add(Val(i)!.Value);\n}\n/* \u524d\u5e8f\u904d\u5386 */\npublic List<int> PreOrder() {\nList<int> res = [];\nDFS(0, \"pre\", res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\npublic List<int> InOrder() {\nList<int> res = [];\nDFS(0, \"in\", res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npublic List<int> PostOrder() {\nList<int> res = [];\nDFS(0, \"post\", res);\nreturn res;\n}\n}\n
        array_binary_tree.go
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\ntype arrayBinaryTree struct {\ntree []any\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newArrayBinaryTree(arr []any) *arrayBinaryTree {\nreturn &arrayBinaryTree{\ntree: arr,\n}\n}\n/* \u8282\u70b9\u6570\u91cf */\nfunc (abt *arrayBinaryTree) size() int {\nreturn len(abt.tree)\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfunc (abt *arrayBinaryTree) val(i int) any {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= abt.size() {\nreturn nil\n}\nreturn abt.tree[i]\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) left(i int) int {\nreturn 2*i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) right(i int) int {\nreturn 2*i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) parent(i int) int {\nreturn (i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) levelOrder() []any {\nvar res []any\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i := 0; i < abt.size(); i++ {\nif abt.val(i) != nil {\nres = append(res, abt.val(i))\n}\n}\nreturn res\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nfunc (abt *arrayBinaryTree) dfs(i int, order string, res *[]any) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif abt.val(i) == nil {\nreturn\n}\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\n*res = append(*res, abt.val(i))\n}\nabt.dfs(abt.left(i), order, res)\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\n*res = append(*res, abt.val(i))\n}\nabt.dfs(abt.right(i), order, res)\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\n*res = append(*res, abt.val(i))\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) preOrder() []any {\nvar res []any\nabt.dfs(0, \"pre\", &res)\nreturn res\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) inOrder() []any {\nvar res []any\nabt.dfs(0, \"in\", &res)\nreturn res\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) postOrder() []any {\nvar res []any\nabt.dfs(0, \"post\", &res)\nreturn res\n}\n
        array_binary_tree.swift
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nprivate var tree: [Int?]\n/* \u6784\u9020\u65b9\u6cd5 */\ninit(arr: [Int?]) {\ntree = arr\n}\n/* \u8282\u70b9\u6570\u91cf */\nfunc size() -> Int {\ntree.count\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfunc val(i: Int) -> Int? {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= size() {\nreturn nil\n}\nreturn tree[i]\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n2 * i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc parent(i: Int) -> Int {\n(i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder() -> [Int] {\nvar res: [Int] = []\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in stride(from: 0, to: size(), by: 1) {\nif let val = val(i: i) {\nres.append(val)\n}\n}\nreturn res\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nprivate func dfs(i: Int, order: String, res: inout [Int]) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nguard let val = val(i: i) else {\nreturn\n}\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\nres.append(val)\n}\ndfs(i: left(i: i), order: order, res: &res)\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\nres.append(val)\n}\ndfs(i: right(i: i), order: order, res: &res)\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\nres.append(val)\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"pre\", res: &res)\nreturn res\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"in\", res: &res)\nreturn res\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder() -> [Int] {\nvar res: [Int] = []\ndfs(i: 0, order: \"post\", res: &res)\nreturn res\n}\n}\n
        array_binary_tree.js
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n#tree;\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(arr) {\nthis.#tree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nsize() {\nreturn this.#tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nval(i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= this.size()) return null;\nreturn this.#tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i) {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nlevelOrder() {\nlet res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < this.size(); i++) {\nif (this.val(i) !== null) res.push(this.val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n#dfs(i, order, res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (this.val(i) === null) return;\n// \u524d\u5e8f\u904d\u5386\nif (order === 'pre') res.push(this.val(i));\nthis.#dfs(this.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order === 'in') res.push(this.val(i));\nthis.#dfs(this.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order === 'post') res.push(this.val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npreOrder() {\nconst res = [];\nthis.#dfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\ninOrder() {\nconst res = [];\nthis.#dfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npostOrder() {\nconst res = [];\nthis.#dfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.ts
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n#tree: (number | null)[];\n/* \u6784\u9020\u65b9\u6cd5 */\nconstructor(arr: (number | null)[]) {\nthis.#tree = arr;\n}\n/* \u8282\u70b9\u6570\u91cf */\nsize(): number {\nreturn this.#tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nval(i: number): number | null {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= this.size()) return null;\nreturn this.#tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i: number): number {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i: number): number {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i: number): number {\nreturn Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nlevelOrder(): number[] {\nlet res = [];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (let i = 0; i < this.size(); i++) {\nif (this.val(i) !== null) res.push(this.val(i));\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n#dfs(i: number, order: Order, res: (number | null)[]): void {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (this.val(i) === null) return;\n// \u524d\u5e8f\u904d\u5386\nif (order === 'pre') res.push(this.val(i));\nthis.#dfs(this.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order === 'in') res.push(this.val(i));\nthis.#dfs(this.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order === 'post') res.push(this.val(i));\n}\n/* \u524d\u5e8f\u904d\u5386 */\npreOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\ninOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\npostOrder(): (number | null)[] {\nconst res = [];\nthis.#dfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.dart
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\nlate List<int?> _tree;\n/* \u6784\u9020\u65b9\u6cd5 */\nArrayBinaryTree(this._tree);\n/* \u8282\u70b9\u6570\u91cf */\nint size() {\nreturn _tree.length;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint? val(int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size()) {\nreturn null;\n}\nreturn _tree[i];\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint? left(int i) {\nreturn 2 * i + 1;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint? right(int i) {\nreturn 2 * i + 2;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint? parent(int i) {\nreturn (i - 1) ~/ 2;\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nList<int> levelOrder() {\nList<int> res = [];\nfor (int i = 0; i < size(); i++) {\nif (val(i) != null) {\nres.add(val(i)!);\n}\n}\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(int i, String order, List<int?> res) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(i) == null) {\nreturn;\n}\n// \u524d\u5e8f\u904d\u5386\nif (order == 'pre') {\nres.add(val(i));\n}\ndfs(left(i)!, order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif (order == 'in') {\nres.add(val(i));\n}\ndfs(right(i)!, order, res);\n// \u540e\u5e8f\u904d\u5386\nif (order == 'post') {\nres.add(val(i));\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nList<int?> preOrder() {\nList<int?> res = [];\ndfs(0, 'pre', res);\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nList<int?> inOrder() {\nList<int?> res = [];\ndfs(0, 'in', res);\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nList<int?> postOrder() {\nList<int?> res = [];\ndfs(0, 'post', res);\nreturn res;\n}\n}\n
        array_binary_tree.rs
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nstruct ArrayBinaryTree {\ntree: Vec<Option<i32>>,\n}\nimpl ArrayBinaryTree {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(arr: Vec<Option<i32>>) -> Self {\nSelf { tree: arr }\n}\n/* \u8282\u70b9\u6570\u91cf */\nfn size(&self) -> i32 {\nself.tree.len() as i32\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nfn val(&self, i: i32) -> Option<i32> {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif i < 0 || i >= self.size() {\nNone\n} else {\nself.tree[i as usize]\n}\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn left(&self, i: i32) -> i32 {\n2 * i + 1\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn right(&self, i: i32) -> i32 {\n2 * i + 2\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfn parent(&self, i: i32) -> i32 {\n(i - 1) / 2\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nfn level_order(&self) -> Vec<i32> {\nlet mut res = vec![];\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor i in 0..self.size() {\nif let Some(val) = self.val(i) {\nres.push(val)\n}\n}\nres\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nfn dfs(&self, i: i32, order: &str, res: &mut Vec<i32>) {\nif self.val(i).is_none() {\nreturn;\n}\nlet val = self.val(i).unwrap();\n// \u524d\u5e8f\u904d\u5386\nif order == \"pre\" {\nres.push(val);\n}\nself.dfs(self.left(i), order, res);\n// \u4e2d\u5e8f\u904d\u5386\nif order == \"in\" {\nres.push(val);\n}\nself.dfs(self.right(i), order, res);\n// \u540e\u5e8f\u904d\u5386\nif order == \"post\" {\nres.push(val);\n}\n}\n/* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"pre\", &mut res);\nres\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"in\", &mut res);\nres\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(&self) -> Vec<i32> {\nlet mut res = vec![];\nself.dfs(0, \"post\", &mut res);\nres\n}\n}\n
        array_binary_tree.c
        /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7ed3\u6784\u4f53 */\ntypedef struct {\nint *tree;\nint size;\n} ArrayBinaryTree;\n/* \u6784\u9020\u51fd\u6570 */\nArrayBinaryTree *newArrayBinaryTree(int *arr, int arrSize) {\nArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));\nabt->tree = malloc(sizeof(int) * arrSize);\nmemcpy(abt->tree, arr, sizeof(int) * arrSize);\nabt->size = arrSize;\nreturn abt;\n}\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayBinaryTree(ArrayBinaryTree *abt) {\nfree(abt->tree);\nfree(abt);\n}\n/* \u8282\u70b9\u6570\u91cf */\nint size(ArrayBinaryTree *abt) {\nreturn abt->size;\n}\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\nint val(ArrayBinaryTree *abt, int i) {\n// \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\nif (i < 0 || i >= size(abt))\nreturn INT_MAX;\nreturn abt->tree[i];\n}\n/* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\n// \u76f4\u63a5\u904d\u5386\u6570\u7ec4\nfor (int i = 0; i < size(abt); i++) {\nif (val(abt, i) != INT_MAX)\nres[index++] = val(abt, i);\n}\n*returnSize = index;\nreturn res;\n}\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nvoid dfs(ArrayBinaryTree *abt, int i, char *order, int *res, int *index) {\n// \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\nif (val(abt, i) == INT_MAX)\nreturn;\n// \u524d\u5e8f\u904d\u5386\nif (strcmp(order, \"pre\") == 0)\nres[(*index)++] = val(abt, i);\ndfs(abt, left(i), order, res, index);\n// \u4e2d\u5e8f\u904d\u5386\nif (strcmp(order, \"in\") == 0)\nres[(*index)++] = val(abt, i);\ndfs(abt, right(i), order, res, index);\n// \u540e\u5e8f\u904d\u5386\nif (strcmp(order, \"post\") == 0)\nres[(*index)++] = val(abt, i);\n}\n/* \u524d\u5e8f\u904d\u5386 */\nint *preOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"pre\", res, &index);\n*returnSize = index;\nreturn res;\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nint *inOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"in\", res, &index);\n*returnSize = index;\nreturn res;\n}\n/* \u540e\u5e8f\u904d\u5386 */\nint *postOrder(ArrayBinaryTree *abt, int *returnSize) {\nint *res = (int *)malloc(sizeof(int) * size(abt));\nint index = 0;\ndfs(abt, 0, \"post\", res, &index);\n*returnSize = index;\nreturn res;\n}\n
        array_binary_tree.zig
        [class]{ArrayBinaryTree}-[func]{}\n
        "},{"location":"chapter_tree/array_representation_of_tree/#733","title":"7.3.3 \u00a0 \u4f18\u70b9\u4e0e\u5c40\u9650\u6027","text":"

        \u4e8c\u53c9\u6811\u7684\u6570\u7ec4\u8868\u793a\u4e3b\u8981\u6709\u4ee5\u4e0b\u4f18\u70b9\u3002

        • \u6570\u7ec4\u5b58\u50a8\u5728\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u5bf9\u7f13\u5b58\u53cb\u597d\uff0c\u8bbf\u95ee\u4e0e\u904d\u5386\u901f\u5ea6\u8f83\u5feb\u3002
        • \u4e0d\u9700\u8981\u5b58\u50a8\u6307\u9488\uff0c\u6bd4\u8f83\u8282\u7701\u7a7a\u95f4\u3002
        • \u5141\u8bb8\u968f\u673a\u8bbf\u95ee\u8282\u70b9\u3002

        \u7136\u800c\uff0c\u6570\u7ec4\u8868\u793a\u4e5f\u5b58\u5728\u4e00\u4e9b\u5c40\u9650\u6027\u3002

        • \u6570\u7ec4\u5b58\u50a8\u9700\u8981\u8fde\u7eed\u5185\u5b58\u7a7a\u95f4\uff0c\u56e0\u6b64\u4e0d\u9002\u5408\u5b58\u50a8\u6570\u636e\u91cf\u8fc7\u5927\u7684\u6811\u3002
        • \u589e\u5220\u8282\u70b9\u9700\u8981\u901a\u8fc7\u6570\u7ec4\u63d2\u5165\u4e0e\u5220\u9664\u64cd\u4f5c\u5b9e\u73b0\uff0c\u6548\u7387\u8f83\u4f4e\u3002
        • \u5f53\u4e8c\u53c9\u6811\u4e2d\u5b58\u5728\u5927\u91cf \\(\\text{None}\\) \u65f6\uff0c\u6570\u7ec4\u4e2d\u5305\u542b\u7684\u8282\u70b9\u6570\u636e\u6bd4\u91cd\u8f83\u4f4e\uff0c\u7a7a\u95f4\u5229\u7528\u7387\u8f83\u4f4e\u3002
        "},{"location":"chapter_tree/avl_tree/","title":"7.5 \u00a0 AVL \u6811 *","text":"

        \u5728\u201c\u4e8c\u53c9\u641c\u7d22\u6811\u201d\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u63d0\u5230\uff0c\u5728\u591a\u6b21\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u540e\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u53ef\u80fd\u9000\u5316\u4e3a\u94fe\u8868\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4ece \\(O(\\log n)\\) \u6076\u5316\u4e3a \\(O(n)\\) \u3002

        \u5982\u56fe 7-24 \u6240\u793a\uff0c\u7ecf\u8fc7\u4e24\u6b21\u5220\u9664\u8282\u70b9\u64cd\u4f5c\uff0c\u8fd9\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\u4fbf\u4f1a\u9000\u5316\u4e3a\u94fe\u8868\u3002

        \u56fe 7-24 \u00a0 AVL \u6811\u5728\u5220\u9664\u8282\u70b9\u540e\u53d1\u751f\u9000\u5316

        \u518d\u4f8b\u5982\uff0c\u5728\u56fe 7-25 \u6240\u793a\u7684\u5b8c\u7f8e\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e24\u4e2a\u8282\u70b9\u540e\uff0c\u6811\u5c06\u4e25\u91cd\u5411\u5de6\u503e\u659c\uff0c\u67e5\u627e\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u968f\u4e4b\u6076\u5316\u3002

        \u56fe 7-25 \u00a0 AVL \u6811\u5728\u63d2\u5165\u8282\u70b9\u540e\u53d1\u751f\u9000\u5316

        1962 \u5e74 G. M. Adelson-Velsky \u548c E. M. Landis \u5728\u8bba\u6587 \"An algorithm for the organization of information\" \u4e2d\u63d0\u51fa\u4e86\u300cAVL \u6811\u300d\u3002\u8bba\u6587\u4e2d\u8be6\u7ec6\u63cf\u8ff0\u4e86\u4e00\u7cfb\u5217\u64cd\u4f5c\uff0c\u786e\u4fdd\u5728\u6301\u7eed\u6dfb\u52a0\u548c\u5220\u9664\u8282\u70b9\u540e\uff0cAVL \u6811\u4e0d\u4f1a\u9000\u5316\uff0c\u4ece\u800c\u4f7f\u5f97\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4fdd\u6301\u5728 \\(O(\\log n)\\) \u7ea7\u522b\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728\u9700\u8981\u9891\u7e41\u8fdb\u884c\u589e\u5220\u67e5\u6539\u64cd\u4f5c\u7684\u573a\u666f\u4e2d\uff0cAVL \u6811\u80fd\u59cb\u7ec8\u4fdd\u6301\u9ad8\u6548\u7684\u6570\u636e\u64cd\u4f5c\u6027\u80fd\uff0c\u5177\u6709\u5f88\u597d\u7684\u5e94\u7528\u4ef7\u503c\u3002

        "},{"location":"chapter_tree/avl_tree/#751-avl","title":"7.5.1 \u00a0 AVL \u6811\u5e38\u89c1\u672f\u8bed","text":"

        AVL \u6811\u65e2\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u4e5f\u662f\u5e73\u8861\u4e8c\u53c9\u6811\uff0c\u540c\u65f6\u6ee1\u8db3\u8fd9\u4e24\u7c7b\u4e8c\u53c9\u6811\u7684\u6240\u6709\u6027\u8d28\uff0c\u56e0\u6b64\u4e5f\u88ab\u79f0\u4e3a\u300c\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 balanced binary search tree\u300d\u3002

        "},{"location":"chapter_tree/avl_tree/#1","title":"1. \u00a0 \u8282\u70b9\u9ad8\u5ea6","text":"

        \u7531\u4e8e AVL \u6811\u7684\u76f8\u5173\u64cd\u4f5c\u9700\u8981\u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u4e3a\u8282\u70b9\u7c7b\u6dfb\u52a0 height \u53d8\u91cf\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class TreeNode:\n\"\"\"AVL \u6811\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                 # \u8282\u70b9\u503c\nself.height: int = 0                # \u8282\u70b9\u9ad8\u5ea6\nself.left: TreeNode | None = None   # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nself.right: TreeNode | None = None  # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nstruct TreeNode {\nint val{};          // \u8282\u70b9\u503c\nint height = 0;     // \u8282\u70b9\u9ad8\u5ea6\nTreeNode *left{};   // \u5de6\u5b50\u8282\u70b9\nTreeNode *right{};  // \u53f3\u5b50\u8282\u70b9\nTreeNode() = default;\nexplicit TreeNode(int x) : val(x){}\n};\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\npublic int val;        // \u8282\u70b9\u503c\npublic int height;     // \u8282\u70b9\u9ad8\u5ea6\npublic TreeNode left;  // \u5de6\u5b50\u8282\u70b9\npublic TreeNode right; // \u53f3\u5b50\u8282\u70b9\npublic TreeNode(int x) { val = x; }\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\npublic int? val = x;    // \u8282\u70b9\u503c\npublic int height;      // \u8282\u70b9\u9ad8\u5ea6\npublic TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\npublic TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\nVal    int       // \u8282\u70b9\u503c\nHeight int       // \u8282\u70b9\u9ad8\u5ea6\nLeft   *TreeNode // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nRight  *TreeNode // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nvar val: Int // \u8282\u70b9\u503c\nvar height: Int // \u8282\u70b9\u9ad8\u5ea6\nvar left: TreeNode? // \u5de6\u5b50\u8282\u70b9\nvar right: TreeNode? // \u53f3\u5b50\u8282\u70b9\ninit(x: Int) {\nval = x\nheight = 0\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval; // \u8282\u70b9\u503c\nheight; //\u8282\u70b9\u9ad8\u5ea6\nleft; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val, left, right, height) {\nthis.val = val === undefined ? 0 : val;\nthis.height = height === undefined ? 0 : height;\nthis.left = left === undefined ? null : left;\nthis.right = right === undefined ? null : right;\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval: number;            // \u8282\u70b9\u503c\nheight: number;         // \u8282\u70b9\u9ad8\u5ea6\nleft: TreeNode | null;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright: TreeNode | null; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {\nthis.val = val === undefined ? 0 : val;\nthis.height = height === undefined ? 0 : height; this.left = left === undefined ? null : left; this.right = right === undefined ? null : right; }\n}\n
        /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nint height;      // \u8282\u70b9\u9ad8\u5ea6\nTreeNode? left;  // \u5de6\u5b50\u8282\u70b9\nTreeNode? right; // \u53f3\u5b50\u8282\u70b9\nTreeNode(this.val, [this.height = 0, this.left, this.right]);\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nval: i32,                               // \u8282\u70b9\u503c\nheight: i32,                            // \u8282\u70b9\u9ad8\u5ea6\nleft: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\nright: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\n}\nimpl TreeNode {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(val: i32) -> Rc<RefCell<Self>> {\nRc::new(RefCell::new(Self {\nval,\nheight: 0,\nleft: None,\nright: None\n}))\n}\n}\n
        /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nTreeNode struct TreeNode {\nint val;\nint height;\nstruct TreeNode *left;\nstruct TreeNode *right;\n} TreeNode;\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\nTreeNode *node;\nnode = (TreeNode *)malloc(sizeof(TreeNode));\nnode->val = val;\nnode->height = 0;\nnode->left = NULL;\nnode->right = NULL;\nreturn node;\n}\n
        \n

        \u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u662f\u6307\u4ece\u8be5\u8282\u70b9\u5230\u5176\u6700\u8fdc\u53f6\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u5373\u6240\u7ecf\u8fc7\u7684\u201c\u8fb9\u201d\u7684\u6570\u91cf\u3002\u9700\u8981\u7279\u522b\u6ce8\u610f\u7684\u662f\uff0c\u53f6\u8282\u70b9\u7684\u9ad8\u5ea6\u4e3a \\(0\\) \uff0c\u800c\u7a7a\u8282\u70b9\u7684\u9ad8\u5ea6\u4e3a \\(-1\\) \u3002\u6211\u4eec\u5c06\u521b\u5efa\u4e24\u4e2a\u5de5\u5177\u51fd\u6570\uff0c\u5206\u522b\u7528\u4e8e\u83b7\u53d6\u548c\u66f4\u65b0\u8282\u70b9\u7684\u9ad8\u5ea6\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def height(self, node: TreeNode | None) -> int:\n\"\"\"\u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\"\"\"\n# \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif node is not None:\nreturn node.height\nreturn -1\ndef update_height(self, node: TreeNode | None):\n\"\"\"\u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\"\"\"\n# \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = max([self.height(node.left), self.height(node.right)]) + 1\n
        avl_tree.cpp
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == nullptr ? -1 : node->height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode->height = max(height(node->left), height(node->right)) + 1;\n}\n
        avl_tree.java
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = Math.max(height(node.left), height(node.right)) + 1;\n}\n
        avl_tree.cs
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint Height(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid UpdateHeight(TreeNode node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height = Math.Max(Height(node.left), Height(node.right)) + 1;\n}\n
        avl_tree.go
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) height(node *TreeNode) int {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif node != nil {\nreturn node.Height\n}\nreturn -1\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) updateHeight(node *TreeNode) {\nlh := t.height(node.Left)\nrh := t.height(node.Right)\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nif lh > rh {\nnode.Height = lh + 1\n} else {\nnode.Height = rh + 1\n}\n}\n
        avl_tree.swift
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfunc height(node: TreeNode?) -> Int {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nnode == nil ? -1 : node!.height\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc updateHeight(node: TreeNode?) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode?.height = max(height(node: node?.left), height(node: node?.right)) + 1\n}\n
        avl_tree.js
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nheight(node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node === null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\n#updateHeight(node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height =\nMath.max(this.height(node.left), this.height(node.right)) + 1;\n}\n
        avl_tree.ts
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nheight(node: TreeNode): number {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node === null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nupdateHeight(node: TreeNode): void {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.height =\nMath.max(this.height(node.left), this.height(node.right)) + 1;\n}\n
        avl_tree.dart
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn node == null ? -1 : node.height;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode? node) {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode!.height = max(height(node.left), height(node.right)) + 1;\n}\n
        avl_tree.rs
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nfn height(node: OptionTreeNodeRc) -> i32 {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nmatch node {\nSome(node) => node.borrow().height,\nNone => -1,\n}\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfn update_height(node: OptionTreeNodeRc) {\nif let Some(node) = node {\nlet left = node.borrow().left.clone();\nlet right = node.borrow().right.clone();\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.borrow_mut().height = std::cmp::max(Self::height(left), Self::height(right)) + 1;\n}\n}\n
        avl_tree.c
        /* \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6 */\nint height(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nif (node != NULL) {\nreturn node->height;\n}\nreturn -1;\n}\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\nint lh = height(node->left);\nint rh = height(node->right);\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nif (lh > rh) {\nnode->height = lh + 1;\n} else {\nnode->height = rh + 1;\n}\n}\n
        avl_tree.zig
        // \u83b7\u53d6\u8282\u70b9\u9ad8\u5ea6\nfn height(self: *Self, node: ?*inc.TreeNode(T)) i32 {\n_ = self;\n// \u7a7a\u8282\u70b9\u9ad8\u5ea6\u4e3a -1 \uff0c\u53f6\u8282\u70b9\u9ad8\u5ea6\u4e3a 0\nreturn if (node == null) -1 else node.?.height;\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nfn updateHeight(self: *Self, node: ?*inc.TreeNode(T)) void {\n// \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\nnode.?.height = @max(self.height(node.?.left), self.height(node.?.right)) + 1;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2","title":"2. \u00a0 \u8282\u70b9\u5e73\u8861\u56e0\u5b50","text":"

        \u8282\u70b9\u7684\u300c\u5e73\u8861\u56e0\u5b50 balance factor\u300d\u5b9a\u4e49\u4e3a\u8282\u70b9\u5de6\u5b50\u6811\u7684\u9ad8\u5ea6\u51cf\u53bb\u53f3\u5b50\u6811\u7684\u9ad8\u5ea6\uff0c\u540c\u65f6\u89c4\u5b9a\u7a7a\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u4e3a \\(0\\) \u3002\u6211\u4eec\u540c\u6837\u5c06\u83b7\u53d6\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u7684\u529f\u80fd\u5c01\u88c5\u6210\u51fd\u6570\uff0c\u65b9\u4fbf\u540e\u7eed\u4f7f\u7528\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def balance_factor(self, node: TreeNode | None) -> int:\n\"\"\"\u83b7\u53d6\u5e73\u8861\u56e0\u5b50\"\"\"\n# \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif node is None:\nreturn 0\n# \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn self.height(node.left) - self.height(node.right)\n
        avl_tree.cpp
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == nullptr)\nreturn 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node->left) - height(node->right);\n}\n
        avl_tree.java
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null)\nreturn 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node.left) - height(node.right);\n}\n
        avl_tree.cs
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint BalanceFactor(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn Height(node.left) - Height(node.right);\n}\n
        avl_tree.go
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfunc (t *aVLTree) balanceFactor(node *TreeNode) int {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif node == nil {\nreturn 0\n}\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn t.height(node.Left) - t.height(node.Right)\n}\n
        avl_tree.swift
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfunc balanceFactor(node: TreeNode?) -> Int {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nguard let node = node else { return 0 }\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node: node.left) - height(node: node.right)\n}\n
        avl_tree.js
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nbalanceFactor(node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node === null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn this.height(node.left) - this.height(node.right);\n}\n
        avl_tree.ts
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nbalanceFactor(node: TreeNode): number {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node === null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn this.height(node.left) - this.height(node.right);\n}\n
        avl_tree.dart
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode? node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node.left) - height(node.right);\n}\n
        avl_tree.rs
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfn balance_factor(node: OptionTreeNodeRc) -> i32 {\nmatch node {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nNone => 0,\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nSome(node) => {\nSelf::height(node.borrow().left.clone()) - Self::height(node.borrow().right.clone())\n}\n}\n}\n
        avl_tree.c
        /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nint balanceFactor(TreeNode *node) {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == NULL) {\nreturn 0;\n}\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn height(node->left) - height(node->right);\n}\n
        avl_tree.zig
        // \u83b7\u53d6\u5e73\u8861\u56e0\u5b50\nfn balanceFactor(self: *Self, node: ?*inc.TreeNode(T)) i32 {\n// \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\nif (node == null) return 0;\n// \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\nreturn self.height(node.?.left) - self.height(node.?.right);\n}\n

        Note

        \u8bbe\u5e73\u8861\u56e0\u5b50\u4e3a \\(f\\) \uff0c\u5219\u4e00\u68f5 AVL \u6811\u7684\u4efb\u610f\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u7686\u6ee1\u8db3 \\(-1 \\le f \\le 1\\) \u3002

        "},{"location":"chapter_tree/avl_tree/#752-avl","title":"7.5.2 \u00a0 AVL \u6811\u65cb\u8f6c","text":"

        AVL \u6811\u7684\u7279\u70b9\u5728\u4e8e\u201c\u65cb\u8f6c\u201d\u64cd\u4f5c\uff0c\u5b83\u80fd\u591f\u5728\u4e0d\u5f71\u54cd\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u7684\u524d\u63d0\u4e0b\uff0c\u4f7f\u5931\u8861\u8282\u70b9\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u65cb\u8f6c\u64cd\u4f5c\u65e2\u80fd\u4fdd\u6301\u201c\u4e8c\u53c9\u641c\u7d22\u6811\u201d\u7684\u6027\u8d28\uff0c\u4e5f\u80fd\u4f7f\u6811\u91cd\u65b0\u53d8\u4e3a\u201c\u5e73\u8861\u4e8c\u53c9\u6811\u201d\u3002

        \u6211\u4eec\u5c06\u5e73\u8861\u56e0\u5b50\u7edd\u5bf9\u503c \\(> 1\\) \u7684\u8282\u70b9\u79f0\u4e3a\u201c\u5931\u8861\u8282\u70b9\u201d\u3002\u6839\u636e\u8282\u70b9\u5931\u8861\u60c5\u51b5\u7684\u4e0d\u540c\uff0c\u65cb\u8f6c\u64cd\u4f5c\u5206\u4e3a\u56db\u79cd\uff1a\u53f3\u65cb\u3001\u5de6\u65cb\u3001\u5148\u53f3\u65cb\u540e\u5de6\u65cb\u3001\u5148\u5de6\u65cb\u540e\u53f3\u65cb\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65cb\u8f6c\u64cd\u4f5c\u3002

        "},{"location":"chapter_tree/avl_tree/#1_1","title":"1. \u00a0 \u53f3\u65cb","text":"

        \u5982\u56fe 7-26 \u6240\u793a\uff0c\u8282\u70b9\u4e0b\u65b9\u4e3a\u5e73\u8861\u56e0\u5b50\u3002\u4ece\u5e95\u81f3\u9876\u770b\uff0c\u4e8c\u53c9\u6811\u4e2d\u9996\u4e2a\u5931\u8861\u8282\u70b9\u662f\u201c\u8282\u70b9 3\u201d\u3002\u6211\u4eec\u5173\u6ce8\u4ee5\u8be5\u5931\u8861\u8282\u70b9\u4e3a\u6839\u8282\u70b9\u7684\u5b50\u6811\uff0c\u5c06\u8be5\u8282\u70b9\u8bb0\u4e3a node \uff0c\u5176\u5de6\u5b50\u8282\u70b9\u8bb0\u4e3a child \uff0c\u6267\u884c\u201c\u53f3\u65cb\u201d\u64cd\u4f5c\u3002\u5b8c\u6210\u53f3\u65cb\u540e\uff0c\u5b50\u6811\u6062\u590d\u5e73\u8861\uff0c\u5e76\u4e14\u4ecd\u7136\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u3002

        <1><2><3><4>

        \u56fe 7-26 \u00a0 \u53f3\u65cb\u64cd\u4f5c\u6b65\u9aa4

        \u5982\u56fe 7-27 \u6240\u793a\uff0c\u5f53\u8282\u70b9 child \u6709\u53f3\u5b50\u8282\u70b9\uff08\u8bb0\u4e3a grandChild \uff09\u65f6\uff0c\u9700\u8981\u5728\u53f3\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grandChild \u4f5c\u4e3a node \u7684\u5de6\u5b50\u8282\u70b9\u3002

        \u56fe 7-27 \u00a0 \u6709 grandChild \u7684\u53f3\u65cb\u64cd\u4f5c

        \u201c\u5411\u53f3\u65cb\u8f6c\u201d\u662f\u4e00\u79cd\u5f62\u8c61\u5316\u7684\u8bf4\u6cd5\uff0c\u5b9e\u9645\u4e0a\u9700\u8981\u901a\u8fc7\u4fee\u6539\u8282\u70b9\u6307\u9488\u6765\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def right_rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u53f3\u65cb\u64cd\u4f5c\"\"\"\nchild = node.left\ngrand_child = child.right\n# \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node\nnode.left = grand_child\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\nself.update_height(child)\n# \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n
        avl_tree.cpp
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\nTreeNode *child = node->left;\nTreeNode *grandChild = child->right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild->right = node;\nnode->left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.java
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode rightRotate(TreeNode node) {\nTreeNode child = node.left;\nTreeNode grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.cs
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? RightRotate(TreeNode? node) {\nTreeNode? child = node?.left;\nTreeNode? grandChild = child?.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nUpdateHeight(node);\nUpdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.go
        /* \u53f3\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) rightRotate(node *TreeNode) *TreeNode {\nchild := node.Left\ngrandChild := child.Right\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.Right = node\nnode.Left = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\nt.updateHeight(child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.swift
        /* \u53f3\u65cb\u64cd\u4f5c */\nfunc rightRotate(node: TreeNode?) -> TreeNode? {\nlet child = node?.left\nlet grandChild = child?.right\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild?.right = node\nnode?.left = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node: node)\nupdateHeight(node: child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.js
        /* \u53f3\u65cb\u64cd\u4f5c */\n#rightRotate(node) {\nconst child = node.left;\nconst grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.#updateHeight(node);\nthis.#updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.ts
        /* \u53f3\u65cb\u64cd\u4f5c */\nrightRotate(node: TreeNode): TreeNode {\nconst child = node.left;\nconst grandChild = child.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.updateHeight(node);\nthis.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.dart
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? rightRotate(TreeNode? node) {\nTreeNode? child = node!.left;\nTreeNode? grandChild = child!.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.right = node;\nnode.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.rs
        /* \u53f3\u65cb\u64cd\u4f5c */\nfn right_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\nmatch node {\nSome(node) => {\nlet child = node.borrow().left.clone().unwrap();\nlet grand_child = child.borrow().right.clone();\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.borrow_mut().right = Some(node.clone());\nnode.borrow_mut().left = grand_child;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nSelf::update_height(Some(node));\nSelf::update_height(Some(child.clone()));\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(child)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\nTreeNode *child, *grandChild;\nchild = node->left;\ngrandChild = child->right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild->right = node;\nnode->left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.zig
        // \u53f3\u65cb\u64cd\u4f5c\nfn rightRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\nvar child = node.?.left;\nvar grandChild = child.?.right;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\nchild.?.right = node;\nnode.?.left = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.updateHeight(node);\nself.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2_1","title":"2. \u00a0 \u5de6\u65cb","text":"

        \u76f8\u5e94\u5730\uff0c\u5982\u679c\u8003\u8651\u4e0a\u8ff0\u5931\u8861\u4e8c\u53c9\u6811\u7684\u201c\u955c\u50cf\u201d\uff0c\u5219\u9700\u8981\u6267\u884c\u56fe 7-28 \u6240\u793a\u7684\u201c\u5de6\u65cb\u201d\u64cd\u4f5c\u3002

        \u56fe 7-28 \u00a0 \u5de6\u65cb\u64cd\u4f5c

        \u540c\u7406\uff0c\u5982\u56fe 7-29 \u6240\u793a\uff0c\u5f53\u8282\u70b9 child \u6709\u5de6\u5b50\u8282\u70b9\uff08\u8bb0\u4e3a grandChild \uff09\u65f6\uff0c\u9700\u8981\u5728\u5de6\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grandChild \u4f5c\u4e3a node \u7684\u53f3\u5b50\u8282\u70b9\u3002

        \u56fe 7-29 \u00a0 \u6709 grandChild \u7684\u5de6\u65cb\u64cd\u4f5c

        \u53ef\u4ee5\u89c2\u5bdf\u5230\uff0c\u53f3\u65cb\u548c\u5de6\u65cb\u64cd\u4f5c\u5728\u903b\u8f91\u4e0a\u662f\u955c\u50cf\u5bf9\u79f0\u7684\uff0c\u5b83\u4eec\u5206\u522b\u89e3\u51b3\u7684\u4e24\u79cd\u5931\u8861\u60c5\u51b5\u4e5f\u662f\u5bf9\u79f0\u7684\u3002\u57fa\u4e8e\u5bf9\u79f0\u6027\uff0c\u6211\u4eec\u53ea\u9700\u5c06\u53f3\u65cb\u7684\u5b9e\u73b0\u4ee3\u7801\u4e2d\u7684\u6240\u6709\u7684 left \u66ff\u6362\u4e3a right \uff0c\u5c06\u6240\u6709\u7684 right \u66ff\u6362\u4e3a left \uff0c\u5373\u53ef\u5f97\u5230\u5de6\u65cb\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def left_rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u5de6\u65cb\u64cd\u4f5c\"\"\"\nchild = node.right\ngrand_child = child.left\n# \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node\nnode.right = grand_child\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\nself.update_height(child)\n# \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n
        avl_tree.cpp
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\nTreeNode *child = node->right;\nTreeNode *grandChild = child->left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild->left = node;\nnode->right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.java
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode leftRotate(TreeNode node) {\nTreeNode child = node.right;\nTreeNode grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.cs
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? LeftRotate(TreeNode? node) {\nTreeNode? child = node?.right;\nTreeNode? grandChild = child?.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nUpdateHeight(node);\nUpdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.go
        /* \u5de6\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) leftRotate(node *TreeNode) *TreeNode {\nchild := node.Right\ngrandChild := child.Left\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.Left = node\nnode.Right = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\nt.updateHeight(child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.swift
        /* \u5de6\u65cb\u64cd\u4f5c */\nfunc leftRotate(node: TreeNode?) -> TreeNode? {\nlet child = node?.right\nlet grandChild = child?.left\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild?.left = node\nnode?.right = grandChild\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node: node)\nupdateHeight(node: child)\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child\n}\n
        avl_tree.js
        /* \u5de6\u65cb\u64cd\u4f5c */\n#leftRotate(node) {\nconst child = node.right;\nconst grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.#updateHeight(node);\nthis.#updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.ts
        /* \u5de6\u65cb\u64cd\u4f5c */\nleftRotate(node: TreeNode): TreeNode {\nconst child = node.right;\nconst grandChild = child.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nthis.updateHeight(node);\nthis.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.dart
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? leftRotate(TreeNode? node) {\nTreeNode? child = node!.right;\nTreeNode? grandChild = child!.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.left = node;\nnode.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.rs
        /* \u5de6\u65cb\u64cd\u4f5c */\nfn left_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\nmatch node {\nSome(node) => {\nlet child = node.borrow().right.clone().unwrap();\nlet grand_child = child.borrow().left.clone();\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.borrow_mut().left = Some(node.clone());\nnode.borrow_mut().right = grand_child;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nSelf::update_height(Some(node));\nSelf::update_height(Some(child.clone()));\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(child)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\nTreeNode *child, *grandChild;\nchild = node->right;\ngrandChild = child->left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild->left = node;\nnode->right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\nupdateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        avl_tree.zig
        // \u5de6\u65cb\u64cd\u4f5c\nfn leftRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\nvar child = node.?.right;\nvar grandChild = child.?.left;\n// \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\nchild.?.left = node;\nnode.?.right = grandChild;\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.updateHeight(node);\nself.updateHeight(child);\n// \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn child;\n}\n
        "},{"location":"chapter_tree/avl_tree/#3","title":"3. \u00a0 \u5148\u5de6\u65cb\u540e\u53f3\u65cb","text":"

        \u5bf9\u4e8e\u56fe 7-30 \u4e2d\u7684\u5931\u8861\u8282\u70b9 3 \uff0c\u4ec5\u4f7f\u7528\u5de6\u65cb\u6216\u53f3\u65cb\u90fd\u65e0\u6cd5\u4f7f\u5b50\u6811\u6062\u590d\u5e73\u8861\u3002\u6b64\u65f6\u9700\u8981\u5148\u5bf9 child \u6267\u884c\u201c\u5de6\u65cb\u201d\uff0c\u518d\u5bf9 node \u6267\u884c\u201c\u53f3\u65cb\u201d\u3002

        \u56fe 7-30 \u00a0 \u5148\u5de6\u65cb\u540e\u53f3\u65cb

        "},{"location":"chapter_tree/avl_tree/#4","title":"4. \u00a0 \u5148\u53f3\u65cb\u540e\u5de6\u65cb","text":"

        \u5982\u56fe 7-31 \u6240\u793a\uff0c\u5bf9\u4e8e\u4e0a\u8ff0\u5931\u8861\u4e8c\u53c9\u6811\u7684\u955c\u50cf\u60c5\u51b5\uff0c\u9700\u8981\u5148\u5bf9 child \u6267\u884c\u201c\u53f3\u65cb\u201d\uff0c\u518d\u5bf9 node \u6267\u884c\u201c\u5de6\u65cb\u201d\u3002

        \u56fe 7-31 \u00a0 \u5148\u53f3\u65cb\u540e\u5de6\u65cb

        "},{"location":"chapter_tree/avl_tree/#5","title":"5. \u00a0 \u65cb\u8f6c\u7684\u9009\u62e9","text":"

        \u56fe 7-32 \u5c55\u793a\u7684\u56db\u79cd\u5931\u8861\u60c5\u51b5\u4e0e\u4e0a\u8ff0\u6848\u4f8b\u9010\u4e2a\u5bf9\u5e94\uff0c\u5206\u522b\u9700\u8981\u91c7\u7528\u53f3\u65cb\u3001\u5148\u5de6\u65cb\u540e\u53f3\u65cb\u3001\u5148\u53f3\u65cb\u540e\u5de6\u65cb\u3001\u5de6\u65cb\u7684\u64cd\u4f5c\u3002

        \u56fe 7-32 \u00a0 AVL \u6811\u7684\u56db\u79cd\u65cb\u8f6c\u60c5\u51b5

        \u5982\u4e0b\u8868\u6240\u793a\uff0c\u6211\u4eec\u901a\u8fc7\u5224\u65ad\u5931\u8861\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u4ee5\u53ca\u8f83\u9ad8\u4e00\u4fa7\u5b50\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50\u7684\u6b63\u8d1f\u53f7\uff0c\u6765\u786e\u5b9a\u5931\u8861\u8282\u70b9\u5c5e\u4e8e\u56fe 7-32 \u4e2d\u7684\u54ea\u79cd\u60c5\u51b5\u3002

        \u8868 7-3 \u00a0 \u56db\u79cd\u65cb\u8f6c\u60c5\u51b5\u7684\u9009\u62e9\u6761\u4ef6

        \u5931\u8861\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50 \u5b50\u8282\u70b9\u7684\u5e73\u8861\u56e0\u5b50 \u5e94\u91c7\u7528\u7684\u65cb\u8f6c\u65b9\u6cd5 \\(> 1\\) \uff08\u5de6\u504f\u6811\uff09 \\(\\geq 0\\) \u53f3\u65cb \\(> 1\\) \uff08\u5de6\u504f\u6811\uff09 \\(<0\\) \u5148\u5de6\u65cb\u540e\u53f3\u65cb \\(< -1\\) \uff08\u53f3\u504f\u6811\uff09 \\(\\leq 0\\) \u5de6\u65cb \\(< -1\\) \uff08\u53f3\u504f\u6811\uff09 \\(>0\\) \u5148\u53f3\u65cb\u540e\u5de6\u65cb

        \u4e3a\u4e86\u4fbf\u4e8e\u4f7f\u7528\uff0c\u6211\u4eec\u5c06\u65cb\u8f6c\u64cd\u4f5c\u5c01\u88c5\u6210\u4e00\u4e2a\u51fd\u6570\u3002\u6709\u4e86\u8fd9\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u5c31\u80fd\u5bf9\u5404\u79cd\u5931\u8861\u60c5\u51b5\u8fdb\u884c\u65cb\u8f6c\uff0c\u4f7f\u5931\u8861\u8282\u70b9\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def rotate(self, node: TreeNode | None) -> TreeNode | None:\n\"\"\"\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\"\"\"\n# \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nbalance_factor = self.balance_factor(node)\n# \u5de6\u504f\u6811\nif balance_factor > 1:\nif self.balance_factor(node.left) >= 0:\n# \u53f3\u65cb\nreturn self.right_rotate(node)\nelse:\n# \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = self.left_rotate(node.left)\nreturn self.right_rotate(node)\n# \u53f3\u504f\u6811\nelif balance_factor < -1:\nif self.balance_factor(node.right) <= 0:\n# \u5de6\u65cb\nreturn self.left_rotate(node)\nelse:\n# \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = self.right_rotate(node.right)\nreturn self.left_rotate(node)\n# \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n
        avl_tree.cpp
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode *rotate(TreeNode *node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint _balanceFactor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (_balanceFactor > 1) {\nif (balanceFactor(node->left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode->left = leftRotate(node->left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (_balanceFactor < -1) {\nif (balanceFactor(node->right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode->right = rightRotate(node->right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.java
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode rotate(TreeNode node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint balanceFactor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = leftRotate(node.left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = rightRotate(node.right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.cs
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode? Rotate(TreeNode? node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint balanceFactorInt = BalanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactorInt > 1) {\nif (BalanceFactor(node?.left) >= 0) {\n// \u53f3\u65cb\nreturn RightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode!.left = LeftRotate(node!.left);\nreturn RightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactorInt < -1) {\nif (BalanceFactor(node?.right) <= 0) {\n// \u5de6\u65cb\nreturn LeftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode!.right = RightRotate(node!.right);\nreturn LeftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.go
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfunc (t *aVLTree) rotate(node *TreeNode) *TreeNode {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\n// Go \u63a8\u8350\u77ed\u53d8\u91cf\uff0c\u8fd9\u91cc bf \u6307\u4ee3 t.balanceFactor\nbf := t.balanceFactor(node)\n// \u5de6\u504f\u6811\nif bf > 1 {\nif t.balanceFactor(node.Left) >= 0 {\n// \u53f3\u65cb\nreturn t.rightRotate(node)\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.Left = t.leftRotate(node.Left)\nreturn t.rightRotate(node)\n}\n}\n// \u53f3\u504f\u6811\nif bf < -1 {\nif t.balanceFactor(node.Right) <= 0 {\n// \u5de6\u65cb\nreturn t.leftRotate(node)\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.Right = t.rightRotate(node.Right)\nreturn t.leftRotate(node)\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n
        avl_tree.swift
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfunc rotate(node: TreeNode?) -> TreeNode? {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nlet balanceFactor = balanceFactor(node: node)\n// \u5de6\u504f\u6811\nif balanceFactor > 1 {\nif self.balanceFactor(node: node?.left) >= 0 {\n// \u53f3\u65cb\nreturn rightRotate(node: node)\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode?.left = leftRotate(node: node?.left)\nreturn rightRotate(node: node)\n}\n}\n// \u53f3\u504f\u6811\nif balanceFactor < -1 {\nif self.balanceFactor(node: node?.right) <= 0 {\n// \u5de6\u65cb\nreturn leftRotate(node: node)\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode?.right = rightRotate(node: node?.right)\nreturn leftRotate(node: node)\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n
        avl_tree.js
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n#rotate(node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nconst balanceFactor = this.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (this.balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn this.#rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = this.#leftRotate(node.left);\nreturn this.#rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (this.balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn this.#leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = this.#rightRotate(node.right);\nreturn this.#leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.ts
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nrotate(node: TreeNode): TreeNode {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nconst balanceFactor = this.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balanceFactor > 1) {\nif (this.balanceFactor(node.left) >= 0) {\n// \u53f3\u65cb\nreturn this.rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = this.leftRotate(node.left);\nreturn this.rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balanceFactor < -1) {\nif (this.balanceFactor(node.right) <= 0) {\n// \u5de6\u65cb\nreturn this.leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = this.rightRotate(node.right);\nreturn this.leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.dart
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode? rotate(TreeNode? node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint factor = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (factor > 1) {\nif (balanceFactor(node!.left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.left = leftRotate(node.left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (factor < -1) {\nif (balanceFactor(node!.right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.right = rightRotate(node.right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.rs
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nfn rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nlet balance_factor = Self::balance_factor(node.clone());\n// \u5de6\u504f\u6811\nif balance_factor > 1 {\nlet node = node.unwrap();\nif Self::balance_factor(node.borrow().left.clone()) >= 0 {\n// \u53f3\u65cb\nSelf::right_rotate(Some(node))\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::left_rotate(left);\nSelf::right_rotate(Some(node))\n}\n}\n// \u53f3\u504f\u6811\nelse if balance_factor < -1 {\nlet node = node.unwrap();\nif Self::balance_factor(node.borrow().right.clone()) <= 0 {\n// \u5de6\u65cb\nSelf::left_rotate(Some(node))\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::right_rotate(right);\nSelf::left_rotate(Some(node))\n}\n} else {\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nnode\n}\n}\n
        avl_tree.c
        /* \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nTreeNode *rotate(TreeNode *node) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nint bf = balanceFactor(node);\n// \u5de6\u504f\u6811\nif (bf > 1) {\nif (balanceFactor(node->left) >= 0) {\n// \u53f3\u65cb\nreturn rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode->left = leftRotate(node->left);\nreturn rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (bf < -1) {\nif (balanceFactor(node->right) <= 0) {\n// \u5de6\u65cb\nreturn leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode->right = rightRotate(node->right);\nreturn leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        avl_tree.zig
        // \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nfn rotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n// \u83b7\u53d6\u8282\u70b9 node \u7684\u5e73\u8861\u56e0\u5b50\nvar balance_factor = self.balanceFactor(node);\n// \u5de6\u504f\u6811\nif (balance_factor > 1) {\nif (self.balanceFactor(node.?.left) >= 0) {\n// \u53f3\u65cb\nreturn self.rightRotate(node);\n} else {\n// \u5148\u5de6\u65cb\u540e\u53f3\u65cb\nnode.?.left = self.leftRotate(node.?.left);\nreturn self.rightRotate(node);\n}\n}\n// \u53f3\u504f\u6811\nif (balance_factor < -1) {\nif (self.balanceFactor(node.?.right) <= 0) {\n// \u5de6\u65cb\nreturn self.leftRotate(node);\n} else {\n// \u5148\u53f3\u65cb\u540e\u5de6\u65cb\nnode.?.right = self.rightRotate(node.?.right);\nreturn self.leftRotate(node);\n}\n}\n// \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#753-avl","title":"7.5.3 \u00a0 AVL \u6811\u5e38\u7528\u64cd\u4f5c","text":""},{"location":"chapter_tree/avl_tree/#1_2","title":"1. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        AVL \u6811\u7684\u8282\u70b9\u63d2\u5165\u64cd\u4f5c\u4e0e\u4e8c\u53c9\u641c\u7d22\u6811\u5728\u4e3b\u4f53\u4e0a\u7c7b\u4f3c\u3002\u552f\u4e00\u7684\u533a\u522b\u5728\u4e8e\uff0c\u5728 AVL \u6811\u4e2d\u63d2\u5165\u8282\u70b9\u540e\uff0c\u4ece\u8be5\u8282\u70b9\u5230\u6839\u8282\u70b9\u7684\u8def\u5f84\u4e0a\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e00\u7cfb\u5217\u5931\u8861\u8282\u70b9\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u4ece\u8fd9\u4e2a\u8282\u70b9\u5f00\u59cb\uff0c\u81ea\u5e95\u5411\u4e0a\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6240\u6709\u5931\u8861\u8282\u70b9\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def insert(self, val):\n\"\"\"\u63d2\u5165\u8282\u70b9\"\"\"\nself._root = self.insert_helper(self._root, val)\ndef insert_helper(self, node: TreeNode | None, val: int) -> TreeNode:\n\"\"\"\u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\nif node is None:\nreturn TreeNode(val)\n# 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9\nif val < node.val:\nnode.left = self.insert_helper(node.left, val)\nelif val > node.val:\nnode.right = self.insert_helper(node.right, val)\nelse:\n# \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\n# 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nreturn self.rotate(node)\n
        avl_tree.cpp
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\nif (node == nullptr)\nreturn new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node->val)\nnode->left = insertHelper(node->left, val);\nelse if (val > node->val)\nnode->right = insertHelper(node->right, val);\nelse\nreturn node;    // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.java
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode insertHelper(TreeNode node, int val) {\nif (node == null)\nreturn new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = insertHelper(node.right, val);\nelse\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.cs
        /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int val) {\nroot = InsertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? InsertHelper(TreeNode? node, int val) {\nif (node == null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = InsertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = InsertHelper(node.right, val);\nelse\nreturn node;     // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nUpdateHeight(node);  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.go
        /* \u63d2\u5165\u8282\u70b9 */\nfunc (t *aVLTree) insert(val int) {\nt.root = t.insertHelper(t.root, val)\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {\nif node == nil {\nreturn NewTreeNode(val)\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif val < node.Val.(int) {\nnode.Left = t.insertHelper(node.Left, val)\n} else if val > node.Val.(int) {\nnode.Right = t.insertHelper(node.Right, val)\n} else {\n// \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = t.rotate(node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.swift
        /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(val: Int) {\nroot = insertHelper(node: root, val: val)\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc insertHelper(node: TreeNode?, val: Int) -> TreeNode? {\nvar node = node\nif node == nil {\nreturn TreeNode(x: val)\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif val < node!.val {\nnode?.left = insertHelper(node: node?.left, val: val)\n} else if val > node!.val {\nnode?.right = insertHelper(node: node?.right, val: val)\n} else {\nreturn node // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nupdateHeight(node: node) // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node: node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.js
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(val) {\nthis.root = this.#insertHelper(this.root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#insertHelper(node, val) {\nif (node === null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val) node.left = this.#insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = this.#insertHelper(node.right, val);\nelse return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nthis.#updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.#rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.ts
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(val: number): void {\nthis.root = this.insertHelper(this.root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\ninsertHelper(node: TreeNode, val: number): TreeNode {\nif (node === null) return new TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val) {\nnode.left = this.insertHelper(node.left, val);\n} else if (val > node.val) {\nnode.right = this.insertHelper(node.right, val);\n} else {\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nthis.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.dart
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\nroot = insertHelper(root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? insertHelper(TreeNode? node, int val) {\nif (node == null) return TreeNode(val);\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node.val)\nnode.left = insertHelper(node.left, val);\nelse if (val > node.val)\nnode.right = insertHelper(node.right, val);\nelse\nreturn node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.rs
        /* \u63d2\u5165\u8282\u70b9 */\nfn insert(&mut self, val: i32) {\nself.root = Self::insert_helper(self.root.clone(), val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn insert_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\nmatch node {\nSome(mut node) => {\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nmatch {\nlet node_val = node.borrow().val;\nnode_val\n}\n.cmp(&val)\n{\nOrdering::Greater => {\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::insert_helper(left, val);\n}\nOrdering::Less => {\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::insert_helper(right, val);\n}\nOrdering::Equal => {\nreturn Some(node); // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\n}\nSelf::update_height(Some(node.clone())); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Self::rotate(Some(node)).unwrap();\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(node)\n}\nNone => Some(TreeNode::new(val)),\n}\n}\n
        avl_tree.c
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(AVLTree *tree, int val) {\ntree->root = insertHelper(tree->root, val);\n}\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\nif (node == NULL) {\nreturn newTreeNode(val);\n}\n/* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9 */\nif (val < node->val) {\nnode->left = insertHelper(node->left, val);\n} else if (val > node->val) {\nnode->right = insertHelper(node->right, val);\n} else {\n// \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\nreturn node;\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.zig
        // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, val: T) !void {\nself.root = (try self.insertHelper(self.root, val)).?;\n}\n// \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\nfn insertHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) !?*inc.TreeNode(T) {\nvar node = node_;\nif (node == null) {\nvar tmp_node = try self.mem_allocator.create(inc.TreeNode(T));\ntmp_node.init(val);\nreturn tmp_node;\n}\n// 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff0c\u5e76\u63d2\u5165\u8282\u70b9\nif (val < node.?.val) {\nnode.?.left = try self.insertHelper(node.?.left, val);\n} else if (val > node.?.val) {\nnode.?.right = try self.insertHelper(node.?.right, val);\n} else {\nreturn node;            // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n}\nself.updateHeight(node);    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n// 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nnode = self.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#2_2","title":"2. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u7c7b\u4f3c\u5730\uff0c\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u8282\u70b9\u65b9\u6cd5\u7684\u57fa\u7840\u4e0a\uff0c\u9700\u8981\u4ece\u5e95\u81f3\u9876\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6240\u6709\u5931\u8861\u8282\u70b9\u6062\u590d\u5e73\u8861\u3002\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig avl_tree.py
        def remove(self, val: int):\n\"\"\"\u5220\u9664\u8282\u70b9\"\"\"\nself._root = self.remove_helper(self._root, val)\ndef remove_helper(self, node: TreeNode | None, val: int) -> TreeNode | None:\n\"\"\"\u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\nif node is None:\nreturn None\n# 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b\nif val < node.val:\nnode.left = self.remove_helper(node.left, val)\nelif val > node.val:\nnode.right = self.remove_helper(node.right, val)\nelse:\nif node.left is None or node.right is None:\nchild = node.left or node.right\n# \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif child is None:\nreturn None\n# \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse:\nnode = child\nelse:\n# \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\ntemp = node.right\nwhile temp.left is not None:\ntemp = temp.left\nnode.right = self.remove_helper(node.right, temp.val)\nnode.val = temp.val\n# \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nself.update_height(node)\n# 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nreturn self.rotate(node)\n
        avl_tree.cpp
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\nif (node == nullptr)\nreturn nullptr;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node->val)\nnode->left = removeHelper(node->left, val);\nelse if (val > node->val)\nnode->right = removeHelper(node->right, val);\nelse {\nif (node->left == nullptr || node->right == nullptr) {\nTreeNode *child = node->left != nullptr ? node->left : node->right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == nullptr) {\ndelete node;\nreturn nullptr;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse {\ndelete node;\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode *temp = node->right;\nwhile (temp->left != nullptr) {\ntemp = temp->left;\n}\nint tempVal = temp->val;\nnode->right = removeHelper(node->right, temp->val);\nnode->val = tempVal;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.java
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode removeHelper(TreeNode node, int val) {\nif (node == null)\nreturn null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = removeHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode child = node.left != null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode temp = node.right;\nwhile (temp.left != null) {\ntemp = temp.left;\n}\nnode.right = removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.cs
        /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int val) {\nroot = RemoveHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? RemoveHelper(TreeNode? node, int val) {\nif (node == null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = RemoveHelper(node.left, val);\nelse if (val > node.val)\nnode.right = RemoveHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode? child = node.left ?? node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode? temp = node.right;\nwhile (temp.left != null) {\ntemp = temp.left;\n}\nnode.right = RemoveHelper(node.right, temp.val!.Value);\nnode.val = temp.val;\n}\n}\nUpdateHeight(node);  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.go
        /* \u5220\u9664\u8282\u70b9 */\nfunc (t *aVLTree) remove(val int) {\nt.root = t.removeHelper(t.root, val)\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {\nif node == nil {\nreturn nil\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node.Val.(int) {\nnode.Left = t.removeHelper(node.Left, val)\n} else if val > node.Val.(int) {\nnode.Right = t.removeHelper(node.Right, val)\n} else {\nif node.Left == nil || node.Right == nil {\nchild := node.Left\nif node.Right != nil {\nchild = node.Right\n}\nif child == nil {\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nreturn nil\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\ntemp := node.Right\nfor temp.Left != nil {\ntemp = temp.Left\n}\nnode.Right = t.removeHelper(node.Right, temp.Val.(int))\nnode.Val = temp.Val\n}\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nt.updateHeight(node)\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = t.rotate(node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.swift
        /* \u5220\u9664\u8282\u70b9 */\nfunc remove(val: Int) {\nroot = removeHelper(node: root, val: val)\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc removeHelper(node: TreeNode?, val: Int) -> TreeNode? {\nvar node = node\nif node == nil {\nreturn nil\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node!.val {\nnode?.left = removeHelper(node: node?.left, val: val)\n} else if val > node!.val {\nnode?.right = removeHelper(node: node?.right, val: val)\n} else {\nif node?.left == nil || node?.right == nil {\nlet child = node?.left != nil ? node?.left : node?.right\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif child == nil {\nreturn nil\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse {\nnode = child\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nvar temp = node?.right\nwhile temp?.left != nil {\ntemp = temp?.left\n}\nnode?.right = removeHelper(node: node?.right, val: temp!.val)\nnode?.val = temp!.val\n}\n}\nupdateHeight(node: node) // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node: node)\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node\n}\n
        avl_tree.js
        /* \u5220\u9664\u8282\u70b9 */\nremove(val) {\nthis.root = this.#removeHelper(this.root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#removeHelper(node, val) {\nif (node === null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val) node.left = this.#removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = this.#removeHelper(node.right, val);\nelse {\nif (node.left === null || node.right === null) {\nconst child = node.left !== null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child === null) return null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse node = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet temp = node.right;\nwhile (temp.left !== null) {\ntemp = temp.left;\n}\nnode.right = this.#removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nthis.#updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.#rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.ts
        /* \u5220\u9664\u8282\u70b9 */\nremove(val: number): void {\nthis.root = this.removeHelper(this.root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nremoveHelper(node: TreeNode, val: number): TreeNode {\nif (node === null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val) {\nnode.left = this.removeHelper(node.left, val);\n} else if (val > node.val) {\nnode.right = this.removeHelper(node.right, val);\n} else {\nif (node.left === null || node.right === null) {\nconst child = node.left !== null ? node.left : node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child === null) {\nreturn null;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet temp = node.right;\nwhile (temp.left !== null) {\ntemp = temp.left;\n}\nnode.right = this.removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nthis.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = this.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.dart
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\nroot = removeHelper(root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? removeHelper(TreeNode? node, int val) {\nif (node == null) return null;\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node.val)\nnode.left = removeHelper(node.left, val);\nelse if (val > node.val)\nnode.right = removeHelper(node.right, val);\nelse {\nif (node.left == null || node.right == null) {\nTreeNode? child = node.left ?? node.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null)\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nelse\nnode = child;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode? temp = node.right;\nwhile (temp!.left != null) {\ntemp = temp.left;\n}\nnode.right = removeHelper(node.right, temp.val);\nnode.val = temp.val;\n}\n}\nupdateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.rs
        /* \u5220\u9664\u8282\u70b9 */\nfn remove(&self, val: i32) {\nSelf::remove_helper(self.root.clone(), val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn remove_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\nmatch node {\nSome(mut node) => {\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif val < node.borrow().val {\nlet left = node.borrow().left.clone();\nnode.borrow_mut().left = Self::remove_helper(left, val);\n} else if val > node.borrow().val {\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::remove_helper(right, val);\n} else if node.borrow().left.is_none() || node.borrow().right.is_none() {\nlet child = if node.borrow().left.is_some() {\nnode.borrow().left.clone()\n} else {\nnode.borrow().right.clone()\n};\nmatch child {\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nNone => {\nreturn None;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nSome(child) => node = child,\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nlet mut temp = node.borrow().right.clone().unwrap();\nloop {\nlet temp_left = temp.borrow().left.clone();\nif temp_left.is_none() {\nbreak;\n}\ntemp = temp_left.unwrap();\n}\nlet right = node.borrow().right.clone();\nnode.borrow_mut().right = Self::remove_helper(right, temp.borrow().val);\nnode.borrow_mut().val = temp.borrow().val;\n}\nSelf::update_height(Some(node.clone())); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = Self::rotate(Some(node)).unwrap();\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nSome(node)\n}\nNone => None,\n}\n}\n
        avl_tree.c
        /* \u5220\u9664\u8282\u70b9 */\n// \u7531\u4e8e\u5f15\u5165\u4e86 stdio.h \uff0c\u6b64\u5904\u65e0\u6cd5\u4f7f\u7528 remove \u5173\u952e\u8bcd\nvoid removeItem(AVLTree *tree, int val) {\nTreeNode *root = removeHelper(tree->root, val);\n}\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\nTreeNode *child, *grandChild;\nif (node == NULL) {\nreturn NULL;\n}\n/* 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b */\nif (val < node->val) {\nnode->left = removeHelper(node->left, val);\n} else if (val > node->val) {\nnode->right = removeHelper(node->right, val);\n} else {\nif (node->left == NULL || node->right == NULL) {\nchild = node->left;\nif (node->right != NULL) {\nchild = node->right;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == NULL) {\nreturn NULL;\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nTreeNode *temp = node->right;\nwhile (temp->left != NULL) {\ntemp = temp->left;\n}\nint tempVal = temp->val;\nnode->right = removeHelper(node->right, temp->val);\nnode->val = tempVal;\n}\n}\n// \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\nupdateHeight(node);\n/* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\nnode = rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        avl_tree.zig
        // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, val: T) void {\nself.root = self.removeHelper(self.root, val).?;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\nfn removeHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) ?*inc.TreeNode(T) {\nvar node = node_;\nif (node == null) return null;\n// 1. \u67e5\u627e\u8282\u70b9\uff0c\u5e76\u5220\u9664\u4e4b\nif (val < node.?.val) {\nnode.?.left = self.removeHelper(node.?.left, val);\n} else if (val > node.?.val) {\nnode.?.right = self.removeHelper(node.?.right, val);\n} else {\nif (node.?.left == null or node.?.right == null) {\nvar child = if (node.?.left != null) node.?.left else node.?.right;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\nif (child == null) {\nreturn null;\n// \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n} else {\nnode = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2 \uff0c\u5219\u5c06\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e2a\u8282\u70b9\u5220\u9664\uff0c\u5e76\u7528\u8be5\u8282\u70b9\u66ff\u6362\u5f53\u524d\u8282\u70b9\nvar temp = node.?.right;\nwhile (temp.?.left != null) {\ntemp = temp.?.left;\n}\nnode.?.right = self.removeHelper(node.?.right, temp.?.val);\nnode.?.val = temp.?.val;\n}\n}\nself.updateHeight(node); // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n// 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\nnode = self.rotate(node);\n// \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\nreturn node;\n}\n
        "},{"location":"chapter_tree/avl_tree/#3_1","title":"3. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        AVL \u6811\u7684\u8282\u70b9\u67e5\u627e\u64cd\u4f5c\u4e0e\u4e8c\u53c9\u641c\u7d22\u6811\u4e00\u81f4\uff0c\u5728\u6b64\u4e0d\u518d\u8d58\u8ff0\u3002

        "},{"location":"chapter_tree/avl_tree/#754-avl","title":"7.5.4 \u00a0 AVL \u6811\u5178\u578b\u5e94\u7528","text":"
        • \u7ec4\u7ec7\u548c\u5b58\u50a8\u5927\u578b\u6570\u636e\uff0c\u9002\u7528\u4e8e\u9ad8\u9891\u67e5\u627e\u3001\u4f4e\u9891\u589e\u5220\u7684\u573a\u666f\u3002
        • \u7528\u4e8e\u6784\u5efa\u6570\u636e\u5e93\u4e2d\u7684\u7d22\u5f15\u7cfb\u7edf\u3002
        • \u7ea2\u9ed1\u6811\u5728\u8bb8\u591a\u5e94\u7528\u4e2d\u6bd4 AVL \u6811\u66f4\u53d7\u6b22\u8fce\u3002\u8fd9\u662f\u56e0\u4e3a\u7ea2\u9ed1\u6811\u7684\u5e73\u8861\u6761\u4ef6\u76f8\u5bf9\u5bbd\u677e\uff0c\u5728\u7ea2\u9ed1\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\u6240\u9700\u7684\u65cb\u8f6c\u64cd\u4f5c\u76f8\u5bf9\u8f83\u5c11\uff0c\u5176\u8282\u70b9\u589e\u5220\u64cd\u4f5c\u7684\u5e73\u5747\u6548\u7387\u66f4\u9ad8\u3002
        "},{"location":"chapter_tree/binary_search_tree/","title":"7.4 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811","text":"

        \u5982\u56fe 7-16 \u6240\u793a\uff0c\u300c\u4e8c\u53c9\u641c\u7d22\u6811 binary search tree\u300d\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u3002

        1. \u5bf9\u4e8e\u6839\u8282\u70b9\uff0c\u5de6\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c \\(<\\) \u6839\u8282\u70b9\u7684\u503c \\(<\\) \u53f3\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u7684\u503c\u3002
        2. \u4efb\u610f\u8282\u70b9\u7684\u5de6\u3001\u53f3\u5b50\u6811\u4e5f\u662f\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5373\u540c\u6837\u6ee1\u8db3\u6761\u4ef6 1. \u3002

        \u56fe 7-16 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811

        "},{"location":"chapter_tree/binary_search_tree/#741","title":"7.4.1 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u64cd\u4f5c","text":"

        \u6211\u4eec\u5c06\u4e8c\u53c9\u641c\u7d22\u6811\u5c01\u88c5\u4e3a\u4e00\u4e2a\u7c7b BinarySearchTree \uff0c\u5e76\u58f0\u660e\u4e00\u4e2a\u6210\u5458\u53d8\u91cf root \uff0c\u6307\u5411\u6811\u7684\u6839\u8282\u70b9\u3002

        "},{"location":"chapter_tree/binary_search_tree/#1","title":"1. \u00a0 \u67e5\u627e\u8282\u70b9","text":"

        \u7ed9\u5b9a\u76ee\u6807\u8282\u70b9\u503c num \uff0c\u53ef\u4ee5\u6839\u636e\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u6765\u67e5\u627e\u3002\u5982\u56fe 7-17 \u6240\u793a\uff0c\u6211\u4eec\u58f0\u660e\u4e00\u4e2a\u8282\u70b9 cur \uff0c\u4ece\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9 root \u51fa\u53d1\uff0c\u5faa\u73af\u6bd4\u8f83\u8282\u70b9\u503c cur.val \u548c num \u4e4b\u95f4\u7684\u5927\u5c0f\u5173\u7cfb\u3002

        • \u82e5 cur.val < num \uff0c\u8bf4\u660e\u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u6267\u884c cur = cur.right \u3002
        • \u82e5 cur.val > num \uff0c\u8bf4\u660e\u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\uff0c\u56e0\u6b64\u6267\u884c cur = cur.left \u3002
        • \u82e5 cur.val = num \uff0c\u8bf4\u660e\u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\u5e76\u8fd4\u56de\u8be5\u8282\u70b9\u3002
        <1><2><3><4>

        \u56fe 7-17 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u67e5\u627e\u8282\u70b9\u793a\u4f8b

        \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u64cd\u4f5c\u4e0e\u4e8c\u5206\u67e5\u627e\u7b97\u6cd5\u7684\u5de5\u4f5c\u539f\u7406\u4e00\u81f4\uff0c\u90fd\u662f\u6bcf\u8f6e\u6392\u9664\u4e00\u534a\u60c5\u51b5\u3002\u5faa\u73af\u6b21\u6570\u6700\u591a\u4e3a\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\uff0c\u5f53\u4e8c\u53c9\u6811\u5e73\u8861\u65f6\uff0c\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def search(self, num: int) -> TreeNode | None:\n\"\"\"\u67e5\u627e\u8282\u70b9\"\"\"\ncur = self._root\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur is not None:\n# \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelif cur.val > num:\ncur = cur.left\n# \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse:\nbreak\nreturn cur\n
        binary_search_tree.cpp
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(int num) {\nTreeNode *cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur->val > num)\ncur = cur->left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.java
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode search(int num) {\nTreeNode cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.cs
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? Search(int num) {\nTreeNode? cur = root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur =\ncur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.go
        /* \u67e5\u627e\u8282\u70b9 */\nfunc (bst *binarySearchTree) search(num int) *TreeNode {\nnode := bst.root\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor node != nil {\nif node.Val.(int) < num {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nnode = node.Right\n} else if node.Val.(int) > num {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nnode = node.Left\n} else {\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nbreak\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn node\n}\n
        binary_search_tree.swift
        /* \u67e5\u627e\u8282\u70b9 */\nfunc search(num: Int) -> TreeNode? {\nvar cur = root\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if cur!.val > num {\ncur = cur?.left\n}\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse {\nbreak\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur\n}\n
        binary_search_tree.js
        /* \u67e5\u627e\u8282\u70b9 */\nsearch(num) {\nlet cur = this.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num) cur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse break;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.ts
        /* \u67e5\u627e\u8282\u70b9 */\nsearch(num: number): TreeNode | null {\nlet cur = this.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > num) cur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse break;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.dart
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? search(int _num) {\nTreeNode? cur = _root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if (cur.val > _num)\ncur = cur.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse\nbreak;\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.rs
        /* \u67e5\u627e\u8282\u70b9 */\npub fn search(&self, num: i32) -> Option<TreeNodeRc> {\nlet mut cur = self.root.clone();\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse if node.borrow().val > num {\ncur = node.borrow().left.clone();\n}\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nelse {\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\ncur\n}\n
        binary_search_tree.c
        /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(BinarySearchTree *bst, int num) {\nTreeNode *cur = bst->root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\nif (cur->val < num) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else if (cur->val > num) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n} else {\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        binary_search_tree.zig
        // \u67e5\u627e\u8282\u70b9\nfn search(self: *Self, num: T) ?*inc.TreeNode(T) {\nvar cur = self.root;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else if (cur.?.val > num) {\ncur = cur.?.left;\n// \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n} else {\nbreak;\n}\n}\n// \u8fd4\u56de\u76ee\u6807\u8282\u70b9\nreturn cur;\n}\n
        "},{"location":"chapter_tree/binary_search_tree/#2","title":"2. \u00a0 \u63d2\u5165\u8282\u70b9","text":"

        \u7ed9\u5b9a\u4e00\u4e2a\u5f85\u63d2\u5165\u5143\u7d20 num \uff0c\u4e3a\u4e86\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u201c\u5de6\u5b50\u6811 < \u6839\u8282\u70b9 < \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\uff0c\u63d2\u5165\u64cd\u4f5c\u6d41\u7a0b\u5982\u56fe 7-18 \u6240\u793a\u3002

        1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\uff1a\u4e0e\u67e5\u627e\u64cd\u4f5c\u76f8\u4f3c\uff0c\u4ece\u6839\u8282\u70b9\u51fa\u53d1\uff0c\u6839\u636e\u5f53\u524d\u8282\u70b9\u503c\u548c num \u7684\u5927\u5c0f\u5173\u7cfb\u5faa\u73af\u5411\u4e0b\u641c\u7d22\uff0c\u76f4\u5230\u8d8a\u8fc7\u53f6\u8282\u70b9\uff08\u904d\u5386\u81f3 \\(\\text{None}\\) \uff09\u65f6\u8df3\u51fa\u5faa\u73af\u3002
        2. \u5728\u8be5\u4f4d\u7f6e\u63d2\u5165\u8282\u70b9\uff1a\u521d\u59cb\u5316\u8282\u70b9 num \uff0c\u5c06\u8be5\u8282\u70b9\u7f6e\u4e8e \\(\\text{None}\\) \u7684\u4f4d\u7f6e\u3002

        \u56fe 7-18 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u63d2\u5165\u8282\u70b9

        \u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e24\u70b9\u3002

        • \u4e8c\u53c9\u641c\u7d22\u6811\u4e0d\u5141\u8bb8\u5b58\u5728\u91cd\u590d\u8282\u70b9\uff0c\u5426\u5219\u5c06\u8fdd\u53cd\u5176\u5b9a\u4e49\u3002\u56e0\u6b64\uff0c\u82e5\u5f85\u63d2\u5165\u8282\u70b9\u5728\u6811\u4e2d\u5df2\u5b58\u5728\uff0c\u5219\u4e0d\u6267\u884c\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\u3002
        • \u4e3a\u4e86\u5b9e\u73b0\u63d2\u5165\u8282\u70b9\uff0c\u6211\u4eec\u9700\u8981\u501f\u52a9\u8282\u70b9 pre \u4fdd\u5b58\u4e0a\u4e00\u8f6e\u5faa\u73af\u7684\u8282\u70b9\u3002\u8fd9\u6837\u5728\u904d\u5386\u81f3 \\(\\text{None}\\) \u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u5230\u5176\u7236\u8282\u70b9\uff0c\u4ece\u800c\u5b8c\u6210\u8282\u70b9\u63d2\u5165\u64cd\u4f5c\u3002
        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def insert(self, num: int):\n\"\"\"\u63d2\u5165\u8282\u70b9\"\"\"\n# \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif self._root is None:\nself._root = TreeNode(num)\nreturn\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\ncur, pre = self._root, None\nwhile cur is not None:\n# \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif cur.val == num:\nreturn\npre = cur\n# \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse:\ncur = cur.left\n# \u63d2\u5165\u8282\u70b9\nnode = TreeNode(num)\nif pre.val < num:\npre.right = node\nelse:\npre.left = node\n
        binary_search_tree.cpp
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == nullptr) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode *cur = root, *pre = nullptr;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur->val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur->left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode *node = new TreeNode(num);\nif (pre->val < num)\npre->right = node;\nelse\npre->left = node;\n}\n
        binary_search_tree.java
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == null) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode node = new TreeNode(num);\nif (pre.val < num)\npre.right = node;\nelse\npre.left = node;\n}\n
        binary_search_tree.cs
        /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (root == null) {\nroot = new TreeNode(num);\nreturn;\n}\nTreeNode? cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == num)\nreturn;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode node = new(num);\nif (pre != null) {\nif (pre.val < num)\npre.right = node;\nelse\npre.left = node;\n}\n}\n
        binary_search_tree.go
        /* \u63d2\u5165\u8282\u70b9 */\nfunc (bst *binarySearchTree) insert(num int) {\ncur := bst.root\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif cur == nil {\nbst.root = NewTreeNode(num)\nreturn\n}\n// \u5f85\u63d2\u5165\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\nvar pre *TreeNode = nil\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor cur != nil {\nif cur.Val == num {\nreturn\n}\npre = cur\nif cur.Val.(int) < num {\ncur = cur.Right\n} else {\ncur = cur.Left\n}\n}\n// \u63d2\u5165\u8282\u70b9\nnode := NewTreeNode(num)\nif pre.Val.(int) < num {\npre.Right = node\n} else {\npre.Left = node\n}\n}\n
        binary_search_tree.swift
        /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(num: Int) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif root == nil {\nroot = TreeNode(x: num)\nreturn\n}\nvar cur = root\nvar pre: TreeNode?\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif cur!.val == num {\nreturn\n}\npre = cur\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = cur?.left\n}\n}\n// \u63d2\u5165\u8282\u70b9\nlet node = TreeNode(x: num)\nif pre!.val < num {\npre?.right = node\n} else {\npre?.left = node\n}\n}\n
        binary_search_tree.js
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (this.root === null) {\nthis.root = new TreeNode(num);\nreturn;\n}\nlet cur = this.root,\npre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val === num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nconst node = new TreeNode(num);\nif (pre.val < num) pre.right = node;\nelse pre.left = node;\n}\n
        binary_search_tree.ts
        /* \u63d2\u5165\u8282\u70b9 */\ninsert(num: number): void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (this.root === null) {\nthis.root = new TreeNode(num);\nreturn;\n}\nlet cur: TreeNode | null = this.root,\npre: TreeNode | null = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val === num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nconst node = new TreeNode(num);\nif (pre!.val < num) pre!.right = node;\nelse pre!.left = node;\n}\n
        binary_search_tree.dart
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int _num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (_root == null) {\n_root = TreeNode(_num);\nreturn;\n}\nTreeNode? cur = _root;\nTreeNode? pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.val == _num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode? node = TreeNode(_num);\nif (pre!.val < _num)\npre.right = node;\nelse\npre.left = node;\n}\n
        binary_search_tree.rs
        /* \u63d2\u5165\u8282\u70b9 */\npub fn insert(&mut self, num: i32) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif self.root.is_none() {\nself.root = Some(TreeNode::new(num));\nreturn;\n}\nlet mut cur = self.root.clone();\nlet mut pre = None;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif node.borrow().val == num {\nreturn;\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\npre = cur.clone();\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = node.borrow().left.clone();\n}\n}\n// \u63d2\u5165\u8282\u70b9\nlet node = TreeNode::new(num);\nlet pre = pre.unwrap();\nif pre.borrow().val < num {\npre.borrow_mut().right = Some(Rc::clone(&node));\n} else {\npre.borrow_mut().left = Some(Rc::clone(&node));\n}\n}\n
        binary_search_tree.c
        /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(BinarySearchTree *bst, int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (bst->root == NULL) {\nbst->root = newTreeNode(num);\nreturn;\n}\nTreeNode *cur = bst->root, *pre = NULL;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur->val == num) {\nreturn;\n}\npre = cur;\nif (cur->val < num) {\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else {\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n}\n}\n// \u63d2\u5165\u8282\u70b9\nTreeNode *node = newTreeNode(num);\nif (pre->val < num) {\npre->right = node;\n} else {\npre->left = node;\n}\n}\n
        binary_search_tree.zig
        // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, num: T) !void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\nif (self.root == null) {\nself.root = try self.mem_allocator.create(inc.TreeNode(T));\nreturn;\n}\nvar cur = self.root;\nvar pre: ?*inc.TreeNode(T) = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur.?.val == num) return;\npre = cur;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else {\ncur = cur.?.left;\n}\n}\n// \u63d2\u5165\u8282\u70b9\nvar node = try self.mem_allocator.create(inc.TreeNode(T));\nnode.init(num);\nif (pre.?.val < num) {\npre.?.right = node;\n} else {\npre.?.left = node;\n}\n}\n

        \u4e0e\u67e5\u627e\u8282\u70b9\u76f8\u540c\uff0c\u63d2\u5165\u8282\u70b9\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\u3002

        "},{"location":"chapter_tree/binary_search_tree/#3","title":"3. \u00a0 \u5220\u9664\u8282\u70b9","text":"

        \u5148\u5728\u4e8c\u53c9\u6811\u4e2d\u67e5\u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u518d\u5c06\u5176\u5220\u9664\u3002

        \u4e0e\u63d2\u5165\u8282\u70b9\u7c7b\u4f3c\uff0c\u6211\u4eec\u9700\u8981\u4fdd\u8bc1\u5728\u5220\u9664\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u201c\u5de6\u5b50\u6811 < \u6839\u8282\u70b9 < \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\u4ecd\u7136\u6ee1\u8db3\u3002

        \u56e0\u6b64\uff0c\u6211\u4eec\u6839\u636e\u76ee\u6807\u8282\u70b9\u7684\u5b50\u8282\u70b9\u6570\u91cf\uff0c\u5206 0\u30011 \u548c 2 \u4e09\u79cd\u60c5\u51b5\uff0c\u6267\u884c\u5bf9\u5e94\u7684\u5220\u9664\u8282\u70b9\u64cd\u4f5c\u3002

        \u5982\u56fe 7-19 \u6240\u793a\uff0c\u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(0\\) \u65f6\uff0c\u8868\u793a\u8be5\u8282\u70b9\u662f\u53f6\u8282\u70b9\uff0c\u53ef\u4ee5\u76f4\u63a5\u5220\u9664\u3002

        \u56fe 7-19 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 0 \uff09

        \u5982\u56fe 7-20 \u6240\u793a\uff0c\u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(1\\) \u65f6\uff0c\u5c06\u5f85\u5220\u9664\u8282\u70b9\u66ff\u6362\u4e3a\u5176\u5b50\u8282\u70b9\u5373\u53ef\u3002

        \u56fe 7-20 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 1 \uff09

        \u5f53\u5f85\u5220\u9664\u8282\u70b9\u7684\u5ea6\u4e3a \\(2\\) \u65f6\uff0c\u6211\u4eec\u65e0\u6cd5\u76f4\u63a5\u5220\u9664\u5b83\uff0c\u800c\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u8282\u70b9\u66ff\u6362\u8be5\u8282\u70b9\u3002\u7531\u4e8e\u8981\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u201c\u5de6\u5b50\u6811 \\(<\\) \u6839\u8282\u70b9 \\(<\\) \u53f3\u5b50\u6811\u201d\u7684\u6027\u8d28\uff0c\u56e0\u6b64\u8fd9\u4e2a\u8282\u70b9\u53ef\u4ee5\u662f\u53f3\u5b50\u6811\u7684\u6700\u5c0f\u8282\u70b9\u6216\u5de6\u5b50\u6811\u7684\u6700\u5927\u8282\u70b9\u3002

        \u5047\u8bbe\u6211\u4eec\u9009\u62e9\u53f3\u5b50\u6811\u7684\u6700\u5c0f\u8282\u70b9\uff08\u4e2d\u5e8f\u904d\u5386\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\uff09\uff0c\u5219\u5220\u9664\u64cd\u4f5c\u6d41\u7a0b\u5982\u56fe 7-21 \u6240\u793a\u3002

        1. \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\u5728\u201c\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u201d\u4e2d\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\uff0c\u8bb0\u4e3a tmp \u3002
        2. \u7528 tmp \u7684\u503c\u8986\u76d6\u5f85\u5220\u9664\u8282\u70b9\u7684\u503c\uff0c\u5e76\u5728\u6811\u4e2d\u9012\u5f52\u5220\u9664\u8282\u70b9 tmp \u3002
        <1><2><3><4>

        \u56fe 7-21 \u00a0 \u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5220\u9664\u8282\u70b9\uff08\u5ea6\u4e3a 2 \uff09

        \u5220\u9664\u8282\u70b9\u64cd\u4f5c\u540c\u6837\u4f7f\u7528 \\(O(\\log n)\\) \u65f6\u95f4\uff0c\u5176\u4e2d\u67e5\u627e\u5f85\u5220\u9664\u8282\u70b9\u9700\u8981 \\(O(\\log n)\\) \u65f6\u95f4\uff0c\u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u540e\u7ee7\u8282\u70b9\u9700\u8981 \\(O(\\log n)\\) \u65f6\u95f4\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_search_tree.py
        def remove(self, num: int):\n\"\"\"\u5220\u9664\u8282\u70b9\"\"\"\n# \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif self._root is None:\nreturn\n# \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\ncur, pre = self._root, None\nwhile cur is not None:\n# \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif cur.val == num:\nbreak\npre = cur\n# \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur.val < num:\ncur = cur.right\n# \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse:\ncur = cur.left\n# \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur is None:\nreturn\n# \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur.left is None or cur.right is None:\n# \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nchild = cur.left or cur.right\n# \u5220\u9664\u8282\u70b9 cur\nif cur != self._root:\nif pre.left == cur:\npre.left = child\nelse:\npre.right = child\nelse:\n# \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nself._root = child\n# \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse:\n# \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\ntmp: TreeNode = cur.right\nwhile tmp.left is not None:\ntmp = tmp.left\n# \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmp.val)\n# \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val\n
        binary_search_tree.cpp
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == nullptr)\nreturn;\nTreeNode *cur = root, *pre = nullptr;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != nullptr) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur->val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur->val < num)\ncur = cur->right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur->left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == nullptr)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur->left == nullptr || cur->right == nullptr) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nTreeNode *child = cur->left != nullptr ? cur->left : cur->right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre->left == cur)\npre->left = child;\nelse\npre->right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n// \u91ca\u653e\u5185\u5b58\ndelete cur;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode *tmp = cur->right;\nwhile (tmp->left != nullptr) {\ntmp = tmp->left;\n}\nint tmpVal = tmp->val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp->val);\n// \u7528 tmp \u8986\u76d6 cur\ncur->val = tmpVal;\n}\n}\n
        binary_search_tree.java
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == null)\nreturn;\nTreeNode cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode child = cur.left != null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode tmp = cur.right;\nwhile (tmp.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.cs
        /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (root == null)\nreturn;\nTreeNode? cur = root, pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == num)\nbreak;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null)\nreturn;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode? child = cur.left ?? cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != root) {\nif (pre!.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode? tmp = cur.right;\nwhile (tmp.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nRemove(tmp.val!.Value);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.go
        /* \u5220\u9664\u8282\u70b9 */\nfunc (bst *binarySearchTree) remove(num int) {\ncur := bst.root\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\nvar pre *TreeNode = nil\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nfor cur != nil {\nif cur.Val == num {\nbreak\n}\npre = cur\nif cur.Val.(int) < num {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728\u53f3\u5b50\u6811\u4e2d\ncur = cur.Right\n} else {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728\u5de6\u5b50\u6811\u4e2d\ncur = cur.Left\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5b50\u8282\u70b9\u6570\u4e3a 0 \u6216 1\nif cur.Left == nil || cur.Right == nil {\nvar child *TreeNode = nil\n// \u53d6\u51fa\u5f85\u5220\u9664\u8282\u70b9\u7684\u5b50\u8282\u70b9\nif cur.Left != nil {\nchild = cur.Left\n} else {\nchild = cur.Right\n}\n// \u5220\u9664\u8282\u70b9 cur\nif cur != bst.root {\nif pre.Left == cur {\npre.Left = child\n} else {\npre.Right = child\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nbst.root = child\n}\n// \u5b50\u8282\u70b9\u6570\u4e3a 2\n} else {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d\u5f85\u5220\u9664\u8282\u70b9 cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\ntmp := cur.Right\nfor tmp.Left != nil {\ntmp = tmp.Left\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nbst.remove(tmp.Val.(int))\n// \u7528 tmp \u8986\u76d6 cur\ncur.Val = tmp.Val\n}\n}\n
        binary_search_tree.swift
        /* \u5220\u9664\u8282\u70b9 */\nfunc remove(num: Int) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif root == nil {\nreturn\n}\nvar cur = root\nvar pre: TreeNode?\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile cur != nil {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif cur!.val == num {\nbreak\n}\npre = cur\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif cur!.val < num {\ncur = cur?.right\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = cur?.left\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur == nil {\nreturn\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur?.left == nil || cur?.right == nil {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nlet child = cur?.left != nil ? cur?.left : cur?.right\n// \u5220\u9664\u8282\u70b9 cur\nif cur !== root {\nif pre?.left === cur {\npre?.left = child\n} else {\npre?.right = child\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nroot = child\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nvar tmp = cur?.right\nwhile tmp?.left != nil {\ntmp = tmp?.left\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(num: tmp!.val)\n// \u7528 tmp \u8986\u76d6 cur\ncur?.val = tmp!.val\n}\n}\n
        binary_search_tree.js
        /* \u5220\u9664\u8282\u70b9 */\nremove(num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (this.root === null) return;\nlet cur = this.root,\npre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val === num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur === null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left === null || cur.right === null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nconst child = cur.left !== null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur !== this.root) {\nif (pre.left === cur) pre.left = child;\nelse pre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nthis.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet tmp = cur.right;\nwhile (tmp.left !== null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nthis.remove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.ts
        /* \u5220\u9664\u8282\u70b9 */\nremove(num: number): void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (this.root === null) return;\nlet cur: TreeNode | null = this.root,\npre: TreeNode | null = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur !== null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val === num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < num) cur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse cur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur === null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left === null || cur.right === null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nconst child: TreeNode | null =\ncur.left !== null ? cur.left : cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur !== this.root) {\nif (pre!.left === cur) pre!.left = child;\nelse pre!.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nthis.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet tmp: TreeNode | null = cur.right;\nwhile (tmp!.left !== null) {\ntmp = tmp!.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nthis.remove(tmp!.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp!.val;\n}\n}\n
        binary_search_tree.dart
        /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int _num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (_root == null) return;\nTreeNode? cur = _root;\nTreeNode? pre = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.val == _num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.val < _num)\ncur = cur.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse\ncur = cur.left;\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\nif (cur == null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.left == null || cur.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nTreeNode? child = cur.left ?? cur.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (cur != _root) {\nif (pre!.left == cur)\npre.left = child;\nelse\npre.right = child;\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n_root = child;\n}\n} else {\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode? tmp = cur.right;\nwhile (tmp!.left != null) {\ntmp = tmp.left;\n}\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremove(tmp.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.val = tmp.val;\n}\n}\n
        binary_search_tree.rs
        /* \u5220\u9664\u8282\u70b9 */\npub fn remove(&mut self, num: i32) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif self.root.is_none() { return; }\nlet mut cur = self.root.clone();\nlet mut pre = None;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile let Some(node) = cur.clone() {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif node.borrow().val == num {\nbreak;\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\npre = cur.clone();\nif node.borrow().val < num {\ncur = node.borrow().right.clone();\n}\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\nelse {\ncur = node.borrow().left.clone();\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif cur.is_none() {\nreturn;\n}\nlet cur = cur.unwrap();\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif cur.borrow().left.is_none() || cur.borrow().right.is_none() {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nlet child = cur.borrow().left.clone().or_else(|| cur.borrow().right.clone());\nlet pre = pre.unwrap();\nlet left = pre.borrow().left.clone().unwrap();\n// \u5220\u9664\u8282\u70b9 cur\nif !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) {\nif Rc::ptr_eq(&left, &cur) {\npre.borrow_mut().left = child;\n} else {\npre.borrow_mut().right = child;\n}\n} else {\n// \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\nself.root = child;\n}\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\nelse {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nlet mut tmp = cur.borrow().right.clone();\nwhile let Some(node) = tmp.clone() {\nif node.borrow().left.is_some() {\ntmp = node.borrow().left.clone();\n} else {\nbreak;\n}\n}\nlet tmpval = tmp.unwrap().borrow().val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmpval);\n// \u7528 tmp \u8986\u76d6 cur\ncur.borrow_mut().val = tmpval;\n}\n}\n
        binary_search_tree.c
        /* \u5220\u9664\u8282\u70b9 */\n// \u7531\u4e8e\u5f15\u5165\u4e86 stdio.h \uff0c\u6b64\u5904\u65e0\u6cd5\u4f7f\u7528 remove \u5173\u952e\u8bcd\nvoid removeItem(BinarySearchTree *bst, int num) {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (bst->root == NULL)\nreturn;\nTreeNode *cur = bst->root, *pre = NULL;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != NULL) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur->val == num)\nbreak;\npre = cur;\nif (cur->val < num) {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u53f3\u5b50\u6811\u4e2d\ncur = cur->right;\n} else {\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u5de6\u5b50\u6811\u4e2d\ncur = cur->left;\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == NULL)\nreturn;\n// \u5224\u65ad\u5f85\u5220\u9664\u8282\u70b9\u662f\u5426\u5b58\u5728\u5b50\u8282\u70b9\nif (cur->left == NULL || cur->right == NULL) {\n/* \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1 */\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\nTreeNode *child = cur->left != NULL ? cur->left : cur->right;\n// \u5220\u9664\u8282\u70b9 cur\nif (pre->left == cur) {\npre->left = child;\n} else {\npre->right = child;\n}\n} else {\n/* \u5b50\u8282\u70b9\u6570\u91cf = 2 */\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nTreeNode *tmp = cur->right;\nwhile (tmp->left != NULL) {\ntmp = tmp->left;\n}\nint tmpVal = tmp->val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nremoveItem(bst, tmp->val);\n// \u7528 tmp \u8986\u76d6 cur\ncur->val = tmpVal;\n}\n}\n
        binary_search_tree.zig
        // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, num: T) void {\n// \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\nif (self.root == null) return;\nvar cur = self.root;\nvar pre: ?*inc.TreeNode(T) = null;\n// \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\nwhile (cur != null) {\n// \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\nif (cur.?.val == num) break;\npre = cur;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\nif (cur.?.val < num) {\ncur = cur.?.right;\n// \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n} else {\ncur = cur.?.left;\n}\n}\n// \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\nif (cur == null) return;\n// \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\nif (cur.?.left == null or cur.?.right == null) {\n// \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\nvar child = if (cur.?.left != null) cur.?.left else cur.?.right;\n// \u5220\u9664\u8282\u70b9 cur\nif (pre.?.left == cur) {\npre.?.left = child;\n} else {\npre.?.right = child;\n}\n// \u5b50\u8282\u70b9\u6570\u91cf = 2\n} else {\n// \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\nvar tmp = cur.?.right;\nwhile (tmp.?.left != null) {\ntmp = tmp.?.left;\n}\nvar tmp_val = tmp.?.val;\n// \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\nself.remove(tmp.?.val);\n// \u7528 tmp \u8986\u76d6 cur\ncur.?.val = tmp_val;\n}\n}\n
        "},{"location":"chapter_tree/binary_search_tree/#4","title":"4. \u00a0 \u4e2d\u5e8f\u904d\u5386\u6709\u5e8f","text":"

        \u5982\u56fe 7-22 \u6240\u793a\uff0c\u4e8c\u53c9\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u9075\u5faa\u201c\u5de6 \\(\\rightarrow\\) \u6839 \\(\\rightarrow\\) \u53f3\u201d\u7684\u904d\u5386\u987a\u5e8f\uff0c\u800c\u4e8c\u53c9\u641c\u7d22\u6811\u6ee1\u8db3\u201c\u5de6\u5b50\u8282\u70b9 \\(<\\) \u6839\u8282\u70b9 \\(<\\) \u53f3\u5b50\u8282\u70b9\u201d\u7684\u5927\u5c0f\u5173\u7cfb\u3002

        \u8fd9\u610f\u5473\u7740\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u8fdb\u884c\u4e2d\u5e8f\u904d\u5386\u65f6\uff0c\u603b\u662f\u4f1a\u4f18\u5148\u904d\u5386\u4e0b\u4e00\u4e2a\u6700\u5c0f\u8282\u70b9\uff0c\u4ece\u800c\u5f97\u51fa\u4e00\u4e2a\u91cd\u8981\u6027\u8d28\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217\u662f\u5347\u5e8f\u7684\u3002

        \u5229\u7528\u4e2d\u5e8f\u904d\u5386\u5347\u5e8f\u7684\u6027\u8d28\uff0c\u6211\u4eec\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u83b7\u53d6\u6709\u5e8f\u6570\u636e\u4ec5\u9700 \\(O(n)\\) \u65f6\u95f4\uff0c\u65e0\u987b\u8fdb\u884c\u989d\u5916\u7684\u6392\u5e8f\u64cd\u4f5c\uff0c\u975e\u5e38\u9ad8\u6548\u3002

        \u56fe 7-22 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u5e8f\u5217

        "},{"location":"chapter_tree/binary_search_tree/#742","title":"7.4.2 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6548\u7387","text":"

        \u7ed9\u5b9a\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u8003\u8651\u4f7f\u7528\u6570\u7ec4\u6216\u4e8c\u53c9\u641c\u7d22\u6811\u5b58\u50a8\u3002\u89c2\u5bdf\u8868 7-2 \uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5404\u9879\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662f\u5bf9\u6570\u9636\uff0c\u5177\u6709\u7a33\u5b9a\u4e14\u9ad8\u6548\u7684\u6027\u80fd\u3002\u53ea\u6709\u5728\u9ad8\u9891\u6dfb\u52a0\u3001\u4f4e\u9891\u67e5\u627e\u5220\u9664\u6570\u636e\u7684\u573a\u666f\u4e0b\uff0c\u6570\u7ec4\u6bd4\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6548\u7387\u66f4\u9ad8\u3002

        \u8868 7-2 \u00a0 \u6570\u7ec4\u4e0e\u641c\u7d22\u6811\u7684\u6548\u7387\u5bf9\u6bd4

        \u65e0\u5e8f\u6570\u7ec4 \u4e8c\u53c9\u641c\u7d22\u6811 \u67e5\u627e\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\) \u63d2\u5165\u5143\u7d20 \\(O(1)\\) \\(O(\\log n)\\) \u5220\u9664\u5143\u7d20 \\(O(n)\\) \\(O(\\log n)\\)

        \u5728\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u201c\u5e73\u8861\u201d\u7684\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 \\(\\log n\\) \u8f6e\u5faa\u73af\u5185\u67e5\u627e\u4efb\u610f\u8282\u70b9\u3002

        \u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u4e0d\u65ad\u5730\u63d2\u5165\u548c\u5220\u9664\u8282\u70b9\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u56fe 7-23 \u6240\u793a\u7684\u94fe\u8868\uff0c\u8fd9\u65f6\u5404\u79cd\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u4f1a\u9000\u5316\u4e3a \\(O(n)\\) \u3002

        \u56fe 7-23 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u9000\u5316

        "},{"location":"chapter_tree/binary_search_tree/#743","title":"7.4.3 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u5e38\u89c1\u5e94\u7528","text":"
        • \u7528\u4f5c\u7cfb\u7edf\u4e2d\u7684\u591a\u7ea7\u7d22\u5f15\uff0c\u5b9e\u73b0\u9ad8\u6548\u7684\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u3002
        • \u4f5c\u4e3a\u67d0\u4e9b\u641c\u7d22\u7b97\u6cd5\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002
        • \u7528\u4e8e\u5b58\u50a8\u6570\u636e\u6d41\uff0c\u4ee5\u4fdd\u6301\u5176\u6709\u5e8f\u72b6\u6001\u3002
        "},{"location":"chapter_tree/binary_tree/","title":"7.1 \u00a0 \u4e8c\u53c9\u6811","text":"

        \u300c\u4e8c\u53c9\u6811 binary tree\u300d\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u4ee3\u8868\u201c\u7956\u5148\u201d\u4e0e\u201c\u540e\u4ee3\u201d\u4e4b\u95f4\u7684\u6d3e\u751f\u5173\u7cfb\uff0c\u4f53\u73b0\u4e86\u201c\u4e00\u5206\u4e3a\u4e8c\u201d\u7684\u5206\u6cbb\u903b\u8f91\u3002\u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u4e8c\u53c9\u6811\u7684\u57fa\u672c\u5355\u5143\u662f\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u503c\u3001\u5de6\u5b50\u8282\u70b9\u5f15\u7528\u548c\u53f3\u5b50\u8282\u70b9\u5f15\u7528\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig
        class TreeNode:\n\"\"\"\u4e8c\u53c9\u6811\u8282\u70b9\u7c7b\"\"\"\ndef __init__(self, val: int):\nself.val: int = val                # \u8282\u70b9\u503c\nself.left: TreeNode | None = None  # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nself.right: TreeNode | None = None # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nint val;          // \u8282\u70b9\u503c\nTreeNode *left;   // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nTreeNode *right;  // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nTreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nTreeNode left;   // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode right;  // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode(int x) { val = x; }\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\npublic int? val = x;    // \u8282\u70b9\u503c\npublic TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\npublic TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\nVal   int\nLeft  *TreeNode\nRight *TreeNode\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc NewTreeNode(v int) *TreeNode {\nreturn &TreeNode{\nLeft:  nil, // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nRight: nil, // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nVal:   v,   // \u8282\u70b9\u503c\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nvar val: Int // \u8282\u70b9\u503c\nvar left: TreeNode? // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nvar right: TreeNode? // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\ninit(x: Int) {\nval = x\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval; // \u8282\u70b9\u503c\nleft; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nright; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\nconstructor(val, left, right) {\nthis.val = val === undefined ? 0 : val;\nthis.left = left === undefined ? null : left;\nthis.right = right === undefined ? null : right;\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nval: number;\nleft: TreeNode | null;\nright: TreeNode | null;\nconstructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\nthis.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\nthis.left = left === undefined ? null : left; // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nthis.right = right === undefined ? null : right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\nint val;         // \u8282\u70b9\u503c\nTreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\nTreeNode(this.val, [this.left, this.right]);\n}\n
        use std::rc::Rc;\nuse std::cell::RefCell;\n/* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\nval: i32,                               // \u8282\u70b9\u503c\nleft: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\nright: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\nimpl TreeNode {\n/* \u6784\u9020\u65b9\u6cd5 */\nfn new(val: i32) -> Rc<RefCell<Self>> {\nRc::new(RefCell::new(Self {\nval,\nleft: None,\nright: None\n}))\n}\n}\n
        /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct TreeNode {\nint val;                // \u8282\u70b9\u503c\nint height;             // \u8282\u70b9\u9ad8\u5ea6\nstruct TreeNode *left;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\nstruct TreeNode *right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n} TreeNode;\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\nTreeNode *node;\nnode = (TreeNode *)malloc(sizeof(TreeNode));\nnode->val = val;\nnode->height = 0;\nnode->left = NULL;\nnode->right = NULL;\nreturn node;\n}\n
        \n

        \u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5f15\u7528\uff08\u6307\u9488\uff09\uff0c\u5206\u522b\u6307\u5411\u300c\u5de6\u5b50\u8282\u70b9 left-child node\u300d\u548c\u300c\u53f3\u5b50\u8282\u70b9 right-child node\u300d\uff0c\u8be5\u8282\u70b9\u88ab\u79f0\u4e3a\u8fd9\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u300c\u7236\u8282\u70b9 parent node\u300d\u3002\u5f53\u7ed9\u5b9a\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u8282\u70b9\u65f6\uff0c\u6211\u4eec\u5c06\u8be5\u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u79f0\u4e3a\u8be5\u8282\u70b9\u7684\u300c\u5de6\u5b50\u6811 left subtree\u300d\uff0c\u540c\u7406\u53ef\u5f97\u300c\u53f3\u5b50\u6811 right subtree\u300d\u3002

        \u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u9664\u53f6\u8282\u70b9\u5916\uff0c\u5176\u4ed6\u6240\u6709\u8282\u70b9\u90fd\u5305\u542b\u5b50\u8282\u70b9\u548c\u975e\u7a7a\u5b50\u6811\u3002\u5982\u56fe 7-1 \u6240\u793a\uff0c\u5982\u679c\u5c06\u201c\u8282\u70b9 2\u201d\u89c6\u4e3a\u7236\u8282\u70b9\uff0c\u5219\u5176\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\u5206\u522b\u662f\u201c\u8282\u70b9 4\u201d\u548c\u201c\u8282\u70b9 5\u201d\uff0c\u5de6\u5b50\u6811\u662f\u201c\u8282\u70b9 4 \u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u201d\uff0c\u53f3\u5b50\u6811\u662f\u201c\u8282\u70b9 5 \u53ca\u5176\u4ee5\u4e0b\u8282\u70b9\u5f62\u6210\u7684\u6811\u201d\u3002

        \u56fe 7-1 \u00a0 \u7236\u8282\u70b9\u3001\u5b50\u8282\u70b9\u3001\u5b50\u6811

        "},{"location":"chapter_tree/binary_tree/#711","title":"7.1.1 \u00a0 \u4e8c\u53c9\u6811\u5e38\u89c1\u672f\u8bed","text":"

        \u4e8c\u53c9\u6811\u7684\u5e38\u7528\u672f\u8bed\u5982\u56fe 7-2 \u6240\u793a\u3002

        • \u300c\u6839\u8282\u70b9 root node\u300d\uff1a\u4f4d\u4e8e\u4e8c\u53c9\u6811\u9876\u5c42\u7684\u8282\u70b9\uff0c\u6ca1\u6709\u7236\u8282\u70b9\u3002
        • \u300c\u53f6\u8282\u70b9 leaf node\u300d\uff1a\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\uff0c\u5176\u4e24\u4e2a\u6307\u9488\u5747\u6307\u5411 \\(\\text{None}\\) \u3002
        • \u300c\u8fb9 edge\u300d\uff1a\u8fde\u63a5\u4e24\u4e2a\u8282\u70b9\u7684\u7ebf\u6bb5\uff0c\u5373\u8282\u70b9\u5f15\u7528\uff08\u6307\u9488\uff09\u3002
        • \u8282\u70b9\u6240\u5728\u7684\u300c\u5c42 level\u300d\uff1a\u4ece\u9876\u81f3\u5e95\u9012\u589e\uff0c\u6839\u8282\u70b9\u6240\u5728\u5c42\u4e3a 1 \u3002
        • \u8282\u70b9\u7684\u300c\u5ea6 degree\u300d\uff1a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u7684\u6570\u91cf\u3002\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u5ea6\u7684\u53d6\u503c\u8303\u56f4\u662f 0\u30011\u30012 \u3002
        • \u4e8c\u53c9\u6811\u7684\u300c\u9ad8\u5ea6 height\u300d\uff1a\u4ece\u6839\u8282\u70b9\u5230\u6700\u8fdc\u53f6\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002
        • \u8282\u70b9\u7684\u300c\u6df1\u5ea6 depth\u300d\uff1a\u4ece\u6839\u8282\u70b9\u5230\u8be5\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002
        • \u8282\u70b9\u7684\u300c\u9ad8\u5ea6 height\u300d\uff1a\u4ece\u8ddd\u79bb\u8be5\u8282\u70b9\u6700\u8fdc\u7684\u53f6\u8282\u70b9\u5230\u8be5\u8282\u70b9\u6240\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u3002

        \u56fe 7-2 \u00a0 \u4e8c\u53c9\u6811\u7684\u5e38\u7528\u672f\u8bed

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u901a\u5e38\u5c06\u201c\u9ad8\u5ea6\u201d\u548c\u201c\u6df1\u5ea6\u201d\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u201d\uff0c\u4f46\u6709\u4e9b\u9898\u76ee\u6216\u6559\u6750\u53ef\u80fd\u4f1a\u5c06\u5176\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8282\u70b9\u7684\u6570\u91cf\u201d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9ad8\u5ea6\u548c\u6df1\u5ea6\u90fd\u9700\u8981\u52a0 1 \u3002

        "},{"location":"chapter_tree/binary_tree/#712","title":"7.1.2 \u00a0 \u4e8c\u53c9\u6811\u57fa\u672c\u64cd\u4f5c","text":""},{"location":"chapter_tree/binary_tree/#1","title":"1. \u00a0 \u521d\u59cb\u5316\u4e8c\u53c9\u6811","text":"

        \u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u9996\u5148\u521d\u59cb\u5316\u8282\u70b9\uff0c\u7136\u540e\u6784\u5efa\u5f15\u7528\uff08\u6307\u9488\uff09\u3002

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree.py
        # \u521d\u59cb\u5316\u4e8c\u53c9\u6811\n# \u521d\u59cb\u5316\u8282\u70b9\nn1 = TreeNode(val=1)\nn2 = TreeNode(val=2)\nn3 = TreeNode(val=3)\nn4 = TreeNode(val=4)\nn5 = TreeNode(val=5)\n# \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2\nn1.right = n3\nn2.left = n4\nn2.right = n5\n
        binary_tree.cpp
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode* n1 = new TreeNode(1);\nTreeNode* n2 = new TreeNode(2);\nTreeNode* n3 = new TreeNode(3);\nTreeNode* n4 = new TreeNode(4);\nTreeNode* n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1->left = n2;\nn1->right = n3;\nn2->left = n4;\nn2->right = n5;\n
        binary_tree.java
        // \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new TreeNode(1);\nTreeNode n2 = new TreeNode(2);\nTreeNode n3 = new TreeNode(3);\nTreeNode n4 = new TreeNode(4);\nTreeNode n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.cs
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new(1);\nTreeNode n2 = new(2);\nTreeNode n3 = new(3);\nTreeNode n4 = new(4);\nTreeNode n5 = new(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.go
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nn1 := NewTreeNode(1)\nn2 := NewTreeNode(2)\nn3 := NewTreeNode(3)\nn4 := NewTreeNode(4)\nn5 := NewTreeNode(5)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.Left = n2\nn1.Right = n3\nn2.Left = n4\nn2.Right = n5\n
        binary_tree.swift
        // \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = TreeNode(x: 1)\nlet n2 = TreeNode(x: 2)\nlet n3 = TreeNode(x: 3)\nlet n4 = TreeNode(x: 4)\nlet n5 = TreeNode(x: 5)\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2\nn1.right = n3\nn2.left = n4\nn2.right = n5\n
        binary_tree.js
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\nn2 = new TreeNode(2),\nn3 = new TreeNode(3),\nn4 = new TreeNode(4),\nn5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.ts
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\nn2 = new TreeNode(2),\nn3 = new TreeNode(3),\nn4 = new TreeNode(4),\nn5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.dart
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode n1 = new TreeNode(1);\nTreeNode n2 = new TreeNode(2);\nTreeNode n3 = new TreeNode(3);\nTreeNode n4 = new TreeNode(4);\nTreeNode n5 = new TreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.left = n2;\nn1.right = n3;\nn2.left = n4;\nn2.right = n5;\n
        binary_tree.rs
        // \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = TreeNode::new(1);\nlet n2 = TreeNode::new(2);\nlet n3 = TreeNode::new(3);\nlet n4 = TreeNode::new(4);\nlet n5 = TreeNode::new(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1.borrow_mut().left = Some(n2.clone());\nn1.borrow_mut().right = Some(n3);\nn2.borrow_mut().left = Some(n4);\nn2.borrow_mut().right = Some(n5);\n
        binary_tree.c
        /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nTreeNode *n1 = newTreeNode(1);\nTreeNode *n2 = newTreeNode(2);\nTreeNode *n3 = newTreeNode(3);\nTreeNode *n4 = newTreeNode(4);\nTreeNode *n5 = newTreeNode(5);\n// \u6784\u5efa\u8282\u70b9\u4e4b\u95f4\u7684\u5f15\u7528\uff08\u6307\u9488\uff09\nn1->left = n2;\nn1->right = n3;\nn2->left = n4;\nn2->right = n5;\n
        binary_tree.zig
        \n
        "},{"location":"chapter_tree/binary_tree/#2","title":"2. \u00a0 \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9","text":"

        \u4e0e\u94fe\u8868\u7c7b\u4f3c\uff0c\u5728\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u6307\u9488\u6765\u5b9e\u73b0\u3002\u56fe 7-3 \u7ed9\u51fa\u4e86\u4e00\u4e2a\u793a\u4f8b\u3002

        \u56fe 7-3 \u00a0 \u5728\u4e8c\u53c9\u6811\u4e2d\u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree.py
        # \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9\np = TreeNode(0)\n# \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = p\np.left = n2\n# \u5220\u9664\u8282\u70b9 P\nn1.left = n2\n
        binary_tree.cpp
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode* P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1->left = P;\nP->left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1->left = n2;\n
        binary_tree.java
        TreeNode P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.cs
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode P = new(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.go
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\np := NewTreeNode(0)\nn1.Left = p\np.Left = n2\n// \u5220\u9664\u8282\u70b9 P\nn1.Left = n2\n
        binary_tree.swift
        let P = TreeNode(x: 0)\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P\nP.left = n2\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2\n
        binary_tree.js
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nlet P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.ts
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nconst P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.dart
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode P = new TreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.left = P;\nP.left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1.left = n2;\n
        binary_tree.rs
        let p = TreeNode::new(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1.borrow_mut().left = Some(p.clone());\np.borrow_mut().left = Some(n2.clone());\n// \u5220\u9664\u8282\u70b9 p\nn1.borrow_mut().left = Some(n2);\n
        binary_tree.c
        /* \u63d2\u5165\u4e0e\u5220\u9664\u8282\u70b9 */\nTreeNode *P = newTreeNode(0);\n// \u5728 n1 -> n2 \u4e2d\u95f4\u63d2\u5165\u8282\u70b9 P\nn1->left = P;\nP->left = n2;\n// \u5220\u9664\u8282\u70b9 P\nn1->left = n2;\n
        binary_tree.zig
        \n

        Note

        \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u63d2\u5165\u8282\u70b9\u53ef\u80fd\u4f1a\u6539\u53d8\u4e8c\u53c9\u6811\u7684\u539f\u6709\u903b\u8f91\u7ed3\u6784\uff0c\u800c\u5220\u9664\u8282\u70b9\u901a\u5e38\u610f\u5473\u7740\u5220\u9664\u8be5\u8282\u70b9\u53ca\u5176\u6240\u6709\u5b50\u6811\u3002\u56e0\u6b64\uff0c\u5728\u4e8c\u53c9\u6811\u4e2d\uff0c\u63d2\u5165\u4e0e\u5220\u9664\u901a\u5e38\u662f\u7531\u4e00\u5957\u64cd\u4f5c\u914d\u5408\u5b8c\u6210\u7684\uff0c\u4ee5\u5b9e\u73b0\u6709\u5b9e\u9645\u610f\u4e49\u7684\u64cd\u4f5c\u3002

        "},{"location":"chapter_tree/binary_tree/#713","title":"7.1.3 \u00a0 \u5e38\u89c1\u4e8c\u53c9\u6811\u7c7b\u578b","text":""},{"location":"chapter_tree/binary_tree/#1_1","title":"1. \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-4 \u6240\u793a\uff0c\u300c\u5b8c\u7f8e\u4e8c\u53c9\u6811 perfect binary tree\u300d\u6240\u6709\u5c42\u7684\u8282\u70b9\u90fd\u88ab\u5b8c\u5168\u586b\u6ee1\u3002\u5728\u5b8c\u7f8e\u4e8c\u53c9\u6811\u4e2d\uff0c\u53f6\u8282\u70b9\u7684\u5ea6\u4e3a \\(0\\) \uff0c\u5176\u4f59\u6240\u6709\u8282\u70b9\u7684\u5ea6\u90fd\u4e3a \\(2\\) \uff1b\u82e5\u6811\u7684\u9ad8\u5ea6\u4e3a \\(h\\) \uff0c\u5219\u8282\u70b9\u603b\u6570\u4e3a \\(2^{h+1} - 1\\) \uff0c\u5448\u73b0\u6807\u51c6\u7684\u6307\u6570\u7ea7\u5173\u7cfb\uff0c\u53cd\u6620\u4e86\u81ea\u7136\u754c\u4e2d\u5e38\u89c1\u7684\u7ec6\u80de\u5206\u88c2\u73b0\u8c61\u3002

        Tip

        \u8bf7\u6ce8\u610f\uff0c\u5728\u4e2d\u6587\u793e\u533a\u4e2d\uff0c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u5e38\u88ab\u79f0\u4e3a\u300c\u6ee1\u4e8c\u53c9\u6811\u300d\u3002

        \u56fe 7-4 \u00a0 \u5b8c\u7f8e\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#2_1","title":"2. \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-5 \u6240\u793a\uff0c\u300c\u5b8c\u5168\u4e8c\u53c9\u6811 complete binary tree\u300d\u53ea\u6709\u6700\u5e95\u5c42\u7684\u8282\u70b9\u672a\u88ab\u586b\u6ee1\uff0c\u4e14\u6700\u5e95\u5c42\u8282\u70b9\u5c3d\u91cf\u9760\u5de6\u586b\u5145\u3002

        \u56fe 7-5 \u00a0 \u5b8c\u5168\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#3","title":"3. \u00a0 \u5b8c\u6ee1\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-6 \u6240\u793a\uff0c\u300c\u5b8c\u6ee1\u4e8c\u53c9\u6811 full binary tree\u300d\u9664\u4e86\u53f6\u8282\u70b9\u4e4b\u5916\uff0c\u5176\u4f59\u6240\u6709\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\u3002

        \u56fe 7-6 \u00a0 \u5b8c\u6ee1\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#4","title":"4. \u00a0 \u5e73\u8861\u4e8c\u53c9\u6811","text":"

        \u5982\u56fe 7-7 \u6240\u793a\uff0c\u300c\u5e73\u8861\u4e8c\u53c9\u6811 balanced binary tree\u300d\u4e2d\u4efb\u610f\u8282\u70b9\u7684\u5de6\u5b50\u6811\u548c\u53f3\u5b50\u6811\u7684\u9ad8\u5ea6\u4e4b\u5dee\u7684\u7edd\u5bf9\u503c\u4e0d\u8d85\u8fc7 1 \u3002

        \u56fe 7-7 \u00a0 \u5e73\u8861\u4e8c\u53c9\u6811

        "},{"location":"chapter_tree/binary_tree/#714","title":"7.1.4 \u00a0 \u4e8c\u53c9\u6811\u7684\u9000\u5316","text":"

        \u56fe 7-8 \u5c55\u793a\u4e86\u4e8c\u53c9\u6811\u7684\u7406\u60f3\u7ed3\u6784\u4e0e\u9000\u5316\u7ed3\u6784\u3002\u5f53\u4e8c\u53c9\u6811\u7684\u6bcf\u5c42\u8282\u70b9\u90fd\u88ab\u586b\u6ee1\u65f6\uff0c\u8fbe\u5230\u201c\u5b8c\u7f8e\u4e8c\u53c9\u6811\u201d\uff1b\u800c\u5f53\u6240\u6709\u8282\u70b9\u90fd\u504f\u5411\u4e00\u4fa7\u65f6\uff0c\u4e8c\u53c9\u6811\u9000\u5316\u4e3a\u201c\u94fe\u8868\u201d\u3002

        • \u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u7406\u60f3\u60c5\u51b5\uff0c\u53ef\u4ee5\u5145\u5206\u53d1\u6325\u4e8c\u53c9\u6811\u201c\u5206\u6cbb\u201d\u7684\u4f18\u52bf\u3002
        • \u94fe\u8868\u5219\u662f\u53e6\u4e00\u4e2a\u6781\u7aef\uff0c\u5404\u9879\u64cd\u4f5c\u90fd\u53d8\u4e3a\u7ebf\u6027\u64cd\u4f5c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u9000\u5316\u81f3 \\(O(n)\\) \u3002

        \u56fe 7-8 \u00a0 \u4e8c\u53c9\u6811\u7684\u6700\u4f73\u7ed3\u6784\u4e0e\u6700\u5dee\u7ed3\u6784

        \u5982\u8868 7-1 \u6240\u793a\uff0c\u5728\u6700\u4f73\u7ed3\u6784\u548c\u6700\u5dee\u7ed3\u6784\u4e0b\uff0c\u4e8c\u53c9\u6811\u7684\u53f6\u8282\u70b9\u6570\u91cf\u3001\u8282\u70b9\u603b\u6570\u3001\u9ad8\u5ea6\u7b49\u8fbe\u5230\u6781\u5927\u503c\u6216\u6781\u5c0f\u503c\u3002

        \u8868 7-1 \u00a0 \u4e8c\u53c9\u6811\u7684\u6700\u4f73\u7ed3\u6784\u4e0e\u6700\u5dee\u7ed3\u6784

        \u5b8c\u7f8e\u4e8c\u53c9\u6811 \u94fe\u8868 \u7b2c \\(i\\) \u5c42\u7684\u8282\u70b9\u6570\u91cf \\(2^{i-1}\\) \\(1\\) \u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u6811\u7684\u53f6\u8282\u70b9\u6570\u91cf \\(2^h\\) \\(1\\) \u9ad8\u5ea6\u4e3a \\(h\\) \u7684\u6811\u7684\u8282\u70b9\u603b\u6570 \\(2^{h+1} - 1\\) \\(h + 1\\) \u8282\u70b9\u603b\u6570\u4e3a \\(n\\) \u7684\u6811\u7684\u9ad8\u5ea6 \\(\\log_2 (n+1) - 1\\) \\(n - 1\\)"},{"location":"chapter_tree/binary_tree_traversal/","title":"7.2 \u00a0 \u4e8c\u53c9\u6811\u904d\u5386","text":"

        \u4ece\u7269\u7406\u7ed3\u6784\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u6811\u662f\u4e00\u79cd\u57fa\u4e8e\u94fe\u8868\u7684\u6570\u636e\u7ed3\u6784\uff0c\u56e0\u6b64\u5176\u904d\u5386\u65b9\u5f0f\u662f\u901a\u8fc7\u6307\u9488\u9010\u4e2a\u8bbf\u95ee\u8282\u70b9\u3002\u7136\u800c\uff0c\u6811\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u8fd9\u4f7f\u5f97\u904d\u5386\u6811\u6bd4\u904d\u5386\u94fe\u8868\u66f4\u52a0\u590d\u6742\uff0c\u9700\u8981\u501f\u52a9\u641c\u7d22\u7b97\u6cd5\u6765\u5b9e\u73b0\u3002

        \u4e8c\u53c9\u6811\u5e38\u89c1\u7684\u904d\u5386\u65b9\u5f0f\u5305\u62ec\u5c42\u5e8f\u904d\u5386\u3001\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u548c\u540e\u5e8f\u904d\u5386\u7b49\u3002

        "},{"location":"chapter_tree/binary_tree_traversal/#721","title":"7.2.1 \u00a0 \u5c42\u5e8f\u904d\u5386","text":"

        \u5982\u56fe 7-9 \u6240\u793a\uff0c\u300c\u5c42\u5e8f\u904d\u5386 level-order traversal\u300d\u4ece\u9876\u90e8\u5230\u5e95\u90e8\u9010\u5c42\u904d\u5386\u4e8c\u53c9\u6811\uff0c\u5e76\u5728\u6bcf\u4e00\u5c42\u6309\u7167\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u8bbf\u95ee\u8282\u70b9\u3002

        \u5c42\u5e8f\u904d\u5386\u672c\u8d28\u4e0a\u5c5e\u4e8e\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386 breadth-first traversal, BFS\u300d\uff0c\u5b83\u4f53\u73b0\u4e86\u4e00\u79cd\u201c\u4e00\u5708\u4e00\u5708\u5411\u5916\u6269\u5c55\u201d\u7684\u9010\u5c42\u904d\u5386\u65b9\u5f0f\u3002

        \u56fe 7-9 \u00a0 \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386

        "},{"location":"chapter_tree/binary_tree_traversal/#1","title":"1. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u901a\u5e38\u501f\u52a9\u201c\u961f\u5217\u201d\u6765\u5b9e\u73b0\u3002\u961f\u5217\u9075\u5faa\u201c\u5148\u8fdb\u5148\u51fa\u201d\u7684\u89c4\u5219\uff0c\u800c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u5219\u9075\u5faa\u201c\u9010\u5c42\u63a8\u8fdb\u201d\u7684\u89c4\u5219\uff0c\u4e24\u8005\u80cc\u540e\u7684\u601d\u60f3\u662f\u4e00\u81f4\u7684\u3002\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree_bfs.py
        def level_order(root: TreeNode | None) -> list[int]:\n\"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\n# \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue: deque[TreeNode] = deque()\nqueue.append(root)\n# \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nres = []\nwhile queue:\nnode: TreeNode = queue.popleft()  # \u961f\u5217\u51fa\u961f\nres.append(node.val)  # \u4fdd\u5b58\u8282\u70b9\u503c\nif node.left is not None:\nqueue.append(node.left)  # \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif node.right is not None:\nqueue.append(node.right)  # \u53f3\u5b50\u8282\u70b9\u5165\u961f\nreturn res\n
        binary_tree_bfs.cpp
        /* \u5c42\u5e8f\u904d\u5386 */\nvector<int> levelOrder(TreeNode *root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue<TreeNode *> queue;\nqueue.push(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvector<int> vec;\nwhile (!queue.empty()) {\nTreeNode *node = queue.front();\nqueue.pop();              // \u961f\u5217\u51fa\u961f\nvec.push_back(node->val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node->left != nullptr)\nqueue.push(node->left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node->right != nullptr)\nqueue.push(node->right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn vec;\n}\n
        binary_tree_bfs.java
        /* \u5c42\u5e8f\u904d\u5386 */\nList<Integer> levelOrder(TreeNode root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode> queue = new LinkedList<>();\nqueue.add(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<Integer> list = new ArrayList<>();\nwhile (!queue.isEmpty()) {\nTreeNode node = queue.poll(); // \u961f\u5217\u51fa\u961f\nlist.add(node.val);           // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null)\nqueue.offer(node.left);   // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null)\nqueue.offer(node.right);  // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.cs
        /* \u5c42\u5e8f\u904d\u5386 */\nList<int> LevelOrder(TreeNode root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode> queue = new();\nqueue.Enqueue(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<int> list = [];\nwhile (queue.Count != 0) {\nTreeNode node = queue.Dequeue(); // \u961f\u5217\u51fa\u961f\nlist.Add(node.val!.Value);       // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null)\nqueue.Enqueue(node.left);    // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null)\nqueue.Enqueue(node.right);   // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.go
        /* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder(root *TreeNode) []any {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nqueue := list.New()\nqueue.PushBack(root)\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5207\u7247\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nnums := make([]any, 0)\nfor queue.Len() > 0 {\n// \u961f\u5217\u51fa\u961f\nnode := queue.Remove(queue.Front()).(*TreeNode)\n// \u4fdd\u5b58\u8282\u70b9\u503c\nnums = append(nums, node.Val)\nif node.Left != nil {\n// \u5de6\u5b50\u8282\u70b9\u5165\u961f\nqueue.PushBack(node.Left)\n}\nif node.Right != nil {\n// \u53f3\u5b50\u8282\u70b9\u5165\u961f\nqueue.PushBack(node.Right)\n}\n}\nreturn nums\n}\n
        binary_tree_bfs.swift
        /* \u5c42\u5e8f\u904d\u5386 */\nfunc levelOrder(root: TreeNode) -> [Int] {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nvar queue: [TreeNode] = [root]\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvar list: [Int] = []\nwhile !queue.isEmpty {\nlet node = queue.removeFirst() // \u961f\u5217\u51fa\u961f\nlist.append(node.val) // \u4fdd\u5b58\u8282\u70b9\u503c\nif let left = node.left {\nqueue.append(left) // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif let right = node.right {\nqueue.append(right) // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\n}\nreturn list\n}\n
        binary_tree_bfs.js
        /* \u5c42\u5e8f\u904d\u5386 */\nfunction levelOrder(root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst queue = [root];\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nconst list = [];\nwhile (queue.length) {\nlet node = queue.shift(); // \u961f\u5217\u51fa\u961f\nlist.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left) queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right) queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn list;\n}\n
        binary_tree_bfs.ts
        /* \u5c42\u5e8f\u904d\u5386 */\nfunction levelOrder(root: TreeNode | null): number[] {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst queue = [root];\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nconst list: number[] = [];\nwhile (queue.length) {\nlet node = queue.shift() as TreeNode; // \u961f\u5217\u51fa\u961f\nlist.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left) {\nqueue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif (node.right) {\nqueue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\n}\nreturn list;\n}\n
        binary_tree_bfs.dart
        /* \u5c42\u5e8f\u904d\u5386 */\nList<int> levelOrder(TreeNode? root) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nQueue<TreeNode?> queue = Queue();\nqueue.add(root);\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nList<int> res = [];\nwhile (queue.isNotEmpty) {\nTreeNode? node = queue.removeFirst(); // \u961f\u5217\u51fa\u961f\nres.add(node!.val); // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null) queue.add(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\nif (node.right != null) queue.add(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}\nreturn res;\n}\n
        binary_tree_bfs.rs
        /* \u5c42\u5e8f\u904d\u5386 */\nfn level_order(root: &Rc<RefCell<TreeNode>>) -> Vec<i32> {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nlet mut que = VecDeque::new();\nque.push_back(Rc::clone(&root));\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nlet mut vec = Vec::new();\nwhile let Some(node) = que.pop_front() {                 // \u961f\u5217\u51fa\u961f\nvec.push(node.borrow().val);                         // \u4fdd\u5b58\u8282\u70b9\u503c\nif let Some(left) = node.borrow().left.as_ref() {\nque.push_back(Rc::clone(left));                  // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif let Some(right) = node.borrow().right.as_ref() {\nque.push_back(Rc::clone(right));                 // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n};\n}\nvec\n}\n
        binary_tree_bfs.c
        /* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(TreeNode *root, int *size) {\n/* \u8f85\u52a9\u961f\u5217 */\nint front, rear;\nint index, *arr;\nTreeNode *node;\nTreeNode **queue;\n/* \u8f85\u52a9\u961f\u5217 */\nqueue = (TreeNode **)malloc(sizeof(TreeNode *) * MAX_SIZE);\n// \u961f\u5217\u6307\u9488\nfront = 0, rear = 0;\n// \u52a0\u5165\u6839\u8282\u70b9\nqueue[rear++] = root;\n// \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n/* \u8f85\u52a9\u6570\u7ec4 */\narr = (int *)malloc(sizeof(int) * MAX_SIZE);\n// \u6570\u7ec4\u6307\u9488\nindex = 0;\nwhile (front < rear) {\n// \u961f\u5217\u51fa\u961f\nnode = queue[front++];\n// \u4fdd\u5b58\u8282\u70b9\u503c\narr[index++] = node->val;\nif (node->left != NULL) {\n// \u5de6\u5b50\u8282\u70b9\u5165\u961f\nqueue[rear++] = node->left;\n}\nif (node->right != NULL) {\n// \u53f3\u5b50\u8282\u70b9\u5165\u961f\nqueue[rear++] = node->right;\n}\n}\n// \u66f4\u65b0\u6570\u7ec4\u957f\u5ea6\u7684\u503c\n*size = index;\narr = realloc(arr, sizeof(int) * (*size));\n// \u91ca\u653e\u8f85\u52a9\u6570\u7ec4\u7a7a\u95f4\nfree(queue);\nreturn arr;\n}\n
        binary_tree_bfs.zig
        // \u5c42\u5e8f\u904d\u5386\nfn levelOrder(comptime T: type, mem_allocator: std.mem.Allocator, root: *inc.TreeNode(T)) !std.ArrayList(T) {\n// \u521d\u59cb\u5316\u961f\u5217\uff0c\u52a0\u5165\u6839\u8282\u70b9\nconst L = std.TailQueue(*inc.TreeNode(T));\nvar queue = L{};\nvar root_node = try mem_allocator.create(L.Node);\nroot_node.data = root;\nqueue.append(root_node); // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\nvar list = std.ArrayList(T).init(std.heap.page_allocator);\nwhile (queue.len > 0) {\nvar queue_node = queue.popFirst().?;    // \u961f\u5217\u51fa\u961f\nvar node = queue_node.data;\ntry list.append(node.val);              // \u4fdd\u5b58\u8282\u70b9\u503c\nif (node.left != null) {\nvar tmp_node = try mem_allocator.create(L.Node);\ntmp_node.data = node.left.?;\nqueue.append(tmp_node);             // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n}\nif (node.right != null) {\nvar tmp_node = try mem_allocator.create(L.Node);\ntmp_node.data = node.right.?;\nqueue.append(tmp_node);             // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n}        }\nreturn list;\n}\n
        "},{"location":"chapter_tree/binary_tree_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u6240\u6709\u8282\u70b9\u88ab\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\uff0c\u5176\u4e2d \\(n\\) \u4e3a\u8282\u70b9\u6570\u91cf\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u6ee1\u4e8c\u53c9\u6811\u65f6\uff0c\u904d\u5386\u5230\u6700\u5e95\u5c42\u4e4b\u524d\uff0c\u961f\u5217\u4e2d\u6700\u591a\u540c\u65f6\u5b58\u5728 \\((n + 1) / 2\\) \u4e2a\u8282\u70b9\uff0c\u5360\u7528 \\(O(n)\\) \u7a7a\u95f4\u3002
        "},{"location":"chapter_tree/binary_tree_traversal/#722","title":"7.2.2 \u00a0 \u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386","text":"

        \u76f8\u5e94\u5730\uff0c\u524d\u5e8f\u3001\u4e2d\u5e8f\u548c\u540e\u5e8f\u904d\u5386\u90fd\u5c5e\u4e8e\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386 depth-first traversal, DFS\u300d\uff0c\u5b83\u4f53\u73b0\u4e86\u4e00\u79cd\u201c\u5148\u8d70\u5230\u5c3d\u5934\uff0c\u518d\u56de\u6eaf\u7ee7\u7eed\u201d\u7684\u904d\u5386\u65b9\u5f0f\u3002

        \u56fe 7-10 \u5c55\u793a\u4e86\u5bf9\u4e8c\u53c9\u6811\u8fdb\u884c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u7684\u5de5\u4f5c\u539f\u7406\u3002\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u5c31\u50cf\u662f\u7ed5\u7740\u6574\u68f5\u4e8c\u53c9\u6811\u7684\u5916\u56f4\u201c\u8d70\u201d\u4e00\u5708\uff0c\u5728\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u9047\u5230\u4e09\u4e2a\u4f4d\u7f6e\uff0c\u5206\u522b\u5bf9\u5e94\u524d\u5e8f\u904d\u5386\u3001\u4e2d\u5e8f\u904d\u5386\u548c\u540e\u5e8f\u904d\u5386\u3002

        \u56fe 7-10 \u00a0 \u4e8c\u53c9\u641c\u7d22\u6811\u7684\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386

        "},{"location":"chapter_tree/binary_tree_traversal/#1_1","title":"1. \u00a0 \u4ee3\u7801\u5b9e\u73b0","text":"

        \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u901a\u5e38\u57fa\u4e8e\u9012\u5f52\u5b9e\u73b0\uff1a

        PythonC++JavaC#GoSwiftJSTSDartRustCZig binary_tree_dfs.py
        def pre_order(root: TreeNode | None):\n\"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nres.append(root.val)\npre_order(root=root.left)\npre_order(root=root.right)\ndef in_order(root: TreeNode | None):\n\"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nin_order(root=root.left)\nres.append(root.val)\nin_order(root=root.right)\ndef post_order(root: TreeNode | None):\n\"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\nif root is None:\nreturn\n# \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npost_order(root=root.left)\npost_order(root=root.right)\nres.append(root.val)\n
        binary_tree_dfs.cpp
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nvec.push_back(root->val);\npreOrder(root->left);\npreOrder(root->right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root->left);\nvec.push_back(root->val);\ninOrder(root->right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root) {\nif (root == nullptr)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root->left);\npostOrder(root->right);\nvec.push_back(root->val);\n}\n
        binary_tree_dfs.java
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.add(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.add(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode root) {\nif (root == null)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.add(root.val);\n}\n
        binary_tree_dfs.cs
        /* \u524d\u5e8f\u904d\u5386 */\nvoid PreOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.Add(root.val!.Value);\nPreOrder(root.left);\nPreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid InOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nInOrder(root.left);\nlist.Add(root.val!.Value);\nInOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid PostOrder(TreeNode? root) {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\nPostOrder(root.left);\nPostOrder(root.right);\nlist.Add(root.val!.Value);\n}\n
        binary_tree_dfs.go
        /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nnums = append(nums, node.Val)\npreOrder(node.Left)\npreOrder(node.Right)\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(node.Left)\nnums = append(nums, node.Val)\ninOrder(node.Right)\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(node *TreeNode) {\nif node == nil {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(node.Left)\npostOrder(node.Right)\nnums = append(nums, node.Val)\n}\n
        binary_tree_dfs.swift
        /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.append(root.val)\npreOrder(root: root.left)\npreOrder(root: root.right)\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root: root.left)\nlist.append(root.val)\ninOrder(root: root.right)\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(root: TreeNode?) {\nguard let root = root else {\nreturn\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root: root.left)\npostOrder(root: root.right)\nlist.append(root.val)\n}\n
        binary_tree_dfs.js
        /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.push(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.push(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root) {\nif (root === null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.push(root.val);\n}\n
        binary_tree_dfs.ts
        /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.push(root.val);\npreOrder(root.left);\npreOrder(root.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root.left);\nlist.push(root.val);\ninOrder(root.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root: TreeNode | null): void {\nif (root === null) {\nreturn;\n}\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root.left);\npostOrder(root.right);\nlist.push(root.val);\n}\n
        binary_tree_dfs.dart
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nlist.add(node.val);\npreOrder(node.left);\npreOrder(node.right);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(node.left);\nlist.add(node.val);\ninOrder(node.right);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode? node) {\nif (node == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(node.left);\npostOrder(node.right);\nlist.add(node.val);\n}\n
        binary_tree_dfs.rs
        /* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\nresult.push(node.borrow().val);\nresult.append(&mut pre_order(node.borrow().left.as_ref()));\nresult.append(&mut pre_order(node.borrow().right.as_ref()));\n}\nresult\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\nresult.append(&mut in_order(node.borrow().left.as_ref()));\nresult.push(node.borrow().val);\nresult.append(&mut in_order(node.borrow().right.as_ref()));\n}\nresult\n}\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\nlet mut result = vec![];\nif let Some(node) = root {\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\nresult.append(&mut post_order(node.borrow().left.as_ref()));\nresult.append(&mut post_order(node.borrow().right.as_ref()));\nresult.push(node.borrow().val);\n}\nresult\n}\n
        binary_tree_dfs.c
        /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\narr[(*size)++] = root->val;\npreOrder(root->left, size);\npreOrder(root->right, size);\n}\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ninOrder(root->left, size);\narr[(*size)++] = root->val;\ninOrder(root->right, size);\n}\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root, int *size) {\nif (root == NULL)\nreturn;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\npostOrder(root->left, size);\npostOrder(root->right, size);\narr[(*size)++] = root->val;\n}\n
        binary_tree_dfs.zig
        // \u524d\u5e8f\u904d\u5386\nfn preOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\ntry list.append(root.?.val);\ntry preOrder(T, root.?.left);\ntry preOrder(T, root.?.right);\n}\n// \u4e2d\u5e8f\u904d\u5386\nfn inOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\ntry inOrder(T, root.?.left);\ntry list.append(root.?.val);\ntry inOrder(T, root.?.right);\n}\n// \u540e\u5e8f\u904d\u5386\nfn postOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\nif (root == null) return;\n// \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\ntry postOrder(T, root.?.left);\ntry postOrder(T, root.?.right);\ntry list.append(root.?.val);\n}\n

        Tip

        \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u4e5f\u53ef\u4ee5\u57fa\u4e8e\u8fed\u4ee3\u5b9e\u73b0\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u7814\u7a76\u3002

        \u56fe 7-11 \u5c55\u793a\u4e86\u524d\u5e8f\u904d\u5386\u4e8c\u53c9\u6811\u7684\u9012\u5f52\u8fc7\u7a0b\uff0c\u5176\u53ef\u5206\u4e3a\u201c\u9012\u201d\u548c\u201c\u5f52\u201d\u4e24\u4e2a\u9006\u5411\u7684\u90e8\u5206\u3002

        1. \u201c\u9012\u201d\u8868\u793a\u5f00\u542f\u65b0\u65b9\u6cd5\uff0c\u7a0b\u5e8f\u5728\u6b64\u8fc7\u7a0b\u4e2d\u8bbf\u95ee\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002
        2. \u201c\u5f52\u201d\u8868\u793a\u51fd\u6570\u8fd4\u56de\uff0c\u4ee3\u8868\u5f53\u524d\u8282\u70b9\u5df2\u7ecf\u8bbf\u95ee\u5b8c\u6bd5\u3002
        <1><2><3><4><5><6><7><8><9><10><11>

        \u56fe 7-11 \u00a0 \u524d\u5e8f\u904d\u5386\u7684\u9012\u5f52\u8fc7\u7a0b

        "},{"location":"chapter_tree/binary_tree_traversal/#2_1","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
        • \u65f6\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u6240\u6709\u8282\u70b9\u88ab\u8bbf\u95ee\u4e00\u6b21\uff0c\u4f7f\u7528 \\(O(n)\\) \u65f6\u95f4\u3002
        • \u7a7a\u95f4\u590d\u6742\u5ea6 \\(O(n)\\) \uff1a\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5373\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u9012\u5f52\u6df1\u5ea6\u8fbe\u5230 \\(n\\) \uff0c\u7cfb\u7edf\u5360\u7528 \\(O(n)\\) \u6808\u5e27\u7a7a\u95f4\u3002
        "},{"location":"chapter_tree/summary/","title":"7.6 \u00a0 \u5c0f\u7ed3","text":""},{"location":"chapter_tree/summary/#1","title":"1. \u00a0 \u91cd\u70b9\u56de\u987e","text":"
        • \u4e8c\u53c9\u6811\u662f\u4e00\u79cd\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff0c\u4f53\u73b0\u201c\u4e00\u5206\u4e3a\u4e8c\u201d\u7684\u5206\u6cbb\u903b\u8f91\u3002\u6bcf\u4e2a\u4e8c\u53c9\u6811\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u503c\u4ee5\u53ca\u4e24\u4e2a\u6307\u9488\uff0c\u5206\u522b\u6307\u5411\u5176\u5de6\u5b50\u8282\u70b9\u548c\u53f3\u5b50\u8282\u70b9\u3002
        • \u5bf9\u4e8e\u4e8c\u53c9\u6811\u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\uff0c\u5176\u5de6\uff08\u53f3\uff09\u5b50\u8282\u70b9\u53ca\u5176\u4ee5\u4e0b\u5f62\u6210\u7684\u6811\u88ab\u79f0\u4e3a\u8be5\u8282\u70b9\u7684\u5de6\uff08\u53f3\uff09\u5b50\u6811\u3002
        • \u4e8c\u53c9\u6811\u7684\u76f8\u5173\u672f\u8bed\u5305\u62ec\u6839\u8282\u70b9\u3001\u53f6\u8282\u70b9\u3001\u5c42\u3001\u5ea6\u3001\u8fb9\u3001\u9ad8\u5ea6\u548c\u6df1\u5ea6\u7b49\u3002
        • \u4e8c\u53c9\u6811\u7684\u521d\u59cb\u5316\u3001\u8282\u70b9\u63d2\u5165\u548c\u8282\u70b9\u5220\u9664\u64cd\u4f5c\u4e0e\u94fe\u8868\u64cd\u4f5c\u65b9\u6cd5\u7c7b\u4f3c\u3002
        • \u5e38\u89c1\u7684\u4e8c\u53c9\u6811\u7c7b\u578b\u6709\u5b8c\u7f8e\u4e8c\u53c9\u6811\u3001\u5b8c\u5168\u4e8c\u53c9\u6811\u3001\u5b8c\u6ee1\u4e8c\u53c9\u6811\u548c\u5e73\u8861\u4e8c\u53c9\u6811\u3002\u5b8c\u7f8e\u4e8c\u53c9\u6811\u662f\u6700\u7406\u60f3\u7684\u72b6\u6001\uff0c\u800c\u94fe\u8868\u662f\u9000\u5316\u540e\u7684\u6700\u5dee\u72b6\u6001\u3002
        • \u4e8c\u53c9\u6811\u53ef\u4ee5\u7528\u6570\u7ec4\u8868\u793a\uff0c\u65b9\u6cd5\u662f\u5c06\u8282\u70b9\u503c\u548c\u7a7a\u4f4d\u6309\u5c42\u5e8f\u904d\u5386\u987a\u5e8f\u6392\u5217\uff0c\u5e76\u6839\u636e\u7236\u8282\u70b9\u4e0e\u5b50\u8282\u70b9\u4e4b\u95f4\u7684\u7d22\u5f15\u6620\u5c04\u5173\u7cfb\u6765\u5b9e\u73b0\u6307\u9488\u3002
        • \u4e8c\u53c9\u6811\u7684\u5c42\u5e8f\u904d\u5386\u662f\u4e00\u79cd\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u65b9\u6cd5\uff0c\u5b83\u4f53\u73b0\u4e86\u201c\u4e00\u5708\u4e00\u5708\u5411\u5916\u6269\u5c55\u201d\u7684\u9010\u5c42\u904d\u5386\u65b9\u5f0f\uff0c\u901a\u5e38\u901a\u8fc7\u961f\u5217\u6765\u5b9e\u73b0\u3002
        • \u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\u7686\u5c5e\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\uff0c\u5b83\u4eec\u4f53\u73b0\u4e86\u201c\u5148\u8d70\u5230\u5c3d\u5934\uff0c\u518d\u56de\u6eaf\u7ee7\u7eed\u201d\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u901a\u5e38\u4f7f\u7528\u9012\u5f52\u6765\u5b9e\u73b0\u3002
        • \u4e8c\u53c9\u641c\u7d22\u6811\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u5143\u7d20\u67e5\u627e\u6570\u636e\u7ed3\u6784\uff0c\u5176\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a \\(O(\\log n)\\) \u3002\u5f53\u4e8c\u53c9\u641c\u7d22\u6811\u9000\u5316\u4e3a\u94fe\u8868\u65f6\uff0c\u5404\u9879\u65f6\u95f4\u590d\u6742\u5ea6\u4f1a\u52a3\u5316\u81f3 \\(O(n)\\) \u3002
        • AVL \u6811\uff0c\u4e5f\u79f0\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\uff0c\u5b83\u901a\u8fc7\u65cb\u8f6c\u64cd\u4f5c\u786e\u4fdd\u5728\u4e0d\u65ad\u63d2\u5165\u548c\u5220\u9664\u8282\u70b9\u540e\u6811\u4ecd\u7136\u4fdd\u6301\u5e73\u8861\u3002
        • AVL \u6811\u7684\u65cb\u8f6c\u64cd\u4f5c\u5305\u62ec\u53f3\u65cb\u3001\u5de6\u65cb\u3001\u5148\u53f3\u65cb\u518d\u5de6\u65cb\u3001\u5148\u5de6\u65cb\u518d\u53f3\u65cb\u3002\u5728\u63d2\u5165\u6216\u5220\u9664\u8282\u70b9\u540e\uff0cAVL \u6811\u4f1a\u4ece\u5e95\u5411\u9876\u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\u3002
        "},{"location":"chapter_tree/summary/#2-q-a","title":"2. \u00a0 Q & A","text":"

        \u5bf9\u4e8e\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\u7684\u4e8c\u53c9\u6811\uff0c\u6811\u7684\u9ad8\u5ea6\u548c\u6839\u8282\u70b9\u7684\u6df1\u5ea6\u90fd\u662f \\(0\\) \u5417\uff1f

        \u662f\u7684\uff0c\u56e0\u4e3a\u9ad8\u5ea6\u548c\u6df1\u5ea6\u901a\u5e38\u5b9a\u4e49\u4e3a\u201c\u7ecf\u8fc7\u7684\u8fb9\u7684\u6570\u91cf\u201d\u3002

        \u4e8c\u53c9\u6811\u4e2d\u7684\u63d2\u5165\u4e0e\u5220\u9664\u4e00\u822c\u7531\u4e00\u5957\u64cd\u4f5c\u914d\u5408\u5b8c\u6210\uff0c\u8fd9\u91cc\u7684\u201c\u4e00\u5957\u64cd\u4f5c\u201d\u6307\u4ec0\u4e48\u5462\uff1f\u53ef\u4ee5\u7406\u89e3\u4e3a\u8d44\u6e90\u7684\u5b50\u8282\u70b9\u7684\u8d44\u6e90\u91ca\u653e\u5417\uff1f

        \u62ff\u4e8c\u53c9\u641c\u7d22\u6811\u6765\u4e3e\u4f8b\uff0c\u5220\u9664\u8282\u70b9\u64cd\u4f5c\u8981\u5206\u4e09\u79cd\u60c5\u51b5\u5904\u7406\uff0c\u5176\u4e2d\u6bcf\u79cd\u60c5\u51b5\u90fd\u9700\u8981\u8fdb\u884c\u591a\u4e2a\u6b65\u9aa4\u7684\u8282\u70b9\u64cd\u4f5c\u3002

        \u4e3a\u4ec0\u4e48 DFS \u904d\u5386\u4e8c\u53c9\u6811\u6709\u524d\u3001\u4e2d\u3001\u540e\u4e09\u79cd\u987a\u5e8f\uff0c\u5206\u522b\u6709\u4ec0\u4e48\u7528\u5462\uff1f

        \u4e0e\u987a\u5e8f\u548c\u9006\u5e8f\u904d\u5386\u6570\u7ec4\u7c7b\u4f3c\uff0c\u524d\u5e8f\u3001\u4e2d\u5e8f\u3001\u540e\u5e8f\u904d\u5386\u662f\u4e09\u79cd\u4e8c\u53c9\u6811\u904d\u5386\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5b83\u4eec\u5f97\u5230\u4e00\u4e2a\u7279\u5b9a\u987a\u5e8f\u7684\u904d\u5386\u7ed3\u679c\u3002\u4f8b\u5982\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\uff0c\u7531\u4e8e\u8282\u70b9\u5927\u5c0f\u6ee1\u8db3 \u5de6\u5b50\u8282\u70b9\u503c < \u6839\u8282\u70b9\u503c < \u53f3\u5b50\u8282\u70b9\u503c \uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u8981\u6309\u7167 \u5de6 $\\rightarrow$ \u6839 $\\rightarrow$ \u53f3 \u7684\u4f18\u5148\u7ea7\u904d\u5386\u6811\uff0c\u5c31\u53ef\u4ee5\u83b7\u5f97\u6709\u5e8f\u7684\u8282\u70b9\u5e8f\u5217\u3002

        \u53f3\u65cb\u64cd\u4f5c\u662f\u5904\u7406\u5931\u8861\u8282\u70b9 node\u3001child\u3001grand_child \u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u90a3 node \u7684\u7236\u8282\u70b9\u548c node \u539f\u6765\u7684\u8fde\u63a5\u4e0d\u9700\u8981\u7ef4\u62a4\u5417\uff1f\u53f3\u65cb\u64cd\u4f5c\u540e\u5c82\u4e0d\u662f\u65ad\u6389\u4e86\uff1f

        \u6211\u4eec\u9700\u8981\u4ece\u9012\u5f52\u7684\u89c6\u89d2\u6765\u770b\u8fd9\u4e2a\u95ee\u9898\u3002\u53f3\u65cb\u64cd\u4f5c right_rotate(root) \u4f20\u5165\u7684\u662f\u5b50\u6811\u7684\u6839\u8282\u70b9\uff0c\u6700\u7ec8 return child \u8fd4\u56de\u65cb\u8f6c\u4e4b\u540e\u7684\u5b50\u6811\u7684\u6839\u8282\u70b9\u3002\u5b50\u6811\u7684\u6839\u8282\u70b9\u548c\u5176\u7236\u8282\u70b9\u7684\u8fde\u63a5\u662f\u5728\u8be5\u51fd\u6570\u8fd4\u56de\u540e\u5b8c\u6210\u7684\uff0c\u4e0d\u5c5e\u4e8e\u53f3\u65cb\u64cd\u4f5c\u7684\u7ef4\u62a4\u8303\u56f4\u3002

        \u5728 C++ \u4e2d\uff0c\u51fd\u6570\u88ab\u5212\u5206\u5230 private \u548c public \u4e2d\uff0c\u8fd9\u65b9\u9762\u6709\u4ec0\u4e48\u8003\u91cf\u5417\uff1f\u4e3a\u4ec0\u4e48\u8981\u5c06 height() \u51fd\u6570\u548c updateHeight() \u51fd\u6570\u5206\u522b\u653e\u5728 public \u548c private \u4e2d\u5462\uff1f

        \u4e3b\u8981\u770b\u65b9\u6cd5\u7684\u4f7f\u7528\u8303\u56f4\uff0c\u5982\u679c\u65b9\u6cd5\u53ea\u5728\u7c7b\u5185\u90e8\u4f7f\u7528\uff0c\u90a3\u4e48\u5c31\u8bbe\u8ba1\u4e3a private \u3002\u4f8b\u5982\uff0c\u7528\u6237\u5355\u72ec\u8c03\u7528 updateHeight() \u662f\u6ca1\u6709\u610f\u4e49\u7684\uff0c\u5b83\u53ea\u662f\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u4e2d\u7684\u4e00\u6b65\u3002\u800c height() \u662f\u8bbf\u95ee\u8282\u70b9\u9ad8\u5ea6\uff0c\u7c7b\u4f3c\u4e8e vector.size() \uff0c\u56e0\u6b64\u8bbe\u7f6e\u6210 public \u4ee5\u4fbf\u4f7f\u7528\u3002

        \u5982\u4f55\u4ece\u4e00\u7ec4\u8f93\u5165\u6570\u636e\u6784\u5efa\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811\uff1f\u6839\u8282\u70b9\u7684\u9009\u62e9\u662f\u4e0d\u662f\u5f88\u91cd\u8981\uff1f

        \u662f\u7684\uff0c\u6784\u5efa\u6811\u7684\u65b9\u6cd5\u5df2\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4ee3\u7801\u4e2d\u7684 build_tree() \u65b9\u6cd5\u4e2d\u7ed9\u51fa\u3002\u81f3\u4e8e\u6839\u8282\u70b9\u7684\u9009\u62e9\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u5c06\u8f93\u5165\u6570\u636e\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u4e2d\u70b9\u5143\u7d20\u4f5c\u4e3a\u6839\u8282\u70b9\uff0c\u518d\u9012\u5f52\u5730\u6784\u5efa\u5de6\u53f3\u5b50\u6811\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u6700\u5927\u7a0b\u5ea6\u4fdd\u8bc1\u6811\u7684\u5e73\u8861\u6027\u3002

        \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u5bf9\u6bd4\u662f\u5426\u4e00\u5b9a\u8981\u7528 equals() \u65b9\u6cd5\uff1f

        \u5728 Java \u4e2d\uff0c\u5bf9\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c== \u7528\u4e8e\u5bf9\u6bd4\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002\u5bf9\u4e8e\u5f15\u7528\u7c7b\u578b\uff0c\u4e24\u79cd\u7b26\u53f7\u7684\u5de5\u4f5c\u539f\u7406\u662f\u4e0d\u540c\u7684\u3002

        • == \uff1a\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5373\u5b83\u4eec\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u662f\u5426\u76f8\u540c\u3002
        • equals()\uff1a\u7528\u6765\u5bf9\u6bd4\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002

        \u56e0\u6b64\uff0c\u5982\u679c\u8981\u5bf9\u6bd4\u503c\uff0c\u6211\u4eec\u5e94\u8be5\u4f7f\u7528 equals() \u3002\u7136\u800c\uff0c\u901a\u8fc7 String a = \"hi\"; String b = \"hi\"; \u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u90fd\u5b58\u50a8\u5728\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u4e2d\uff0c\u5b83\u4eec\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u56e0\u6b64\u4e5f\u53ef\u4ee5\u7528 a == b \u6765\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u3002

        \u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u5230\u6700\u5e95\u5c42\u4e4b\u524d\uff0c\u961f\u5217\u4e2d\u7684\u8282\u70b9\u6570\u91cf\u662f \\(2^h\\) \u5417\uff1f

        \u662f\u7684\uff0c\u4f8b\u5982\u9ad8\u5ea6 \\(h = 2\\) \u7684\u6ee1\u4e8c\u53c9\u6811\uff0c\u5176\u8282\u70b9\u603b\u6570 \\(n = 7\\) \uff0c\u5219\u5e95\u5c42\u8282\u70b9\u6570\u91cf \\(4 = 2^h = (n + 1) / 2\\) \u3002

        "}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 114cae3c386516a6967d9cdec1892ced09c76d29..99a9d810344e6ec6798eed087e5735501cdb704e 100644 GIT binary patch delta 15 WcmaFH{*0YXzMF%i=iNrO2h0F1M+L6{ delta 15 WcmaFH{*0YXzMF%C_3}ox2h0E|mIVy}